From 043cd7390988742a9658c454235b360a287ed6de Mon Sep 17 00:00:00 2001 From: hagne Date: Fri, 19 Jan 2024 17:14:29 -0700 Subject: [PATCH] function to open picarro files --- atmPy/gases/instruments/__init__.py | 0 atmPy/gases/instruments/picarro.py | 43 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 atmPy/gases/instruments/__init__.py create mode 100644 atmPy/gases/instruments/picarro.py diff --git a/atmPy/gases/instruments/__init__.py b/atmPy/gases/instruments/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/atmPy/gases/instruments/picarro.py b/atmPy/gases/instruments/picarro.py new file mode 100644 index 0000000..8854e4e --- /dev/null +++ b/atmPy/gases/instruments/picarro.py @@ -0,0 +1,43 @@ +import types +import pathlib as pl +import pandas as pd + +def open_file(path, verbose = False): + p2f = pl.Path(path) + + if p2f.is_file(): + p2fs = [p2f] + + elif p2f.is_dir(): + p2fs = p2f.glob('*') + + elif isinstance(p2f, (types.GeneratorType, list, tuple)): + p2fs = p2f + + else: + assert(False), f'Type {type(p2fs)} not implemented' + + + + df = pd.DataFrame() + for p2f in p2fs: + if verbose: + print(p2f.as_posix()) + dft = pd.read_csv(p2f) + df = pd.concat([df,dft]) + + df.index = pd.to_datetime(df.TMSTAMP) + df.sort_index(inplace=True) + df.index.name = 'time' + coords = df.loc[:,['Latitude', 'Longitude', 'Elevation']].iloc[0] + df = df.drop(['TMSTAMP','Frac_DOY', 'Frac_time', 'DOY', 'Year', 'Hour', 'Min','Latitude', 'Longitude', 'Elevation'], axis = 1) + + ds = df.to_xarray() + + ds.attrs['coordinates'] = '; '.join([f'{i[0]}:{i[1]}' for i in zip(coords.index, coords.values)]) + return Picarro(ds) + + +class Picarro(object): + def __init__(self, dataset): + self.dataset = dataset \ No newline at end of file