<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <div class="clearfix" style="padding
Step1:  Quitting <a id="lipdquit"></a>
Quitting the session is important. This will perform cleanup functions and reclaim the space of opened LiPD files on your computer
</p>
</div>
Step2:  Reading Files<a id="lipdread"></a>
There are four valid file types that you may import. Use the appropriate function for the file type that you would like to read. 
LiPD (.lpd)
Excel (.xls or .xlsx)
NOAA text (.txt)
<div class="alert alert-warning" role="alert" style="margin
Step3:  Excel Spreadsheet Converter <a id="excel"></a>
Microsoft Excel spreadsheets must be converted to LiPD before any LiPD functions can be used. Use the Excel template to create an Excel file with your data.  Make sure to follow the formatting guidelines and the hints noted throughout the spreadsheet.
<div class="alert alert-warning" role="alert" style="margin
Step4:  NOAA Converter <a id="noaa"></a>
National Oceanic and Atmospheric Administration (NOAA) text files must be converted to LiPD before any LiPD functions can be used. The converter is designed to parse data from the NOAA text template. Please insert your data in this template format to ensure a complete and accurate conversion to LiPD. Use the example file as a reference for correct formatting.
<u>LPD to NOAA</u>
Step5:  DOI Updater <a id="doi"></a>
The DOI updater will take your LiPD files and update them with the most recent information provided by doi.org. The updater will run once per LiPD, and will skip any LiPD files that were updated previously. 
<div class="alert alert-warning" role="alert" style="margin
Step6:  Writing Files <a id="writelipds"></a>
Save all datasets currently loaded to LiPD files.
Step7:  Pickling Data <a id="pickle"></a>
The Pickle module is a python core module allows us to share LiPD data with python 2.7 users. It won't have the support or functions of LiPD Utilities, but it will give access to the data. 
A Pickle file (.pklz) is a compressed archive file. It's small size makes sharing easy.
Step8:  Other Functions<a id="other"></a>
The functions below are not critical to the use of LiPD Utilities, but are included for convenience as helper functions that may make your workflow easier. 
SHOW data  <a id="showdata"></a>
Show functions are useful for printing data to the console. Note
Step9:  Library Data <a id="lipd_lib"></a>
All LiPD Library data is stored in Python "objects" that allow us to manage and manipulate the data more easily. However, storing and pickling the data in this structure is not ideal for most situations. The JSON format is recommended as it is universal and easier to share.
getLibrary()<br>
* Returns
Step10:  Library Data (example)  <a id=""></a>
Library data holds many datasets that are sorted by name. Below is an example of what the library looks like. There are three files in this library, and one file is expanded to show its contents.
Step11:  TimeSeries  <a id="timeseries"></a>
TimeSeries functions are useful creating, filtering, and exporting TimeSeries from the LiPD data in the workspace.
extractTs()<br>
* Returns
Step12:  Pandas  Dataframes<a id="pandas"></a>
ensToDf(arrays)
* Returns
Step13:  <div class="alert alert-warning" role="alert" style="margin
Step14:  Removing LiPDs <a id="removelipds"></a>
removeLipd(filename)
* Remove one dataset from the LiPD Library
removeLipds()
* Remove all datasets from the LiPD Library
<ASSISTANT_TASK:>
Python Code:
import lipd
Explanation: <div class="clearfix" style="padding: 10px; padding-left: 0px; padding-top: 40px">
<img src="https://www.dropbox.com/s/y8dd1z3sl4uofep/lipd_logo.png?raw=1" width="700px" class="pull-right" style="display: inline-block; margin: 0px;">
</div>
Welcome to the LiPD Quickstart Notebook!
This Notebook was created to help you get familiar with the commands you can use in LiPD. Follow each step and experiment as much as you'd like! Each step will help prepare you for the next step. 
For this tutorial we will be using the example files found in the Github Repostiory's Examples folder.
Last Notebook Edit : 05.10.17
Table of Contents
Install Package
Import Package
Reading Files
Load LiPDs
Viewing LiPD data
Library Data
Extract TimeSeries
Timeseries Object
Excel Converter
NOAA Converter
DOI Updater
Pandas
Remove files
Glossary
Install Package <a id="install"></a>
This guide assumes that you have already followed the installation steps and the LiPD package is installed on your computer. 
Import Package <a id="lipdimport"></a>
Import the LiPD package into your python environment. 
</p>
</div>
End of explanation
lipd.quit()
Explanation: Quitting <a id="lipdquit"></a>
Quitting the session is important. This will perform cleanup functions and reclaim the space of opened LiPD files on your computer
</p>
</div>
End of explanation
# Read File - GUI
lipd.readLipd()
lipd.readExcel()
lipd.readNoaa()
# Read File - with path argument - no GUI
lipd.readLipd("/path/to/file.lpd")
lipd.readExcel("/path/to/file.xls")
lipd.readNoaa("/path/to/file.txt")
# Read Directory - GUI
lipd.readLipds()
lipd.readExcels()
lipd.readNoaas()
# Read Directory - with path argument - no GUI
lipd.readLipds("/path/to/dir/")
lipd.readExcels("/path/to/dir/")
lipd.readNoaas("/path/to/dir/")
# Read Directory - all file types - GUI
lipd.readAll()
# Read Directory - all file types - no GUI
lipd.readAll("/path/to/dir/")
Explanation: Reading Files<a id="lipdread"></a>
There are four valid file types that you may import. Use the appropriate function for the file type that you would like to read. 
LiPD (.lpd)
Excel (.xls or .xlsx)
NOAA text (.txt)
<div class="alert alert-warning" role="alert" style="margin: 10px">
<p>**NOTE**</p>
<p> All "read" functions accept a file path argument. If the path argument is left empty, a GUI window will appear and allow you to choose a file or choose a directory.
</p><br>
<p>
If you want to multi-select speciic files, but not an entire directory, use any singular read function under without a providing a path argument. Use the GUI to multi-select the files you want.  
</p>
</div>
End of explanation
lipd.excel()
Explanation: Excel Spreadsheet Converter <a id="excel"></a>
Microsoft Excel spreadsheets must be converted to LiPD before any LiPD functions can be used. Use the Excel template to create an Excel file with your data.  Make sure to follow the formatting guidelines and the hints noted throughout the spreadsheet.
<div class="alert alert-warning" role="alert" style="margin: 10px">
<p>**NOTE**</p>
<p> The Excel converter runs every `.xls` and `.xlsx` file currently loaded.
</p>
</div>
End of explanation
# Run the function
lipd.noaa()
# Choose a conversion 
Which conversion?
1. LPD to NOAA
2. NOAA to LPD
Explanation: NOAA Converter <a id="noaa"></a>
National Oceanic and Atmospheric Administration (NOAA) text files must be converted to LiPD before any LiPD functions can be used. The converter is designed to parse data from the NOAA text template. Please insert your data in this template format to ensure a complete and accurate conversion to LiPD. Use the example file as a reference for correct formatting.
<u>LPD to NOAA</u>:<br>
Converts all LiPD files into NOAA text files. Creates one NOAA text file for each data table found in the LiPD file. The LiPD file is updated to include the WDC URL that links to the corresponding NOAA dataset that it creates.
<br><br>
<u>NOAA to LPD</u>:<br>
Converts NOAA text file into a LiPD file.
<br><br>
<u>NOAA text template</u>:<br>
NOAA template
<u>Example File</u>:<br>
khider2011b.txt
<br>
<div class="alert alert-warning" role="alert" style="margin: 10px">
<p>**NOTE**</p>
<p> The NOAA converter will run for every `.txt` file currently loaded.<p>
<br>
<p>These conversions are both potentially lossy conversions. We have worked hard to map data between formats, but there are some keys that remain unmapped and will not be transferred to the new file format.</p>
</div>
End of explanation
lipd.doi()
Explanation: DOI Updater <a id="doi"></a>
The DOI updater will take your LiPD files and update them with the most recent information provided by doi.org. The updater will run once per LiPD, and will skip any LiPD files that were updated previously. 
<div class="alert alert-warning" role="alert" style="margin: 10px">
<p>**NOTE**</p>
<p> `doi()` will update each LiPD file loaded after `readLipds()`
</p>
</div>
End of explanation
# Write Files - GUI
lipd.writeLipds()
# Write with path argument - No GUI
lipd.writeLipds("/path/to/dir/")
Explanation: Writing Files <a id="writelipds"></a>
Save all datasets currently loaded to LiPD files.
End of explanation
import pickle
import gzip
# Read a pickle file
f = gzip.open('filename.pklz','rb')
newData = pickle.load(f)
f.close()
# Write a pickle file 
yourData = {'a':'blah','b':range(10)}
f = gzip.open('filename.pklz','wb')
pickle.dump(yourData,f)
f.close()
Explanation: Pickling Data <a id="pickle"></a>
The Pickle module is a python core module allows us to share LiPD data with python 2.7 users. It won't have the support or functions of LiPD Utilities, but it will give access to the data. 
A Pickle file (.pklz) is a compressed archive file. It's small size makes sharing easy.
End of explanation
odp_csv = lipd.getCsv("ODP1098B12.lpd")
odp_metadata = lipd.getMetadata("ODP1098B12.lpd")
Explanation: Other Functions<a id="other"></a>
The functions below are not critical to the use of LiPD Utilities, but are included for convenience as helper functions that may make your workflow easier. 
SHOW data  <a id="showdata"></a>
Show functions are useful for printing data to the console. Note: Some consoles will truncate extensive output. Printing large data to the console may not work well. 
showLipds()<br>
* Show the names of the LiPD files in the current LiPD Library.
showMetadata(filename)<br>
* Show metadata for a specific dataset
showCsv(filename)<br>
* Show CSV data for a specific dataset
showDfs(dataframe_dictionary)<br>
* Show a list of dataframes in a dataframe dictionary
GET data  <a id="getdata"></a>
Get functions are useful for retrieving data and placing it in the workspace as a variable.
getCsv(filename)<br>
* Returns: dictionary
* Get the values for the specific dataset.
<br>
getMetadata(filename)<br>
* Returns: dictionary
* Get the metadata for the specific dataset.
<br>
End of explanation
D = lipd.getLibrary()
Explanation: Library Data <a id="lipd_lib"></a>
All LiPD Library data is stored in Python "objects" that allow us to manage and manipulate the data more easily. However, storing and pickling the data in this structure is not ideal for most situations. The JSON format is recommended as it is universal and easier to share.
getLibrary()<br>
* Returns: dictionary
* Retrieves the LiPD Library as a Python dictionary.
<br>
End of explanation
%%html
<img src="./d.png" />
Explanation: Library Data (example)  <a id=""></a>
Library data holds many datasets that are sorted by name. Below is an example of what the library looks like. There are three files in this library, and one file is expanded to show its contents.
End of explanation
%%html
<img src="./tso1.png" />
<img src="./tso2.png" />
time_series = lipd.extractTs()
new_time_series = lipd.find("archiveType is marine sediment", time_series)
new_time_series = lipd.find("geo_meanElev <= -1000 && geo_meanElev > -1100", time_series)
lipd.collapseTs(time_series)
Explanation: TimeSeries  <a id="timeseries"></a>
TimeSeries functions are useful creating, filtering, and exporting TimeSeries from the LiPD data in the workspace.
extractTs()<br>
* Returns: dictionary
* Creates a time series from the data in the workspace.
<br>
collapseTs(time_series)<br>
* Returns: none
* Puts time series data back into the workspace data. 
<br>
find(expression, time_series)<br>
* Returns: List, all objects that matched the expression
* Find all time series objects that match a certain criteria. 
<div class="alert alert-warning" role="alert" style="margin: 10px">
<p>**WARNING**</p>
    <p>`collapseTs()` will overwrite the contents of the LiPD Library</p>
</div>
TimeSeries Object (example)  <a id="tso"></a>
A time series holds many time series objects. Below is an example of what the contents of a time series object look like.
End of explanation
dfs_lipd = lipd.lipdToDf("ODP1098B12.lpd")
lipd.showDfs(dfs_lipd)
dfs_lipd["metadata"]
dfs_lipd["paleoData"]["ODP1098B12.Paleo1.measurementTable1.csv"]
dfs_lipd["chronData"]["ODP1098B12.Chron1.measurementTable1.csv"]
Explanation: Pandas  Dataframes<a id="pandas"></a>
ensToDf(arrays)
* Returns: data frame (obj)
* Create an ensemble data frame from some given nested numpy arrays
lipdToDf(filename)
* Returns: data frame(s) (dictionary)
* Creates a collection of pandas data frames from LiPD data
tsToDf(time_series, filename)
* Returns: data frame(s) (dictionary)
* Creates a collection of pandas data frames from a TimeSeries object. The CSV data frame will be plot with depth, age, and year columns when available.
<div class="alert alert-warning" role="alert" style="margin: 10px">
<p>**NOTE**</p>
    <p>After creating the data frames, calling a specific data frame variable will display the formatted data frame. </p>
</div>
End of explanation
dfs_ts = lipd.tsToDf(time_series, "ODP1098B12_data_SST")
showDfs(dfs_ts)
dfs_ts["metadata"]
dfs_ts["paleoData"]
dfs_ts["chronData"]["ODP1098B12"]
Explanation: <div class="alert alert-warning" role="alert" style="margin: 10px">
<p>**NOTE**</p>
    <p>TimeSeries objects are not able to use the autocomplete feature for filenames. Be sure to run `showTsos()` and copy/paste the TimeSeries object of interest</p>
</div>
End of explanation
lipd.removeLipds()
Explanation: Removing LiPDs <a id="removelipds"></a>
removeLipd(filename)
* Remove one dataset from the LiPD Library
removeLipds()
* Remove all datasets from the LiPD Library
End of explanation
<END_TASK>