Skip to content

Commit 42591bc

Browse files
committed
shorten 'sums' filename and add exp. config verification
1 parent 5d42392 commit 42591bc

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

GEOSldas_App/util/postproc/ObsFcstAna_stats/postproc_ObsFcstAna.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77
import os
8+
import yaml
89

910
import sys; sys.path.append('../../shared/python/')
1011

@@ -34,7 +35,7 @@ def __init__(self, exp_list, start_time, end_time, sum_path='./', outid=None):
3435
self.obsparam_list = [item['obsparam'] for item in exp_list]
3536
self.sum_path = sum_path
3637

37-
# determine experiment that supplies obs data
38+
# Determine experiment that supplies obs data
3839
self.obs_from = -1
3940
for exp_idx, exp in enumerate(exp_list):
4041
if exp.get('use_obs', None): # found use_obs=True
@@ -46,13 +47,37 @@ def __init__(self, exp_list, start_time, end_time, sum_path='./', outid=None):
4647
if self.obs_from < 0: self.obs_from = 0 # by default, obs data are from exp_list[0]
4748
print(f"obs data are from {self.exptag_list[self.obs_from]}")
4849

49-
# If not provided, assemble filename of monthly sums, including info of all experiments
50+
# Tag of the output sums files. If not provided, use main exptag
5051
if outid is None:
51-
self.outid = '_'.join([item for item in self.exptag_list])
52-
# append "obs_from" info if obs data are from supplemental experiment
53-
if self.obs_from > 0:
54-
self.outid = self.outid + '_Obs_from_' + self.exptag_list[self.obs_from]
55-
52+
self.outid = self.exptag_list[0]
53+
54+
# Verify the configuration every time when current class is initialized
55+
# to avoid saving sums with different configs in the same directory
56+
57+
# Same configurations should have identical values for these fields
58+
config_verify = ['expdir','expid','exptag','domain','use_obs','species_list']
59+
60+
# Construct config for each experiment
61+
config_list = []
62+
for exp in exp_list:
63+
config_list.append({var:exp[var] for var in config_verify if var in exp})
64+
65+
# File of configuration for verification
66+
f_config = self.sum_path + '/' + self.outid + '_config.yaml'
67+
68+
# Save a new file or compare current configuration with previously saved
69+
if not os.path.exists(f_config):
70+
with open(f_config, 'w') as f:
71+
yaml.dump(config_list, f, default_flow_style=False)
72+
print(f'Configuration saved to {f_config}')
73+
else:
74+
with open(f_config,'r') as f:
75+
saved_exp_list = yaml.safe_load(f)
76+
print(f'Found saved configuration')
77+
78+
if config_list != saved_exp_list:
79+
print('user configuration is different from previously saved '+f_config)
80+
sys.exit()
5681
# ----------------------------------------------------------------------------------------------------------
5782
#
5883
# Function to compute monthly sums from x-hourly ObsFcstAna data for a single month.

0 commit comments

Comments
 (0)