Skip to content

Commit

Permalink
Merge pull request #35 from NOAA-CEFI-Portal/develop
Browse files Browse the repository at this point in the history
Including the Cold Pool Index in index module
  • Loading branch information
chiaweh2 authored Jun 21, 2024
2 parents 757ad27 + 550cd86 commit d3063fd
Show file tree
Hide file tree
Showing 18 changed files with 7,531 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gha_pytest_pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR pytest unittest
name: PR unittest

on:
pull_request:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/gha_pytest_push.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: push pytest unittest
name: unittest

on:
push:
branches:
- develop
- main

jobs:
Expand Down
105 changes: 103 additions & 2 deletions mom6/mom6_module/mom6_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def __init__(
ds_data : xr.Dataset,
ssh_name : str = 'ssh'
) -> None:
"""_summary_
"""
Parameters
----------
ds_data : xr.Dataset
Expand Down Expand Up @@ -187,3 +186,105 @@ def generate_index(
ds_gs['gulf_stream_index'] = da_gs_index

return ds_gs

class ColdPoolIndex:
"""
This class is used to create the Cold Pool Index calculation
Original sources are [Ross et al., 2023](https://gmd.copernicus.org/articles/16/6943/2023/).
and [GFDL CEFI github repository]
(https://github.com/NOAA-GFDL/CEFI-regional-MOM6/blob/main
/diagnostics/physics/NWA12/coldpool.py)
"""
def __init__(
self,
ds_data: xr.Dataset,
ds_cpi_mask: xr.Dataset,
bottom_temp_name: str = 'bottomT',
mask_name: str = 'CPI_mask'
) -> None:
"""
Parameters
----------
ds_data: xr.Dataset
The bottom temperature dataset used to
derive the cold pool index.
ds_cpi_mask: xr.Dataset
The CPI mask.
bottomT_name" str
The bottom temperature variable name in the data set
mask_name" str
The CPI mask variable name in the `ds_cpi_mask`
"""
self.dataset = ds_data
self.mask = ds_cpi_mask
self.varname = bottom_temp_name
self.maskname = mask_name

def regrid_and_mask(self)->xr.DataArray:
"""
Regrid data from MOM6 model to the mask grid
to apply the mask
Returns
-------
da_regrid : xr.DataArray
regridded and masked dataset
"""
ds_mask = self.mask
ds_data = self.dataset

# Regrid the regional MOM6 data to GLORYS grid
# Use xesmf to create regridder using bilinear method
# !!!! Regridded only suited for geolon and geolat to x and y
regridder = xe.Regridder(
ds_data.rename({'geolon':'lon','geolat':'lat'}),
ds_mask,
"bilinear",
unmapped_to_nan=True
)

# Perform regrid using adaptive masking
# https://pangeo-xesmf.readthedocs.io/en/latest/
# notebooks/Masking.html#Adaptive-masking
da_regrid = regridder(ds_data[self.varname], skipna=True, na_thres=0.25).compute()
da_regrid = da_regrid*ds_mask[self.maskname]

return da_regrid

def generate_index(self):
'''
Masked data to the Coldpool Domain and Calculate Index
Coldpool Domain:
Depth: Between 20m and 200m isobath
Time: Between June and September from 1959 to 2022
Temperature: Average bottom temperature was cooler than 10 degrees Celsius (and > 6?)
Location: Mid-Atlantic Bight (MAB) domain between 38N-41.5N and between 75W-68.5W
Returns
-------
da_cpi_ann : xr.DataArray
Yearly cold pool index calculation based on yearly climatology
'''
#Get masked data and regrid it
da_regrid = self.regrid_and_mask()

#Calculate annual time series and long term mean at each grid
da_tob_jun2sep = da_regrid.where(
(da_regrid['time.month']>=6)&
(da_regrid['time.month']<=9),
drop=True
)
da_tob_ann = (
da_tob_jun2sep
.groupby(da_tob_jun2sep['time.year'])
.mean(dim='time')
).compute()
da_tob_ann_ltm = da_tob_ann.mean('year')

#Compute Cold Pool Index using the logic found here:
# https://noaa-edab.github.io/tech-doc/cold_pool.html
da_tob_ann_anom = da_tob_ann-da_tob_ann_ltm
da_cpi_ann = da_tob_ann_anom.mean(['latitude', 'longitude'])

return da_cpi_ann
Loading

0 comments on commit d3063fd

Please sign in to comment.