various update

This commit is contained in:
Noe Brucy
2024-03-22 15:06:07 +01:00
parent 006cbca80f
commit ca984eac44
5 changed files with 154 additions and 61 deletions
+12 -17
View File
@@ -52,7 +52,6 @@ class RunSelector:
time=None,
unit_time=None,
allow_nodata=False,
fallback_namelist=True,
):
"""
Select runs and outputs with several filter options.
@@ -72,7 +71,7 @@ class RunSelector:
"last" select only the last output.
"all" preselect all outputs (default)
nml_filename : str name of the namelist (should be the same for all outputs)
nml_filename : str name of the default namelist (otherwise look into the output files)
filter_name : str, filter runs by name. Default "*"
filter_nml : tuple or list of tupple.
@@ -107,15 +106,10 @@ class RunSelector:
self.path_in = path_in
self.nml_filename = nml_filename
self.fallback_nml = fallback_namelist
self.allow_nodata = allow_nodata
self.namelist = {}
do_tests = (
(not self.fallback_nml)
or (len(filter_nml) > 0)
or (sort_run_by is not None)
)
do_tests = not self.allow_nodata
self.runs = self.get_runs(
in_runs, filter_name, filter_nml, sort_run_by, do_tests=do_tests
)
@@ -226,7 +220,16 @@ class RunSelector:
def load_namelist(self, run, path=None):
if path is None:
path = f"{self.path_in}/{run}/{self.nml_filename}"
names = glob.glob(
self.path_in + "/" + run + "/output_[0-9][0-9][0-9][0-9][0-9]"
)
i = 0
path = self.path_in + "/" + run + "/" + self.nml_filename
while not os.path.exists(path) and i < len(names):
path = f"{names[i]}/namelist.txt"
i += 1
return NamelistRecursive(f90nml.read(path))
def get_nml_value(self, nml_key, run):
@@ -448,14 +451,6 @@ class RunSelector:
else:
return []
# Be sure we have a namelist
if self.fallback_nml and run not in self.namelist:
self.logger.warning(
f"Used fallback namelist for run {run} from output {nums[0]}"
)
path = f"{self.path_in}/{run}/output_{nums[0]:05}/namelist.txt"
self.namelist[run] = self.load_namelist(run, path=path)
# -- Time getter according to unit_time
if unit_time is None: