### Install pangaeapy from GitHub Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/index.md Install the pangaeapy module directly from its GitHub repository using pip. ```bash pip install git+https://github.com/pangaea-data-publisher/pangaeapy.git ``` -------------------------------- ### Install pangaeapy from PyPI Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/index.md Install the pangaeapy module from the Python Package Index (PyPI) using pip. ```bash pip install pangaeapy ``` -------------------------------- ### Complete Workflow Example Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Demonstrates a full workflow: searching for datasets, loading a dataset with caching, exploring metadata, analyzing data with pandas, filtering, and downloading. ```python from pangaeapy import PanQuery, PanDataSet import pandas as pd # Step 1: Search for datasets query = PanQuery("Arctic sea ice thickness", limit=10) print(f"Found {query.totalcount} datasets") # Step 2: Load first dataset with caching doi = query.get_dois()[0] if query.result else None if doi: ds = PanDataSet(doi, enable_cache=True) # Step 3: Explore metadata print(f"Title: {ds.title}") print(f"Citation: {ds.citation}") print(f"Parameters: {list(ds.params.keys())}") # Step 4: Analyze data with pandas df = ds.data print(f"Data shape: {df.shape}") print(f"Data types: {df.dtypes}") print(f"Summary statistics: {df.describe()}") # Step 5: Filter and process data if 'Date/Time' in df.columns: df['Date/Time'] = pd.to_datetime(df['Date/Time']) recent_data = df[df['Date/Time'] > '2020-01-01'] print(f"Recent data points: {len(recent_data)}") # Step 6: Export results ds.download() # Save as CSV ``` -------------------------------- ### Initialize PanDataSet and Import Libraries Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Spectral analysis SPECMAP.ipynb Imports necessary libraries and initializes a PanDataSet object with a given dataset ID. Ensure you have pangaeapy, astropy, scipy, numpy, pandas, and matplotlib installed. ```python from pangaeapy import PanDataSet from astropy.timeseries import LombScargle from scipy.signal import find_peaks, peak_prominences import numpy as np import pandas as pd from matplotlib import pyplot as plt ds=PanDataSet(441706) ``` -------------------------------- ### Get Data Summary Statistics Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/basics/Basic 2 - dataframe.ipynb Generate descriptive statistics for the DataFrame columns using the describe() method. This provides count, mean, std, min, max, and quartile values. ```python ds.data.describe() ``` -------------------------------- ### Get Unique Depth Values Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/ADCP.ipynb Find all unique values present in the 'Depth water' column. ```python ds.data['Depth water'].unique() ``` -------------------------------- ### Get Column Statistics Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/example.ipynb Generate descriptive statistics for a specific column (e.g., 'Temp') in the dataset. ```python ds.data['Temp'].describe() ``` -------------------------------- ### Initialize PanDataSet for Binary Data with Authentication Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/user_guide.md When working with binary data sets, which can be large, you must provide an authentication token ('auth_token') obtained from your PANGAEA user profile. This is required for downloading the complete dataset. ```python ds = PanDataSet(944070, enable_cache=True, cachedir='/path/to/your/storage', auth_token='abcdfeghijklmnopqrstuvwxyz') ``` -------------------------------- ### Plot PCA Loadings (Initial Attempt) Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Principal Component Analysis.ipynb Generates a scatter plot of the first two principal components' loadings, with elements labeled. This is an initial visualization attempt. ```python fig = plt.figure(figsize = (6,5)) plt.plot(pcaload['PC1'],pcaload['PC2'], '.',color='k', label=pcaload['Element'],markersize=1) for i, p in pcaload.iterrows(): plt.text(p['PC1'], p['PC2'], str(p['Element']),fontsize=10) ``` -------------------------------- ### Download All Files from Binary Dataset Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/how_to.md Download all files from a binary dataset. Requires a PANGAEA user account and a bearer token for authentication. The cache directory must also be specified. ```python ds = PanDataSet(956151, enable_cache=True, cachedir='/your/cache/path', auth_token='your_personal_bearer_token') filenames = ds.download() ``` -------------------------------- ### Pagination and Result Limits Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Demonstrates how to control the number of results and implement pagination for large search result sets using PanQuery's limit and offset parameters. ```python from pangaeapy import PanQuery # Get first 100 results query1 = PanQuery("ocean carbon", limit=100, offset=0) print(f"Total available: {query1.totalcount}") print(f"Retrieved: {len(query1.result)}") # Get next 100 results (pagination) query2 = PanQuery("ocean carbon", limit=100, offset=100) print(f"Retrieved (page 2): {len(query2.result)}") ``` -------------------------------- ### Download Binary and Tabular Data from PANGAEA Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Use the `download()` method to save tabular data as CSV or download binary files. Specify row indices and columns for selective binary downloads. Authentication is required for downloading all binary files. ```python from pangaeapy import PanDataSet # Download tabular dataset as CSV ds = PanDataSet(900388, enable_cache=True, cachedir='/your/cache/path') filepaths = ds.download() print(f"Downloaded files: {filepaths}") # Output: ['/your/cache/path/900388_data.csv'] # Download specific binary files by row indices ds = PanDataSet(956151, enable_cache=True, cachedir='/your/cache/path') filepaths = ds.download(indices=[0, 1, 2], columns=['Binary']) print(f"Downloaded files: {filepaths}") # Download all binary files (requires auth_token) ds = PanDataSet( 956151, enable_cache=True, cachedir='/your/cache/path', auth_token='your_personal_bearer_token' ) filepaths = ds.download() print(f"Downloaded files: {filepaths}") ``` -------------------------------- ### Initialize PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/ADCP.ipynb Import necessary libraries and initialize a PanDataSet object with a given DOI. ```python from pangaeapy.pandataset import PanDataSet import pandas as pd import matplotlib.pyplot as plt ds = PanDataSet('10.1594/PANGAEA.864110') ``` -------------------------------- ### View First Rows of Data Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/basics/Basic 2 - dataframe.ipynb Access the dataset's data as a pandas DataFrame and display the first few rows using the head() method. ```python ds.data.head() ``` -------------------------------- ### Basic Usage of PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/index.md Demonstrates how to initialize a PanDataSet object with a DOI and access its title and data. ```python from pangaeapy import PanDataSet ds = PanDataSet(787140) print(ds.title) print(ds.data.head()) ``` -------------------------------- ### Import pangaeapy Library Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/basics/Basic 3 - plotting with pandas.ipynb Import the necessary PanDataSet class from the pangaeapy library. ```python from pangaeapy import PanDataSet ``` -------------------------------- ### Perform PCA and Prepare Loadings DataFrame Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Principal Component Analysis.ipynb Performs PCA with 2 components and prepares the loadings for visualization. The component loadings are transposed and column names are cleaned to represent elements. ```python sklearn_pca = sklearnPCA(n_components=2) pcaresult = sklearn_pca.fit(X_std).transform(X_std) pcaload=pd.DataFrame(sklearn_pca.components_).transpose() pcaload=pcaload.rename(columns={0:'PC1',1:'PC2'}) pcaload['Element']=elementcols pcaload['Element']=pcaload['Element'].str.extract(r'([A-Z][a-z]?)') pcaload.head() ``` -------------------------------- ### Initialize PanDataSet for Tabular Data Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/user_guide.md Instantiate PanDataSet with a dataset ID to access tabular data. Enable caching for local storage using pickle. The default cache directory is ~/.pangaeapy_cache/. ```python from pangaeapy import PanDataSet ds = PanDataSet(900388, enable_cache=True) ``` -------------------------------- ### Download Binary Data Files from PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/user_guide.md For binary data sets, the download() method returns a list of file paths for the downloaded components. These paths can then be used with appropriate modules (e.g., xarray for netCDF) to process the data. ```python filepaths = ds.download() ``` -------------------------------- ### Load and Access PANGAEA Dataset Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Initialize PanDataSet with a dataset ID or DOI to fetch metadata and tabular data. Access metadata attributes and the data as a pandas DataFrame. Inspect parameter details and print dataset summary information. ```python from pangaeapy import PanDataSet # Load a dataset using its numeric ID ds = PanDataSet(787140) # Access dataset metadata print(f"Title: {ds.title}") print(f"DOI: {ds.doi}") print(f"Citation: {ds.citation}") print(f"Year: {ds.year}") print(f"Abstract: {ds.abstract}") # Access authors (list of PanAuthor objects) for author in ds.authors: print(f"Author: {author.fullname}, ORCID: {author.ORCID}") # Access the data as a pandas DataFrame print(ds.data.head()) # Get parameter information for param_name, param in ds.params.items(): print(f"Parameter: {param_name}, Unit: {param.unit}, Type: {param.type}") # Print dataset summary information ds.info() ``` -------------------------------- ### Load PANGAEA Dataset Metadata Only Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Initialize PanDataSet with `include_data=False` to retrieve only metadata, significantly speeding up initialization by skipping the data table download. Access various metadata fields including title, DOI, authors, keywords, projects, time extent, and license. ```python from pangaeapy import PanDataSet # Load only metadata (no data table download) ds = PanDataSet(787140, include_data=False) # Access metadata print(f"Title: {ds.title}") print(f"DOI: {ds.doi}") print(f"Authors: {[a.fullname for a in ds.authors]}") print(f"Keywords: {ds.keywords}") print(f"Projects: {[(p.label, p.name) for p in ds.projects]}") print(f"Time extent: {ds.mintimeextent} to {ds.maxtimeextent}") print(f"License: {ds.licence.name if ds.licence else 'N/A'}") ``` -------------------------------- ### Calculate and Prepare Distances Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/SIMMAX.ipynb Merges sample and analog datasets, calculates distances, handles zero distances by replacing them with a very small value, and sets a multi-level index for further processing. ```python Distances = pd.merge(sampleDS.data[['Event','Latitude','Longitude', 'Depth']].assign(k=1), analogDS.data[['Event','Latitude','Longitude','Temperature']].assign(k=1), on='k', suffixes=('1', '2')).drop('k', axis=1) Distances['Event1']=Distances['Event1']+'_'+Distances['Depth'].map(str) Distances['Distance']=Distances.apply(getDistance, axis=1) #But we need to avoid to run into a division by zero trap, preperae by the simmean algo which will snap if distance is zero: (sj/dj) #Therefore we need to replace zero distances by a very, very low distance e.g. 0.000000001 m or so Distances.loc[Distances['Distance']==0,'Distance']=0.00000000001 Distances.set_index(['Event1', 'Event2'], inplace=True) ``` -------------------------------- ### Set Custom Cache Directory Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/how_to.md Configure a custom directory for caching downloaded data. This is useful for managing storage space and organization. ```python ds = PanDataSet(956151, enable_cache=True, cachedir='/path/to/your/storage') ``` -------------------------------- ### Initialize PanDataSet Object Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/basics/Basic 1 - load a PANGAEA dataset.ipynb Create an instance of PanDataSet using either an integer ID or a DOI. This object represents a specific PANGAEA dataset. ```python ds=PanDataSet(896621) ``` -------------------------------- ### Download Specific File from Binary Dataset Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/how_to.md Download a specific file from a binary dataset by providing the row index and column name. Ensure you have the dataset's DOI. ```python ds = PanDataSet(956151, enable_cache=True, cachedir='/your/cache/path') filenames = ds.download(indices=[3], columns=["Binary"]) ``` -------------------------------- ### Initialize PanDataSet and Load Data Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/SIMMAX.ipynb Initializes PanDataSet objects for specific datasets and loads data from a CSV file. This is a prerequisite for further data processing. ```python from pangaeapy import PanDataSet import math import sys import pandas as pd analogDS = PanDataSet('10.1594/PANGAEA.77352') sampleDS=PanDataSet('10.1594/PANGAEA.55156') #The annual mean #levitus=pd.read_csv('woa13_decav_t00mn01v2.csv',sep=';') #summer levitus=pd.read_csv('woa13_decav_t15mn01.csv',sep=';') #Compare with: #http://discovery.ucl.ac.uk/101363/1/2002PA000774.pdf ``` -------------------------------- ### Initialize PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/example.ipynb Initialize a PanDataSet object using a PANGAEA dataset ID. The ID can be a numerical ID or a DOI. ```python from pangaeapy.pandataset import PanDataSet #ds = PanDataSet('734969') #ds = PanDataSet(734969) ds = PanDataSet('10.1594/PANGAEA.734969') ``` -------------------------------- ### PanDataSet Class Initialization Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/api.md Initializes a PanDataSet object to hold information for a specific PANGAEA dataset. ```APIDOC ## Class pangaeapy.PanDataSet ### Description Initializes a PANGAEA PanDataSet object which holds necessary information, including data and metadata, to analyze a given PANGAEA dataset. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **id** (str) - The identifier of a PANGAEA dataset. An integer number or a DOI is accepted here. * **paramlist** (list) - Not described. * **deleteFlag** (str) - Defines a flag for which data should not be included if quality flags are available. Possible values are listed at https://wiki.pangaea.de/wiki/Quality_flag. * **enable_cache** (boolean) - If True, PanDataSet objects are cached as pickle files to avoid unnecessary downloads. Defaults to False. * **cachedir** (str) - The directory for caching pickle files. Will be created if it doesn't exist. * **include_data** (boolean) - Determines if the data table is downloaded and added to the self.data dataframe. Set to False if only metadata is of interest. Defaults to True. * **expand_terms** (list or int) - Indicates if found ontology terms for parameters shall be expanded for the given list of terminology ids, i.e., add their hierarchy terms/classification. * **auth_token** (str) - The PANGAEA authentication token, available at https://www.pangaea.de/user/. * **cache_expiry_days** (int) - The duration a cached pickle/cache is accepted. After this, pangaeapy will reload the data and ignore the cache. Defaults to 1. ### Attributes * **id** (str) - The identifier of a PANGAEA dataset. * **uri** (str) - The PANGAEA DOI (alternative label). * **doi** (str) - The PANGAEA DOI. * **title** (str) - The title of the dataset. * **abstract** (str) - The abstract or summary of the dataset. * **year** (int) - The publication year of the dataset. * **authors** (list of PanAuthor) - A list containing the PanAuthor objects (author info) of the dataset. * **citation** (str) - The full citation of the dataset. * **params** (list of PanParam) - A list of all PanParam objects (parameters) used in this dataset. * **parameters** (list of PanParam) - Synonym for self.params. * **events** (list of PanEvent) - A list of all PanEvent objects (events) used in this dataset. * **projects** (list of PanProject) - A list containing the PanProjects objects referenced by this dataset. * **mintimeextent** (str) - A string containing the minimum time extent of the dataset. * **maxtimeextent** (str) - A string containing the maximum time extent of the dataset. * **data** (pandas.DataFrame) - A pandas DataFrame holding all the data. * **loginstatus** (str) - Indicates if the dataset is protected. Default value: ‘unrestricted’. * **isCollection** (boolean) - Indicates if this dataset is a collection dataset within a collection of child datasets. * **collection_members** (list) - A list of DOIs of all child datasets if the dataset is a collection dataset. * **moratorium** (str) - A label providing the date until the dataset is under moratorium. * **datastatus** (str) - A label providing details about the dataset's status (published, in review, or deleted). * **registrystatus** (str) - A string indicating the registration status of a dataset. * **licence** (PanLicence) - A licence object, usually Creative Commons. * **auth_token** (str) - The PANGAEA authentication token. * **cache_expiry_days** (int) - The duration a cached pickle/cache is accepted. * **cachedir** (str) - The full path to the cache directory. * **keywords** (list[str]) - A list of keyword names. ### Methods #### check_pickle() Verifies if a cached pickle file needs to be refreshed (reloaded). Files are checked after 24 hrs earliest but only updated if the metadata indicates changes occurred. * **Parameters:** * **expirydays** - Not described. * **Returns:** * bool - True if the pickle needs refreshing, False otherwise. #### from_pickle() Reads a PanDataSet object from a pickle file. #### to_pickle() Writes a PanDataSet object to a pickle file. #### setID(id) Initializes the ID of a data set if it was not defined in the constructor. * **Parameters:** * **id** (str) - The identifier of a PANGAEA dataset. An integer number or a DOI is accepted here. ``` -------------------------------- ### Initialize PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/basics/Basic 3 - plotting with pandas.ipynb Initialize a PanDataSet object with a specific dataset ID. This loads the dataset for further use. ```python ds=PanDataSet(900968) ``` -------------------------------- ### Enable Caching for PANGAEA Datasets Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Configure PanDataSet to cache datasets locally as pickle files, preventing redundant downloads. Customize the cache directory and set cache expiry duration in days. ```python from pangaeapy import PanDataSet # Enable caching with default location (~/.pangaeapy_cache/) ds = PanDataSet(900388, enable_cache=True) # Enable caching with custom directory ds = PanDataSet(900388, enable_cache=True, cachedir='/path/to/your/storage') # Set cache expiry (default is 1 day) ds = PanDataSet(900388, enable_cache=True, cache_expiry_days=7) # Access cached data print(ds.data.head()) ``` -------------------------------- ### Access Protected PANGAEA Datasets with Authentication Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Initialize PanDataSet with an authentication token to access protected datasets. Ensure the token is valid and provided during initialization. Check login status and moratorium information. ```python from pangaeapy import PanDataSet # Access a protected dataset with authentication token ds = PanDataSet( 944070, enable_cache=True, cachedir='/path/to/your/storage', auth_token='your_personal_bearer_token' ) # Check login status print(f"Login status: {ds.loginstatus}") print(f"Moratorium: {ds.moratorium}") # Access data if authorized print(ds.data.head()) ``` -------------------------------- ### Initial Data Plotting Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Generalized Additive Models (GAM).ipynb Plots the 'G. ruber δ18O' data against 'Age' from the loaded dataset to visualize the raw observations. Adjusts the figure size for better readability. ```python ds.data.plot(x='Age',y='G. ruber δ18O', figsize=(12,5), color='k') ``` -------------------------------- ### Import Libraries for GAM Analysis Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Generalized Additive Models (GAM).ipynb Imports the necessary libraries: PanDataSet from pangaeapy for data handling and pyplot from matplotlib for plotting. ```python from pangaeapy import PanDataSet from matplotlib import pyplot as plt ``` -------------------------------- ### Import Libraries and Define Helper Function Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Principal Component Analysis.ipynb Imports necessary libraries for data manipulation, plotting, and PCA. Includes a helper function to remove duplicate columns after merging dataframes. ```python from pangaeapy import PanDataSet import pandas as pd from matplotlib import pyplot as plt from sklearn.decomposition import PCA as sklearnPCA from sklearn.preprocessing import StandardScaler #a helper function to delete duplicate columns which are added by the pd.merge actions def drop_y(df): # list comprehension of the cols that end with '_y' to_drop = [x for x in df if x.endswith('_y')] df.drop(to_drop, axis=1, inplace=True) ``` -------------------------------- ### Calculate Similarity Index (SIMMAX) Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/SIMMAX.ipynb Calculates the square root of the sum of squared percentages for specified foraminifera columns in both sample and analog datasets. It then computes the similarity index and combines it with distance and other relevant data. ```python #Lets do the SIMMAX import numpy as np #sum of squared percentages sampleDS.data['SQRTSUM']=np.sqrt((sampleDS.data[foramCols]**2).sum(axis=1)) analogDS.data['SQRTSUM']=np.sqrt((analogDS.data[foramCols]**2).sum(axis=1)) sampleIdx=sampleDS.data[foramCols].div(sampleDS.data['SQRTSUM'], axis=0) analogIdx=analogDS.data[foramCols].div(analogDS.data['SQRTSUM'], axis=0) sampleIdx['Event']=sampleDS.data['Event']+'_'+sampleDS.data['Depth'].map(str) sampleIdx.set_index('Event', inplace=True) analogIdx['Event']=analogDS.data['Event'] analogIdx.set_index('Event', inplace=True) SimIndex = pd.DataFrame( (analogIdx[foramCols].values * sampleIdx[foramCols].values[:, None]).reshape(-1, analogIdx.shape[1]), pd.MultiIndex.from_product([sampleIdx.index, analogIdx.index]), sampleIdx.columns ) Similars=pd.DataFrame(SimIndex.sum(axis=1), columns=['Similarity']) Similars['Distance']=Distances['Distance'] Similars['Latitude']=Distances['Latitude1'] Similars['Longitude']=Distances['Longitude1'] Similars['Temperature']=Distances['Temperature'] ``` -------------------------------- ### Import pygam for GAM Fitting Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Generalized Additive Models (GAM).ipynb Imports the LinearGAM class from the pygam module, which is required for fitting Generalized Additive Models. ```python from pygam import LinearGAM ``` -------------------------------- ### Inspect Dataset Columns Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/basics/Basic 3 - plotting with pandas.ipynb View the column names of the loaded dataset. pangaeapy uses short names for data labeling. ```python ds.data.columns ``` -------------------------------- ### Plot Temperature and Salinity Profile Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/example.ipynb Plot temperature and salinity against water depth for a specific event. Uses a secondary y-axis for salinity. ```python ds.data.loc['PS04/223-1'].plot(x='Depth water', y=['Temp','Sal'],style='-', secondary_y='Sal') ``` -------------------------------- ### Import necessary libraries Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Smoothing.ipynb Imports the required libraries for data manipulation, interpolation, and plotting. ```python from pangaeapy import PanDataSet import matplotlib.pyplot as plt import numpy as np from scipy.interpolate import interp1d ``` -------------------------------- ### Combine Results Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Combines results from multiple queries and prints the total count. ```python all_results = query1.result + query2.result print(f"Total retrieved: {len(all_results)}") ``` -------------------------------- ### Create DataFrame of Peaks and Sort by Prominence Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Spectral analysis SPECMAP.ipynb Organizes the identified peaks, their prominences, and corresponding frequencies (in ka) into a pandas DataFrame. The DataFrame is then sorted in descending order of prominence to easily identify the most significant frequencies. ```python powerpeaks=pd.DataFrame({'peak':peaks,'promi':prominences,'ka':1/f[peaks]}) powerpeaks=powerpeaks.sort_values('promi', ascending=False) powerpeaks.head(3) ``` -------------------------------- ### Clean and Convert Data Units Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Principal Component Analysis.ipynb Cleans the dataset by converting values from percentage to mg/kg and recalculating oxide weights to element weights using a provided dictionary. This ensures consistent units for analysis. ```python # 1) the dataset has data expressed in % as well as in mg/kg, we therefore need to clean the data first # in order to have the same units here. We recalculate % to mg/kg with a factor of 10000 # 2) oxides need to be converted to elementt weights oxide={'SiO2':2.1392, 'TiO2':1.6681, 'Al2O3':1.8895, 'Fe2O3':1.4297, 'MnO':1.2912, 'MgO':1.6582, 'CaO':1.3992, 'Na2O':1.3480, 'K2O':1.2046, 'P2O5':2.2916, 'SO3':2.4972} for pshort,param in ds1.params.items(): if pshort in oxide: dsdata[pshort]=dsdata[pshort].divide(oxide[pshort]) if param.unit=='mg/kg': dsdata[pshort]=dsdata[pshort].divide(10000) ``` -------------------------------- ### Search PANGAEA Repository Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Perform a basic text search on the PANGAEA repository using PanQuery. Displays total results, individual result details, and extracts DOIs. ```python from pangaeapy import PanQuery # Basic text search query = PanQuery("sediment temperature") print(f"Total results: {query.totalcount}") # Access search results for result in query.result: print(f"URI: {result['URI']}") print(f"Type: {result['type']}") # 'member' or 'collection' print(f"Position: {result['position']}") # Get list of DOIs from search results dois = query.get_dois() print(f"DOIs found: {dois}") ``` -------------------------------- ### Prepare Data for GAM Fitting Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Generalized Additive Models (GAM).ipynb Extracts the 'Age' and 'G. ruber δ18O' columns from the dataset and converts them into NumPy arrays, preparing them for the GAM fitting process. ```python X=ds.data['Age'].values y=ds.data['G. ruber δ18O'].values ``` -------------------------------- ### Download Specific Indices and Columns from PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/user_guide.md Use this method to download specific files by providing a list of row indices and desired column names. This can be done without a bearer token, simplifying code sharing for tutorials or specific data subsets. Ensure the cachedir is set to your desired storage location. ```python ds = PanDataSet(956151, enable_cache=True, cachedir='/path/to/your/storage') filepaths = ds.download(indices=[0, 1, 2], columns=['Binary']) ``` -------------------------------- ### Import UnivariateSpline Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Smoothing.ipynb Imports the UnivariateSpline function from Scipy for alternative data smoothing. ```python from scipy.interpolate import UnivariateSpline ``` -------------------------------- ### Load Pangaea Dataset Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Smoothing.ipynb Loads a dataset from Pangaea using its unique identifier. Ensure you have the correct dataset ID. ```python ds=PanDataSet(894182) ``` -------------------------------- ### Create Pivot Table for Velocity Data Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/ADCP.ipynb Create a pivot table from the dataset's data, filtering by date range and using 'Depth water' as index, 'Date/Time' as columns, and 'VC' (velocity component) as values. Missing values are filled with 0. ```python mf= pd.pivot_table(ds.data.loc['2012-04-01':'2012-06-20'], index='Depth water', columns='Date/Time', values='VC',fill_value=0) mf.head() ``` -------------------------------- ### PanQuery Class Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/api.md Class for running and analyzing PANGAEA search queries. ```APIDOC ### Class: pangaeapy.PanQuery #### Description Runs and analyzes results of PANGAEA search queries. #### Parameters - **query** (str) - Required - The query string following the specs at www.pangaea.de. - **bbox** (tuple of floats, optional) - The bounding box to define geographical search constraints following the GeoJSON specs – (minlon, minlat, maxlon, maxlat). - **limit** (int, default 10) - The maximum number of results returned (cannot be higher than 500). - **offset** (int, default 0) - The offset of the search results. #### Attributes - **totalcount** (int) - The number of total search results. - **error** (str) - In case an error occurs, this attribute holds the latest one. ### Example Usage ```python from pangaeapy import PanQuery # Search for datasets related to 'ocean temperature' within a bounding box query = "ocean temperature" bbox = (10.0, 50.0, 20.0, 60.0) # minlon, minlat, maxlon, maxlat pq = PanQuery(query, bbox=bbox, limit=50) print(f"Total results found: {pq.totalcount}") # Access search results (e.g., dataset IDs) # for result in pq.results(): # print(result['id']) # Check for errors # if pq.error: # print(f"An error occurred: {pq.error}") ``` ``` -------------------------------- ### Plot Salinity Profile Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/example.ipynb Plot salinity against water depth for a specific event using a dotted line style. ```python ds.data.loc['PS04/223-1'].plot(x='Depth water', y=['Sal'],style='.-') ``` -------------------------------- ### Export Dataset to Frictionless Data Package Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Export datasets to the Frictionless Data Package format for enhanced interoperability. The function can also return the package object without saving. ```python from pangaeapy import PanDataSet ds = PanDataSet(787140, enable_cache=True) # Export to Frictionless Data Package ds.to_frictionless(filelocation='/path/to/output') # Creates: /path/to/output/787140_frictionless/ # Get package object without saving package = ds.to_frictionless(save=False) ``` -------------------------------- ### Filter and Select Top Similarities Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/SIMMAX.ipynb Filters the Similars DataFrame for similarities >= 0.9, then sorts by similarity in descending order, and finally selects the top 10 most similar analog events for each sample event. The index is then renamed for clarity. ```python #Original SIMMAX is using those values with similarity index >0.79 only #mostSimilars=Similars.loc[(Similars['Similarity']>=0.79)] #The revised SIMMAX is using the 10 top most similars with sim inded >0.9 mostSimilars=Similars[Similars['Similarity']>=0.9].sort_values(by='Similarity',ascending=False).groupby(level=0).head(10).sort_index(level=0,sort_remaining=False) mostSimilars.index.names=['sampleEvent', 'analogEvent'] ``` -------------------------------- ### Export Dataset to NetCDF Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Export PANGAEA datasets to NetCDF format, supporting both SeaDataNet (SDN) and PANGAEA styles. Can also retrieve the NetCDF object without saving. ```python from pangaeapy import PanDataSet ds = PanDataSet(787140, enable_cache=True) # Export to SeaDataNet NetCDF format (default) ds.to_netcdf(filelocation='/path/to/output', type='sdn') # Export to PANGAEA-style NetCDF format ds.to_netcdf(filelocation='/path/to/output', type='pan') # Get NetCDF object without saving to disk netcdf_obj = ds.to_netcdf(save=False) ``` -------------------------------- ### Plot Data with Pandas Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/basics/Basic 3 - plotting with pandas.ipynb Use the standard pandas plot method to visualize data from the PanDataSet. Ensure the data is loaded into `ds.data`. ```python ds.data.plot(x='Age', y='CaCO3') ``` -------------------------------- ### Handle Quality Flags in PANGAEA Datasets Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Initialize PanDataSet with `deleteFlag` to exclude data points with specific quality control flags. The `qcdata` attribute provides access to quality control information. ```python from pangaeapy import PanDataSet # Exclude questionable data (flagged with '?') ds = PanDataSet(787140, deleteFlag='?') ``` -------------------------------- ### Display GAM Summary Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Generalized Additive Models (GAM).ipynb Prints a detailed summary of the fitted Linear GAM model, including statistical measures, feature significance, and potential warnings related to model identifiability and p-value accuracy. ```python gam.summary() ``` -------------------------------- ### Extract Temperature Data using getLevitusTemp Function Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/SIMMAX.ipynb Defines and uses the getLevitusTemp function to extract temperature data from a loaded dataset based on latitude, longitude, and depth. Handles missing values and finds the closest depth. ```python def getLevitusTemp(lat, lon, lev): depth=30 t=0 #select the values for the upper water column temp=lev[['0','5','10','15','20','25','30','35','40','45','50']][(lev['LATITUDE']== (math.floor(lat)+0.5)) & (lev['LONGITUDE']== (math.floor(lon)+0.5))] #delete empty cells temp=temp.dropna(axis=1).to_dict(orient='list') #cast dict keys from string to int temp={int(key): value for key, value in temp.items()} temp_keys=list(temp.keys()) #find the closest available water depth value closest=min(temp_keys, key=lambda x:abs(x-depth)) if len(temp[closest])>0: t=temp[closest][0] if t==None: print(str(lat)+' x '+str(lon)) t=0 else: print(str(lat)+' + '+str(lon)) t=0 return t analogDS.data['Temperature']=analogDS.data.apply(lambda x: getLevitusTemp(x['Latitude'],x['Longitude'], levitus), axis=1) ``` -------------------------------- ### Visualize Data with Seaborn Heatmap Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/ADCP.ipynb Use seaborn to create a heatmap visualization of a dataset. Ensure matplotlib and seaborn are imported. This snippet assumes 'mf' is a pre-defined dataset. ```python #import matplotlib.pyplot as plt import seaborn as sns import numpy as np import matplotlib.ticker as ticker import matplotlib.dates as mdates fig=plt.figure(figsize=(18,4)) ax=sns.heatmap(mf, square=False,cmap="jet") #ax.xaxis.set_major_locator(ticker.LinearLocator(numticks=6)) plt.show() ``` -------------------------------- ### Display DataFrame Columns Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Principal Component Analysis.ipynb Prints the column names of the merged DataFrame to verify the data structure after loading and merging. ```python dsdata.columns ``` -------------------------------- ### Download Tabular Data from PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/user_guide.md The download() method saves the tabular data set to a CSV file in the configured cache directory. It returns a list containing the path to the downloaded file. ```python >>> ds.download() Dataset saved to /path/to/your/storage/900388_data.csv ['/path/to/your/storage/900388_data.csv'] ``` -------------------------------- ### Print Citations Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/SIMMAX.ipynb Prints the citation information for the analogDS and sampleDS datasets. This is important for academic and research use to properly attribute data sources. ```python print(analogDS.citation) print() print(sampleDS.citation) ``` -------------------------------- ### Access Dataset Title Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/basics/Basic 1 - load a PANGAEA dataset.ipynb Retrieve the title of the loaded PANGAEA dataset. ```python ds.title ``` -------------------------------- ### Access Topotype Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/example.ipynb Retrieve the topotype of the dataset, which describes the data's structure (e.g., 'profile series'). ```python ds.topotype ``` -------------------------------- ### Iterate Through Events Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/example.ipynb Loop through the events associated with the dataset and print their labels. This is useful for datasets with multiple series or profiles. ```python for ev in ds.events: print(ev.label) ``` -------------------------------- ### Specify Custom Cache Directory for PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/user_guide.md When initializing PanDataSet, you can specify a custom directory for caching data by providing the 'cachedir' keyword argument. ```python ds = PanDataSet(900388, enable_cache=True, cachedir='/path/to/your/storage') ``` -------------------------------- ### Load and Merge PANGAEA Datasets Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Principal Component Analysis.ipynb Loads data from four specified PANGAEA datasets and merges them into a single pandas DataFrame. It uses a helper function to clean up duplicate columns introduced during the merge process. ```python ds1 = PanDataSet(900972) ds2 = PanDataSet(900971) ds3 = PanDataSet(900967) ds4 = PanDataSet(900968) #just for convenience, since data is organised in two ways we merge it in two steps dsC=pd.merge(ds2.data,ds3.data,left_on='Depth',right_on='Depth',suffixes=('', '_y')) drop_y(dsC) dsN=pd.merge(ds1.data,ds4.data,left_on='Depth',right_on='Depth',suffixes=('', '_y')) drop_y(dsN) #now we concat the frames and drop the index dsdata=pd.concat([dsN,dsC]) dsdata = dsdata.reset_index(drop=True) ``` -------------------------------- ### Load PANGAEA Dataset Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Generalized Additive Models (GAM).ipynb Loads a specific PANGAEA dataset using its identifier. This dataset will be used for subsequent analysis and plotting. ```python ds = PanDataSet('10.1594/PANGAEA.857573') ``` -------------------------------- ### Data Retrieval and Processing Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/api.md Methods for retrieving and processing data from PANGAEA datasets. ```APIDOC ## GET /api/events ### Description Retrieves all events with their attributes as columns in a DataFrame. ### Method GET ### Endpoint /api/events ### Parameters #### Query Parameters - **campaign_names** (list) - Required - List of campaign names to retrieve events for. ### Response #### Success Response (200) - **dataframe** (DataFrame) - A DataFrame containing all events and their attributes. ### Response Example { "dataframe": "[DataFrame content]" } ``` ```APIDOC ## POST /api/data/set ### Description Populates the data DataFrame with data from a PANGAEA dataset. ### Method POST ### Endpoint /api/data/set ### Parameters #### Request Body - **addEventColumns** (boolean) - Optional - If True, adds event-related columns (Latitude, Longitude, Elevation, Date/Time, Event) if they are not present in the dataset. Defaults to True. ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. ### Response Example { "status": "Data successfully loaded" } ``` ```APIDOC ## GET /api/metadata/set ### Description Initializes the metadata of the PanDataSet object using the information from a PANGAEA metadata XML file. ### Method GET ### Endpoint /api/metadata/set ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. ### Response Example { "status": "Metadata initialized" } ``` ```APIDOC ## GET /api/geometry ### Description Retrieves the real geometry (topographic type) of the dataset based on x, y, z, and t information from the data frame content. This method is experimental. ### Method GET ### Endpoint /api/geometry ### Response #### Success Response (200) - **geometry** (object) - The geometry information of the dataset. ### Response Example { "geometry": { "type": "Point", "coordinates": [10.0, 20.0, 5.0] } } ``` ```APIDOC ## GET /api/paramdict ### Description Translates the parameter object list into a dictionary. ### Method GET ### Endpoint /api/paramdict ### Response #### Success Response (200) - **param_dict** (dict) - A dictionary representing the parameter objects. ### Response Example { "param_dict": { "parameter1": "value1", "parameter2": "value2" } } ``` ```APIDOC ## GET /api/info ### Description Returns a set of basic information about the PANGAEA dataset. ### Method GET ### Endpoint /api/info ### Response #### Success Response (200) - **info** (object) - Basic information about the dataset. ### Response Example { "info": { "dataset_id": "12345", "title": "Sample Dataset", "creation_date": "2023-01-01" } } ``` -------------------------------- ### Calculate and Display Prominent Frequencies Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Spectral analysis SPECMAP.ipynb Calculates the actual frequencies (in ka) corresponding to the identified peaks by taking the reciprocal of the frequencies. This step translates the spectral analysis results into interpretable time scales. ```python 1/f[peaks] ``` -------------------------------- ### Plot PCA Components by Age Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/advanced/Advanced - Principal Component Analysis.ipynb Visualizes the first two principal components (PCA1 and PCA2) colored by 'Age'. This plot helps identify potential age-related clusters in the data. ```python fig = plt.figure(figsize = (6,5)) plt.scatter(dsdata['PCA1'],dsdata['PCA2'], c=dsdata['Age']) plt.xlabel('PCA1') plt.ylabel('PCA2') plt.show() ``` -------------------------------- ### PangaeaPy Query and DOI Retrieval Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/api.md This section details how to perform queries and retrieve Digital Object Identifiers (DOIs) using the PangaeaPy library. ```APIDOC ## PangaeaPy Query and DOI Retrieval ### Description This section details how to perform queries and retrieve Digital Object Identifiers (DOIs) using the PangaeaPy library. ### Query Parameters #### Request Body - **query** (str) - Required - The query provided by the user. ### Response #### Success Response (200) - **result** (list of dictionaries) - A list of retrieved search results. ### Method: get_dois() #### Description Get the list of DOIs contained in the search result. #### Returns A list of DOIs. #### Return type list of str ``` -------------------------------- ### Export Dataset to Darwin Core Archive Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Export biodiversity-related datasets to the Darwin Core Archive (DwC-A) format. The function can also return the DwC-A object without saving. ```python from pangaeapy import PanDataSet ds = PanDataSet(787140, enable_cache=True) # Export to Darwin Core Archive ds.to_dwca() # Creates: [cachedir]/787140_dwca/ # Get DwC-A object without saving dwca = ds.to_dwca(save=False) ``` -------------------------------- ### Access Tabular Data with PanDataSet Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/docs/user_guide.md After initializing a PanDataSet object for tabular data, the data can be accessed as a pandas DataFrame via the 'data' attribute. The head() method displays the first few rows. ```python >>> ds.data.head() Time sec Altitude ... Event Date/Time 0 38314.0 6 ... P5_232_HALO_2022_2203100101 2022-03-10 10:10:04 1 38315.0 6 ... P5_232_HALO_2022_2203100101 2022-03-10 10:10:04 2 38316.0 6 ... P5_232_HALO_2022_2203100101 2022-03-10 10:10:04 3 38317.0 6 ... P5_232_HALO_2022_2203100101 2022-03-10 10:10:04 4 38318.0 6 ... P5_232_HALO_2022_2203100101 2022-03-10 10:10:04 [5 rows x 17 columns] ``` -------------------------------- ### Expand Parameter Terms Source: https://context7.com/pangaea-data-publisher/pangaeapy/llms.txt Expands ontology terms for parameters in a PanDataSet, useful for semantic analysis. Requires specifying the dataset ID and optionally term IDs for expansion. ```python from pangaeapy import PanDataSet # Expand terms for specific terminology IDs ds = PanDataSet(787140, expand_terms=[18]) # Expand PANGAEA terminology (ID 18) # Access expanded term information for parameters for param_name, param in ds.params.items(): print(f"Parameter: {param_name}") for term in param.terms: print(f" Term: {term['name']}") print(f" URI: {term['semantic_uri']}") print(f" Ontology ID: {term['ontology']}") if 'classification' in term: print(f" Classification: {term['classification']}") ``` -------------------------------- ### Identify Foraminifera Columns Source: https://github.com/pangaea-data-publisher/pangaeapy/blob/master/examples/SIMMAX.ipynb Iterates through a predefined list of foraminifera parameters and appends those present in the sample dataset to a list for further analysis. ```python #Forams used by Pflaumann et. al in SIMMAX28 #G. mentum = Globorotalia cultrata and tumida foramCols=[] foramParams=['G. bulloides','G. calida','G. falconensis','G. quinqueloba','G. rubescens','G. digitata','G. aequilateralis', 'G. conglobatus','G. ruber p','G. ruber w', 'G. tenellus','G. trilobus tril','G. trilobus sac','O. universa', 'S. dehiscens','G. crassaformis','G. mentum', 'G. hirsuta', 'G. inflata', 'G. scitula','G. truncatulinoides', 'N. dutertrei','N. pachyderma s','P/D int','G. glutinata','P. obliquiloculata'] for fP in foramParams: if fP in sampleDS.data.columns: foramCols.append(fP) ```