cpt-io

xarray - cptv10.tsv file reader & writer

View the Project on GitHub iri-pycpt/cpt-io

CPT-IO

A python library for reading and writing CPTv10-formatted tab-separated values (tsv) files via Xarray

Maintainer: IRI (pycpt-help@iri.columbia.edu)

Installation

CPT-IO and all CPT-packages are distributed through anaconda as platform-independent “noarch” packages.

CPT-IO can be installed through anaconda’s package manager, conda which can be installed from here

once you have conda installed, cpt-io and most other python packages can be installed with the following command:

conda install -c conda-forge -c hallkjc01 cptio

it is, however, highly recommended that you use Anaconda environments to manage your python packages. In that case, you would use:

conda create -c conda-forge -c hallkjc01 -n environment_name cptio

to install cpt-io.

Usage

CPT-IO has two main functions: cptio.open_cptdataset(...) and cptio.to_cptv10(...). open_cptdataset reads a CPTv10.tsv-formatted file, and returns an Xarray DataArray representing its contents. to_cptv10 takes a CPTv10.tsv-compatible Xarray DataArray, and writes it to a CPTv10.tsv formatted file.

An example of open_cptdataset:

import cptio as cio 
da = cio.open_cptdataset("/Path/To/CPTv10/cptv10.tsv") 
# print or echo da to see an xarray dataarray

An example of to_cptv10:

import cptio as cio 
da = cio.open_cptdataset("/Path/To/CPTv10/cptv10.tsv") 
# print or echo da to see an xarray dataarray

cio.to_cptv10(da, "new_output_file.tsv") 
# this line writes da back to a new cptv10-file

CPTv10 Format & cptio.to_cptv10()

The CPTv10 file format is a plain-text format capable of representing high-dimensional gridded data, like NetCDF or HDF5. It is read/write/size inefficient compared to those mainstream, highly-optimized formats, but allows the user to manually inspect data in text editors and spreadsheet applications. NetCDF, HDF5 and TIFF files should be used for data archiving where possible.

to_cptv10, and accordingly, the Climate Prediction Tool itself, require data to adhere to certain constraints. They are detailed here.