Source code for pycif.plugins.datastreams.fields.bc_plugin_template.get_domain

"""
Retrieves the characteristics of the spatial domain on which the data is provided.

Args:
------
- ref_dir: directory where the original data files are found
- ref_file: (template) name of the original files
- input_interval: XX???XXX
- target_dir: directory where the links to the orginal files are created

Returns:
---------
- the setup of the domain, done in section "Initializes domain"



"""

import numpy as np

from .....utils.classes.setup import Setup


[docs] def get_domain(ref_dir, ref_file, input_interval, target_dir, tracer=None): print('Here, read the horizontal grid e.g. longitudes and latitudes') domain_file = None print('Several possibilities: a) read a reference file') print(' b) read any file among all the available data files') print('c) read a file specified in the yaml') # XXX Put examples XXX print('Domain file for template BCs:', domain_file) # Better to raise exception if no domain is found if domain_file is None: raise Exception( "BC template domain could not be initialized as no file was found" ) print('From this file, obtain the coordinates of the centers and/or the corners of the grid cells') print('If corners or centers are not available, deduce them from the available information') print('WARNING: the grid must not be overlapping e.g for a global grid, the last grid cell must not be the same as the first') print('Order the centers and corners latitudes and longitudes in increasing order') print('Get the min and max latitude and longitude of centers + the number of longitudes and latitudes') print('Here, read the vertical information, from the same file as the horizontal information or from another') print('Get the number of vertical levels') print('Get or deduce the coefficients XXX et si on n\'est pas en sigma??XXX from bottom to top.') # Initializes domain setup = Setup.from_dict( { "domain": { "plugin": { "name": "template", "version": "std", "type": "domain", }, "xmin": lon_min, # minimum longitude for centers "xmax": lon_max, # maximum longitude for centers "ymin": lat_min, # minimum latitude for centers "ymax": lat_max, # maximum latitude for centers "nlon": nlon, # number of longitudinal cells "nlat": nlat, # number of latitudinal cells "nlev": nlevs, # number of vertical levels "sigma_a": sigma_a, "sigma_b": sigma_b, "pressure_unit": "Pa" # adapted to sigmas } } ) Setup.load_setup(setup, level=1) # if lon and lat are vectors, convert into a grid with # zlon, zlat = np.meshgrid(lon, lat) setup.domain.zlon = zlon # longitudes of centers setup.domain.zlat = zlat # latitudes of centers setup.domain.zlonc = zlonc # longitudes of corners setup.domain.zlatc = zlatc # latitudes of corners return setup.domain