netcdf to grd

Added by takaya 10 months ago

Dear Sir

I want to convert the netcdf below to grd file.

It looks like not regularly spaced in longitude and latitude. I have done it by xyz2grd already.
However, I wish to do it without text file converting.
Could you suggest me how to do it?

dimensions:
lon = 1328 ;
lat = 1264 ;
variables:
float Longitudes(lon, lat) ;
Longitudes:valid_range = 0.04119034f, 359.9588f ;
Longitudes:long_name = "Longitudes, region: Antarctic" ;
float Latitudes(lon, lat) ;
Latitudes:valid_range = -89.95921f, -39.26437f ;
Latitudes:long_name = "Latitudes, region: Antarctic" ;
float ice_concentration(lon, lat) ;
ice_concentration:valid_range = 0.f, 100.f ;
ice_concentration:long_name = "ASI Ice Concentration, Version: 5.3, 20171115, res: 6.25000, AMSR2, Region: Antarctic" ;
ice_concentration:grid_information = "longitude-latitude grid for these data to be found at: http://www.iup.uni-bremen.de:8084/amsredata/asi_daygrid_swath/s6250/grid_coordinates/" ;

Regards,

takaya namba


Replies (7)

RE: netcdf to grd - Added by Paul 10 months ago

You will need to grid this onto equidistant grid, so the path would be grd2xyz | blockmean | surface with suitable arguments. I dont think the text representation is your biggest problems since the reinterpolation will introduce more distortions than any roundoff. But if you are worried you can use -bo3d on grd2xyz and blockmean -bi3d on blockmean and surface.

RE: netcdf to grd - Added by takaya 10 months ago

Thank you for your suggestion.

I tried
grd2xyz -bo3d ll_ice_final.nc |blockmean -bi3d -R-179.0/179.0/-89.0/-39.0 -I0.15 |surface -I0.15 -Gll_ice_final.grd -R

surface: No datapoints inside region, aborts

I has done ncdump and grdinfo, the information tell that "ll_ice_final.grd" is not proper grd but still netcdf(2 dimensions).
because grdinfo tells that the range(min and max) of lon and lat are the size of dimension sizes, 1328 of lon and 1264. For grd2xyz, the file type must be grd type. and the range of x and y must be -180 ~ 180 degree in longitude and -90 ~ 40 degree in latitudes.

I ask you if the dimension name of grd file must be the same as the variable names of x and y direction?
How can I solve the problem?
How can I change netcdf(2 dimension) to proper grd file.
I hope that you can understand my poor explanation.

#ncdump ll_ice_final.nc

netcdf ll_ice_final {
dimensions:
lon = 1328 ;
lat = 1264 ;
variables:
float Longitudes(lon, lat) ;
Longitudes:valid_range = 0.04119034f, 359.9588f ;
Longitudes:long_name = "Longitudes, region: Antarctic" ;
float Latitudes(lon, lat) ;
Latitudes:valid_range = -89.95921f, -39.26437f ;
Latitudes:long_name = "Latitudes, region: Antarctic" ;
float ice_concentration(lon, lat) ;
ice_concentration:valid_range = 0.f, 100.f ;
ice_concentration:long_name = "ASI Ice Concentration, Version: 5.3, 20171115, res: 6.25000, AMSR2, Region: Antarctic" ;
ice_concentration:grid_information = "longitude-latitude grid for these data to be found at: http://www.iup.uni-bremen.de:8084/amsredata/asi_daygrid_swath/s6250/grid_coordinates/" ;

#grdinfo ll_ice_final.nc
ll_ice_final.nc: Remark:
ll_ice_final.nc: Gridline node registration used [Cartesian grid]
ll_ice_final.nc: Grid file format: nf = GMT netCDF format (32-bit float), COARDS, CF-1.5
ll_ice_final.nc: x_min: 0.0000 x_max: 1263.0000 x_inc: 1.0000 name: nx: 1264
ll_ice_final.nc: y_min: 0.0000 y_max: 1327.0000 y_inc: 1.0000 name: ny: 1328
ll_ice_final.nc: z_min: 0.0412 z_max: 359.9588 name: Longitudes, region: Antarctic
ll_ice_final.nc: scale_factor: 1.0000 add_offset: 0.0000
ll_ice_final.nc: format: netCDF-4 chunk_size: 0,0 shuffle: off deflation_level: 0

Regards,

Takaya Namba

RE: netcdf to grd - Added by Paul 10 months ago

So clearly not a COARDS-compliant grid. Perhaps try to dump out using the variable names; see http://gmt.soest.hawaii.edu/doc/5.4.2/GMT_Docs.html#gmt-file-formats and try to dump longitude, latitude, ice_concentration.

RE: netcdf to grd - Added by Joaquim 10 months ago

I think the best is to use grdedit and fix the -R and -I so that the headers metadata show the correct values. Not difficult, just have to calculate the correct x_inc/y_inc and use the limits stored in the file.

RE: netcdf to grd - Added by takaya 10 months ago

Thank you for your suggestion.
I tried

grdedit -A ll_ice_final.nc -R-180.0/180.0/-90.0/-40.0

[Session grdedit (0)]: Error returned from GMT API: GMT_GRID_WRITE_ERROR (19) (three same lines are repeated)

In "ll_ice_final.nc", Longitudes and Latitudes of the two variables are two dimensions of lon and lat.
Is it still possible to use grdedit for this file?

Regards,

Takaya Namba

RE: netcdf to grd - Added by Joaquim 10 months ago

Ah, I see so you have 3 arrays, one with the data and the other 2 with lon and lats. Than you will have to do something similar to what we do in our 3rth example of the "GMT/Matlab Toolbox" paper. You can find an example implemented in Julia here https://github.com/GenericMappingTools/GMT.jl/blob/master/WL_Example_III.ipynb

RE: netcdf to grd - Added by takaya 10 months ago

Thank you for your suggestion.

I will look at the site and study it.

Regards,

Takaya Namba

(1-7/7)