Curvilinear to latlon grid


I want to convert the .nc files which are in the curvilinear format (with different dimension sizes). I want to convert them into rectilinear projections.

Could you please let me know how I can do that?


Does `grdsample ˋ look like something that could work for your problem ?

Thanks for your suggestion.
I tried like

gmt grdsample -T

But, errors comes as

grdsample [WARNING]: “nTimes_Aerosol_NearUV_Swath”, NetCDF: Variable not found
If something bad happens later, try importing via GDAL.
grdsample [WARNING]: “nXtrack_Aerosol_NearUV_Swath”, NetCDF: Variable not found
If something bad happens later, try importing via GDAL.

It helps to read the docs

I can read the NetCDF files via


gdalinfo NETCDF:"":FinalAerosolOpticalDepth_Aerosol_NearUV_Swath

But, I could not find the code to convert the curvilinear grid format to rectangular grid format.

Could you please help me with this?


Humm @kunalbali. It looks like you are working with a satellite swath ? (Aura near UV Aerosol depth ?)
Are you working in which level ? (1B ? 2B ?).
You can use “ncdump -c” and check the header and coordinate information. I guess you are getting this error because your file is not a curvelinear grid per si, but a SWATH (that is, for the satellite it is a square grid, but projected on the surface of the planet will appear curvelinear. That is, the per-pixel reference lat/lon will be warped).

In this case there are some tips&tricks that you can use to reproject on the surface as you wish.
However, if it really is the case that it is an Aura file, have you ever thought about using L4 (gridded) ?

Yes they look satellite data that often (from what I see) do not come gridded but instead with the array of values and two arrays of coordinates (lon and lat). What needs to be done first here is to create a grid and for that you need to extract a data layer and the two layers with the coordinates, merge them such that at the end you have lon lat z that you’ll feed later into a gridder module (nearneighbor is normally good enough) to compute a grid.

It’s this that I do in the Julia RemoteS package and illustrated here

However, people like to invent and the lon, lat arrays in your files have non-common missing values (-1.26765e+030 in your case) that are not even declared as as variable attributes. So this will cause some confusion as those points must be removed in advance.

You may find some useful answer here: Plot geo-map for MITgcm grid


Thanks for your time on my query.
Yes, It is Aura (OMI L2) files. Initially, the files were in .he5 but I converted them into .nc using the NCL converter. The main issue is coming from the dimension size. Each file has different dimension sizes and that’s why I can not merge/concatenate all the files into one file. I tried with NCO. It can merge the files with NCO, but it is possible only if the initial file has a lower/or lowest dimension size compared to the other files. But doing this also changed the grid position.

the dimension such as

nTimes_Aerosol_NearUV_Swath = 607 ;

varies with files. So, I guess, either I need to fix these dimensions sizes first OR I need to make all the files into a rectangular grid projection then I can easily work on it.

Regarding L4, I don’t find L4 data. Also, as you know, L2 is considered of good quality with higher resolution data. So I guess, I have to be strict on L2 data only.


Hello @kunalbali,
Now the problem is clearer. I’ve had some experience with swaths and without a little programming, there’s no way to solve it.
Basically you need, for each file (ie you need to loop), (1) convert to netcdf, and (2) extract the per pixel information from lat, lon, value. With this xyz, you can create a regular grid with different gmt techniques.

As programming is required, I suggest using pygmt, as python will give you the versatility you need to run your workflow. (obs: Of course, you can also use h5py to directly read the HDF file).

Good luck.

netCDF4 (non-classic, i.e, compressed) is HDF5 too