I figured out the answer some time ago but I hope this will help other people that are dipping their toes into the NetCDF file format.
I found that the easiest way to create a new NetCDF file containing several GeoTIFF files is using GDAL and then using NCO and CDO tools (Provided by unidata) to add the appropriate metadata.
First you convert the GeoTIFF´s to NetCDF using:
gdal_translate -of netCDF -co "FOMRAT=NC4" foo.tif foo.nc
This creates a netCDF in NC4 format (which is the newest version at this time) with some basic metadata like coordinate system, pixel size etc.
Then I rename the variable information to what I want it to be (In my case SST) with the appropriately registered long and short name From the unidata convention page):
ncrename -v Band1,SST foo.nc
ncatted -O -a long_name,SST,o,c,sea_surface_temperature foo.nc
The first renames the variable Band1 to the wanted variable SST.
The second adds the long name of the SST variable.
In my case I added time data to the new nc file using:
ncap2 -Oh -s "tin=$d;" -S mean.nco foo.nc new_foo.nc
where the mean.nco file looks as follows:
/***.nco ncap2 script***/
defdim("time",1);
time[time]=tin;
time@long_name="Time";
time@units="days since 2000-00-00 00:00:00";
time@standard_name="time";
time@axis="T";
time@coordinate_defines="point";
time@calendar="standard";
/***SST_M@long_name="Sea surface temperature mean";
SST_M@units="Celsius"
/***********/
This adds the third coordinate time where T=$d, which in my case was the january or 1. Then this time is set to the file using:
cdo settime,$d new_foo.nc newer_foo.nc
Finally all the files converted to NetCDF are joined together using:
cdo mergetime folder_containing_all_nc/*.nc final.nc
This joins all files with the appropriate timestamp to one file. This can be with several parameters in one file.
Hope this helps someone.
Greetings,
Frans
Best Answer
it's a bit old but here I am. Unfortunately GDAL does not fully support the NetCDF standard and Sentinel 3 netcdf are one of those unfortunate case.
The following is a simple script written in kotlin unsing the java bindings:
this perfectly works with Sentinel 1 OCN products, but with Sentinel 3 GDAL gives some strange errors while parsing the file:
After some throubleshooting it seems that it does not automatically apply the scale factor and offset of each variable, and so he have to deal with raw lat-lon coordinates and he does not know what to do with it.
I hope this will get fixed soon