Reputation: 45
I'm pretty new to both python and dealing with netCDF files, I've been trying for some time to subset a CMIP output by latitude. All the examples I've been following seem to do this pretty straightforward by just extracting based on lat/lon.
The issue I have is that for my experiment the dimensions are in 'nlat' and 'nlon' format (I gather this is number of latitudes). So far I've figured out this is probably something to do with the grid and that I will need to convert it from an array in order to get 'real' latitudes and longitudes (which I can then subset).
This experiment contains ocean chlorophyll data, my ultimate aim is to be able to subset the experiment to get averages over latitudinal bands in the Southern Hemisphere. I'm not looking for a precise answer of how to get to this, but more if anyone has any pointers on how I can transform this file to be dealing with real coordinates.
Any advice would be really appreciated. Thanks!
The full dump of file info is here:
Conventions: CF-1.7 CMIP-6.2
activity_id: ScenarioMIP
branch_method: standard
branch_time_in_child: 735110.0
branch_time_in_parent: 735110.0
case_id: 1731
cesm_casename: b.e21.BSSP245cmip6.f09_g17.CMIP6-SSP2-4.5.102
contact: [email protected]
creation_date: 2020-05-26T19:43:22Z
data_specs_version: 01.00.31
experiment: SSP-based RCP scenario with medium radiative forcing by the end of the century. Following approximately RCP4.5 global forcing pathway with SSP2 socioeconomic conditions. Radiative forcing reaches a level of 4.5 W/m2 in 2100. Concentration-driven.
experiment_id: ssp245
external_variables: areacello volcello
forcing_index: 1
frequency: mon
further_info_url: https://furtherinfo.es-doc.org/CMIP6.NCAR.CESM2.ssp245.none.r11i1p1f1
grid: native gx1v7 displaced pole grid (384x320 latxlon)
grid_label: gn
initialization_index: 1
institution: National Center for Atmospheric Research, Climate and Global Dynamics Laboratory, 1850 Table Mesa Drive, Boulder, CO 80305, USA
institution_id: NCAR
mip_era: CMIP6
model_doi_url: https://doi.org/10.5065/D67H1H0V
nominal_resolution: 100 km
parent_activity_id: CMIP
parent_experiment_id: historical
parent_mip_era: CMIP6
parent_source_id: CESM2
parent_time_units: days since 0001-01-01 00:00:00
parent_variant_label: r11i1p1f1
physics_index: 1
product: model-output
realization_index: 11
realm: ocnBgchem
source: CESM2 (2017): atmosphere: CAM6 (0.9x1.25 finite volume grid; 288 x 192 longitude/latitude; 32 levels; top level 2.25 mb); ocean: POP2 (320x384 longitude/latitude; 60 levels; top grid cell 0-10 m); sea_ice: CICE5.1 (same grid as ocean); land: CLM5 0.9x1.25 finite volume grid; 288 x 192 longitude/latitude; 32 levels; top level 2.25 mb); aerosol: MAM4 (0.9x1.25 finite volume grid; 288 x 192 longitude/latitude; 32 levels; top level 2.25 mb); atmoschem: MAM4 (0.9x1.25 finite volume grid; 288 x 192 longitude/latitude; 32 levels; top level 2.25 mb); landIce: CISM2.1; ocnBgchem: MARBL (320x384 longitude/latitude; 60 levels; top grid cell 0-10 m)
source_id: CESM2
source_type: AOGCM BGC AER
sub_experiment: none
sub_experiment_id: none
table_id: Omon
tracking_id: hdl:21.14100/2f01427e-7a24-40fe-93a6-88c87923afea
variable_id: chl
variant_info: CMIP6 SSP2-4.5 experiments (2015-2100) with CAM6, interactive land (CLM5), coupled ocean (POP2) with biogeochemistry (MARBL), interactive sea ice (CICE5.1), and non-evolving land ice (CISM2.1).
variant_label: r11i1p1f1
dimensions(sizes): nlat(384), vertices(4), lev(15), time(600), d2(2), nlon(320)
variables(dimensions): float32 chl(time,lev,nlat,nlon), float64 lat(nlat,nlon), float64 lev(lev), float64 lon(nlat,nlon), int32 nlat(nlat), int32 nlon(nlon), float64 time(time), float64 time_bnds(time,d2), float32 lat_bnds(nlat,nlon,vertices), float32 lon_bnds(nlat,nlon,vertices), float32 lev_bnds(lev,d2)
groups:
Upvotes: 0
Views: 375
Reputation: 3397
The easiest way to deal with this is Python is possibly my nctoolkit package (https://nctoolkit.readthedocs.io/en/latest/). You could do this using xarray, but you would need to modify any code for each CMIP model grid.
nctoolkit uses CDO as a backend, and should be able to handle more or less any CMIP grid, apart from the group that uses a highly irregular grid. But the one you mention should be fine.
If you wanted to work out the mean by latitude (zonal mean) for the southern hemisphere, you could do the following:
import nctoolkit as nc
ds = nc.open_data("infile.nc")
ds.crop(lat = [-90,0])
ds.zonal_mean()
# to visualize
ds.plot()
Upvotes: 2