Source code for pycif.plugins.modes.co2mvs.utils.adjoint
from .....utils import path
from .....utils.yml import ordered_dump
from logging import info
import subprocess
[docs]
def run_adjoint(self, ):
workdir = self.workdir
controlvect = self.controlvect
platform = self.platform
# Create the batch directory
ref_fwd_dir = f"{workdir}/sub_runs/backward_propagation"
path.init_dir(ref_fwd_dir)
# Dump the reference control vector to the directory
controlvect.dump(
f"{ref_fwd_dir}/controlvect.pickle",
to_netcdf=controlvect.save_out_netcdf,
dir_netcdf=f"{ref_fwd_dir}/controlvect/")
# Updating configuration dictionary
yml_dict = \
self.from_yaml(
self.reference_instances["reference_setup"].def_file)
yml_dict["workdir"] = ref_fwd_dir
yml_dict["mode"] = {
**yml_dict["mode"],
**{"plugin": {
"name": "footprint",
"version": "std"
}
}
}
yml_dict["obsoperator"]["ref_fwd_dir"] = f"{ref_fwd_dir}/../ref_forward/"
# Dumps new yml file
yml_file = f"{ref_fwd_dir}/config_backward_adjoint.yml"
with open(yml_file, "w") as outfile:
ordered_dump(outfile, yml_dict)
# Running the forward
info("Running the backward propagation of increments as a sub-process")
process = subprocess.Popen(
f"{platform.python} -m pycif {yml_file}".split(),
cwd=ref_fwd_dir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = process.communicate()