JMMP-Group / nordic-seas-validation

MIT License
0 stars 0 forks source link

Add class to extract sections from model #17

Closed malmans2 closed 2 years ago

malmans2 commented 2 years ago

I'm doing a bit of validation this week, so I've added a class to extract sections from model. I've added 3 functions. All of them only use the domain_cfg to find indexes corresponding to the observations. That indexes can be used with isel to extract data from the model. Functions are:

  1. nearest_neighbor - uses xoak under the hood
  2. zigzag_section - section following the model grid
  3. velocity_points_along_zigzag_section - index needed to extract velocities and compute accurate volume fluxes (i.e., u and v points laying on a zigzag path along the f-grid)

I've adapted from other scripts, so make sure that everything is working as expected because we don't have tests right now. Example usage:

from nsv import SectionFinder, Standardizer
import xarray as xr
rootpath = "/noc/msm/scratch/nemo2/IMMERSE/malmans/SHARED/GSRIDGE36Z"
domain = xr.open_mfdataset(f"{rootpath}/GRID/GSRIDGE36Z_domain_cfg.nc", drop_variables=("x", "y"))
ds_tgrid = xr.open_mfdataset(f"{rootpath}/OUTPUT/2012/GSRIDGE36Z_5d_mean_grid_T_20120105-20120109.nc")
section_obs = Standardizer().latrabjarg_climatology
finder = SectionFinder(domain)
stations = finder.nearest_neighbor(
    lons=section_obs.cf["longitude"],
    lats=section_obs.cf["latitude"],
    grid="t"
)
section_model = ds_tgrid.isel({dim: stations[f"{dim}_index"] for dim in ("x", "y")})
section_model.cf["sea_water_potential_temperature"].plot(center=False, ylim=(700, 0))

image

malmans2 commented 2 years ago

Cool, thanks for the review! I'll merge so we can start using/testing it. (I'll probably add some quick test as soon as I can) The structure is quite lightweight - it should be easy to add more algorithms in the future.

leonchafik commented 2 years ago

This is very helpful and neat @malmans2 Thanks!