This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def select_interior(ds): | |
| """ | |
| discard "exterior" u,v,rho-points to build a symetric grid | |
| Parameters: | |
| ds (xarray.Dataset): ROMS dataset | |
| """ | |
| ds = ds.isel(xi_rho=slice(1,-1), eta_rho=slice(1,-1)) | |
| if 'xi_v' in ds.dims: | |
| ds = ds.isel(xi_v=slice(1,-1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def rename_dims(ds): | |
| """ rename dimensions | |
| Parameters: | |
| ds (xarray.Dataset): ROMS dataset | |
| """ | |
| ds = ds.rename({'xi_rho': 'xh', 'xi_v': 'xh', 'xi_u': 'xq', 'xi_psi': 'xq', | |
| 'eta_rho': 'yh', 'eta_v': 'yq', 'eta_u': 'yh', 'eta_psi': 'yq', | |
| 'ocean_time': 'time' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_coords(ds): | |
| """ set coordinate variables as xarray coordinates | |
| Parameters: | |
| ds (xarray.Dataset): ROMS dataset | |
| """ | |
| ds = ds.set_coords(['Cs_r', 'Cs_w', 'hc', 'h', 'Vtransform', 'time', | |
| 'lon_rho', 'lon_v', 'lon_u', 'lon_psi', | |
| 'lat_rho', 'lat_v', 'lat_u', 'lat_psi']) | |
| return ds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import xarray as xr | |
| import glob | |
| # use glob to create a list of files to convert | |
| filelist = glob.glob('data/CCS2_avg_*.nc') | |
| # path to grid file | |
| gridfile = 'grid/CCS2_grid.nc' | |
| # output store name | |
| store_name = 'CCS2_store' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import xarray as xr | |
| from xgcm import Grid | |
| CCS2 = xr.open_zarr(CCS2_store, consolidated=True) | |
| # Create xgcm grid object | |
| grid_ccs2 = Grid(CCS2, coords={'X': {'center': 'xh', 'outer': 'xq'}, | |
| 'Y': {'center': 'yh', 'outer': 'yq'}, | |
| 'Z': {'center': 's_rho', 'outer': 's_w'}}, | |
| periodic=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def compute_depth_layers(ds, grid, hmin=0.1): | |
| """ compute depths of ROMS vertical levels (Vtransform = 2) """ | |
| # compute vertical transformation functional | |
| S_rho = (ds.hc * ds.s_rho + ds.Cs_r * ds.h) / (ds.hc + ds.h) | |
| S_w = (ds.hc * ds.s_w + ds.Cs_w * ds.h) / (ds.hc + ds.h) | |
| # compute depth of rho (layers) and w (interfaces) points | |
| z_rho = ds.zeta + (ds.zeta + ds.h) * S_rho | |
| z_w = ds.zeta + (ds.zeta + ds.h) * S_w |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import cmocean | |
| plt.figure(figsize=[10,8]) | |
| CCS2['v'].isel(time=12, yq=500).plot(x='lon_v', y='z_v', | |
| vmin=-0.25, vmax=0.25, | |
| cmap=cmocean.cm.balance, | |
| subplot_kws={'facecolor': 'grey'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cmocean | |
| import cartopy.crs as ccrs | |
| import matplotlib.pyplot as plt | |
| # extract temperature and depth for a given time | |
| snapshot = CCS2.isel(time=50) | |
| temp_snapshot = snapshot['temp'] | |
| depth_snapshot = snapshot['z_rho'] | |
| # compute temperature at 100 meters depth using xgcm.transform |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import xarray as xr | |
| import numpy as np | |
| from matplotlib import pyplot as plt | |
| from matplotlib import animation | |
| import matplotlib.image as image | |
| import cartopy.crs as ccrs | |
| from owslib.wms import WebMapService | |
| from matplotlib import cm | |
| import os | |
| from xgcm import Grid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: meatpotatoes | |
| channels: | |
| - conda-forge | |
| dependencies: | |
| - python | |
| - pip | |
| - black | |
| - cartopy | |
| - cftime | |
| - cmocean |