Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read HDF4 file? #356

Closed
daxinnan opened this issue Apr 27, 2020 · 7 comments
Closed

How to read HDF4 file? #356

daxinnan opened this issue Apr 27, 2020 · 7 comments

Comments

@daxinnan
Copy link

I see an example for HDF5 as follows:

using GMT
file = "A2016152023000.L2_LAC_SST.nc=gd?HDF5:\"A2016152023000.L2_LAC_SST.nc\"";
sst  = gmt("read -Tg " * file * ":https://geophysical_data/sst");

Now I have a HDF4 file, and I run `gdalinfo "filename.hdf".

PS C:\Users\usrname\Desktop> gdalinfo ".\2014068005444_41824_CS_2B-GEOPROF-LIDAR_GRANULE_P2_R05_E06_F00.hdf"
Driver: HDF4/Hierarchical Data Format Release 4
Files: .\2014068005444_41824_CS_2B-GEOPROF-LIDAR_GRANULE_P2_R05_E06_F00.hdf
Size is 512, 512
Metadata:
  HDFEOSVersion=HDFEOS_V2.5
Subdatasets:
  SUBDATASET_1_NAME=HDF4_EOS:EOS_SWATH:".\2014068005444_41824_CS_2B-GEOPROF-LIDAR_GRANULE_P2_R05_E06_F00.hdf":2B-GEOPROF-LIDAR:CloudFraction
  SUBDATASET_1_DESC=[37082x125] CloudFraction 2B-GEOPROF-LIDAR (8-bit integer)
...
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  512.0)
Upper Right (  512.0,    0.0)
Lower Right (  512.0,  512.0)
Center      (  256.0,  256.0)

I'm a new one to use gmt. I don't know how to use the information to read HDF4 in julia.
Any one can help me? Thank you, guys.

@joa-quim
Copy link
Member

Try this. The logic to be followed is that explained in GDAL docs to access to subdatasets.

file = "2014068005444_41824_CS_2B-GEOPROF-LIDAR_GRANULE_P2_R05_E06_F00.hdf=gd?HDF4_EOS:EOS_SWATH:\"2014068005444_41824_CS_2B-GEOPROF-LIDAR_GRANULE_P2_R05_E06_F00.hdf\":2B-GEOPROF-LIDAR:CloudFraction";

out = gmt("read -Tg " * file);

@daxinnan
Copy link
Author

Maybe there is an error about my gmt,

julia> out = gmt("read -Tg " * file);
ERROR: could not load library "libgmt"
libgmt.so: 无法打开共享对象文件: 没有那个文件或目录 # I guess it means Can't open share object file, No such file or directory.
Stacktrace:
 [1] GMT_Create_Session at /home/usrname/.julia/packages/GMT/VY9y7/src/libgmt.jl:6 [inlined] (repeats 2 times)
 [2] gmt(::String) at /home/usrname/.julia/packages/GMT/VY9y7/src/gmt_main.jl:125
 [3] top-level scope at none:0

julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, haswell)
Environment:
  JULIA_NUM_THREADS = 4
$ gmt --version
6.0.0

My system is Ubuntu 20.04, I use xarray by using PyCall temporarily.

@daxinnan
Copy link
Author

When I run ]test GMT, some errors occur. I'll push the relative information later.

@joa-quim
Copy link
Member

Ah, you are on Linux and probably did not install GMT on a standard place so the OS does not know where the GMT shared libs are. Try this from the README.md

On OSX, with a manual GMT build and dependencies obtained with Homebrew (that are installed at /user/local/lib), I had to help Julia finding MY libgmt.dylib, with (this line should than be added to the ~/.julia/config/startup.jl file)

using Libdl
push!(Libdl.DL_LOAD_PATH, "/Users/j/programs/gmt6/lib")

@daxinnan
Copy link
Author

daxinnan commented May 1, 2020

Sorry for replying late, I run the code at terminal:

ldconfig -p | grep libgmt
	libgmt.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libgmt.so.6

and install gmt like ythis:

sudo aptitude install gmt gmt-dcw gmt-gshhg

What does the meaning of "/Users/j/programs/gmt6/lib"?

Error in detail:

julia> file = "2014068005444_41824_CS_2B-GEOPROF_GRANULE_P1_R05_E06_F00.hdf=gd?HDF4_EOS:EOS_SWATH:\"2014068005444_41824_CS_2B-GEOPROF_GRANULE_P1_R05_E06_F00.hdf\""
"2014068005444_41824_CS_2B-GEOPROF_GRANULE_P1_R05_E06_F00.hdf=gd?HDF4_EOS:EOS_SWATH:\"2014068005444_41824_CS_2B-GEOPROF_GRANULE_P1_R05_E06_F00.hdf\""

julia> out = gmt("read -Tg " * file * ":2B-GEOPROF:CPR_Cloud_mask");
ERROR: could not load library "libgmt"
libgmt.so: 无法打开共享对象文件: 没有那个文件或目录
Stacktrace:
 [1] GMT_Create_Session at /home/usrname/.julia/packages/GMT/VY9y7/src/libgmt.jl:6 [inlined] (repeats 2 times)
 [2] gmt(::String) at /home/usrname/.julia/packages/GMT/VY9y7/src/gmt_main.jl:125
 [3] top-level scope at REPL[16]:1
caused by [exception 1]
UndefVarError: API not defined
Stacktrace:
 [1] gmt(::String) at /home/usrname/.julia/packages/GMT/VY9y7/src/gmt_main.jl:122
 [2] top-level scope at REPL[16]:1

@joa-quim
Copy link
Member

joa-quim commented May 1, 2020

What does the meaning of "/Users/j/programs/gmt6/lib"?

It means the path to the directory where you have libgmt.so. The one above, is an example of my own case. Several people have reported this trouble and solved it the DL_LOAD_PATH setting.

Now, I have no idea why some people need to do that. The Travis CI tests run on a Linux machine and they run fine.

@joa-quim
Copy link
Member

Can I close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants