Skip to content
Snippets Groups Projects
Commit 0e88b899 authored by lkugler's avatar lkugler
Browse files

evaluate only if necessary

parent 21edb694
No related branches found
No related tags found
No related merge requests found
...@@ -204,26 +204,32 @@ def get_parametrized_error(obscfg, osf_prior): ...@@ -204,26 +204,32 @@ def get_parametrized_error(obscfg, osf_prior):
NotImplementedError('sat_channel not implemented', obscfg.get("sat_channel")) NotImplementedError('sat_channel not implemented', obscfg.get("sat_channel"))
def set_obserr_assimilate_in_obsseqout(oso, osf_prior, outfile="./obs_seq.out"): def set_obserr_assimilate_in_obsseqout(oso, outfile="./obs_seq.out"):
""""Overwrite existing variance values in obs_seq.out files """"Overwrite existing variance values in obs_seq.out files
Args: Args:
oso (ObsSeq): python representation of obs_seq.out file, will be modified and written to file oso (ObsSeq): python representation of obs_seq.out file, will be modified and written to file
osf_prior (ObsSeq): python representation of obs_seq.final (output of filter in evaluate-mode without posterior)
contains prior values; used for parameterized errors
Returns: Returns:
None (writes to file) None (writes to file)
Variables:
osf_prior (ObsSeq): python representation of obs_seq.final (output of filter in evaluate-mode without posterior)
contains prior values; used for parameterized errors
""" """
for obscfg in exp.observations: for obscfg in exp.observations:
kind_str = obscfg['kind'] kind_str = obscfg['kind'] # e.g. 'RADIOSONDE_TEMPERATURE'
kind = osq.obs_kind_nrs[kind_str] kind = osq.obs_kind_nrs[kind_str] # e.g. 263
# modify each kind separately, one after each other # modify observation error of each kind sequentially
where_oso_iskind = oso.df.kind == kind where_oso_iskind = oso.df.kind == kind
where_osf_iskind = osf_prior.df.kind == kind
if obscfg["error_assimilate"] == False: if obscfg["error_assimilate"] == False:
osf_prior = obsseq.ObsSeq(cluster.dartrundir + "/obs_seq.final") # this file will be generated by `evaluate()`
where_osf_iskind = osf_prior.df.kind == kind
assim_err = get_parametrized_error(obscfg, osf_prior.df[where_osf_iskind]) assim_err = get_parametrized_error(obscfg, osf_prior.df[where_osf_iskind])
oso.df.loc[where_oso_iskind, 'variance'] = assim_err**2 oso.df.loc[where_oso_iskind, 'variance'] = assim_err**2
#assert np.allclose(assim_err, oso.df['variance']**2) # check #assert np.allclose(assim_err, oso.df['variance']**2) # check
...@@ -233,7 +239,9 @@ def set_obserr_assimilate_in_obsseqout(oso, osf_prior, outfile="./obs_seq.out"): ...@@ -233,7 +239,9 @@ def set_obserr_assimilate_in_obsseqout(oso, osf_prior, outfile="./obs_seq.out"):
oso.to_dart(outfile) oso.to_dart(outfile)
def qc_obs(time, oso, osf_prior): def qc_obs(time, oso):
osf_prior = obsseq.ObsSeq(cluster.dartrundir + "/obs_seq.final")
# obs should be superobbed already! # obs should be superobbed already!
for i, obscfg in enumerate(exp.observations): for i, obscfg in enumerate(exp.observations):
if i > 0: if i > 0:
...@@ -328,9 +336,6 @@ def evaluate(assim_time, ...@@ -328,9 +336,6 @@ def evaluate(assim_time,
copy(cluster.dart_rundir + "/obs_seq.final", fout) copy(cluster.dart_rundir + "/obs_seq.final", fout)
print(fout, "saved.") print(fout, "saved.")
osf = obsseq.ObsSeq(cluster.dart_rundir + "/obs_seq.final")
return osf
def generate_obsseq_out(time): def generate_obsseq_out(time):
...@@ -526,6 +531,10 @@ def main(time, prior_init_time, prior_valid_time, prior_path_exp): ...@@ -526,6 +531,10 @@ def main(time, prior_init_time, prior_valid_time, prior_path_exp):
None None
""" """
nproc = cluster.max_nproc nproc = cluster.max_nproc
do_QC = getattr(exp, "reject_smallFGD", False) # True: triggers additional evaluations of prior & posterior
# for which observation type do we have a parametrized observation error?
error_is_parametrized = [obscfg["error_assimilate"] == False for obscfg in exp.observations]
prepare_run_DART_folder() prepare_run_DART_folder()
nml = dart_nml.write_namelist() nml = dart_nml.write_namelist()
...@@ -540,15 +549,17 @@ def main(time, prior_init_time, prior_valid_time, prior_path_exp): ...@@ -540,15 +549,17 @@ def main(time, prior_init_time, prior_valid_time, prior_path_exp):
print(" 1) get observations with specified obs-error") print(" 1) get observations with specified obs-error")
oso = get_obsseq_out(time) oso = get_obsseq_out(time)
print(" 2.1) evaluate prior for all observations (incl rejected)") # is any observation error parametrized?
osf_prior = evaluate(time, output_format="%Y-%m-%d_%H:%M_obs_seq.final-eval_prior_allobs") if any(error_is_parametrized) or do_QC:
print(" (optional) evaluate prior for all observations (incl rejected)")
evaluate(time, output_format="%Y-%m-%d_%H:%M_obs_seq.final-eval_prior_allobs")
print(" 2.2) assign observation-errors for assimilation ") print(" assign observation-errors for assimilation ")
set_obserr_assimilate_in_obsseqout(oso, osf_prior, outfile=cluster.dart_rundir + "/obs_seq.out") set_obserr_assimilate_in_obsseqout(oso, outfile=cluster.dartrundir + "/obs_seq.out")
if getattr(exp, "reject_smallFGD", False): if do_QC:
print(" 2.3) reject observations? ") print(" 2.3) reject observations? ")
qc_obs(time, oso, osf_prior) qc_obs(time, oso)
if prior_inflation_type == '2': if prior_inflation_type == '2':
prepare_inflation_2(time, prior_init_time) prepare_inflation_2(time, prior_init_time)
...@@ -561,9 +572,10 @@ def main(time, prior_init_time, prior_valid_time, prior_path_exp): ...@@ -561,9 +572,10 @@ def main(time, prior_init_time, prior_valid_time, prior_path_exp):
if prior_inflation_type == '2': if prior_inflation_type == '2':
archive_inflation_2(time) archive_inflation_2(time)
print(" 4) evaluate posterior observations for all observations (incl rejected)") if do_QC:
write_list_of_inputfiles_posterior(time) print(" 4) evaluate posterior observations for all observations (incl rejected)")
if getattr(exp, "reject_smallFGD", False): write_list_of_inputfiles_posterior(time)
copy(cluster.archivedir+'/obs_seq_out/'+time.strftime('%Y-%m-%d_%H:%M_obs_seq.out-beforeQC'), copy(cluster.archivedir+'/obs_seq_out/'+time.strftime('%Y-%m-%d_%H:%M_obs_seq.out-beforeQC'),
cluster.dart_rundir+'/obs_seq.out') cluster.dart_rundir+'/obs_seq.out')
evaluate(time, output_format="%Y-%m-%d_%H:%M_obs_seq.final-eval_posterior_allobs") evaluate(time, output_format="%Y-%m-%d_%H:%M_obs_seq.final-eval_posterior_allobs")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment