Source code for pycif.plugins.datastreams.fluxes.unstructured_NetCDF.get_domain
import os
import itertools
from logging import debug
from ....domains.unstructured_NetCDF import grid_arguments, vcoord_arguments
from .....utils.classes.setup import Setup
[docs]
def get_domain(ref_dir, ref_file, input_interval=None, target_dir=None, tracer=None):
"""Read information from the reference file
to define the data horizontal and, if relevant, vertical domain.
Args:
ref_dir (str): the path to the input files
ref_file (str): format of the input files
input_interval (list): simulation interval (start and end dates)
target_dir (str): where to copy
tracer: the tracer Plugin
Return:
domain (Domain): a domain class object, with the definition of the
center grid cells coordinates, as well as corners
"""
# Getting tracer's input files
if tracer is not None and hasattr(tracer, 'input_files'):
domain_file = list(itertools.chain.from_iterable(
tracer.input_files.values()))
if not domain_file:
raise ValueError(f"no 'input_files' found for tracer '{tracer}'")
domain_file = domain_file[0]
else:
domain_file = os.path.join(ref_dir, ref_file)
if not os.path.isfile(domain_file):
raise FileNotFoundError(f"file '{domain_file}' not found")
input_arguments = {key: val for key, val in Setup.to_dict(tracer).items()
if key in [*grid_arguments, *vcoord_arguments]}
debug(f"Reading unstructured 'gridded_netcdf' domain from '{domain_file}' "
f"with arguments: {input_arguments}")
# Initializes domain
plugin = Setup.from_dict({
'domain': {
'plugin': {
'type': "domain",
'name': "gridded_netcdf",
'version': "unstructured"
},
'file': domain_file,
**input_arguments
}
})
# Loads the domain plugin
Setup.load_setup(plugin, level=1)
return plugin.domain