# GDAL NetCDF corruption/compatability

**URL:** <https://forum.hdfgroup.org/t/gdal-netcdf-corruption-compatability/11727>\
**Category:** h5py\
**Created:** [November 16, 2023, 10:39pm UTC](https://forum.hdfgroup.org/t/gdal-netcdf-corruption-compatability/11727 "2023-11-16T22:39:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben.wright](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@ben.wright](https://forum.hdfgroup.org/u/ben.wright)\
**Post date:** [November 16, 2023, 10:39pm UTC](https://forum.hdfgroup.org/t/gdal-netcdf-corruption-compatability/11727/1 "2023-11-16T22:39:57Z")

</div>

Hi there, i’m attempting to create a netcdf for a specifc data type (a digital elevation model) using a converted GeoTIFF. I’m converting this geotiff using GDAL. When I try to open the netcdf using h5py (which is the library i’m reliant on for what I need), it’s saying it can’t read it. Yet I can open the file absolutely fine using ncdump or xarray. Does anyone have any ideas as to how I can resolve this to get the file open in h5py? I can’t attach the file itself but here’s a copy of the ncdump -h output:

> \*ncdump -h Copernicus\_DEM\_test2.nc \*  
> _netcdf Copernicus\_DEM\_test2 {_  
> _dimensions:_
> 
> - lon = 15900 ;\*
> - lat = 12609 ;\*  
> _variables:_
> - char crs ;\*
> - 
> 
> ```
> crs:grid_mapping_name = "latitude_longitude" ;*
> 
> ```
> 
> - 
> 
> ```
> crs:long_name = "CRS definition" ;*
> 
> ```
> 
> - 
> 
> ```
> crs:longitude_of_prime_meridian = 0. ;*
> 
> ```
> 
> - 
> 
> ```
> crs:semi_major_axis = 6378137. ;*
> 
> ```
> 
> - 
> 
> ```
> crs:inverse_flattening = 298.257223563 ;*
> 
> ```
> 
> - 
> 
> ```
> crs:spatial_ref = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" ;*
> 
> ```
> 
> - 
> 
> ```
> crs:crs_wkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" ;*
> 
> ```
> 
> - 
> 
> ```
> crs:GeoTransform = "24.17635924150868 0.0002694945852358565 0 -28.51387459087979 0 -0.0002694945852358565 " ;*
> 
> ```
> 
> - double lat(lat) ;\*
> - 
> 
> ```
> lat:standard_name = "latitude" ;*
> 
> ```
> 
> - 
> 
> ```
> lat:long_name = "latitude" ;*
> 
> ```
> 
> - 
> 
> ```
> lat:units = "degrees_north" ;*
> 
> ```
> 
> - double lon(lon) ;\*
> - 
> 
> ```
> lon:standard_name = "longitude" ;*
> 
> ```
> 
> - 
> 
> ```
> lon:long_name = "longitude" ;*
> 
> ```
> 
> - 
> 
> ```
> lon:units = "degrees_east" ;*
> 
> ```
> 
> - float Band1(lat, lon) ;\*
> - 
> 
> ```
> Band1:long_name = "GDAL Band Number 1" ;*
> 
> ```
> 
> - 
> 
> ```
> Band1:_FillValue = 9.96921e+36f ;*
> 
> ```
> 
> - 
> 
> ```
> Band1:grid_mapping = "crs" ;*
> 
> ```
> 
> _// global attributes:_
> 
> - 
> 
> ```
> :GDAL_AREA_OR_POINT = "Area" ;*
> 
> ```
> 
> - 
> 
> ```
> :Conventions = "CF-1.5" ;*
> 
> ```
> 
> - 
> 
> ```
> :GDAL = "GDAL 3.6.3, released 2023/03/07" ;*
> 
> ```
> 
> - 
> 
> ```
> :history = "Wed Nov 15 13:48:31 2023: GDAL CreateCopy( /home/bwright/Documents/active/insar/data/jagers_CGG_test/Copernicus_DEM_test2.nc, ... )" ;*
> 
> ```
> 
> _}_

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![hyoklee](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/hyoklee/32/1528_2.png) [@hyoklee](https://forum.hdfgroup.org/u/hyoklee)\
**Post date:** [November 16, 2023, 10:53pm UTC](https://forum.hdfgroup.org/t/gdal-netcdf-corruption-compatability/11727/2 "2023-11-16T22:53:53Z")

</div>

Is there a chance that the converted file is netCDF-3, not netCDF-4?  
Only netCDF-4 is based on HDF5.  
h5py can open only netCDF-4, not netCDF-3.  
You can use h5dump on your .nc file to make sure that the converted file is netCDF-4.

---

<div class="post-metadata">

**Author:** ![ben.wright](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@ben.wright](https://forum.hdfgroup.org/u/ben.wright)\
**Post date:** [November 22, 2023, 2:12pm UTC](https://forum.hdfgroup.org/t/gdal-netcdf-corruption-compatability/11727/3 "2023-11-22T14:12:20Z")

</div>

I don’t believe so. I seemed to resolve my issue by extracting ‘Band1’ from the gdal output using xarray using xds[‘Band1’].to\_netcdf(‘path/to/output’). The other band appears to be a data array labeled ‘crs’ which contains some of the reference system information.

---

<div class="post-metadata">

**Author:** ![dave.allured](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@dave.allured](https://forum.hdfgroup.org/u/dave.allured)\
**Post date:** [November 22, 2023, 2:35pm UTC](https://forum.hdfgroup.org/t/gdal-netcdf-corruption-compatability/11727/4 "2023-11-22T14:35:05Z")

</div>

Diagnostics please. Show the output from these two shell commands.

ncdump -k Copernicus\_DEM\_test2.nc  
od -N16 -c Copernicus\_DEM\_test2.nc

---

<div class="post-metadata">

**Author:** ![ben.wright](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@ben.wright](https://forum.hdfgroup.org/u/ben.wright)\
**Post date:** [November 22, 2023, 3:13pm UTC](https://forum.hdfgroup.org/t/gdal-netcdf-corruption-compatability/11727/5 "2023-11-22T15:13:50Z")

</div>

Both tools report the file as “classic”. Apologies, I think you were right the first time around! I’ve done some further reading and it appears that GDAL does not default to NetCDF4 and the additional command of “-co FORMAT=NC4” is required when using gdal\_translate.
