<jupyter_start><jupyter_text>This notebook loads a paleoclimate dataset (based on a coral record from [DeLong et al. (2011)](https://www.sciencedirect.com/science/article/pii/S0031018211002501?casa_token=<KEY>)). The first column contains the time information. The rest of the columns contain the actual record and instrumental data.<jupyter_code>!pip install demjson --upgrade #deals with demjson issue with setuputils
import pandas as pd # to load the record
import matplotlib.pyplot as plt
import pyleoclim as pyleo #to work with the record<jupyter_output>Requirement already satisfied: demjson in /Users/deborahkhider/opt/anaconda3/envs/paleodev/lib/python3.9/site-packages (2.2.4)<jupyter_text>Data loadingGet the data from NOAA:<jupyter_code>!wget https://www.ncei.noaa.gov/pub/data/paleo/coral/atlantic/tortugas2011.xls<jupyter_output>--2022-02-10 10:10:07--  https://www.ncei.noaa.gov/pub/data/paleo/coral/atlantic/tortugas2011.xls
Resolving www.ncei.noaa.gov (www.ncei.noaa.gov)... 192.168.3.11, 172.16.17.32, 172.16.31.10, ...
Connecting to www.ncei.noaa.gov (www.ncei.noaa.gov)|192.168.3.11|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 133632 (130K) [application/vnd.ms-excel]
Saving to: ‘tortugas2011.xls’

tortugas2011.xls    100%[===================>] 130.50K   462KB/s    in 0.3s    

2022-02-10 10:10:08 (462 KB/s) - ‘tortugas2011.xls’ saved [133632/133632]<jupyter_text>And put in a Pandas DataFrame:<jupyter_code>df = pd.read_excel('tortugas2011.xls', sheet_name=1,header=[0,2])
df.head()<jupyter_output><empty_output><jupyter_text>The following cell will create 5 `pyleoclim.Series` objects:* One with Siderastrea Sidera Sr/Ca for the first coral head (column 1, 0-index)* One with Sideratra Sidera Sr/Ca for the second coral head (column 4)* One with Montrastraea Faveolata Sr/Ca (column 7)* One for instrumental data (DRTO, column 10)* One for instrumental data (Sand Key SST, column 12)<jupyter_code>ts_ss_1 = pyleo.Series(time=df.iloc[:,0], value=df.iloc[:,1],time_unit='yr CE',value_unit='mmol/mol',
                       time_name='Time', value_name='S. sidera Sr/Ca',label = 'S. sidera head1')
ts_ss_2 = pyleo.Series(time=df.iloc[:,0], value=df.iloc[:,4],time_unit='yr CE',value_unit='mmol/mol',
                       time_name='Time', value_name='S. sidera Sr/Ca',label = 'S. sidera head2')
ts_mf = pyleo.Series(time=df.iloc[:,0], value=df.iloc[:,7],time_unit='yr CE',value_unit='mmol/mol',
                       time_name='Time', value_name='M. faveolata Sr/Ca',label = 'M. faveolata')
ts_drto = pyleo.Series(time=df.iloc[:,0], value=df.iloc[:,10],time_unit='yr CE',value_unit='$^\circ$C',
                       time_name='Time', value_name='Sea Surface Temperature',label = 'DRTO')
ts_sk = pyleo.Series(time=df.iloc[:,0], value=df.iloc[:,12],time_unit='yr CE',value_unit='$^\circ$C',
                       time_name='Time', value_name='Sea Surface Temperature',label = 'Sand Key')<jupyter_output><empty_output><jupyter_text>PlottingThis is how I would plot the three coral records using Matplotlib:<jupyter_code>fig,ax=plt.subplots(figsize=(20,4))
plt.plot(df.iloc[:,0], df.iloc[:,1], label = "Siderastrea sidera")
plt.plot(df.iloc[:,0], df.iloc[:,4], label = "Siderastrea sidera")
plt.plot(df.iloc[:,0], df.iloc[:,7], label = "Montastraea faveolata")
plt.xlabel('Time')
plt.ylabel('Sr/Ca (mmol/mol)')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Using Pyleoclim:<jupyter_code>fig,ax = ts_ss_1.plot()
ts_ss_2.plot(ax=ax)
ts_mf.plot(ax=ax)
ax.set_ylabel('Sr/Ca (mmol/mol)')<jupyter_output><empty_output><jupyter_text>Similarly for the instrumental data, the Matplotlib version is:<jupyter_code>fig,ax=plt.subplots(figsize=(20,4))
plt.plot(df.iloc[:,0], df.iloc[:,10], label = "DRTO")
plt.plot(df.iloc[:,0], df.iloc[:,12], label = "Sand Key")
plt.xlabel('Time')
plt.ylabel('SST')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Pyleoclim version<jupyter_code>fig,ax = ts_drto.plot()
ts_sk.plot(ax=ax)<jupyter_output><empty_output><jupyter_text>AnalysisBelow are a few common analysis we can do easily with Pyleoclim. I'm using the first coral record as an example. Slicing<jupyter_code>ts_slice = ts_ss_1.slice([1995,2002])
ts_slice.plot()<jupyter_output><empty_output><jupyter_text>Spectral AnalysisFirst, let's use MultiTaper analysis with an interpolations scheme to get evenly-spaced data and a significance test based on Monte-Carlo AR1<jupyter_code>psd_MTM = ts_ss_1.interp().standardize().spectral(method='mtm').signif_test(number=200)
psd_MTM.plot()<jupyter_output>Performing spectral analysis on individual series: 100%|█| 200/200 [00:01<00:00,<jupyter_text>Not surprisingly, it has a pretty strong annual cycle. Let's use another method that doesn't require interpolation<jupyter_code>psd_LS = ts_ss_1.standardize().spectral(method='lomb_scargle').signif_test(number=200)
psd_LS.plot()<jupyter_output>Performing spectral analysis on individual series: 100%|█| 200/200 [00:00<00:00,
{'fraction_non_alphanumeric': 0.15521730422591629, 'fraction_numerical': 0.05147206088523933, 'mean_word_length': 5.897790055248619, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 43, 'https://': 3, 'lorem ipsum': 0, 'www.': 7, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '215422', 'license': 'Apache-2.0', 'n_tokens_mistral': 2118, 'n_tokens_neox': 1899, 'n_words': 371, 'path': 'Playing with Series in Pyleoclim.ipynb', 'repo_name': 'LinkedEarth/paleoPandas', 'size': '5088'}