Re: Problem with regriddig 1km curvlinear data set to 8km curvlinear data set

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Feb 21 2013 - 22:46:34 MST

Dear Kamal,

Thanks for explaining your problem further.

From your description, it sounds like you want the Daymet variable(s) to be regridded to the WRF grid.

Just saying "DstGridType" = "curvilinear" is not enough. You actually need to provide ESMF_regrid with the lat/lon arrays for the WRF grid.

We have some ESMF regridding templates, and one of them shows how to go from a curvilinear grid (that is defined on a NetCDF file) to a WRF grid (also defined on a NetCDF grid).

Go to:

http://www.ncl.ucar.edu/Applications/Templates/

and look at the "ESMF_curv_to_WRF.ncl" file.

You have most of the work done already.

I don't have your full script, but here's what the regridding part of it should look like. You will obviously need to change "YYYY.nc" to the name of the WRF file. I'm assuming the WRF grid is called XLAT and XLONG on the file, and that they are both 3-dimensional.You may have to change this as necessary:

. . .
;---Open data source file
 sfile = addfile(DataPathName,"r")

;---Get the source file data (Daymet) lat/lon grid: used for src grid description
 lat2d = sfile->lat
 lon2d = sfile->lon

 dim2d = dimsizes(lat2d)
 nlat = dim2d(0)
 mlon = dim2d(1)

;---Get the Daymet source variable
 var = sfile->$vname$ ; (time, y, x)

;---Define assorted source grid (Daymet) options
 Opt@SrcGridType = "curvilinear"
 Opt@SrcGridLat = lat2d
 Opt@SrcGridLon = lon2d
 Opt@SrcRegional = True
 Opt@SrcFileName = srcPathName ; grid description

;---Data file containing destination grid
 dfile = addfile("YYYY.nc","r")

;---Set up regridding options
 Opt = True

;---"bilinear" is the default. "patch" and "conserve" are other options.
 Opt@InterpMethod = method

 Opt@SrcGridLat = lat2d
 Opt@SrcGridLon = lon2d
 Opt@SrcRegional = True ;;--Change (maybe)
 Opt@SrcInputFileName = srcPathName

 Opt@DstGridLat = dfile->XLAT(0,:,:) ; destination grid
 Opt@DstGridLon = dfile->XLONG(0,:,:)
 Opt@DstRegional = True ;;--Change (maybe)
 Opt@DstFileName = dstPathName ; grid description of source tile

 Opt@ForceOverwrite = True
 Opt@PrintTimings = True
 Opt@Debug = True

 var_regrid = ESMF_regrid(var,Opt) ; Do the regridding

 printVarSummary(var_regrid)

--Mary

On Feb 21, 2013, at 4:40 PM, mmkamal@uwaterloo.ca wrote:

> Hi Marry,
>
>
> I am sorry that I could not make it clear about the problem. Let me explain my problem first:
>
> 1) I have a Daymet netCDF file with 1km x 1km data (Data description is given in the first mail) but I want it as 8kmx8km in order to compare with WRF model output (My WRF model's output resolution is dx=dy=8km).
>
> 2) I saw that NCL have different example script to convert from one form of data into another. So, I have decided to use http://www.ncl.ucar.edu/Applications/Scripts/daymet_3.ncl
>
> 3) The above script is to convert the Daymet netCDF file with 1km x 1km data into rectilinear grd with desired (in the script it is 0.1 degree) resolution.
>
> 4) I have tried using this script to convert the DAYMET data into curvilinear grid instead of the default rectilinear grid(I am not sure whether I can use this script for my task or not?).
>
> 5) Since my input data set is on curvilinear grid and I want my regridded data set to be in curvilinear grid as well. So, I have set (I am not sure whether I am allowed to do so or not)
>
> Opt@SrcGridType = "curvilinear"
>
> Opt@DstGridType = "curvilinear"
>
> 6) I need the regridded data set into curvilinear grid because my WRF models output is on curvilinear grid.
>
>
> I hope I am able to explain my problem. Therefore, I need you suggestion that how can I use the above NCL script for my job.
>
>
>
> Thanks
> Kamal
>
>
>
>
>
>
> Quoting Mary Haley <haley@ucar.edu>:
>
>> Hi Kamal,
>>
>> I'm taking this offline until we can get some confusion cleared up.
>>
>> I don't know what you mean by an "8 km curvilinear grid".
>>
>> I can see that you have the 1 km grid on a file. Do you
>> also have the 8km grid on a file?
>>
>> Remember, a curvilinear grid is one that has to be defined
>> by 2D lat/lon arrays. If you just want a 1 km grid that
>> can be represented by 1D coordinate arrays, then
>> this is a rectilinear grid.
>>
>> What you have in your code for the destination grid is
>> a rectilinear grid, so I'm not sure what you mean when
>> you say you want it to be curvilinear.
>>
>> --Mary
>>
>>
>> On Feb 21, 2013, at 1:43 PM, mmkamal@uwaterloo.ca wrote:
>>
>>> Hi Marry,
>>>
>>> What I am trying to do is to convert source data (DAYMET in 1km
>>> curvilinear grd) into 8km curvilinear grd. I do not know which part of
>>> the code I should change in that case.
>>>
>>> Thanks
>>> Kamal
>>>
>>>
>>> Quoting Mary Haley <haley@ucar.edu>:
>>>
>>>> You have conflicting code below. It looks like you are setting up
>>>> your *source* grid to be the curvilinear grid. I thought you wanted
>>>> the destination grid to be the curvilinear one?
>>>>
>>>> You need to use the SrcXXX options for the grid that you are
>>>> starting with, and the DstXXX options for the grid you want to
>>>> regrid to.
>>>>
>>>> You also have this, which is contradictory:
>>>>
>>>>> lat = fspan( min(lat2d),max(lat2d), kpts )
>>>>> lon = fspan( min(lon2d),max(lon2d), kpts )
>>>>>
>>>>> printVarSummary(lat)
>>>>>
>>>>> printVarSummary(lon)
>>>>> Opt@DstGridType = "curvilinear"
>>>>> Opt@DstGridLat = lat
>>>>> Opt@DstGridLon = lon
>>>>> Opt@DstRegional = True
>>>>> Opt@DstFileName = dstPathName ; grid description of source tile
>>>>
>>>> You're saying the destination grid is curvilinear, and then giving
>>>> it rectilinear coordinates.
>>>>
>>>> If you indeed want to go from the curvilinear grid to the
>>>> rectilinear one, then don't set:
>>>>
>>>>> Opt@DstGridType = "curvilinear"
>>>>
>>>> Just remove that line all together.
>>>>
>>>> If you want to go from the rectilinear grid to the curvilinear grid,
>>>> then you need to swap your Dst and Src options.
>>>> Do not set DstGridType or SrcGridType. ESMF_regrid can figure these
>>>> out from the coordinates you're giving it.
>>>>
>>>> --Mary
>>>>
>>>>
>>>> On Feb 21, 2013, at 11:06 AM, mmkamal@uwaterloo.ca wrote:
>>>>
>>>>> Hi Marry,
>>>>>
>>>>>
>>>>> Thank you for your mail. Could you please suggest me which part of
>>>>> the code I should change by what ? Here you go the code I am using:
>>>>>
>>>>> ==========================================================
>>>>> ;---Open data source file
>>>>> sfile = addfile(DataPathName,"r")
>>>>>
>>>>> ;---Get the source file data (Daymet) lat/lon grid: used for src
>>>>> grid description
>>>>> lat2d = sfile->lat
>>>>> lon2d = sfile->lon
>>>>>
>>>>> dim2d = dimsizes(lat2d)
>>>>> nlat = dim2d(0)
>>>>> mlon = dim2d(1)
>>>>>
>>>>> ;---Get the Daymet source variable
>>>>> var = sfile->$vname$ ; (time, y, x)
>>>>>
>>>>> ;---Define assorted source grid (Daymet) options
>>>>> Opt@SrcGridType = "curvilinear"
>>>>> Opt@SrcGridLat = lat2d
>>>>> Opt@SrcGridLon = lon2d
>>>>> Opt@SrcRegional = True
>>>>> Opt@SrcFileName = srcPathName ; grid description
>>>>> of source tile
>>>>> ;---Create the destination lat/lon grid
>>>>> dll = 0.1 ; tenth of degree spacing
>>>>> kpts= toint(2.0/dll)+1 ; 2 deg is Daymet
>>>>> grid spacing
>>>>> lat = fspan( min(lat2d),max(lat2d), kpts )
>>>>> lon = fspan( min(lon2d),max(lon2d), kpts )
>>>>>
>>>>> printVarSummary(lat)
>>>>>
>>>>> printVarSummary(lon)
>>>>> Opt@DstGridType = "curvilinear"
>>>>> Opt@DstGridLat = lat
>>>>> Opt@DstGridLon = lon
>>>>> Opt@DstRegional = True
>>>>> Opt@DstFileName = dstPathName ; grid description of source tile
>>>>>
>>>>> ;---Set method
>>>>> Opt@InterpMethod = method
>>>>>
>>>>> var_regrid = ESMF_regrid(var,Opt) ; Do the regridding for 'var'
>>>>> printVarSummary(var_regrid)
>>>>>
>>>>> end
>>>>>
>>>>> =============================================================================
>>>>>
>>>>>
>>>>> Thanks
>>>>> Kamal
>>>>>
>>>>>
>>>>>
>>>>> Quoting Mary Haley <haley@ucar.edu>:
>>>>>
>>>>>> Hi Kamal,
>>>>>>
>>>>>> You can't simply change the DstGridType to curvilinear. Really,
>>>>>> that option
>>>>>> should only be used when you are calling ESMF_regrid_with_weights.
>>>>>>
>>>>>> A curvilinear grid means you have two-dimensional (2D) lat/lon arrays that
>>>>>> represent the grid.
>>>>>>
>>>>>> If you want to regrid to a curvilinear grid, then you need to provide the
>>>>>> curvilinear lat/lon coordinates via these two options:
>>>>>>
>>>>>> Opt@DstGridLat = lat
>>>>>> Opt@DstGridLon = lon
>>>>>> In this particular example, "lat" and "lon are calculated as 1D
>>>>>> coordinate arrays. You need to
>>>>>> replace this code with the 2D lat/lon arrays that represent your
>>>>>> curvilinear grid.
>>>>>>
>>>>>> --Mary
>>>>>>
>>>>>> On Feb 20, 2013, at 2:29 PM, mmkamal@uwaterloo.ca wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have been trying to re-grid DAYMET 1km dataset into 8km using the
>>>>>>> example NCL script prepared to convert from curvlinear to rectilinear
>>>>>>> grd (http://www.ncl.ucar.edu/Applications/Scripts/daymet_3.ncl). My
>>>>>>> problem is that I want to convert 1km curvlinear DAYMET data into 8km
>>>>>>> curvlinear dataset. Therefore, I set the
>>>>>>>
>>>>>>> Opt@DstGridType = "curvilinear"
>>>>>>>
>>>>>>>
>>>>>>> I have not changed any other option in the example script. The script
>>>>>>> works fine when used to convert from curvlinear to rectilinear grd but
>>>>>>> failed when trying to use to convert 1km curvlinear DAYMET data into
>>>>>>> 8km curvlinear data set. It gives the following error message:
>>>>>>>
>>>>>>>
>>>>>>> gpc-f101n084-$ ncl test.ncl
>>>>>>> Copyright (C) 1995-2012 - All Rights Reserved
>>>>>>> University Corporation for Atmospheric Research
>>>>>>> NCAR Command Language Version 6.1.0
>>>>>>> The use of this software is governed by a License Agreement.
>>>>>>> See http://www.ncl.ucar.edu/ for more details.
>>>>>>>
>>>>>>> Variable: lat
>>>>>>> Type: double
>>>>>>> Total Size: 168 bytes
>>>>>>> 21 values
>>>>>>> Number of Dimensions: 1
>>>>>>> Dimensions and sizes: [21]
>>>>>>> Coordinates:
>>>>>>>
>>>>>>> Variable: lon
>>>>>>> Type: double
>>>>>>> Total Size: 168 bytes
>>>>>>> 21 values
>>>>>>> Number of Dimensions: 1
>>>>>>> Dimensions and sizes: [21]
>>>>>>> Coordinates:
>>>>>>> fatal:Number of dimensions in parameter (1) of (curvilinear_to_SCRIP)
>>>>>>> is (1), (2) dimensions were expected
>>>>>>> fatal:["Execute.c":7743]:Execute: Error occurred at or near line 2978
>>>>>>> in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>>>>>>>
>>>>>>> fatal:["Execute.c":7743]:Execute: Error occurred at or near line 3098
>>>>>>> in file $NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl
>>>>>>>
>>>>>>> fatal:["Execute.c":7743]:Execute: Error occurred at or near line 100
>>>>>>> in file test.ncl
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ==================================================
>>>>>>> Here is the source data description:
>>>>>>> ==================================================
>>>>>>> gpc-f101n084-$
>>>>>>> /scinet/gpc/Libraries/netcdf-4.1.3/serial_gcc/bin/ncdump -h
>>>>>>> prcp.2010_12296.nc
>>>>>>> netcdf prcp.2010_12296 {
>>>>>>> dimensions:
>>>>>>> x = 212 ;
>>>>>>> y = 250 ;
>>>>>>> time = 365 ;
>>>>>>> nv = 2 ;
>>>>>>> variables:
>>>>>>> short lambert_conformal_conic ;
>>>>>>> lambert_conformal_conic:grid_mapping_name =
>>>>>>> "lambert_conformal_conic" ;
>>>>>>> lambert_conformal_conic:longitude_of_central_meridian
>>>>>>> = -100. ;
>>>>>>>
>>>>>>> lambert_conformal_conic:latitude_of_projection_origin = 42.5 ;
>>>>>>> lambert_conformal_conic:false_easting = 0. ;
>>>>>>> lambert_conformal_conic:false_northing = 0. ;
>>>>>>> lambert_conformal_conic:standard_parallel = 25., 60. ;
>>>>>>> double x(x) ;
>>>>>>> x:units = "m" ;
>>>>>>> x:long_name = "x coordinate of projection" ;
>>>>>>> x:standard_name = "projection_x_coordinate" ;
>>>>>>> double y(y) ;
>>>>>>> y:units = "m" ;
>>>>>>> y:long_name = "y coordinate of projection" ;
>>>>>>> y:standard_name = "projection_y_coordinate" ;
>>>>>>> double time(time) ;
>>>>>>> time:long_name = "time" ;
>>>>>>> time:calendar = "standard" ;
>>>>>>> time:units = "days since 1980-01-01 00:00:00 UTC" ;
>>>>>>> time:bounds = "time_bnds" ;
>>>>>>> double lat(y, x) ;
>>>>>>> lat:units = "degrees_north" ;
>>>>>>> lat:long_name = "latitude coordinate" ;
>>>>>>> lat:standard_name = "latitude" ;
>>>>>>> double lon(y, x) ;
>>>>>>> lon:units = "degrees_east" ;
>>>>>>> lon:long_name = "longitude coordinate" ;
>>>>>>> lon:standard_name = "longitude" ;
>>>>>>> short yearday(time) ;
>>>>>>> yearday:long_name = "yearday" ;
>>>>>>> yearday:valid_range = 1s, 365s ;
>>>>>>> float prcp(time, y, x) ;
>>>>>>> prcp:long_name = "daily total precipitation" ;
>>>>>>> prcp:units = "mm/day" ;
>>>>>>> prcp:missing_value = -9999.f ;
>>>>>>> prcp:_FillValue = -9999.f ;
>>>>>>> prcp:valid_range = 0.f, 200.f ;
>>>>>>> prcp:coordinates = "lat lon" ;
>>>>>>> prcp:grid_mapping = "lambert_conformal_conic" ;
>>>>>>> prcp:cell_methods = "area: sum time: sum" ;
>>>>>>> double time_bnds(time, nv) ;
>>>>>>>
>>>>>>> // global attributes:
>>>>>>> :tileid = 12296s ;
>>>>>>> :start_year = 2010s ;
>>>>>>> :source = "Daymet Software Version 2.0" ;
>>>>>>> :Version_software = "Daymet Software Version 2.0" ;
>>>>>>> :Version_data = "Daymet Data Version 2.1" ;
>>>>>>> :Conventions = "CF-1.4" ;
>>>>>>> :citation = "Please see http://daymet.ornl.gov/ for
>>>>>>> current Daymet data citation information" ;
>>>>>>> :references = "Please see http://daymet.ornl.gov/ for
>>>>>>> current information on Daymet references" ;
>>>>>>> }
>>>>>>>
>>>>>>> ===========================================================================
>>>>>>>
>>>>>>>
>>>>>>> I look forward to hearing from you.
>>>>>>>
>>>>>>> Thanks
>>>>>>> Kamal
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
>
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Feb 21 22:46:49 2013

This archive was generated by hypermail 2.1.8 : Fri Feb 22 2013 - 17:42:16 MST