Skip to content

GEUS-Glaciology-and-Climate/pyNEAD

Repository files navigation

pyNEAD - Python interface to NEAD file format

https://zenodo.org/badge/DOI/10.5281/zenodo.7728588.svg

Table of contents

WARNING

  • This is alpha level software under development.
  • Please contact Ken Mankoff <[email protected]> before using.

The NEAD format

Iosifescu Enescu, I., Bavay, M., Plattner, G.-K. (2020). Sharing and reusing meteorological data. WMO Data Conference 2020 - Earth System Data Exchange in the 21st Century (Virtual Conference).

The NEAD file format is documented at https://github.com/GEUS-PROMICE/NEAD

Installation

pip install git+https://github.com/GEUS-PROMICE/pyNEAD.git

List of functions:

read

write

read_header

write_header

Takes a set of NEAD file attributes, field names and field attributes and builds an text header file

build_header_obj

Takes a set of NEAD file attributes, field names and field attributes and builds a [configparser](https://docs.python.org/3/library/configparser.html) object that can be used directly by write_nead

Usage

Read a NEAD file:

import nead
ds = nead.read("sample.csv")
print(ds)

Ignore all the metadata and work with a Pandas dataframe:

import nead
ds = nead.read("sample.csv", index_col=0)
ds.to_dataframe()
timestampTARHVWISWR
2010-06-22 12:00:002521.2320
2010-06-22 13:00:003602.4340
2010-06-22 14:00:002.8562330

Convert to MKS units and also pass arguments to the Pandas read_csv command:

import nead
ds = nead.read("sample.csv", MKS=True, index_col=0)
print(ds)

You can access the per-variable properties or the NEAD header properties in the .attrs dictionary.

Details about one variable:

import nead
ds = nead.read("sample.csv", index_col=0)
print(ds['TA'])
<xarray.DataArray 'TA' (timestamp: 3)>
array([2. , 3. , 2.8])
Coordinates:
  * timestamp  (timestamp) datetime64[ns] 2010-06-22T12:00:00 ... 2010-06-22T...
Attributes:
    add_value:     273.15
    scale_factor:  1.0

Access the attributes dictionary

print(ds['TA'].attrs)
{'add_value': 273.15, 'scale_factor': 1.0}

Access the global attributes:

for k in ds.attrs.keys():
    print(k, " : ", ds.attrs[k])
station_id  :  test_station
latitude  :  46.5
longitude  :  9.8
altitude  :  1500
nodata  :  -999
timezone  :  1
field_delimiter  :  ,