とらりもん - HDF4 Diff
- Added parts are displayed like this.
- Deleted parts are displayed
like this.
(We assume you are using Ubuntu Linux 16.04)
!documents
* [[https://portal.hdfgroup.org/display/HDF4/HDF4]]
!What is HDF?
* HDF is a data format which is common and popular for satellite data especially of NASA and JAXA.
* There are HDF4 and HDF5.
* HDF5 may be simpler and easier to understand and handle.
If you want to use HDF5, go to [[HDF5]] page!!
!Install HDF4 libraries:
$ sudo apt-get install hdf4-tools libhdf4-dev libhdf4-0 libhdf4-0-alt
!HDF4 useful commands
* to check contents of HDF4 files:
hdfls
ncdump-hdf
!Handling HDF4 file in python (Ubuntu 16.04)
First, install the HDF4 module in your python3 environment.
$ sudo pip3 install python-hdf4
Let's take an example of treating this file (Terra/MODIS vegetation index)
[[https://e4ftl01.cr.usgs.gov/MOLT/MOD13C2.006/2009.01.01/]]
Go into the python shell by $ ipython3 and ...
import numpy as np
from pyhdf.SD import SD, SDC # HDF library module
hdf=SD("./MOD13C2.A2009001.006.2015186072610.hdf", SDC.READ) # SD=scientific data
hdf.datasets() # show details of the SD
ndvi_sds=hdf.select('CMG 0.05 Deg Monthly NDVI') # select a SDS (scientific dataset)
ndvi=ndvi_sds.get() # read the main body (raster data) of the SDS
nan_index=np.where(ndvi==ndvi_sds.attributes()['_FillValue']) # locate no-data (fill value)
ndvi=ndvi / ndvi_sds.attributes()['scale_factor'] # apply scaling (digital number to real data)
ndvi[nan_index]=np.nan # assign NaN to no-data
import matplotlib.pyplot as plt
plt.imshow(ndvi)
plt.show()
# other useful methods ...
ndvi.attributes()
ndvi.dimensions()
ndvi.get()
ndvi.getcal()
ndvi.getfillvalue()
ndvi.getrange()
ndvi.info()
# if you want to know more detail, try help(ndvi)
!documents
* [[https://portal.hdfgroup.org/display/HDF4/HDF4]]
!What is HDF?
* HDF is a data format which is common and popular for satellite data especially of NASA and JAXA.
* There are HDF4 and HDF5.
* HDF5 may be simpler and easier to understand and handle.
If you want to use HDF5, go to [[HDF5]] page!!
!Install HDF4 libraries:
$ sudo apt-get install hdf4-tools libhdf4-dev libhdf4-0 libhdf4-0-alt
!HDF4 useful commands
* to check contents of HDF4 files:
hdfls
ncdump-hdf
!Handling HDF4 file in python (Ubuntu 16.04)
First, install the HDF4 module in your python3 environment.
$ sudo pip3 install python-hdf4
Let's take an example of treating this file (Terra/MODIS vegetation index)
[[https://e4ftl01.cr.usgs.gov/MOLT/MOD13C2.006/2009.01.01/]]
Go into the python shell by $ ipython3 and ...
import numpy as np
from pyhdf.SD import SD, SDC # HDF library module
hdf=SD("./MOD13C2.A2009001.006.2015186072610.hdf", SDC.READ) # SD=scientific data
hdf.datasets() # show details of the SD
ndvi_sds=hdf.select('CMG 0.05 Deg Monthly NDVI') # select a SDS (scientific dataset)
ndvi=ndvi_sds.get() # read the main body (raster data) of the SDS
nan_index=np.where(ndvi==ndvi_sds.attributes()['_FillValue']) # locate no-data (fill value)
ndvi=ndvi / ndvi_sds.attributes()['scale_factor'] # apply scaling (digital number to real data)
ndvi[nan_index]=np.nan # assign NaN to no-data
import matplotlib.pyplot as plt
plt.imshow(ndvi)
plt.show()
# other useful methods ...
ndvi.attributes()
ndvi.dimensions()
ndvi.get()
ndvi.getcal()
ndvi.getfillvalue()
ndvi.getrange()
ndvi.info()
# if you want to know more detail, try help(ndvi)