roocs / clisops

Climate Simulation Operations
https://clisops.readthedocs.io/en/latest/
Other
21 stars 9 forks source link

Grid halo #141

Closed sol1105 closed 10 months ago

sol1105 commented 3 years ago

Description

Climate model data can be provided on grids that feature a halo, which are duplicated columns at the eastern and/or western bounds of the model grid (eg. MPI-ESM1-2-LR/HR MPIOM). Here is a quote from the NEMO ocean engine document:

Since bicubic interpolation requires the calculation of gradients at eachpoint on the grid, the corresponding arrays are dimensioned with a halo of width one grid point all the way around. When the array of points from the data file is adjacent to an edge of the data grid, the halo is either a copy of the row/column next to it (non-cyclical case), or is a copy of one from the first few columns on the opposite side of the grid (cyclical case).

The cyclical case is sketched here: Screenshot from 2021-03-04 18-05-29

The data on the halo grid points might influence the clisops operators:

Regarding the halo there are two more issues:

A first way to identify the unique columns of a grid

# 2D latitude and longitude arrays - create an array of (lat,lon) tuples
latlon_halo=np.array(list(zip(ds["latitude"].values.ravel(),ds["longitude"].values.ravel())),
                     dtype=('double,double')).reshape(ds["longitude"].values.shape)

# use numpy.unique to identify unique columns
latlon_no_halo,indices=np.unique(latlon_halo, axis=1, return_index=True)

Looking forward to your comments and suggestions :)

sol1105 commented 3 years ago

Here a jupyter notebook in which I try to detect duplicate cells in most of the CMIP6 ocean model grids: https://nbviewer.jupyter.org/github/roocs/regrid-prototype/blob/main/docs/notebooks/Detect_duplicated_grid_cells.ipynb

sol1105 commented 3 years ago

For the model CESM2-FV2 the duplicated grid cells do not result from a halo but from missing values within the lat and lon coordinate variables. I do not think that this is conformal with CF or CMIP requirements, but how would clisops react to that?

Here eg. the lon variable as shown by ncview: Screenshot from 2021-03-12 08-02-01

agstephens commented 3 years ago

@sol1105 I just saw some code from the Met Office for removing the halo from their own models. I am just noting it here in case it is of use to us. It uses NCO:

ncks -O -dx,1,360 -dy,1,330 filename -o temporary_filename
sol1105 commented 10 months ago

The missing value problem with data from CESM2-FV2 has to be addressed in a daops/dachar fix as it results from a not set _FillValue attribute. With lon values outside [-360, 360] degrees and lat values outside [-90,90] for these not masked missing values, clisops will raise an exception.

The general issue with the halo has been solved in #243 : adaptive masking can be used to renormalize contributions from halo cells (duplicated cells) even when not "activating" adaptive masking for renormalization of partly masked cells. Excerpt from core.regrid.regrid:

# Re-normalize at least contributions from duplicated cells, if adaptive masking is deactivated
 if (adaptive_masking_threshold < 0 or adaptive_masking_threshold > 1) and grid_in.contains_duplicated_cells:
        adaptive_masking_threshold = 0.0
        grid_out.ds[data_var] = weights.regridder(
                    grid_in.ds[data_var],
                    skipna=True,
                    na_thres=adaptive_masking_threshold,
                )