Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid halo #141

Closed
sol1105 opened this issue Mar 4, 2021 · 4 comments
Closed

Grid halo #141

sol1105 opened this issue Mar 4, 2021 · 4 comments

Comments

@sol1105
Copy link
Contributor

sol1105 commented Mar 4, 2021

  • clisops version: 0.6.1

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:

  • averaging: the duplicated values might influence global / regional / polygon averages
  • subset: subset by area/shape might select the duplicate grid points which might or might not be desired
  • regrid: I experienced problems creating regridding weights (other than bilinear and nearest neighbour) with xESMF when a halo was present

Regarding the halo there are two more issues:

  • In case of a staggered grid ("On a staggered grid the scalar variables (pressure, density, total enthalpy etc.) are stored in the cell centers of the control volumes, whereas the velocity or momentum variables are located at the cell faces.") one may not simply cut off the halo for variables defined on the cell faces/vertices as for them the halo columns/rows hold actual (not duplicated) information. When dealing with variables defined on the u-points or v-points of a staggered grid, one has to rotate these into latitudinal and longitudinal direction before regridding (and probably also before a spacial average?!).
  • In case of MPI-ESM1-2-HR MPIOM there are also extra rows added that have to be removed before processing / analysing the data. These extra rows are also part of the halo. Due to the grid layout, some rows almost have a north-south alignment (see the notebook linked in the next post). In that regard it seems for some grids rows/columns are only partially duplicated.

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
Copy link
Contributor Author

sol1105 commented Mar 10, 2021

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
Copy link
Contributor Author

sol1105 commented Mar 12, 2021

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
Copy link
Collaborator

@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
Copy link
Contributor Author

sol1105 commented Nov 23, 2023

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,
                )

@sol1105 sol1105 closed this as completed Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants