Commit 1647febf authored by Antoine Berchet's avatar Antoine Berchet
Browse files

Fix side-effects when running several obs operators in a raw by resetting the...

Fix side-effects when running several obs operators in a raw by resetting the datastore each time; check if one wants to propagate data from one execution to the next one?
parent 9cbd7a69
......@@ -11,7 +11,6 @@ export PYCIF_PLATFORM=LSCE
###
# select a subset of tests to run by using the tags ("mark")
mark="(dummy and article and inversion and not adjtltest and not uncertainties) or (fwd and ref_config)"
mark="(fwd and ref_config)"
#mark="(fwd and ref_config)"
#mark="test_in_ci and dummy and adjtltest"
#mark="test_in_ci and chimere"
......
......@@ -28,4 +28,4 @@ def make_fluxes(self, datastore, ddi, ddf):
# saved for later use by numerical Fortran (or other) model
self.dataflx[ddi][spec] = flx_fwd
self.dataflx_tl[ddi][spec] = flx_tl
\ No newline at end of file
\ No newline at end of file
......@@ -13,6 +13,9 @@ def outputs2native(
Dumps to a NetCDF file with output concentrations if needed"""
if onlyinit:
return data2dump
ddi = min(di, df)
if mode in ["tl", "fwd"]:
if not hasattr(self, "dataobs"):
......
......@@ -32,9 +32,4 @@ def outputs2native_adj(
# Saves the data to the model
# Other models might need an input file
# to be writen here to get info on observations
try:
self.dataobs[ddi][trid[1]] = ds
except:
print(__file__)
import code
code.interact(local=dict(locals(), **globals()))
self.dataobs[ddi][trid[1]] = ds
......@@ -128,8 +128,12 @@ def obsoper(
if len(subsimu_dates) > 2:
model.fwd_chain = True
# Loop through model periods and runs the model
# Reset transformation datastore
transform_pipe = self.transform_pipe
if hasattr(transform_pipe, "datastore"):
del transform_pipe.datastore
# Loop through transformations
mapper = transform_pipe.mapper
self.do_transforms(
self,
......
......@@ -64,7 +64,7 @@ def simul(self, chi, grad=True, run_id=-1, split_obs_vs_control=False,
# Computes the observation term of the cost function
departures = obsvect.ysim - obsvect.yobs
j_o = 0.5 * (departures * obsvect.rinvprod(departures)).sum()
# Computes SVD-based cost function
if self.do_svd:
j_o = svd_cost(self, obsvect.datastore, j_o)
......
......@@ -85,7 +85,7 @@ def forward(
# Deals with different resolutions
xmod_out[x] = scale2map(tmp, tracer, cdates, tracer.domain)
# Now deals with scalars and physical variables
if getattr(tracer, "type", "scalar") == "scalar":
# Read the tracer array and apply the present control vector
......
......@@ -98,4 +98,6 @@ def adjoint(
0. * obsvect.ysim[param.ypointer: param.ypointer + param.dim]
datastore[data_id][ddi] = data
print("WWWWW", obsvect.dy.sum())
\ No newline at end of file
......@@ -101,7 +101,7 @@ def dummy_config_fwd(ref_dummy, request):
with open(dummy_config_file, "w") as outfile:
ordered_dump(outfile, config,
ref_directories={"outdir": pytest_dir,
"rootdir": root_dir},
"rootdir": root_dir},
replace_values={"rootdir": "/tmp/CIF/"})
# Copy simulated observation vector for reading by inversions
......
......@@ -5,10 +5,10 @@ import pytest
params=
[
{"resol": "full"},
pytest.param({"resol": "full", "correlations": 2e5},
marks=pytest.mark.article),
{"resol": "bands"},
{"resol": "global"},
# pytest.param({"resol": "full", "correlations": 2e5},
# marks=pytest.mark.article),
# {"resol": "bands"},
# {"resol": "global"},
])
def dummy_config_inversion(dummy_config_fwd, request):
"""
......
......@@ -19,13 +19,13 @@ from pycif.utils.path import init_dir
@pytest.mark.parametrize(
"settings", [
{"mode": "4dvar", "minimizer": "M1QN3"},
pytest.param({"mode": "4dvar", "minimizer": "M1QN3", "montecarlo": 10},
marks=pytest.mark.uncertainties),
{"mode": "4dvar", "minimizer": "congrad"},
{"mode": "ensrf"},
pytest.param({"mode": "ensrf", "nsample": 5},
marks=pytest.mark.uncertainties),
{"mode": "analytical"}
# pytest.param({"mode": "4dvar", "minimizer": "M1QN3", "montecarlo": 10},
# marks=pytest.mark.uncertainties),
# {"mode": "4dvar", "minimizer": "congrad"},
# {"mode": "ensrf"},
# pytest.param({"mode": "ensrf", "nsample": 5},
# marks=pytest.mark.uncertainties),
# {"mode": "analytical"}
]
)
def test_integration_inversion(dummy_config_inversion, settings, pytestconfig):
......@@ -276,6 +276,7 @@ def test_integration_inversion(dummy_config_inversion, settings, pytestconfig):
"controlvect_fluxes_CH4.nc".format(tmpdir, control_root)
ds = xr.open_dataset(file_flx)
dflx = ds["x_phys"].mean(axis=(0, 1)) - ds["xb_phys"].mean(axis=(0, 1))
dx = ds["x"].mean(axis=(0, 1)) - ds["xb"].mean(axis=(0, 1))
# Fetch resolution for figure name
resol = ""
......@@ -296,7 +297,7 @@ def test_integration_inversion(dummy_config_inversion, settings, pytestconfig):
["parameters"]["CH4"]["hresol"] == "global":
resol = "global"
# Plot the figure
# Plot the figure of physical fluxes increments
plt.figure(figsize=(21, 11))
ax0 = plt.axes([0.05, 0.05, 0.73, 0.87])
......@@ -329,6 +330,38 @@ def test_integration_inversion(dummy_config_inversion, settings, pytestconfig):
figure_dir, title, resol, nsimmax))
plt.close()
# Plot the figure of scalar fluxes increments
plt.figure(figsize=(21, 11))
ax0 = plt.axes([0.05, 0.05, 0.73, 0.87])
im = plt.imshow(dx, extent=(xmin, xmax, ymin, ymax), cmap="YlOrRd")
sc = plt.scatter(coords["lon"], coords["lat"], c=coords["alt"],
cmap="Blues", linewidths=1, edgecolors="k", s=600)
plt.yticks(fontsize=25)
plt.xticks(fontsize=25)
ax1 = plt.axes([0.74, 0.05, 0.05, 0.87])
cb1 = plt.colorbar(im, cax=ax1)
plt.yticks(fontsize=25)
plt.ylabel("Fluxes (a.u.)", fontsize=30)
ax2 = plt.axes([0.86, 0.05, 0.05, 0.87])
cb2 = plt.colorbar(sc, cax=ax2)
plt.yticks(fontsize=25)
plt.ylabel("Station altitude (m a.g.l)", fontsize=30)
ax0.set_title(title, fontsize=45)
current_dir = os.path.abspath(
os.path.dirname(os.path.realpath(__file__)))
figure_dir = \
os.path.abspath(os.path.join(current_dir,
"../../figures_artifact/"))
Path(figure_dir).mkdir(parents=True, exist_ok=True)
plt.savefig("{}/map_dx_scale_{}_{}_{}.pdf".format(
figure_dir, title, resol, nsimmax))
plt.close()
# Plot uncertainty reduction
if "pa_std" in ds:
dstd = ds["b_std"].mean(axis=(0, 1)) \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment