Skip to content

Commit

Permalink
Merge pull request #1060 from metno/read-colocated-files-857
Browse files Browse the repository at this point in the history
Read colocated files made outside of pyaerocom
  • Loading branch information
lewisblake authored Apr 25, 2024
2 parents ec22475 + 275c996 commit 2b17ceb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyaerocom/aeroval/experiment_processor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import glob
import logging

from pyaerocom.aeroval._processing_base import HasColocator, ProcessingEngine
Expand Down Expand Up @@ -52,6 +53,18 @@ def _run_single_entry(self, model_name, obs_name, var_list):
f"marked to be used only as part of a superobs "
f"network"
)
elif ocfg["only_json"]:
if not ocfg["coldata_dir"]:
raise Exception(
f"No coldata_dir provided for an obs network for which only_json=True. The assumption of setting only_json=True is that colocated files already exist, and so a directory for these files must be provided."
)
else:
preprocessed_coldata_dir = ocfg["coldata_dir"]
mask = f"{preprocessed_coldata_dir}/*.nc"
files_to_convert = glob.glob(mask)
engine = ColdataToJsonEngine(self.cfg)
engine.run(files_to_convert)

else:
col = self.get_colocator(model_name, obs_name)
if self.cfg.processing_opts.only_json:
Expand Down
12 changes: 12 additions & 0 deletions pyaerocom/aeroval/obsentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ class ObsEntry(BrowseDict):
read_opts_ungridded : :obj:`dict`, optional
dictionary that specifies reading constraints for ungridded reading
(c.g. :class:`pyaerocom.io.ReadUngridded`).
only_json : bool
Only to be set if the obs entry already has colocated data files which were
preprocessed outside of pyaerocom. Setting to True will skip the colcoation
and just create the JSON output.
coldata_dir : str
Only to be set if the obs entry already has colocated data files which were
preprocessed outside of pyaerocom. This is the directory in which the
colocated data files are located.
"""

SUPPORTED_VERT_CODES = ["Column", "Profile", "Surface"] # , "2D"]
Expand All @@ -74,6 +83,9 @@ def __init__(self, **kwargs):
self.profile_layer_limits = None

self.read_opts_ungridded = {}
# attributes for reading colocated data files made outside of pyaerocom
self.only_json = False
self.coldata_dir = None

self.update(**kwargs)
self.check_cfg()
Expand Down

0 comments on commit 2b17ceb

Please sign in to comment.