How to create regular lat/lon NC file from a "line NC file"
Added by david moreno over 7 years ago
Hi, I have a netcdf file with the following structure:
dimensions:
nobs = UNLIMITED ; // (23562010 currently)
variables:
double Observation_Type(nobs) ;
double Latitude(nobs) ;
double Longitude(nobs) ;
double Pressure(nobs) ;
double Analysis_Use_Flag(nobs) ;
double u_Obs_Minus_Forecast_unadjusted(nobs) ;
double u_Obs_Minus_Forecast_unadjusted(nobs) ;
I need to create a LAT/LOn regular netcdf file where lat and lon are the coordinates of the fields observation_type, pressure, Analysis_use, u_Obs_Minus_Forecast_unadjusted, v_Obs_Minus_Forecast_unadjusted.
Basically, I'll choose a delta lat and delta lon and each values of the variables that falls within each lat/lon bin would be averaged to get one variable value per lat/lon cell.
I will also need to add a time coordinate/time stamp. Each of the input nc files have in its name the corresponding time (ex, name_20100115_00z.nc). How can I add this info as a coordinate or time stamp inside the files, since I will have several times inside each output nc file?
Any suggestions in how can I do this with NCO, or CDO?
Thanks!
Replies (2)
RE: How to create regular lat/lon NC file from a "line NC file" - Added by Karin Meier-Fleischer over 7 years ago
Hi David,
in my opinion there is no way to remap the station data to a regular grid using cdo (hopefully I'm not wrong). But you can use NCL to read the data and regrid it with ESMF to a regular latlon grid. Here is the example how to read and regrid the Pressure variable from a file called data.nc and write it to a new file called data_regridded.nc.
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" begin f = addfile("data.nc","r") ;-- open file for reading Pressure = f->Pressure ;-- read variable lat1d = f->Latitude ;-- read latitudes lon1d = f->Longitude ;-- read longitudes ;-- ESMF settings Opt = True ;-- regridding options Opt@ForceOverwrite = True ;-- overwrite existing temporary files Opt@SrcGridLat = lat1d ;-- latitude of source grid Opt@SrcGridLon = lon1d ;-- longitude of source grid Opt@DstGridType = "0.5deg" ;-- 0.5 x 0.5 degrees destination grid Opt@DstLLCorner = (/-90.0d, 0.0d /) ;-- destination lower left grid corner Opt@DstURCorner = (/ 90.0d, 360.0d /) ;-- destination upper right grid corner Pressure_regrid = ESMF_regrid(Pressure,Opt) printVarSummary(pw_regrid) ;-- print variable information to stdout ;-- write regridded data to new netcdf file system("rm -rf data_regridded.nc") ;-- first, delete if exists ofile = addfile("data_regridded.nc","c") ;-- open file for creation ofile->Pressure = Pressure_regrid ;-- write variable Pressure to file end
Let us assume the NCL script is named station2regular.ncl then run the NCL script
ncl station2regular.ncl
To add the date as a time variable to the file you can use the cdo operator settaxis
cdo -settaxis,2010-01-15,00:00:00,1day data_regridded.nc data_regridded_plus_date.nc
Hope this helps
-Karin
RE: How to create regular lat/lon NC file from a "line NC file" - Added by david moreno over 7 years ago
Thanks so much Karin, I'll give it a try!!