Skip to content

Commit

Permalink
function to open picarro files
Browse files Browse the repository at this point in the history
  • Loading branch information
hagne committed Jan 20, 2024
1 parent ec8b6aa commit 043cd73
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Empty file.
43 changes: 43 additions & 0 deletions atmPy/gases/instruments/picarro.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 043cd73

Please sign in to comment.