12
11. Regridding data See https://climatedataguide.ucar.edu/climate-data-tools-and-analysis/ regridding-overview for some background. Regridding can be much more than simple linear interpolation. Let’s compare two monthly mean datasets: Download another precipitation dataset, this time from MERRA2: https://gmao.gsfc.nasa.gov/reanalysis/MERRA-2/data_access/ Follow the data access (MDISC) link. Choose temporal resolution of 1 month. Choose ‘Subject’ of Precipitation. There will be many choices there. Which one? Check the documentation here: https://gmao.gsfc.nasa.gov/pubs/docs/Bosilovich785.pdf Search on the word ‘precipitation’ and you will have 44 instances. You want a monthly mean total precipitation (not anvil, convective, etc.) so the best match seems to be variable PRECTOTOCORR. Bias corrected total precipitation with units kg m-2 s -1. Scrolling up from that variable in the table on page 33, you see the data has 576 longitudes and 361 latitudes, and that it is 1-hourly data (24 in a day). Notice the title: tavg1_2d_flx_Nx (M2T1NXFLX): Surface Flux Diagnostics The best match seems to be the fourth (11/2018) dataset down: MERRA-2 tavgM_2d_flx_Nx: 2d,Monthly mean,Time-Averaged,Single- Level,Assimilation,Surface Flux Diagnostics V5.12.4 (M2TMNXFLX.5.12.4) - Atmospheric Radiation, Atmospheric Temperature, Atmospheric Water Vapor Click on that link and go to the ‘Online Archive’ button. Then go to the year 1995. To download the first month there in nc4 format, January, you first need to register. Find the link to do that and

grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

  • Upload
    haduong

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

Page 1: grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

11. Regridding data

See

https://climatedataguide.ucar.edu/climate-data-tools-and-analysis/regridding-overview

for some background. Regridding can be much more than simple linear interpolation.

Let’s compare two monthly mean datasets:

Download another precipitation dataset, this time from MERRA2: https://gmao.gsfc.nasa.gov/reanalysis/MERRA-2/data_access/

Follow the data access (MDISC) link. Choose temporal resolution of 1 month. Choose ‘Subject’ of Precipitation. There will be many choices there. Which one? Check the documentation here:

https://gmao.gsfc.nasa.gov/pubs/docs/Bosilovich785.pdf

Search on the word ‘precipitation’ and you will have 44 instances. You want a monthly mean total precipitation (not anvil, convective, etc.) so the best match seems to be variable PRECTOTOCORR. Bias corrected total precipitation with units kg m-2 s -1. Scrolling up from that variable in the table on page 33, you see the data has 576 longitudes and 361 latitudes, and that it is 1-hourly data (24 in a day). Notice the title: tavg1_2d_flx_Nx (M2T1NXFLX): Surface Flux Diagnostics

The best match seems to be the fourth (11/2018) dataset down:

MERRA-2 tavgM_2d_flx_Nx: 2d,Monthly mean,Time-Averaged,Single-Level,Assimilation,Surface Flux Diagnostics V5.12.4 (M2TMNXFLX.5.12.4) - Atmospheric Radiation, Atmospheric Temperature, Atmospheric Water Vapor

Click on that link and go to the ‘Online Archive’ button. Then go to the year 1995. To download the first month there in nc4 format, January, you first need to register. Find the link to do that and follow the steps. When you are done you should receive an email confirmation.

To access the data you have to do some additional approvals. Follow the instructions (separate page is opened). Use the back button to return to the page listing files and download the .nc4 file. Transfer it to use on Lorenz (or wherever you intend to do this exercise).

Do an ncdump –h on the file to ensure that PRECTOTCORR is there.

Page 2: grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

