Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import argparse
import utilities.generic
import models.nemo.utilities.argument_parser
import models.nemo.utilities.base_experiment_plan
import models.nemo.enkf_tools.launch_enkf_experiment
import models.nemo.enkf_tools.update_enkf_experiment_plan
import models.nemo.enkf_tools.utilities.enkf_experiment
import models.nemo.enkf_tools.utilities.enkf_experiment_plan as enkf_experiment_plan
#############
# functions #
#############
def dummy_assimilation_operations(version, configuration, name, leg_index):
'''
Operations done during a dummy assimilation job, which is submitted when observations are marked
as missing.
'''
# update the experiment plan
models.nemo.enkf_tools.update_enkf_experiment_plan.update_enkf_experiment_plan(version=version,
configuration=configuration, name=name,
call=models.nemo.enkf_tools.update_enkf_experiment_plan.FROM_DUMMY_ASSIMILATION)
# create the experiment object
experiment = models.nemo.enkf_tools.utilities.enkf_experiment.EnKFExperiment(version=version,
configuration=configuration, name=name)
experiment_plan = experiment.get_experiment_plan(for_modification=True)
# check that all member experiments are completed
leg = experiment_plan.get_leg(index=leg_index)
if leg.status != enkf_experiment_plan.LEG_STATUS_ASSIMILATION_RUNNING:
if leg.status == enkf_experiment_plan.LEG_STATUS_ALL_MEMBERS_EXTENDED:
experiment_plan.unlock_and_close()
raise utilities.generic.ClimateToolboxException(
'Not all member experiments are completed up to leg %s.'
%models.nemo.utilities.base_experiment_plan.format_leg_index(index=leg_index))
else:
assert False, 'the status of leg %s was not expected to be "%s"'%(
models.nemo.utilities.base_experiment_plan.format_leg_index(index=leg_index), leg.status)
# comment:
# - if the status was supposed to be "LEG_STATUS_ALL_MEMBERS_COMPLETED",
# "update_enkf_experiment_plan" has already set it to "LEG_STATUS_ASSIMILATION_RUNNING"
# to avoid coming back (for a very short time) to a state suggesting that the assimilation
# is not ongoing yet
# - the objective of this tool is actually only to wait that all members are completed, so
# there is nothing more to do
# - the tool is probably more complex than it needs to be, but it has been done in such a
# way that it follows the same philosophy than an actual assimilation job
# mark the leg as skipped
print('The assimilation for leg %s has been skipped, because'%leg.format_index()
+ ' observation files are marked as missing at date %s.\n'%leg.get_next_leg_start_date())
leg.status = enkf_experiment_plan.LEG_STATUS_ASSIMILATION_SKIPPED
# write the updated experiment plan
experiment_plan.rewrite()
# re-launch the experiment
print('Re-launching the experiment to proceed with the next leg...\n')
models.nemo.enkf_tools.launch_enkf_experiment.launch_enkf_experiment(version=version,
configuration=configuration, name=name)
#################
# main function #
#################
def main():
parser = argparse.ArgumentParser()
models.nemo.utilities.argument_parser.add_argument_version(parser=parser)
models.nemo.utilities.argument_parser.add_argument_configuration(parser=parser)
models.nemo.utilities.argument_parser.add_argument_name(parser=parser)
models.nemo.utilities.argument_parser.add_argument_leg_index(parser=parser)
arguments = vars(parser.parse_args())
try:
dummy_assimilation_operations(**arguments)
except utilities.generic.ClimateToolboxException as e:
e.display()
if __name__ == '__main__':
main()