Skip to content

Commit

Permalink
Cleanup, logging and formatting with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
dulte committed Sep 16, 2024
1 parent 354910e commit eabe83c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
9 changes: 7 additions & 2 deletions src/pyaro_readers/eeareader/EEATimeseriesReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
FLAGS_VALID = {-99: False, -1: False, 1: True, 2: False, 3: False, 4: True}
VERIFIED_LVL = [1, 2, 3]
DATA_TOML = path.join(path.dirname(__file__), "data.toml")
# Path(__file__).parent / "data.toml"
FILL_COUNTRY_FLAG = False

TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
Expand Down Expand Up @@ -75,7 +74,6 @@ def __init__(
self,
filename,
filters={},
fill_country_flag: bool = FILL_COUNTRY_FLAG,
):
self._filename = filename
self._stations = {}
Expand Down Expand Up @@ -146,6 +144,7 @@ def _read_polars(self, filters, filename) -> None:
polars.read_parquet(file), (start_date, end_date)
)
if lf.is_empty():
logger.info(f"Data for file {file} is empty. Skipping")
continue
else:
lf = polars.read_parquet(file)
Expand Down Expand Up @@ -176,6 +175,9 @@ def _read_polars(self, filters, filename) -> None:
try:
station_metadata = self.metadata[df.row(0)[0].split("/")[-1]]
except:
logger.info(
f"Could not extract the metadata for {df.row(0)[0].split("/")[-1]}"
)
continue

file_unit = self._convert_unit(df.row(0)[df.get_column_index("Unit")])
Expand Down Expand Up @@ -249,6 +251,9 @@ def _read_metadata(self, folder: str) -> dict:
lat = float(words[4])
alt = float(words[5])
except:
logger.info(
f"Could not interpret lat, lon, alt for line {line} in metadata. Skipping"
)
continue
metadata[words[0]] = {
"lon": lon,
Expand Down
15 changes: 6 additions & 9 deletions src/pyaro_readers/eeareader/eeadownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def make_pollutant_url_list(self, pollutants: list[str]) -> list[str]:

@app.command(name="download")
def download_default(
self, save_loc: Path, dataset: int = DATABASES["VERIFIED"], pollutants: list | None= None,
self,
save_loc: Path,
dataset: int = DATABASES["VERIFIED"],
pollutants: list | None = None,
) -> None:
if not save_loc.is_dir():
save_loc.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -265,21 +268,15 @@ def postprocess(


if __name__ == "__main__":
#app()
# app()

pollutants = [
"SO2",
"SO4--",
"SO4 (H2SO4 aerosols) (SO4--)",
]
eead = EEADownloader()
eead.download_default(
Path(
"/nird/home/dulte/data/EEA"
),
pollutants = pollutants

)
eead.download_default(Path("/nird/home/dulte/data/EEA"), pollutants=pollutants)

# eead.postprocess_all_files(
# Path(
Expand Down
6 changes: 2 additions & 4 deletions src/pyaro_readers/eeareader/utils/generate_data_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
"HNO3",
]

changeunit = {
"SO4--" : '{ unit = "µg /m3", factor = 2995.82 }'
}
changeunit = {"SO4--": '{ unit = "µg /m3", factor = 2995.82 }'}

with open("response.json", "r") as f:
properties = {}
Expand All @@ -60,7 +58,7 @@
target.write(f'"{poll}",\n')
target.write("]\n\n")

target.write('[changeunits]\n')
target.write("[changeunits]\n")
for s in changeunit:
target.write(f'"{s}" = {changeunit[s]}\n')
target.write("]\n\n")
Expand Down

0 comments on commit eabe83c

Please sign in to comment.