Source code for pycif.plugins.domains.iconart.read_domain


from logging import error
import numpy as np
import xarray as xr
import pandas as pd
import os


[docs] def read_grid(domain, **kwargs): """Read iconart iso-cosahedral grid from a netCDF file. Args: domain (dictionary): dictionary defining the domain. Should include filegrid to be able to read the grid from a file Return: Grid dictionary with meshgrids for center lon/lat and corner lon/lat Notes: """ # Loading the grid dyngrid = xr.open_dataset(domain.dynamics_grid) # True when the domain cannot be defined with a regular 2D array; # instead, it is stored as a flat list of grid cells domain.unstructured_domain = True # Saving information to domain shape # From Warning in http://community-inversion.eu/documentation/plugins/domains/index.html # In the case of unstructured domains, the expected dimensions (nlon / nlat) should ALWAYS be set to: # nlon = number of grid cells nlat = 1 domain.nlon = dyngrid['cell'].size domain.nlat = 1 # A default value is set here. # The real value will be updated when the model is initialize based on the namelist. domain.nlev = 65 # Putting the data into the domain domain.zlon = np.rad2deg(dyngrid['lon_cell_centre'].values)[np.newaxis, :] domain.zlat = np.rad2deg(dyngrid['lat_cell_centre'].values)[np.newaxis, :] # zlonc / zlatc for unstructured domains, # the expected dimension is nvertices / ncells # Need transpose to have correct dimension domain.zlonc = np.rad2deg(dyngrid['clon_vertices'].values.T) domain.zlatc = np.rad2deg(dyngrid['clat_vertices'].values.T) # Do not set the vertical coordinates because it depends # on the simulation # Reading cell areas domain.cell_area = dyngrid['cell_area'].values domain.areas = domain.cell_area[np.newaxis, :] # Attribute the resolution to the domain domain.resolution = f"R{dyngrid.grid_root}B{dyngrid.grid_level:02}" dyngrid.close()