Commit 74233811 authored by pavan kumar.siligam's avatar pavan kumar.siligam

2d variables with cdo

parent 82580fe3
*.nc
*.pyc
notebooks/tmp
notebooks/.ipynb_checkpoints
.gitignore
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was created using \"Python 2.7.12\" kernel from jupyerhub service from DKRZ"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>.container { width:100% !important; }</style>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# this code will expand the width of the cells to fit the entire screen \n",
"from IPython.core.display import display, HTML\n",
"display(HTML(\"<style>.container { width:100% !important; }</style>\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# processing 2d variables using cdo"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## overview\n",
"\n",
"- selecting variable of interest\n",
"- setting grid information\n",
"- selecting stations of interest\n",
"- selecting region of interest\n",
"- remapping to regular grid (lat, lon)\n",
"- chaining cdo operators\n",
"- working with multiple files, merging data-sets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"for this exercise, we consider the following file"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"filename = '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### selecting variable of interest"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since, we picked 2d_cloud file, we select the following variable\n",
"\n",
"clwvi\n",
" - **standard_name**: tqc_dia\n",
" - **long_name**: total column integrated cloud water (diagnostic)\n",
" - **units**: kg m$^{-2}$\n",
"\n",
"syntax:\n",
"\n",
"```cdo selvar,<varname> ifile ofile```"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" prw clwvi clivi clt z_pbl rain_gsp_rate ice_gsp_rate snow_gsp_rate hail_gsp_rate graupel_gsp_rate hbas_con htop_con cct t_ctop ccb t_cbase clch clcm clcl htop_dc\r\n",
"cdo showname: Processed 20 variables ( 0.03s )\r\n"
]
}
],
"source": [
"! cdo showvar $filename"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cdo selname: Processed 1336938240 values from 20 variables over 60 timesteps ( 11.96s )\r\n"
]
}
],
"source": [
"#!mkdir tmp\n",
"!cdo -O selvar,clwvi $filename tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" clwvi\r\n",
"cdo showname: Processed 1 variable ( 0.01s )\r\n"
]
}
],
"source": [
"!cdo showvar tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### setting grid information"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Typically, data files do not have grid information. Since, we the data file belongs to domain DOM03 we set the following grid file.\n",
"\n",
"syntax:\n",
"\n",
"```cdo setgrid,grid ifile ofile```"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"gridfile = \"/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc\""
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cdo setgrid: Processed 1336938240 values from 1 variable over 60 timesteps ( 24.47s )\r\n"
]
}
],
"source": [
"!cdo -O setgrid,$gridfile tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"netcdf \\2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid {\r\n",
"dimensions:\r\n",
"\tcell = 22282304 ;\r\n",
"\tnv = 3 ;\r\n",
"\ttime = UNLIMITED ; // (60 currently)\r\n",
"variables:\r\n",
"\tdouble clon(cell) ;\r\n",
"\t\tclon:standard_name = \"longitude\" ;\r\n",
"\t\tclon:long_name = \"center longitude\" ;\r\n",
"\t\tclon:units = \"radian\" ;\r\n",
"\t\tclon:bounds = \"clon_bnds\" ;\r\n",
"\tdouble clon_bnds(cell, nv) ;\r\n",
"\tdouble clat(cell) ;\r\n",
"\t\tclat:standard_name = \"latitude\" ;\r\n",
"\t\tclat:long_name = \"center latitude\" ;\r\n",
"\t\tclat:units = \"radian\" ;\r\n",
"\t\tclat:bounds = \"clat_bnds\" ;\r\n",
"\tdouble clat_bnds(cell, nv) ;\r\n",
"\tdouble time(time) ;\r\n",
"\t\ttime:standard_name = \"time\" ;\r\n",
"\t\ttime:units = \"day as %Y%m%d.%f\" ;\r\n",
"\t\ttime:calendar = \"proleptic_gregorian\" ;\r\n",
"\t\ttime:axis = \"T\" ;\r\n",
"\tfloat clwvi(time, cell) ;\r\n",
"\t\tclwvi:standard_name = \"tqc_dia\" ;\r\n",
"\t\tclwvi:long_name = \"total column integrated cloud water (diagnostic)\" ;\r\n",
"\t\tclwvi:units = \"kg m**-2\" ;\r\n",
"\t\tclwvi:param = \"215.1.0\" ;\r\n",
"\t\tclwvi:CDI_grid_type = \"unstructured\" ;\r\n",
"\t\tclwvi:coordinates = \"clat clon\" ;\r\n",
"\r\n",
"// global attributes:\r\n",
"\t\t:_NCProperties = \"version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.14\" ;\r\n",
"\t\t:CDI = \"Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)\" ;\r\n",
"\t\t:history = \"Fri Feb 09 10:16:13 2018: cdo -O setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc\\nFri Feb 09 10:15:20 2018: cdo -O selvar,clwvi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc\\nFri Feb 10 11:38:21 2017: cdo -P 12 mergetime /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_1+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_2+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/DATA3/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\\n/work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/build/x86_64-unknown-linux-gnu/bin/icon at 20160912 140913\" ;\r\n",
"\t\t:source = \"@\" ;\r\n",
"\t\t:institution = \"Max Planck Institute for Meteorology\" ;\r\n",
"\t\t:Conventions = \"CF-1.4\" ;\r\n",
"\t\t:title = \"ICON simulation\" ;\r\n",
"\t\t:references = \"see MPIM/DWD publications\" ;\r\n",
"\t\t:comment = \"HDCP2 Sammelaccount (k203095) on m21241 (Linux 2.6.32-573.3.1.el6.x86_64 x86_64)\" ;\r\n",
"\t\t:cdo_openmp_thread_number = 12 ;\r\n",
"\t\t:CDO = \"Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)\" ;\r\n",
"}\r\n"
]
}
],
"source": [
"! ncdump -h tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### selecting station(s) of interest"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For some time now, I was under the impression that cdo did not have an operator to select stations from a grid file, but it turns out that it could be done using remapnn operator.\n",
"\n",
"The help text of this remapnn operator, totally gives it away."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"NAME\r\n",
" remapnn, gennn - Nearest neighbor remapping\r\n",
"\r\n",
"SYNOPSIS\r\n",
" <operator>,grid infile outfile\r\n",
"\r\n",
"DESCRIPTION\r\n",
" This module contains operators for a nearest neighbor remapping of fields between grids\r\n",
" in spherical coordinates.\r\n",
"\r\n",
"OPERATORS\r\n",
" remapnn Nearest neighbor remapping\r\n",
" Performs a nearest neighbor remapping on all input fields.\r\n",
" gennn Generate nearest neighbor remap weights\r\n",
" Generates nearest neighbor remapping weights for the first input field and writes the result to a file.\r\n",
" The format of this file is NetCDF following the SCRIP convention.\r\n",
" Use the operator remap to apply this remapping weights to a data file with the same source grid.\r\n",
"\r\n",
"PARAMETER\r\n",
" grid STRING Target grid description file or name\r\n",
"\r\n",
"ENVIRONMENT\r\n",
" REMAP_EXTRAPOLATE \r\n",
" This variable is used to switch the extrapolation feature 'on' or 'off'.\r\n",
" By default the extrapolation is enabled for this remapping method.\r\n",
" CDO_GRIDSEARCH_RADIUS\r\n",
" Grid search radius in degree, default 180 degree.\r\n"
]
}
],
"source": [
"!cdo --help remapnn"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Considering station c12 (lon=14.110, lat=52.210) for the exercise"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cdo remapnn: Nearest neighbor weights from unstructured (22282304) to lonlat (1x1) grid\n",
"cdo remapnn: 1cdo remapnn: Processed 1336938240 values from 1 variable over 60 timesteps ( 59.96s )\n"
]
}
],
"source": [
"!cdo -O remapnn,lon=14.110/lat=52.210 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_c12.nc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"verifying with ncdump"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"netcdf \\2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_c12 {\r\n",
"dimensions:\r\n",
"\tlon = 1 ;\r\n",
"\tlat = 1 ;\r\n",
"\ttime = UNLIMITED ; // (60 currently)\r\n",
"variables:\r\n",
"\tfloat lon(lon) ;\r\n",
"\t\tlon:standard_name = \"longitude\" ;\r\n",
"\t\tlon:long_name = \"longitude\" ;\r\n",
"\t\tlon:units = \"degrees_east\" ;\r\n",
"\t\tlon:axis = \"X\" ;\r\n",
"\tfloat lat(lat) ;\r\n",
"\t\tlat:standard_name = \"latitude\" ;\r\n",
"\t\tlat:long_name = \"latitude\" ;\r\n",
"\t\tlat:units = \"degrees_north\" ;\r\n",
"\t\tlat:axis = \"Y\" ;\r\n",
"\tdouble time(time) ;\r\n",
"\t\ttime:standard_name = \"time\" ;\r\n",
"\t\ttime:units = \"day as %Y%m%d.%f\" ;\r\n",
"\t\ttime:calendar = \"proleptic_gregorian\" ;\r\n",
"\t\ttime:axis = \"T\" ;\r\n",
"\tfloat clwvi(time, lat, lon) ;\r\n",
"\t\tclwvi:standard_name = \"tqc_dia\" ;\r\n",
"\t\tclwvi:long_name = \"total column integrated cloud water (diagnostic)\" ;\r\n",
"\t\tclwvi:units = \"kg m**-2\" ;\r\n",
"\t\tclwvi:param = \"215.1.0\" ;\r\n",
"\r\n",
"// global attributes:\r\n",
"\t\t:_NCProperties = \"version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.14\" ;\r\n",
"\t\t:CDI = \"Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)\" ;\r\n",
"\t\t:history = \"Fri Feb 09 10:16:40 2018: cdo -O remapnn,lon=14.110/lat=52.210 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_c12.nc\\nFri Feb 09 10:16:13 2018: cdo -O setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc\\nFri Feb 09 10:15:20 2018: cdo -O selvar,clwvi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc\\nFri Feb 10 11:38:21 2017: cdo -P 12 mergetime /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_1+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_2+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/DATA3/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\\n/work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/build/x86_64-unknown-linux-gnu/bin/icon at 20160912 140913\" ;\r\n",
"\t\t:source = \"@\" ;\r\n",
"\t\t:institution = \"Max Planck Institute for Meteorology\" ;\r\n",
"\t\t:Conventions = \"CF-1.4\" ;\r\n",
"\t\t:title = \"ICON simulation\" ;\r\n",
"\t\t:references = \"see MPIM/DWD publications\" ;\r\n",
"\t\t:comment = \"HDCP2 Sammelaccount (k203095) on m21241 (Linux 2.6.32-573.3.1.el6.x86_64 x86_64)\" ;\r\n",
"\t\t:cdo_openmp_thread_number = 12 ;\r\n",
"\t\t:CDO = \"Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)\" ;\r\n",
"data:\r\n",
"\r\n",
" lon = 14.11 ;\r\n",
"\r\n",
" lat = 52.21 ;\r\n",
"}\r\n"
]
}
],
"source": [
"!ncdump -v lon,lat tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_c12.nc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### selecting region of interest"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We select a 10x10 km grid around Joice station (50.909, 6.414)\n",
"\n",
"REGION = 6.2710, 6.5559, 50.8190, 50.9979\n",
"\n",
"syntax:\n",
"\n",
"```cdo sellonlatbox,lon1,lon2,lat1,lat2 ifile ofile```"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cdo sellonlatbox: Processed 1336938240 values from 1 variable over 60 timesteps ( 5.74s )\r\n"
]
}
],
"source": [
"!cdo -O sellonlatbox,6.2710,6.5559,50.8190,50.9979 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"dumping the header to check 'ncells' in the dimension"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"netcdf \\2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10 {\r\n",
"dimensions:\r\n",
"\tcell = 16338 ;\r\n",
"\tnv = 3 ;\r\n",
"\ttime = UNLIMITED ; // (60 currently)\r\n",
"variables:\r\n",
"\tdouble clon(cell) ;\r\n",
"\t\tclon:standard_name = \"longitude\" ;\r\n",
"\t\tclon:long_name = \"center longitude\" ;\r\n",
"\t\tclon:units = \"radian\" ;\r\n",
"\t\tclon:bounds = \"clon_bnds\" ;\r\n",
"\tdouble clon_bnds(cell, nv) ;\r\n",
"\tdouble clat(cell) ;\r\n",
"\t\tclat:standard_name = \"latitude\" ;\r\n",
"\t\tclat:long_name = \"center latitude\" ;\r\n",
"\t\tclat:units = \"radian\" ;\r\n",
"\t\tclat:bounds = \"clat_bnds\" ;\r\n",
"\tdouble clat_bnds(cell, nv) ;\r\n",
"\tdouble time(time) ;\r\n",
"\t\ttime:standard_name = \"time\" ;\r\n",
"\t\ttime:units = \"day as %Y%m%d.%f\" ;\r\n",
"\t\ttime:calendar = \"proleptic_gregorian\" ;\r\n",
"\t\ttime:axis = \"T\" ;\r\n",
"\tfloat clwvi(time, cell) ;\r\n",
"\t\tclwvi:standard_name = \"tqc_dia\" ;\r\n",
"\t\tclwvi:long_name = \"total column integrated cloud water (diagnostic)\" ;\r\n",
"\t\tclwvi:units = \"kg m**-2\" ;\r\n",
"\t\tclwvi:param = \"215.1.0\" ;\r\n",
"\t\tclwvi:CDI_grid_type = \"unstructured\" ;\r\n",
"\t\tclwvi:coordinates = \"clat clon\" ;\r\n",
"\r\n",
"// global attributes:\r\n",
"\t\t:_NCProperties = \"version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.14\" ;\r\n",
"\t\t:CDI = \"Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)\" ;\r\n",
"\t\t:history = \"Fri Feb 09 10:17:43 2018: cdo -O sellonlatbox,6.2710,6.5559,50.8190,50.9979 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc\\nFri Feb 09 10:16:13 2018: cdo -O setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc\\nFri Feb 09 10:15:20 2018: cdo -O selvar,clwvi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc\\nFri Feb 10 11:38:21 2017: cdo -P 12 mergetime /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_1+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_2+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/DATA3/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\\n/work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/build/x86_64-unknown-linux-gnu/bin/icon at 20160912 140913\" ;\r\n",
"\t\t:source = \"@\" ;\r\n",
"\t\t:institution = \"Max Planck Institute for Meteorology\" ;\r\n",
"\t\t:Conventions = \"CF-1.4\" ;\r\n",
"\t\t:title = \"ICON simulation\" ;\r\n",
"\t\t:references = \"see MPIM/DWD publications\" ;\r\n",
"\t\t:comment = \"HDCP2 Sammelaccount (k203095) on m21241 (Linux 2.6.32-573.3.1.el6.x86_64 x86_64)\" ;\r\n",
"\t\t:cdo_openmp_thread_number = 12 ;\r\n",
"\t\t:CDO = \"Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)\" ;\r\n",
"}\r\n"
]
}
],
"source": [
"!ncdump -h tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"#\r\n",
"# gridID 1\r\n",
"#\r\n",
"gridtype = unstructured\r\n",
"gridsize = 16338\r\n",
"xname = clon\r\n",
"xdimname = cell\r\n",
"xlongname = \"center longitude\"\r\n",
"xunits = \"radian\"\r\n",
"yname = clat\r\n",
"ydimname = cell\r\n",
"ylongname = \"center latitude\"\r\n",
"yunits = \"radian\"\r\n",
"vdimname = nv\r\n",
"nvertex = 3\r\n",
"xvals = 0.113197699174129 0.113214957106932 0.113159315049856 0.113253341760467 \r\n",
" 0.113096771005351 0.113108851132979 0.113114027830132 0.113058384584808 \r\n",
" 0.113164493800421 0.113147236423399 0.113202879578879 0.113152414768621 \r\n",
" 0.113063559226833 0.113101947301689 0.11305147719576 0.113046302958092 \r\n",
" 0.113053210389446 0.113041129166376 0.113091595162638 0.114168229417848 \r\n",
" 0.11412984965885 0.114180285308162 0.114185511321636 0.11412462615274 \r\n",
" 0.114112569162082 0.114163004257405 0.114235946383656 0.114218663930281 \r\n",
" 0.114274325504936 0.114223891590975 0.114135073614791 0.114173455031543 \r\n",
" 0.114123015818008 0.114117792266988 0.114269095789069 0.114286378796514 \r\n",
" 0.114230718322774 0.114246403878359 0.114229119711954 0.114284786307159 \r\n",
" 0.114234348285445 0.114279555678084 0.114241174903115 0.114291609370232 \r\n",
" 0.114296840397846 0.114290017380741 0.114302071876861 0.114307303807685 \r\n",
" 0.114251633307601 0.114178681095906 0.114195964703908 0.114140298025593 \r\n",
" 0.114190737792546 0.11402375100028 0.114062131407526 0.114011691008249 \r\n",
" 0.11400647246644 0.11406735245964 0.114079411353059 0.114084633259471 \r\n"
]
}
],
"source": [
"!cdo -s griddes tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc | head -n 30"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### remapping to regular grid (lat, lon)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For remapping there are two important things\n",
"- defining target grid description\n",
"- kind of remapping. example: conservative, nearest-neighborhood, etc..\n",
"\n",
"The second one is very easy as it is just a matter of choosing the desired operator.\n",
"\n",
"Defining target grid description requires some work as it is completely up to the user how the target grid is defined (subjective to the use case). Fortunately, there exists a helper python script which makes it easy in generating the target grid description for a regular grid.\n",
"\n",
"First, checking out the --help of the python script"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"usage: gridspec.py [-h] [-o OUTFILE] (-r RESOLUTION | -d {DOM01,DOM02,DOM03})\r\n",
" (-b BOUNDS | -f NCFILE)\r\n",
"\r\n",
"Generates description of the target grid for a given resolution and lat-lon\r\n",
"bounds. This description is one of the input parameters for the cdo operator\r\n",
"'remap'.\r\n",
"\r\n",
"optional arguments:\r\n",
" -h, --help show this help message and exit\r\n",
" -o OUTFILE, --outfile OUTFILE\r\n",
" File to which output must be written. (default: stdout)\r\n",
" -r RESOLUTION, --resolution RESOLUTION\r\n",
" Resolution of the target grid in Kilometers.\r\n",
" -d {DOM01,DOM02,DOM03}, --domain {DOM01,DOM02,DOM03}\r\n",
" Domain to be used for calculating resolution. In this case, the resolution of\r\n",
" the target grid is most similar to the native resolution of the domain\r\n",
" selected. The triangle edge lengths in the ICON grid are 625m, 312m, 156m for\r\n",
" DOM01, DOM02, DOM03, respectively.\r\n",
" -b BOUNDS, --bounds BOUNDS\r\n",
" Comma separated corner tics of region of interest given as\r\n",
" 'lon1,lon2,lat1,lat2'. These corner tics refer to the lower left and upper\r\n",
" right corners.\r\n",
" -f NCFILE, --ncfile NCFILE\r\n",
" Grid file from which the corner tics are to be read. Use this option if\r\n",
" the full extent of grid is considered to be the region of interest.\r\n",
"\r\n",
"options '--resolution' and '--domain' are mutually exclusive.\r\n",
"Provide either one of these.\r\n",
"In case of option '--domain', the resolution obtained from the specified domain\r\n",
"(DOM01,DOM02,DOM03) is obtained by multiplying the native triangle edge length\r\n",
"with a factor of 0.67 which is equivalent to defining the resolution as square\r\n",
"root of the area of the triangle.\r\n",
"For details about this factor, please refer to:\r\n",
"(http://onlinelibrary.wiley.com/doi/10.1002/2015MS000431/full#jame20180-app-0003)\r\n",
"\r\n",
"\"A. Dipankar, B. Stevens, R. Heinze, C. Moseley, G. Zängl, M. Giorgetta, and\r\n",
"S. Brdar (2015),Large eddy simulation using the general circulation model ICON,\r\n",
"J. Adv. Model. Earth Syst., 7, 963–986, doi:10.1002/2015MS000431.\"\r\n",
"\r\n",
"options '--bounds' and '--ncfile' are also mutually exclusive.\r\n",
"Provide either one of these.\r\n",
"\r\n",
"Example:\r\n",
"--------\r\n",
"1. To generate a grid description for a 10x10 grid around joyce for DOM03\r\n",
"\r\n",
" python gridspec.py --outfile joyce_10x10_griddes --domain DOM03 --bounds 6.2715,6.5564,50.8191,50.9988\r\n",
"\r\n",
"2. To generate a grid description for entire domain for DOM03\r\n",
"\r\n",
" python gridspec.py -d DOM03 -f /work/bm0834/k203095/OUTPUT/GRIDS/GRID_3d_fine_DOM03_ML.nc\r\n",
"\r\n",
"3. To generate a grid description for a custom resolution of 400m\r\n",
"\r\n",
" python gridspec.py --resolution=0.4 --bounds 6.2715,6.5564,50.8191,50.9988\r\n",
"\r\n",
" TIP: Leave no whitespaces between the option and its value.\r\n",
"\r\n",
" python gridspec.py -ogriddes -dDOM02 -b6.27,6.55,50.81,50.99\r\n",
" python gridspec.py --outfile=griddes --domain=DOM02 --bounds=6.27,6.55,50.81,50.99\r\n"
]
}
],
"source": [
"! python ../scripts/gridspec.py --help"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"The recommended way to use this script is to supply **resolution** and **bounds**\n",
"\n",
"Since, the file we are working with is from DOM03 we can choose resolution as 0.156 to stay close to original grid resolution. But one can choose to go coarser than that. For this demo, we will stick to 0.156\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gridtype = lonlat\r\n",
"gridsize = 16383\r\n",
"xname = lon\r\n",
"xlongname = longitude\r\n",
"xunits = degrees_east\r\n",
"yname = lat\r\n",
"ylongname = latitude\r\n",
"yunits = degrees_north\r\n",
"xsize = 129\r\n",
"ysize = 127\r\n",
"xfirst = 6.271\r\n",
"xinc = 0.0022\r\n",
"yfirst = 50.819\r\n",
"yinc = 0.0014\r\n"
]
}
],
"source": [
"!/work/bm0834/k202101/utils/gridspec.py -r 0.156 -b 6.2710,6.5559,50.8190,50.9979"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"!/work/bm0834/k202101/utils/gridspec.py -r 0.156 -b 6.2710,6.5559,50.8190,50.9979 -o tmp/joyce_10x10_griddes_dom03"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### remap\n",
"\n",
"```cdo remapnn,griddes ifile ofile```"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cdo remapnn: Nearest neighbor weights from unstructured (16338) to lonlat (129x127) grid\n",
"cdo remapnn: 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 91cdo remapnn: Processed 980280 values from 1 variable over 60 timesteps ( 0.06s )\n"
]
}
],
"source": [
"!cdo remapnn,tmp/joyce_10x10_griddes_dom03 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_ll.nc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### checking the grid description"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"#\r\n",
"# gridID 1\r\n",
"#\r\n",
"gridtype = lonlat\r\n",
"gridsize = 16383\r\n",
"xsize = 129\r\n",
"ysize = 127\r\n",
"xname = lon\r\n",
"xlongname = \"longitude\"\r\n",
"xunits = \"degrees_east\"\r\n",
"yname = lat\r\n",
"ylongname = \"latitude\"\r\n",
"yunits = \"degrees_north\"\r\n",