parsac.job.gotm module
- class parsac.job.gotm.Output(name, file, expression, times, zs)
Bases:
NamedTupleCreate new instance of Output(name, file, expression, times, zs)
- class parsac.job.gotm.OutputExtractor(output: Output, wrappednc: NcDict, logger: Logger)
Bases:
objectThis class encapsulates all information necessary to extract a variable from the model output and (optionally) to interpolate the extracted values to the time and location of observations.
- class parsac.job.gotm.OutputPlotter(times: list[datetime], zs: ndarray | None, values: ndarray, obs_times: list[datetime], obs_zs: ndarray | None, previous: dict[str, OutputPlotter])
Bases:
ComparisonPlotterThis class encapsulates the model output and observations necessary to produce a comparison plot for single variable. It also provides one method plot to plot the data in a matplotlib axes object.
Instances of this class will be created in workers and then pickled to be sent to the main process for plotting. Therefore, all its attributes must be picklable.
- plot(ax: matplotlib.axes.Axes, logger: Logger) None
Plot model output versus observations.
- class parsac.job.gotm.Simulation(setup_dir: PathLike[str] | str, *, executable: PathLike[str] | str = 'gotm', exclude_files: Iterable[str] = ('*.nc', '*.cache'), exclude_dirs: Iterable[str] = ('*',), args: Iterable[str] = (), **kwargs: Any)
Bases:
RunnerA simulation with GOTM (General Ocean Turbulence Model).
Call
get_parameter()to select a configurable parameter from a YAML file. This parameter can subsequently be targeted in optimization or sensitivity analysis.Call
request_comparison()to link a model output to observations. This can subsequently contribute to the objective function (likelihood) when performing optimization.Call
record_output()to record specific model outputs. These serve as target metrics to assess the sensitivity of when performing sensitivity analysis. When performing optimization, these outputs will be recorded as diagnostics accompanying each evaluated parameter set.- Parameters:
setup_dir – path to the GOTM setup directory
executable – path to the GOTM executable It can be an absolute path, a path relative to the current working directory, or the name of the executable available via the
PATHenvironment variable.exclude_files – patterns to exclude files from being copied to the working directory
exclude_dirs – patterns to exclude directories from being copied to the working directory
args – additional arguments to pass to the GOTM executable
kwargs – additional keyword arguments to pass to the parent class
parsac.core.Runner.
- get_parameter(file: PathLike[str] | str, variable_path: str, default: Any = None) InitializedParameter
Get a parameter from a YAML file.
The parameter is identified by the path to the YAML file and the location of the variable in the file. This location is a path-like string that uses slashes to separate nested dictionaries, e.g. “a/b/c” for variable c in this file:
a: b: c: 42.0
- Parameters:
file – path to the YAML file (relative to the setup directory)
variable_path – location of the variable in the YAML file
default – default value if the variable is not found. This must be specified for parameters that are not present yet in the YAML file.
- Returns:
A parameter object that can be used in optimization or sensitivity analysis. The value that the parameter has in the YAML file (or
default, if the parameter is not present) is available as theinitial_valueattribute of the parameter.
- output2extractor: dict[str, OutputExtractor]
- prepare_work_dir(work_dir: Path | None) Tuple[Path, bool]
Prepare a work directory. It will reuse an existing work directory (without emptying it), unless you provide an explicit directory path that is different from the previous call.
- record_output(output_file: PathLike[str] | str, output_expression: str)
Request an expression of output variables to be recorded.
In sensitivity analysis, this output will serve as one of the targets to assess the sensitivity of. In optimization, it will serve as additional metric recorded along with each model result.
- Parameters:
output_file – path to the NetCDF output file (relative to the setup directory)
output_expression – expression to evaluate in the output file. It should return a scalar value.
- request_comparison(output_file: PathLike[str] | str, output_expression: str, obs_file: PathLike[str] | str, *, obs_file_format: TextFormat = TextFormat.DEPTH_EXPLICIT, obs_variable: str | None = None, obs_depth_variable: str | None = None, spinupyears: int = 0, mindepth: float = -inf, maxdepth: float = inf) Comparison | None
Request comparison of model results and observations for a particular variable.
- Parameters:
output_file – path to the NetCDF output file (relative to the setup directory)
output_expression – expression to evaluate in the output file. It should produce the model equivalent of the provided observations. It can reference variables from the output file as well as
numpyfunctions.obs_file – path to the file with observations (relative to the current working directory)
obs_file_format – format of the observations file Used only if
obs_fileis a whitespace-separated text file.obs_variable – variable name in the NetCDF file with observations Used only if
obs_fileis a NetCDF file.obs_depth_variable – name of depth variable in the NetCDF file with observations Used only if
obs_fileis a NetCDF file.spinupyears – number of years to skip from the beginning of the simulation when comparing model results to the observations
mindepth – minimum depth of observations; shallower observations are ignored
maxdepth – maximum depth of observations; deeper observations are ignored