diff --git a/src/tbxsectors.py b/src/tbxsectors.py index f78487ad92ff8e640562623ae59857265f499726..52fc45c52cd684aa51647f7de36618d146485759 100644 --- a/src/tbxsectors.py +++ b/src/tbxsectors.py @@ -5,7 +5,6 @@ import matplotlib.path as mpath import cartopy.crs as ccrs import cartopy.feature as cfeat from pathlib import Path -from pyproj import CRS, Transformer def define_sectors(ref="RH"): """ @@ -86,8 +85,9 @@ def interp_mask2grid(target_grid=None, Inputs: - target_grid: the target grid on which to interpolate the NSIDC mask. It can be a xr.Dataset containing lat and lon variables defining the grid, or a string mentioning the grid: - if weights='ORCA1_nh', use the weights for Northern Hemisphere ORCA1 config; - if 'ORCA025_nh', use the weights for NorthH for ORCA025 + - if 'ORCA1_nh', use the mask for Northern Hemisphere ORCA1 config; + - if 'ORCA025_nh', use the mask for Northern Hemisphere for ORCA025; + - any other string: a user-calculated mask already interpolated on the target grid. #TODO: need to add full ORCA1 and ORCA025, as well as ORCA12 and ORCA12_nh -maskFile: path and name of file containing the NSIDC mask. @@ -101,41 +101,22 @@ def interp_mask2grid(target_grid=None, ds_mask_interp = xr.open_dataset(Path.cwd().joinpath('../data/NSIDCRegionsMask_ORCA025_nh.nc')) else: ds_mask_interp = xr.open_dataset(target_grid) - else: + else: # If the target grid is a dataset or dataarray, interpolate the mask onto it. # First of all, load the mask ds_mask = xr.open_dataset(maskFile) - # ------------- If no lat-lon in the ds_mask, calculate and add them ------------- - if 'lat' not in list(ds_mask.coords): - # Convert from projected coordinates to lat-lon coordinates - # A first issue is that the mask is provided in North Polar Stereographic projection - # Extract the x and y (projection) coordinates and grid them (from 1D to 2D) - x_mask, y_mask = np.meshgrid(ds_mask.x, ds_mask.y) - # Define the projection and geographic systems according to CRS conventions. - orig_crs = CRS.from_epsg(3413) # North Polar Stereographic from NSIDC - target_crs = CRS.from_epsg(4326) # Geographic coordinate system (i.e. lat-lon) - # Use pyproj.Transformer to convert from NSIDC projection to lat-lon coordinates - transformer = Transformer.from_crs(orig_crs, target_crs) - lat_src, lon_src = transformer.transform(x_mask, y_mask) - # Assign the new coordinates to the dataset - ds_mask = ds_mask.assign_coords({'lon': (['y', 'x'], lon_src), 'lat': (['y', 'x'], lat_src)}) - # ------------- Bulk of the function: interpolate the mask to the ds grid ------------- - # If 'weights' are given, load them directly. If not, calculate them - # But since xesmf does not exist yet on `cyclone`, need to deal with it. - # try: # If xesmf exists, create or load the regridder and regrid - import xesmf as xe # type: ignore + # Import xesmf. Will throw an error if not available + import xesmf as xe + # Create a regridder. Regridder = xe.Regridder(ds_mask, target_grid, method='bilinear') # Now apply this regridder to the mask ds_mask_interp = Regridder(ds_mask) - # except ImportError: # If the import failed, send an error - # print("ERROR: xesmf could not be loaded, go to `coriolis`.") - # return - # return the interpolated mask. + # Return the interpolated mask. return ds_mask_interp def groupby_sectors(ds, ref=None, - target_gd=None, + target_gd=None, maskFile=Path.cwd().joinpath('../data/NSIDCRegions_N3.125km_v1.1_wLatLon_df1.nc')): """ Define sectors and Groupby a dataset or dataArray into those sectors. diff --git a/src/test_tbxsectors.ipynb b/src/test_tbxsectors.ipynb index 09ed7623a9616693837317d09c98237a1cef10a4..4aa546465885dd571d31429db422032a758e2e4a 100644 --- a/src/test_tbxsectors.ipynb +++ b/src/test_tbxsectors.ipynb @@ -426,14 +426,14 @@ " comment: SSTs were observed by conventional thermometer...\n", " summary: ERSST.v5 is developed based on v4 after revisi...\n", " dataset_title: NOAA Extended Reconstructed SST V5\n", - " data_modified: 2022-06-07</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-617b2a36-6a01-43a6-98bc-213f8d857a4e' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-617b2a36-6a01-43a6-98bc-213f8d857a4e' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>lat</span>: 89</li><li><span class='xr-has-index'>lon</span>: 180</li><li><span class='xr-has-index'>time</span>: 624</li><li><span>nbnds</span>: 2</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-cd075066-2506-42fe-b9e6-918525704870' class='xr-section-summary-in' type='checkbox' checked><label for='section-cd075066-2506-42fe-b9e6-918525704870' class='xr-section-summary' >Coordinates: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lat</span></div><div class='xr-var-dims'>(lat)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>88.0 86.0 84.0 ... -86.0 -88.0</div><input id='attrs-80c5e381-20ad-4a3c-93a2-f0a58cf71ddf' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-80c5e381-20ad-4a3c-93a2-f0a58cf71ddf' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-4c3a98f7-ae4e-4fdb-ab63-4c0dfcdd8804' class='xr-var-data-in' type='checkbox'><label for='data-4c3a98f7-ae4e-4fdb-ab63-4c0dfcdd8804' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>degrees_north</dd><dt><span>long_name :</span></dt><dd>Latitude</dd><dt><span>actual_range :</span></dt><dd>[ 88. -88.]</dd><dt><span>standard_name :</span></dt><dd>latitude</dd><dt><span>axis :</span></dt><dd>Y</dd><dt><span>coordinate_defines :</span></dt><dd>center</dd></dl></div><div class='xr-var-data'><pre>array([ 88., 86., 84., 82., 80., 78., 76., 74., 72., 70., 68., 66.,\n", + " data_modified: 2022-06-07</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-81559d84-6a3c-4a43-a7e8-65f5079f799a' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-81559d84-6a3c-4a43-a7e8-65f5079f799a' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>lat</span>: 89</li><li><span class='xr-has-index'>lon</span>: 180</li><li><span class='xr-has-index'>time</span>: 624</li><li><span>nbnds</span>: 2</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-b9866729-ac90-4bf4-88d9-f80de0a7de78' class='xr-section-summary-in' type='checkbox' checked><label for='section-b9866729-ac90-4bf4-88d9-f80de0a7de78' class='xr-section-summary' >Coordinates: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lat</span></div><div class='xr-var-dims'>(lat)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>88.0 86.0 84.0 ... -86.0 -88.0</div><input id='attrs-20bc68b0-f9eb-417e-b43b-b63332a0b822' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-20bc68b0-f9eb-417e-b43b-b63332a0b822' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f0c66eae-4c07-4dd7-a118-82e4c65c844d' class='xr-var-data-in' type='checkbox'><label for='data-f0c66eae-4c07-4dd7-a118-82e4c65c844d' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>degrees_north</dd><dt><span>long_name :</span></dt><dd>Latitude</dd><dt><span>actual_range :</span></dt><dd>[ 88. -88.]</dd><dt><span>standard_name :</span></dt><dd>latitude</dd><dt><span>axis :</span></dt><dd>Y</dd><dt><span>coordinate_defines :</span></dt><dd>center</dd></dl></div><div class='xr-var-data'><pre>array([ 88., 86., 84., 82., 80., 78., 76., 74., 72., 70., 68., 66.,\n", " 64., 62., 60., 58., 56., 54., 52., 50., 48., 46., 44., 42.,\n", " 40., 38., 36., 34., 32., 30., 28., 26., 24., 22., 20., 18.,\n", " 16., 14., 12., 10., 8., 6., 4., 2., 0., -2., -4., -6.,\n", " -8., -10., -12., -14., -16., -18., -20., -22., -24., -26., -28., -30.,\n", " -32., -34., -36., -38., -40., -42., -44., -46., -48., -50., -52., -54.,\n", " -56., -58., -60., -62., -64., -66., -68., -70., -72., -74., -76., -78.,\n", - " -80., -82., -84., -86., -88.], dtype=float32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lon</span></div><div class='xr-var-dims'>(lon)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>0.0 2.0 4.0 ... 354.0 356.0 358.0</div><input id='attrs-1047f3d1-8a6b-4f71-be07-e50552553ee3' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-1047f3d1-8a6b-4f71-be07-e50552553ee3' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-054f9696-a55e-4b93-af02-5fe10e1c189e' class='xr-var-data-in' type='checkbox'><label for='data-054f9696-a55e-4b93-af02-5fe10e1c189e' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>degrees_east</dd><dt><span>long_name :</span></dt><dd>Longitude</dd><dt><span>actual_range :</span></dt><dd>[ 0. 358.]</dd><dt><span>standard_name :</span></dt><dd>longitude</dd><dt><span>axis :</span></dt><dd>X</dd><dt><span>coordinate_defines :</span></dt><dd>center</dd></dl></div><div class='xr-var-data'><pre>array([ 0., 2., 4., 6., 8., 10., 12., 14., 16., 18., 20., 22.,\n", + " -80., -82., -84., -86., -88.], dtype=float32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lon</span></div><div class='xr-var-dims'>(lon)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>0.0 2.0 4.0 ... 354.0 356.0 358.0</div><input id='attrs-3900fac9-18ef-47d7-b685-536223b1d714' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-3900fac9-18ef-47d7-b685-536223b1d714' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f8a1997f-f32a-4d5f-a348-4e89a672c680' class='xr-var-data-in' type='checkbox'><label for='data-f8a1997f-f32a-4d5f-a348-4e89a672c680' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>degrees_east</dd><dt><span>long_name :</span></dt><dd>Longitude</dd><dt><span>actual_range :</span></dt><dd>[ 0. 358.]</dd><dt><span>standard_name :</span></dt><dd>longitude</dd><dt><span>axis :</span></dt><dd>X</dd><dt><span>coordinate_defines :</span></dt><dd>center</dd></dl></div><div class='xr-var-data'><pre>array([ 0., 2., 4., 6., 8., 10., 12., 14., 16., 18., 20., 22.,\n", " 24., 26., 28., 30., 32., 34., 36., 38., 40., 42., 44., 46.,\n", " 48., 50., 52., 54., 56., 58., 60., 62., 64., 66., 68., 70.,\n", " 72., 74., 76., 78., 80., 82., 84., 86., 88., 90., 92., 94.,\n", @@ -448,10 +448,10 @@ " 288., 290., 292., 294., 296., 298., 300., 302., 304., 306., 308., 310.,\n", " 312., 314., 316., 318., 320., 322., 324., 326., 328., 330., 332., 334.,\n", " 336., 338., 340., 342., 344., 346., 348., 350., 352., 354., 356., 358.],\n", - " dtype=float32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>1970-01-01 ... 2021-12-01</div><input id='attrs-86445ef8-0794-4eb0-ad7a-e2b196a7d734' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-86445ef8-0794-4eb0-ad7a-e2b196a7d734' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-d0688bd1-41d4-46ee-883d-608aa3a9cbee' class='xr-var-data-in' type='checkbox'><label for='data-d0688bd1-41d4-46ee-883d-608aa3a9cbee' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Time</dd><dt><span>delta_t :</span></dt><dd>0000-01-00 00:00:00</dd><dt><span>avg_period :</span></dt><dd>0000-01-00 00:00:00</dd><dt><span>prev_avg_period :</span></dt><dd>0000-00-07 00:00:00</dd><dt><span>standard_name :</span></dt><dd>time</dd><dt><span>axis :</span></dt><dd>T</dd><dt><span>actual_range :</span></dt><dd>[19723. 81204.]</dd></dl></div><div class='xr-var-data'><pre>array(['1970-01-01T00:00:00.000000000', '1970-02-01T00:00:00.000000000',\n", + " dtype=float32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>1970-01-01 ... 2021-12-01</div><input id='attrs-761df052-15dd-4f9d-a3eb-9dd198584c9b' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-761df052-15dd-4f9d-a3eb-9dd198584c9b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-0d453433-b763-4d9f-9d71-791e6126d401' class='xr-var-data-in' type='checkbox'><label for='data-0d453433-b763-4d9f-9d71-791e6126d401' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Time</dd><dt><span>delta_t :</span></dt><dd>0000-01-00 00:00:00</dd><dt><span>avg_period :</span></dt><dd>0000-01-00 00:00:00</dd><dt><span>prev_avg_period :</span></dt><dd>0000-00-07 00:00:00</dd><dt><span>standard_name :</span></dt><dd>time</dd><dt><span>axis :</span></dt><dd>T</dd><dt><span>actual_range :</span></dt><dd>[19723. 81204.]</dd></dl></div><div class='xr-var-data'><pre>array(['1970-01-01T00:00:00.000000000', '1970-02-01T00:00:00.000000000',\n", " '1970-03-01T00:00:00.000000000', ..., '2021-10-01T00:00:00.000000000',\n", " '2021-11-01T00:00:00.000000000', '2021-12-01T00:00:00.000000000'],\n", - " dtype='datetime64[ns]')</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-21e2d998-912a-4b2b-922b-5cf328c110de' class='xr-section-summary-in' type='checkbox' checked><label for='section-21e2d998-912a-4b2b-922b-5cf328c110de' class='xr-section-summary' >Data variables: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>time_bnds</span></div><div class='xr-var-dims'>(time, nbnds)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-e312316b-f460-4cda-b92d-ec1def9a42f4' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-e312316b-f460-4cda-b92d-ec1def9a42f4' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-c469ad2d-0dc0-4979-a8b3-35316a3217e0' class='xr-var-data-in' type='checkbox'><label for='data-c469ad2d-0dc0-4979-a8b3-35316a3217e0' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Time Boundaries</dd></dl></div><div class='xr-var-data'><pre>[1248 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>sst</span></div><div class='xr-var-dims'>(time, lat, lon)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-11fa0d23-edea-4794-9d46-e29961a5263a' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-11fa0d23-edea-4794-9d46-e29961a5263a' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-895cabfb-d4c4-4135-9044-74d9d9bab8e7' class='xr-var-data-in' type='checkbox'><label for='data-895cabfb-d4c4-4135-9044-74d9d9bab8e7' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Monthly Means of Sea Surface Temperature</dd><dt><span>units :</span></dt><dd>degC</dd><dt><span>var_desc :</span></dt><dd>Sea Surface Temperature</dd><dt><span>level_desc :</span></dt><dd>Surface</dd><dt><span>statistic :</span></dt><dd>Mean</dd><dt><span>dataset :</span></dt><dd>NOAA Extended Reconstructed SST V5</dd><dt><span>parent_stat :</span></dt><dd>Individual Values</dd><dt><span>actual_range :</span></dt><dd>[-1.8 42.32636]</dd><dt><span>valid_range :</span></dt><dd>[-1.8 45. ]</dd></dl></div><div class='xr-var-data'><pre>[9996480 values with dtype=float32]</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-b758896a-0afa-4f90-ade3-9ffa41c4d304' class='xr-section-summary-in' type='checkbox' ><label for='section-b758896a-0afa-4f90-ade3-9ffa41c4d304' class='xr-section-summary' >Indexes: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>lat</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-603ec69e-ff36-4a44-8299-137afdf32a3c' class='xr-index-data-in' type='checkbox'/><label for='index-603ec69e-ff36-4a44-8299-137afdf32a3c' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([ 88.0, 86.0, 84.0, 82.0, 80.0, 78.0, 76.0, 74.0, 72.0,\n", + " dtype='datetime64[ns]')</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-818c9d07-6279-4381-a159-dfddcdabbedb' class='xr-section-summary-in' type='checkbox' checked><label for='section-818c9d07-6279-4381-a159-dfddcdabbedb' class='xr-section-summary' >Data variables: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>time_bnds</span></div><div class='xr-var-dims'>(time, nbnds)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-0183bb35-9dbc-405f-b0c4-ff1e9dcb3cf1' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-0183bb35-9dbc-405f-b0c4-ff1e9dcb3cf1' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-d6e0cf86-3f5c-474b-adb1-9f2ebc705836' class='xr-var-data-in' type='checkbox'><label for='data-d6e0cf86-3f5c-474b-adb1-9f2ebc705836' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Time Boundaries</dd></dl></div><div class='xr-var-data'><pre>[1248 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>sst</span></div><div class='xr-var-dims'>(time, lat, lon)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-f054578a-4302-4cb9-836c-13bfd82bc991' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-f054578a-4302-4cb9-836c-13bfd82bc991' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-8a48391d-5ce6-4c88-957f-79ed97be7bd6' class='xr-var-data-in' type='checkbox'><label for='data-8a48391d-5ce6-4c88-957f-79ed97be7bd6' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Monthly Means of Sea Surface Temperature</dd><dt><span>units :</span></dt><dd>degC</dd><dt><span>var_desc :</span></dt><dd>Sea Surface Temperature</dd><dt><span>level_desc :</span></dt><dd>Surface</dd><dt><span>statistic :</span></dt><dd>Mean</dd><dt><span>dataset :</span></dt><dd>NOAA Extended Reconstructed SST V5</dd><dt><span>parent_stat :</span></dt><dd>Individual Values</dd><dt><span>actual_range :</span></dt><dd>[-1.8 42.32636]</dd><dt><span>valid_range :</span></dt><dd>[-1.8 45. ]</dd></dl></div><div class='xr-var-data'><pre>[9996480 values with dtype=float32]</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-6550167f-199c-4477-a012-edbd4a108385' class='xr-section-summary-in' type='checkbox' ><label for='section-6550167f-199c-4477-a012-edbd4a108385' class='xr-section-summary' >Indexes: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>lat</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-7d7c4015-bb4d-49ce-94e1-08bf2a058d55' class='xr-index-data-in' type='checkbox'/><label for='index-7d7c4015-bb4d-49ce-94e1-08bf2a058d55' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([ 88.0, 86.0, 84.0, 82.0, 80.0, 78.0, 76.0, 74.0, 72.0,\n", " 70.0, 68.0, 66.0, 64.0, 62.0, 60.0, 58.0, 56.0, 54.0,\n", " 52.0, 50.0, 48.0, 46.0, 44.0, 42.0, 40.0, 38.0, 36.0,\n", " 34.0, 32.0, 30.0, 28.0, 26.0, 24.0, 22.0, 20.0, 18.0,\n", @@ -461,19 +461,19 @@ " -38.0, -40.0, -42.0, -44.0, -46.0, -48.0, -50.0, -52.0, -54.0,\n", " -56.0, -58.0, -60.0, -62.0, -64.0, -66.0, -68.0, -70.0, -72.0,\n", " -74.0, -76.0, -78.0, -80.0, -82.0, -84.0, -86.0, -88.0],\n", - " dtype='float64', name='lat'))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>lon</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-bbea7f43-1180-4025-907c-65db0e9df80f' class='xr-index-data-in' type='checkbox'/><label for='index-bbea7f43-1180-4025-907c-65db0e9df80f' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([ 0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,\n", + " dtype='float64', name='lat'))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>lon</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-8ae9f8f6-3bf0-4d05-873f-f47625c76def' class='xr-index-data-in' type='checkbox'/><label for='index-8ae9f8f6-3bf0-4d05-873f-f47625c76def' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([ 0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,\n", " 18.0,\n", " ...\n", " 340.0, 342.0, 344.0, 346.0, 348.0, 350.0, 352.0, 354.0, 356.0,\n", " 358.0],\n", - " dtype='float64', name='lon', length=180))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>time</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-1e7ba2f4-8bd2-46e0-b945-51a0a17adae2' class='xr-index-data-in' type='checkbox'/><label for='index-1e7ba2f4-8bd2-46e0-b945-51a0a17adae2' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(DatetimeIndex(['1970-01-01', '1970-02-01', '1970-03-01', '1970-04-01',\n", + " dtype='float64', name='lon', length=180))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>time</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-c37f2c12-162f-409e-afcd-d295c0da6766' class='xr-index-data-in' type='checkbox'/><label for='index-c37f2c12-162f-409e-afcd-d295c0da6766' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(DatetimeIndex(['1970-01-01', '1970-02-01', '1970-03-01', '1970-04-01',\n", " '1970-05-01', '1970-06-01', '1970-07-01', '1970-08-01',\n", " '1970-09-01', '1970-10-01',\n", " ...\n", " '2021-03-01', '2021-04-01', '2021-05-01', '2021-06-01',\n", " '2021-07-01', '2021-08-01', '2021-09-01', '2021-10-01',\n", " '2021-11-01', '2021-12-01'],\n", - " dtype='datetime64[ns]', name='time', length=624, freq=None))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-8b69c8d4-a4dc-42dc-8f89-75ebffd8fb92' class='xr-section-summary-in' type='checkbox' ><label for='section-8b69c8d4-a4dc-42dc-8f89-75ebffd8fb92' class='xr-section-summary' >Attributes: <span>(37)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>climatology :</span></dt><dd>Climatology is based on 1971-2000 SST, Xue, Y., T. M. Smith, and R. W. Reynolds, 2003: Interdecadal changes of 30-yr SST normals during 1871.2000. Journal of Climate, 16, 1601-1612.</dd><dt><span>description :</span></dt><dd>In situ data: ICOADS2.5 before 2007 and NCEP in situ data from 2008 to present. Ice data: HadISST ice before 2010 and NCEP ice after 2010.</dd><dt><span>keywords_vocabulary :</span></dt><dd>NASA Global Change Master Directory (GCMD) Science Keywords</dd><dt><span>keywords :</span></dt><dd>Earth Science > Oceans > Ocean Temperature > Sea Surface Temperature ></dd><dt><span>instrument :</span></dt><dd>Conventional thermometers</dd><dt><span>source_comment :</span></dt><dd>SSTs were observed by conventional thermometers in Buckets (insulated or un-insulated canvas and wooded buckets) or Engine Room Intaker</dd><dt><span>geospatial_lon_min :</span></dt><dd>-1.0</dd><dt><span>geospatial_lon_max :</span></dt><dd>359.0</dd><dt><span>geospatial_laty_max :</span></dt><dd>89.0</dd><dt><span>geospatial_laty_min :</span></dt><dd>-89.0</dd><dt><span>geospatial_lat_max :</span></dt><dd>89.0</dd><dt><span>geospatial_lat_min :</span></dt><dd>-89.0</dd><dt><span>geospatial_lat_units :</span></dt><dd>degrees_north</dd><dt><span>geospatial_lon_units :</span></dt><dd>degrees_east</dd><dt><span>cdm_data_type :</span></dt><dd>Grid</dd><dt><span>project :</span></dt><dd>NOAA Extended Reconstructed Sea Surface Temperature (ERSST)</dd><dt><span>original_publisher_url :</span></dt><dd>http://www.ncdc.noaa.gov</dd><dt><span>References :</span></dt><dd>https://www.ncdc.noaa.gov/data-access/marineocean-data/extended-reconstructed-sea-surface-temperature-ersst-v5 at NCEI and http://www.esrl.noaa.gov/psd/data/gridded/data.noaa.ersst.v5.html</dd><dt><span>source :</span></dt><dd>In situ data: ICOADS R3.0 before 2015, NCEP in situ GTS from 2016 to present, and Argo SST from 1999 to present. Ice data: HadISST2 ice before 2015, and NCEP ice after 2015</dd><dt><span>title :</span></dt><dd>NOAA ERSSTv5 (in situ only)</dd><dt><span>history :</span></dt><dd>created 07/2017 by PSD data using NCEI's ERSST V5 NetCDF values</dd><dt><span>institution :</span></dt><dd>This version written at NOAA/ESRL PSD: obtained from NOAA/NESDIS/National Centers for Environmental Information and time aggregated. Original Full Source: NOAA/NESDIS/NCEI/CCOG</dd><dt><span>citation :</span></dt><dd>Huang et al, 2017: Extended Reconstructed Sea Surface Temperatures Version 5 (ERSSTv5): Upgrades, Validations, and Intercomparisons. Journal of Climate, https://doi.org/10.1175/JCLI-D-16-0836.1</dd><dt><span>platform :</span></dt><dd>Ship and Buoy SSTs from ICOADS R3.0 and NCEP GTS</dd><dt><span>standard_name_vocabulary :</span></dt><dd>CF Standard Name Table (v40, 25 January 2017)</dd><dt><span>processing_level :</span></dt><dd>NOAA Level 4</dd><dt><span>Conventions :</span></dt><dd>CF-1.6, ACDD-1.3</dd><dt><span>metadata_link :</span></dt><dd>:metadata_link = https://doi.org/10.7289/V5T72FNM (original format)</dd><dt><span>creator_name :</span></dt><dd>Boyin Huang (original)</dd><dt><span>date_created :</span></dt><dd>2017-06-30T12:18:00Z (original)</dd><dt><span>product_version :</span></dt><dd>Version 5</dd><dt><span>creator_url_original :</span></dt><dd>https://www.ncei.noaa.gov</dd><dt><span>license :</span></dt><dd>No constraints on data access or use</dd><dt><span>comment :</span></dt><dd>SSTs were observed by conventional thermometers in Buckets (insulated or un-insulated canvas and wooded buckets), Engine Room Intakers, or floats and drifters</dd><dt><span>summary :</span></dt><dd>ERSST.v5 is developed based on v4 after revisions of 8 parameters using updated data sets and advanced knowledge of ERSST analysis</dd><dt><span>dataset_title :</span></dt><dd>NOAA Extended Reconstructed SST V5</dd><dt><span>data_modified :</span></dt><dd>2022-06-07</dd></dl></div></li></ul></div></div>" + " dtype='datetime64[ns]', name='time', length=624, freq=None))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-044651d8-9cce-4d4c-ad2c-34ad549915d2' class='xr-section-summary-in' type='checkbox' ><label for='section-044651d8-9cce-4d4c-ad2c-34ad549915d2' class='xr-section-summary' >Attributes: <span>(37)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>climatology :</span></dt><dd>Climatology is based on 1971-2000 SST, Xue, Y., T. M. Smith, and R. W. Reynolds, 2003: Interdecadal changes of 30-yr SST normals during 1871.2000. Journal of Climate, 16, 1601-1612.</dd><dt><span>description :</span></dt><dd>In situ data: ICOADS2.5 before 2007 and NCEP in situ data from 2008 to present. Ice data: HadISST ice before 2010 and NCEP ice after 2010.</dd><dt><span>keywords_vocabulary :</span></dt><dd>NASA Global Change Master Directory (GCMD) Science Keywords</dd><dt><span>keywords :</span></dt><dd>Earth Science > Oceans > Ocean Temperature > Sea Surface Temperature ></dd><dt><span>instrument :</span></dt><dd>Conventional thermometers</dd><dt><span>source_comment :</span></dt><dd>SSTs were observed by conventional thermometers in Buckets (insulated or un-insulated canvas and wooded buckets) or Engine Room Intaker</dd><dt><span>geospatial_lon_min :</span></dt><dd>-1.0</dd><dt><span>geospatial_lon_max :</span></dt><dd>359.0</dd><dt><span>geospatial_laty_max :</span></dt><dd>89.0</dd><dt><span>geospatial_laty_min :</span></dt><dd>-89.0</dd><dt><span>geospatial_lat_max :</span></dt><dd>89.0</dd><dt><span>geospatial_lat_min :</span></dt><dd>-89.0</dd><dt><span>geospatial_lat_units :</span></dt><dd>degrees_north</dd><dt><span>geospatial_lon_units :</span></dt><dd>degrees_east</dd><dt><span>cdm_data_type :</span></dt><dd>Grid</dd><dt><span>project :</span></dt><dd>NOAA Extended Reconstructed Sea Surface Temperature (ERSST)</dd><dt><span>original_publisher_url :</span></dt><dd>http://www.ncdc.noaa.gov</dd><dt><span>References :</span></dt><dd>https://www.ncdc.noaa.gov/data-access/marineocean-data/extended-reconstructed-sea-surface-temperature-ersst-v5 at NCEI and http://www.esrl.noaa.gov/psd/data/gridded/data.noaa.ersst.v5.html</dd><dt><span>source :</span></dt><dd>In situ data: ICOADS R3.0 before 2015, NCEP in situ GTS from 2016 to present, and Argo SST from 1999 to present. Ice data: HadISST2 ice before 2015, and NCEP ice after 2015</dd><dt><span>title :</span></dt><dd>NOAA ERSSTv5 (in situ only)</dd><dt><span>history :</span></dt><dd>created 07/2017 by PSD data using NCEI's ERSST V5 NetCDF values</dd><dt><span>institution :</span></dt><dd>This version written at NOAA/ESRL PSD: obtained from NOAA/NESDIS/National Centers for Environmental Information and time aggregated. Original Full Source: NOAA/NESDIS/NCEI/CCOG</dd><dt><span>citation :</span></dt><dd>Huang et al, 2017: Extended Reconstructed Sea Surface Temperatures Version 5 (ERSSTv5): Upgrades, Validations, and Intercomparisons. Journal of Climate, https://doi.org/10.1175/JCLI-D-16-0836.1</dd><dt><span>platform :</span></dt><dd>Ship and Buoy SSTs from ICOADS R3.0 and NCEP GTS</dd><dt><span>standard_name_vocabulary :</span></dt><dd>CF Standard Name Table (v40, 25 January 2017)</dd><dt><span>processing_level :</span></dt><dd>NOAA Level 4</dd><dt><span>Conventions :</span></dt><dd>CF-1.6, ACDD-1.3</dd><dt><span>metadata_link :</span></dt><dd>:metadata_link = https://doi.org/10.7289/V5T72FNM (original format)</dd><dt><span>creator_name :</span></dt><dd>Boyin Huang (original)</dd><dt><span>date_created :</span></dt><dd>2017-06-30T12:18:00Z (original)</dd><dt><span>product_version :</span></dt><dd>Version 5</dd><dt><span>creator_url_original :</span></dt><dd>https://www.ncei.noaa.gov</dd><dt><span>license :</span></dt><dd>No constraints on data access or use</dd><dt><span>comment :</span></dt><dd>SSTs were observed by conventional thermometers in Buckets (insulated or un-insulated canvas and wooded buckets), Engine Room Intakers, or floats and drifters</dd><dt><span>summary :</span></dt><dd>ERSST.v5 is developed based on v4 after revisions of 8 parameters using updated data sets and advanced knowledge of ERSST analysis</dd><dt><span>dataset_title :</span></dt><dd>NOAA Extended Reconstructed SST V5</dd><dt><span>data_modified :</span></dt><dd>2022-06-07</dd></dl></div></li></ul></div></div>" ], "text/plain": [ "<xarray.Dataset>\n", @@ -562,7 +562,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -641,7 +641,7 @@ { "data": { "text/plain": [ - "<xarray.plot.facetgrid.FacetGrid at 0x7f75f5999ab0>" + "<xarray.plot.facetgrid.FacetGrid at 0x7f6c37b0a3e0>" ] }, "execution_count": 6, @@ -720,7 +720,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -729,7 +729,7 @@ "Text(0.5, 1.02, 'SST Anomalies for each Southern Ocean sector (Raphael & Hobbs 2014 definition)')" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" }, @@ -747,6 +747,7 @@ "source": [ "# Divide by sector and average directly.\n", "da_sst_mean_south = tbsec.groupby_sectors(ds_test.sst, ref='RH').mean()\n", + "# Then calculate a climatology and remove it from the SST to get anomalies.\n", "da_sst_anom_south = da_sst_mean_south.groupby('time.month') - da_sst_mean_south.groupby('time.month').mean()\n", "# Plot the time series anomalies\n", "gs = da_sst_anom_south.plot(col='sector', col_wrap=3)\n",