Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# the keys are `standard_name` attribute
dimension_data = {
"x_grid_index": irange,
"x_grid_index_at_u_location": irange,
"x_grid_index_at_f_location": irange,
"y_grid_index": jrange,
"y_grid_index_at_v_location": jrange,
"y_grid_index_at_f_location": jrange,
"z_grid_index": krange,
"z_grid_index_at_lower_w_location": krange,
"z_grid_index_at_upper_w_location": krange,
"z_grid_index_at_w_location": krange_p1,
}
for dim in self._dimensions:
dim_meta = dimensions[dim]
dims = dim_meta['dims']
attrs = dim_meta['attrs']
data = dimension_data[attrs['standard_name']]
dim_variable = xr.Variable(dims, data, attrs)
self._variables[dim] = dim_variable
# possibly add the llc dimension
# seems sloppy to hard code this here
# TODO: move this metadata to variables.py
if self.llc:
self._dimensions.append(LLC_FACE_DIMNAME)
data = np.arange(self.nface)
attrs = {'standard_name': 'face_index'}
dims = [LLC_FACE_DIMNAME]
self._variables[LLC_FACE_DIMNAME] = xr.Variable(dims, data, attrs)
self.dirname = dirname
self._ignore_unknown_vars = ignore_unknown_vars
# The endianness of the files
# By default, MITgcm does big endian
if endian not in ['>', '<', '=']:
raise ValueError("Invalid byte order (endian=%s)" % endian)
self.endian = endian
# storage dicts for variables and attributes
self._variables = xr.core.pycompat.OrderedDict()
self._attributes = xr.core.pycompat.OrderedDict()
self._dimensions = []
# the dimensions are theoretically the same for all datasets
[self._dimensions.append(k) for k in dimensions]
self.llc = (self.geometry == 'llc')
# TODO: and maybe here a check for the presence of layers?
# Now we need to figure out the dimensions of the numerical domain,
# i.e. nx, ny, nz. We do this by peeking at the grid file metadata
self.nz, self.nface, self.ny, self.nx = (
_guess_model_dimensions(dirname, self.llc))
self.layers = _guess_layers(dirname)
# Now set up the corresponding coordinates.
# Rather than assuming the dimension names, we use Comodo conventions
# to parse the dimension metdata.
# http://pycomodo.forge.imag.fr/norm.html
irange = np.arange(self.nx)
jrange = np.arange(self.ny)