Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Griesfeller committed Apr 15, 2024
1 parent 8941e59 commit 8e254ab
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 29 deletions.
60 changes: 37 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ The MSC-W database contains the EBAS database for 1990-2021 and the EEA_Airquip
contain already hourly data if enough hours have been measured. Therefore, `resolution` is a
required parameter.

### nilupmfebas: EBAS format (Nasa-Ames)
Reader for random EBAS data in NASA-AMES format. This reader is tested only with PMF data provided by
NILU, but should in principle able to read any random text file in EBAS NASA-AMES.
The variables provided contain in EBAS terms a combination of matrix and component with a number sign (#)
as seperator (e.g. `pm10_pm25#total_carbon` or `pm10#organic_carbon` or `pm10#galactosan`)

## Usage
### aeronetsunreader
Expand Down Expand Up @@ -106,29 +111,38 @@ with pyaro.open_timeseries(
data.values

```


### geocoder_reverse_natural_earth
geocoder_reverse_natural_earth is small helper to identify country codes for obs networks that don't mention the
countrycode of a station in their location data
### nilupmfebas
```python
from geocoder_reverse_natural_earth import (
Geocoder_Reverse_NE,
Geocoder_Reverse_Exception,
)
geo = Geocoder_Reverse_NE()
print(geo.lookup(60, 10)["ISO_A2_EH"])
lat = 78.2361926
lon = 15.3692614
try:
geo.lookup(lat, lon)
except Geocoder_Reverse_Exception as grex:
dummy = geo.lookup_nearest(lat, lon)
if dummy is None:
print(f"error: {lat},{lon}")
else:
print(dummy["ISO_A2_EH"])


import pyaro
TEST_URL = "/home/jang/data/Python3/pyaro-readers/tests/testdata/PMF_EBAS/NO0042G.20171109070000.20220406124026.high_vol_sampler..pm10.4mo.1w.NO01L_hvs_week_no42_pm10.NO01L_NILU_sunset_002.lev2.nas"
TEST_URL = "/home/jang/data/Python3/pyaro-readers/tests/testdata/PMF_EBAS/NO0042G.20171109070000.20220406124026.high_vol_sampler..pm10.4mo.1w.NO01L_hvs_week_no42_pm10.NO01L_NILU_sunset_002.lev2.nas"

def main():
with pyaro.open_timeseries(
'nilupmfebas', TEST_URL, filters=[]
) as ts:
variables = ts.variables()
for var in variables:

data = ts.data(var)
print(f"var:{var} ; unit:{data.units}")
# stations
print(set(data.stations))
# start_times
print(data.start_times)
for idx, time in enumerate(data.start_times):
print(f"{time}_{data.values[idx]}")

# stop_times
data.end_times
# latitudes
data.latitudes
# longitudes
data.longitudes
# altitudes
data.altitudes
# values
data.values

```

26 changes: 20 additions & 6 deletions src/pyaro_readers/nilupmfebas/EbasPmfReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tqdm import tqdm

from pathlib import Path
import cf_units

logger = logging.getLogger(__name__)

Expand All @@ -32,6 +33,7 @@ def __init__(
self._set_filters(filters)
self._header = []
self._opts = {"default": ReadEbasOptions()}
self._variables = {}

realpath = Path(filename).resolve()

Expand All @@ -41,12 +43,12 @@ def __init__(
bar = tqdm(desc=tqdm_desc, total=len(files))

for _ridx, file in enumerate(files):
# print(file)
bar.update(1)
self.read_file(file)
bar.close()
elif Path(realpath).is_file():
self.read_file(realpath)
# print(realpath)

else:
# filename is something else
Expand Down Expand Up @@ -97,8 +99,21 @@ def read_file(self, filename):
pass

var_name = f"{matrix}#{self._file_dummy.var_defs[var_idx].name}"
if add_meta_flag:
stat_name = self._file_dummy.meta["station_code"]
if var_name not in self._variables:
self._variables[var_name] = (
var_name,
self._file_dummy.meta["unit"],
)
else:
var_name_ext = f"{self._variables[var_name]}0"
self._variables[var_name] = (
var_name_ext,
self._file_dummy.meta["unit"],
)

var_unit = self._file_dummy.var_defs[var_idx].unit
stat_name = self._file_dummy.meta["station_code"]
if stat_name not in self._stations:
country = self._file_dummy.meta["station_code"][0:2]

lat = float(self._file_dummy.meta["station_latitude"])
Expand All @@ -119,9 +134,8 @@ def read_file(self, filename):
add_meta_flag = False

# we might want to put a CF compliant unit here
self._data[var_name] = NpStructuredData(
var_name, self._file_dummy.meta["unit"]
)
self._data[var_name] = NpStructuredData(var_name, var_unit)
# self._data[var_name] = []
# now add ts after ts
for t_idx, ts in enumerate(self._file_dummy.start_meas):
self._data[var_name].append(
Expand Down

0 comments on commit 8e254ab

Please sign in to comment.