fzgrotja@lorenz:~/Course/ATM150/2018/NCL$ ncdump -h MERRA2_200.tavgM_2d_flx_Nx.199501.nc4netcdf MERRA2_200.tavgM_2d_flx_Nx.199501 {dimensions: lon = 576 ; lat = 361 ; time = UNLIMITED ; // (1 currently)variables: double lon(lon) ; lon:long_name = "longitude" ; lon:units = "degrees_east" ; lon:vmax = 1.e+15f ; lon:vmin = -1.e+15f ; lon:valid_range = -1.e+15f, 1.e+15f ; double lat(lat) ; lat:long_name = "latitude" ; lat:units = "degrees_north" ; lat:vmax = 1.e+15f ; lat:vmin = -1.e+15f ; lat:valid_range = -1.e+15f, 1.e+15f ; int time(time) ; time:long_name = "time" ; time:units = "minutes since 1995-01-01 00:30:00" ; time:time_increment = 60000 ; time:begin_date = 19950101 ; time:begin_time = 3000 ; time:vmax = 1.e+15f ; time:vmin = -1.e+15f ; time:valid_range = -1.e+15f, 1.e+15f ;;;; float PRECTOT(time, lat, lon) ; PRECTOT:long_name = "total_precipitation" ; PRECTOT:units = "kg m-2 s-1" ; PRECTOT:_FillValue = 1.e+15f ; PRECTOT:missing_value = 1.e+15f ; PRECTOT:fmissing_value = 1.e+15f ; PRECTOT:vmax = 1.e+15f ; PRECTOT:vmin = -1.e+15f ; PRECTOT:valid_range = -1.e+15f, 1.e+15f ; float PRECTOTCORR(time, lat, lon) ; PRECTOTCORR:long_name = "total_precipitation" ; PRECTOTCORR:units = "kg m-2 s-1" ; PRECTOTCORR:_FillValue = 1.e+15f ; PRECTOTCORR:missing_value = 1.e+15f ; PRECTOTCORR:fmissing_value = 1.e+15f ; PRECTOTCORR:vmax = 1.e+15f ; PRECTOTCORR:vmin = -1.e+15f ; PRECTOTCORR:valid_range = -1.e+15f, 1.e+15f ;;;

Like the precip.mon.mean.nc data, it is a fixed grid. We need to find the month for the first dataset to match. January 1995 appears to be index 192. So, we’ll want hyperslab P(192,:,:)

To keep the program simple, start with file ce5_BlWhRe.ncl as we shall do the entire, global domain.

Create a new program: ce5a_regrid.ncl

Look at both of your files with ncdump –h.

MERRA2 uses double lon and double lat and int time (in minutes since 1995…)

precip.mon.mean.nc uses float lat, float lon, and double time (in hours since 1800….)

Page 3: grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

The units are different. Convert to common units (mm/day) and use any scale and add_offset values.

Look at the NCL website for regridding: https://www.ncl.ucar.edu/Applications/regrid.shtml

Consider example 6 as a guide to preserve the global precipitation average and noting that both datasets use fixed (interval, i.e. not Gaussian) grids. Regridding from higher to the lower resolution grid.

Search functions: latGlobeFo and lonGlobeFo and look at how to call them. These assume the data is the full range on the globe while the ‘o’ on the end means offset from the pole; no ‘o’ on end starts at pole. Similar for the longitude function. The ‘precip’ variable in precip.mon.mean.nc IS offset.

Call regridding but preserve the horizontal mean using function: area_conserve_remap_Wrap

;************************************************; Based on NCL example code: ce5_BlWhRe.ncl;; Concepts illustrated:; - taking a dimension average (e.g. over time); - deviation from time average; - make negative values dashed lines; - specify contour interval and range; - use blue (negative) with red (positive) color shading; - read in another dataset, regrid it to match the lower res, take difference;;************************************************; These files are loaded by default in NCL V6.2.0 and newerload "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; remove first two columnsload "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" ;remove first two columnsload "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; more libraries;************************************************begin;************************************************; read in netCDF file a = addfile("precip.mon.mean.nc","r") b = addfile("MERRA2_200.tavgM_2d_flx_Nx.199501.nc4","r");************************************************; read in precip P = a->precip(192,::-1,:) ; read single month of precip values and reverse latitude PM2 = b->PRECTOTCORR(0,:,:); convert PM2 units: kg m-2 s-1 into mm/day like the CMAP data. print(PM2(73,36)) ; example value before conversion PM2_fctr = 60.*60.*24./0.997 ;sec/day * mm/m * 1/water density PM2 = PM2 * PM2_fctr PM2@long_name = "MERRA2 High Res" ;give it a new, specific long_name PM2@units = "mm/day" ;update units label print(PM2(73,36)) ; same value after conversion printVarSummary (P) ; check the dimensions, etc. of new variable printVarSummary (PM2) ; check the dimensions, etc. of new variable

Page 4: grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

;Remove the next 3 lines from previous file (Ptm & Pd12 definitions); Ptm = dim_avg_Wrap( P(lat|:, lon|:, time|:) ) ; calc time average ;Pd12 = Ptm ; lazy way to copy attributes into new array Pd12 ;Pd12 = P(lat|:,lon|:,time|11) - Ptm(lat|:,lon|:) ; December 1979 difference from time mean

Lat = a->lat ; get dimension values and make array for Lat npLat = dimsizes(Lat) ; get dimension of Lon Lon = a->lon ; get dimension values and make array for Lon npLon = dimsizes(Lon) ; get dimension of Lon CmapLat = latGlobeFo(npLat, "lat", "Latitude", "degrees_north") ;array of offset latitude values CmapLon = lonGlobeFo(npLon, "lon", "Longitude", "degrees_east") ;array of offset long. values opt = False ; because arrays are global PM2gnu = area_conserve_remap_Wrap(PM2&lon, PM2&lat, PM2, CmapLon, CmapLat, opt) PM2gnu@long_name = "MERRA2 Low Res" ;give new low resolution file a new name Pd12 = P ; lazy way to transfer coordinate and other attributes Pd12 = P - PM2gnu Pd12@long_name = "January 1995 CMAP-MERRA2 anomaly" printVarSummary (Pd12) ; check the dimensions, etc. of new variable;************************************************; create default plot of 2-D part of array wks = gsn_open_wks("ncgm","ce5_BlWhRe") ; send graphics to ncgm file res = True ; plot mods desired res@gsnContourNegLineDashPattern = 2 ; sets negative contours to dash pattern 2 res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels res@cnMinLevelValF = -14. ; set min contour level res@cnMaxLevelValF = 14. ; set max contour level res@cnLevelSpacingF = 1. ; set contour spacing gsn_define_colormap(wks,"BlWhRe") ; choose existing colormap res@cnFillOn = True ; Fill contours;---This next resource not needed in NCL V6.1.0 res@gsnSpreadColors = True ; use full range of colors plot = gsn_csm_contour_map(wks,P(:,:),res) ; create a default plot plot = gsn_csm_contour_map(wks,PM2(:,:),res) ; create a default plot plot = gsn_csm_contour_map(wks,PM2gnu(:,:),res) ; create a default plot plot = gsn_csm_contour_map(wks,Pd12(:,:),res) ; create a default plotend

Notice a few details:

Changing the long_name and units attributes

Plotting the different versions, plus the anomaly.

Output and plots on the next page:

ncl ce5a_regrid.ncl Copyright (C) 1995-2018 - All Rights Reserved

Page 5: grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

University Corporation for Atmospheric Research NCAR Command Language Version 6.5.0 The use of this software is governed by a License Agreement. See http://www.ncl.ucar.edu/ for more details.

Variable: PM2 (subsection)Type: floatTotal Size: 4 bytes 1 valuesNumber of Dimensions: 1Dimensions and sizes: [1]Coordinates:Number Of Attributes: 11 lon : -157.5 lat : -53.5 valid_range : ( -1e+15, 1e+15 ) vmin : -1e+15 vmax : 1e+15 fmissing_value : 1e+15 missing_value : 1e+15 _FillValue : 1e+15 units : kg m-2 s-1 long_name : total_precipitation time : 0(0) 3.624674e-05

Variable: PM2 (subsection)Type: floatTotal Size: 4 bytes 1 valuesNumber of Dimensions: 1Dimensions and sizes: [1]Coordinates:Number Of Attributes: 11 lon : -157.5 lat : -53.5 valid_range : ( -1e+15, 1e+15 ) vmin : -1e+15 vmax : 1e+15 fmissing_value : 1e+15 missing_value : 1e+15 _FillValue : 1e+15 units : mm/day long_name : MERRA2 High Res time : 0(0) 3.141142

Variable: PType: floatTotal Size: 41472 bytes 10368 valuesNumber of Dimensions: 2Dimensions and sizes: [lat | 72] x [lon | 144]Coordinates: lat: [-88.75..88.75] lon: [1.25..358.75]Number Of Attributes: 16 time : 1709328 long_name : Average Monthly Rate of Precipitation valid_range : ( 0, 70 ) units : mm/day add_offset : 0 scale_factor : 1 missing_value : -9.96921e+36 precision : 2 least_significant_digit : 2 var_desc : Precipitation dataset : CPC Merged Analysis of Precipitation Standard level_desc : Surface

Page 6: grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

statistic : Mean parent_stat : Mean actual_range : ( 0, 56.54 ) _FillValue : -9.96921e+36

Variable: PM2Type: floatTotal Size: 831744 bytes 207936 valuesNumber of Dimensions: 2Dimensions and sizes: [lat | 361] x [lon | 576]Coordinates: lat: [ -90.. 90] lon: [-180..179.375]Number Of Attributes: 9 time : 0 long_name : MERRA2 High Res units : mm/day _FillValue : 1e+15 missing_value : 1e+15 fmissing_value : 1e+15 vmax : 1e+15 vmin : -1e+15 valid_range : ( -1e+15, 1e+15 )

Variable: Pd12Type: floatTotal Size: 41472 bytes 10368 valuesNumber of Dimensions: 2Dimensions and sizes: [lat | 72] x [lon | 144]Coordinates: lat: [-88.75..88.75] lon: [1.25..358.75]Number Of Attributes: 16 _FillValue : -9.96921e+36 actual_range : ( 0, 56.54 ) parent_stat : Mean statistic : Mean level_desc : Surface dataset : CPC Merged Analysis of Precipitation Standard var_desc : Precipitation least_significant_digit : 2 precision : 2 missing_value : -9.96921e+36 scale_factor : 1 add_offset : 0 units : mm/day valid_range : ( 0, 70 ) long_name : January 1995 CMAP-MERRA2 anomaly time : 1709328

Graphical output on next page:

Page 7: grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

CMAP data

MERRA2 full resolution

Page 8: grotjahn.ucdavis.edugrotjahn.ucdavis.edu/course/atm150/2018/NCL/NCL-example-regri… · Web viewSearch on the word ‘precipitation’ and you will have 44 instances. You want a monthly

MERRA2 at CMAP resolution

CMAP-MERRA2