[Scilab-users] HDF5 write data to file
Lester Anderson
arctica1963 at gmail.com
Fri May 27 17:13:10 CEST 2022
Hi all,
The Scilab (SOD) format is the way forward since netCDF and HDF5 are very
similar, but have slightly different naming conventions. I have a
Geographic grid with the structure below, but cannot seem to get the output
file dimensions right, i.e. the x and y coordinates in degrees and not
pixel reference.
File structure from ncdisp('filename')
Source: Test_10-FAA.grd
Format: netcdf4
Global Attributes:
Conventions = "COARDS, CF-1.5"
title = ""
history = "grdsample -R-10/10/-10/10 -I1m @GMTAPI at -000001
-Gc:\Temp\Test_10-FAA.grd -fg --GMT_HISTORY=false"
description = ""
GMT_version = "5.4.3 (r19528) [64-bit] [MP]"
node_offset = 1
Dimensions:
lon = 1200
lat = 1200
Variables:
lon
Size: 1200
Dimensions: lon
Datatype: double
Attributes:
long_name = "longitude"
units = "degrees_east"
actual_range = -10 10
lat
Size: 1200
Dimensions: lat
Datatype: double
Attributes:
long_name = "latitude"
units = "degrees_north"
actual_range = -10 10
z
Size: 1200x1200
Dimensions: lon,lat
Datatype: single
Attributes:
long_name = "z"
_FillValue = NaN
actual_range = -104.9617 456.6511
b=h5open('Test_out.grd','w');
h5write(b,'lat',lat);
h5write(b,'lon',lon);
h5write(b,'data',data);
h5close(b)
save('Test_output.sod','lon','lat','data')
Saving the output creates a file composed of the three datasets (lon, lat,
data). Plotting the data in Scilab via Sgrayplot(x,y,z) it looks correct,
oriented properly and axes of longitude and latitude.
Anyone know how to set the correct attributes to get the HDF5 file
recognised as Geographic?
Lester
On Wed, 25 May 2022 at 15:17, Lester Anderson <arctica1963 at gmail.com> wrote:
> Hi all,
>
> I just found a useful way of getting netCDF files into Scilab via HDF5
> (just found this!):
>
> a=h5open('Test_10-FAA.grd');
> h5ls(a)
> // "lat" "dataset" // "lon" "dataset" // "z" "dataset" // "Conventions" "attribute"// "GMT_version" "attribute"// "_NCProperties" "attribute"// "description" "attribute"// "history" "attribute"// "node_offset" "attribute"// "title" "attribute"
> lon=h5read(a, 'lon');lat=h5read(a, 'lat');data=h5read(a, 'z');
>
> h5close(a);
>
> The data plots fine via Sgrayplot(lon,lat,data,zminmax=[-25,25]) . I need
> to know how to write data out to essentially replicate the input netCDF
> file, so any pointers/examples would be helpful. It would be good to output
> a file in a format that GMT (Generic Mapping Tools) would recognise.
>
> The use of HDF5 seems to solve the issues of working with netCDF-4 files.
>
> Lester
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20220527/96cb243c/attachment.htm>
More information about the users
mailing list