Skip to content
Snippets Groups Projects
Commit d87d6267 authored by Antoine Berchet's avatar Antoine Berchet
Browse files

CHIMERE seems to be fixed as well

parent fd2362ea
No related branches found
No related tags found
1 merge request!28Fix issue with global domains and find_gridcells; speed up regrid for...
......@@ -76,4 +76,8 @@ def ini_periods(self, **kwargs):
self.iniobs = {ddi: False for ddi in self.subsimu_dates}
self.reset_obs = {ddi: True for ddi in self.subsimu_dates}
# Keep in memory whether a given period has a successor period
# The info is used by the adjoint to fetch or not the aend file
self.chain = {ddi: True for ddi in self.subsimu_dates[:-1]}
self.chain[self.subsimu_dates[-2]] = False
\ No newline at end of file
def make_nml(self, runsubdir, sdc, mode):
def make_nml(self, runsubdir, sdc, mode, ddi):
# Default values
nvegtype = getattr(self, "nvegtype", 16)
......@@ -136,7 +136,7 @@ def make_nml(self, runsubdir, sdc, mode):
f.write("afnout = '{}/aout.'\n".format(runsubdir))
ainit = 1 if (mode == "adj" and hasattr(self, "chain")) else 0
ainit = 1 if (mode == "adj" and self.chain[ddi]) else 0
f.write("iopainit = {}\n".format(ainit))
netcdfoutput = 1 if self.dumpncoutput else 0
......
......@@ -75,7 +75,7 @@ def native2inputs(
# Deals with the nml file
elif input_type == "nml":
make_nml(self, runsubdir, sdc, mode)
make_nml(self, runsubdir, sdc, mode, ddi)
# Deals with fluxes
# WARNING: Not specified emissions are set to zero??
......
......@@ -150,10 +150,6 @@ def obsoper(
info("The run was correctly initialized")
return
# Re-initalizing the chain argument
if hasattr(model, "chain"):
del model.chain
# Dump observation vector for later use in fwd and tl modes
# Otherwise dumps the control vector
if mode in ["fwd", "tl"]:
......
......@@ -70,13 +70,13 @@ def ini_mapper(
mapper["subsimus"] = {}
for di in input_dates:
outdates = np.sort(np.unique(np.append(
default_dict["input_dates"][di],
input_dates[di],
transform.orig_parameter_plg.dates
)))
outdates = outdates[
outdates >= np.min(default_dict["input_dates"][di])]
outdates >= np.min(input_dates[di])]
outdates = outdates[
outdates <= np.max(default_dict["input_dates"][di])]
outdates <= np.max(input_dates[di])]
outdates = pd.DatetimeIndex(outdates).to_pydatetime()
mapper["subsimus"][di] = {
"inputs": {},
......@@ -90,4 +90,5 @@ def ini_mapper(
mapper["subsimus"][di]["outputs"][trid][di]
mapper["fixed_subsimus"] = True
return mapper
......@@ -154,7 +154,7 @@ def adjoint(
model=transform.model,
**kwargs
).data
# Vertical aggregation
vdata = np.sum(sensit_data[mask] * phys, axis=0)
vaggreg = vmap2vaggreg(vdata[np.newaxis], tracer, tracer.domain)
......@@ -168,4 +168,9 @@ def adjoint(
* tracer.hresoldim
* tracer.vresoldim
] += map2scale(vaggreg, tracer, tracer.domain).flatten()
print(ddi, k, period, control_slice, data_slice,
map2scale(vaggreg, tracer, tracer.domain).flatten().sum(),
controlvect.dx.sum())
\ No newline at end of file
......@@ -111,11 +111,11 @@ def forward(
scale = reindex(
xmod_out["scale"],
levels={"time": outdates, "lev": inputs.lev},
levels={"time": outdates[:-1], "lev": inputs.lev},
)
inputs = reindex(
inputs,
levels={"time": outdates},
levels={"time": outdates[:-1]},
)
xmod_out["spec"] = inputs * scale
......@@ -123,7 +123,7 @@ def forward(
if mode == "tl":
incr = reindex(
xmod_out["incr"],
levels={"time": outdates, "lev": inputs.lev},
levels={"time": outdates[:-1], "lev": inputs.lev},
)
xmod_out["incr"] = incr * inputs
......
......@@ -23,13 +23,13 @@ def dateslice(tracer, di, df):
ddi = min(di, df)
ddf = max(di, df)
if hasattr(tracer, "dates") and hasattr(tracer, "period"):
if hasattr(tracer, "dates") and hasattr(tracer, "tresol"):
dates = np.append(
tracer.dates, tracer.dates[-1] + datetime.timedelta(1)
)
chunk = np.where((dates[1:] > ddi) & (dates[:-1] <= ddf))[0]
# When no period is specified and/or no date,
# When no tresol is specified and/or no date,
# just take all the first element
else:
chunk = [0]
......
......@@ -19,7 +19,4 @@ def adjoint(
if not onlyinit:
transform.model.run(runsubdir, mode, workdir, min(di, df),
do_simu=do_simu, **kwargs)
# Keep in memory the fact that it is (or not) a chained simulation
transform.model.chain = min(di, df)
\ No newline at end of file
\ No newline at end of file
......@@ -18,7 +18,3 @@ def forward(
if not onlyinit:
transform.model.run(runsubdir, mode, workdir, min(di, df),
do_simu=do_simu, **kwargs)
# Keep in memory the fact that it is (or not) a chained simulation
transform.model.chain = min(di, df)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment