Read MODIS HDF4 as xarray¶
import xarray as xr
from osgeo import gdal
xr.set_options(display_style='html')
%matplotlib inline
Find full subdataset names¶
def get_subdataset(file, varnames):
g = gdal.Open(path)
subdatasets = g.GetSubDatasets()
l = []
for varname in varnames:
l.extend( [s[0] for s in subdatasets if varname in s[0].split(':')[-1] ])
return l
Read subdatasets in xarray¶
def read_hdf4(file, varnames):
ld = []
fname_list = get_subdataset(file, varnames)
for fname in fname_list:
myDataset = xr.open_rasterio(fname)
ld.append(myDataset.to_dataset(name=fname.split(':')[-1]))
return xr.merge(ld)
varnames = ['cloud_top_temperature_1km', 'Cloud_Effective_Radius', 'Cloud_Optical_Thickness', 'Cloud_Multi_Layer_Flag']
path = 'MYD06_L2.A2019001.1850.061.2019002154022.hdf'
dset = read_hdf4(path, varnames)
/opt/conda/envs/pangeo/lib/python3.8/site-packages/rasterio/__init__.py:221: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
s = DatasetReader(path, driver=driver, sharing=sharing, **kwargs)
dset
<xarray.Dataset> Dimensions: (band: 1, x: 1354, y: 2030) Coordinates: * band (band) int64 1 * y (y) float64 0.5 1.5 ... 2.03e+03 * x (x) float64 0.5 1.5 ... 1.354e+03 Data variables: cloud_top_temperature_1km (band, y, x) int16 ... Cloud_Effective_Radius (band, y, x) int16 ... Cloud_Effective_Radius_PCL (band, y, x) int16 ... Cloud_Effective_Radius_16 (band, y, x) int16 ... Cloud_Effective_Radius_16_PCL (band, y, x) int16 ... Cloud_Effective_Radius_37 (band, y, x) int16 ... Cloud_Effective_Radius_37_PCL (band, y, x) int16 ... Cloud_Effective_Radius_1621 (band, y, x) int16 ... Cloud_Effective_Radius_1621_PCL (band, y, x) int16 ... Cloud_Effective_Radius_Uncertainty (band, y, x) int16 ... Cloud_Effective_Radius_Uncertainty_16 (band, y, x) int16 ... Cloud_Effective_Radius_Uncertainty_37 (band, y, x) int16 ... Cloud_Effective_Radius_Uncertainty_1621 (band, y, x) int16 ... Cloud_Optical_Thickness (band, y, x) int16 ... Cloud_Optical_Thickness_PCL (band, y, x) int16 ... Cloud_Optical_Thickness_16 (band, y, x) int16 ... Cloud_Optical_Thickness_16_PCL (band, y, x) int16 ... Cloud_Optical_Thickness_37 (band, y, x) int16 ... Cloud_Optical_Thickness_37_PCL (band, y, x) int16 ... Cloud_Optical_Thickness_1621 (band, y, x) int16 ... Cloud_Optical_Thickness_1621_PCL (band, y, x) int16 ... Cloud_Optical_Thickness_Uncertainty (band, y, x) int16 ... Cloud_Optical_Thickness_Uncertainty_16 (band, y, x) int16 ... Cloud_Optical_Thickness_Uncertainty_37 (band, y, x) int16 ... Cloud_Optical_Thickness_Uncertainty_1621 (band, y, x) int16 ... Cloud_Multi_Layer_Flag (band, y, x) uint8 ...
xarray.Dataset
- band: 1
- x: 1354
- y: 2030
- band(band)int641
array([1])
- y(y)float640.5 1.5 2.5 ... 2.028e+03 2.03e+03
array([5.0000e-01, 1.5000e+00, 2.5000e+00, ..., 2.0275e+03, 2.0285e+03, 2.0295e+03])
- x(x)float640.5 1.5 2.5 ... 1.352e+03 1.354e+03
array([5.0000e-01, 1.5000e+00, 2.5000e+00, ..., 1.3515e+03, 1.3525e+03, 1.3535e+03])
- cloud_top_temperature_1km(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (-15000.0,)
- descriptions :
- ('Cloud Top Temperature at 1-km resolution from LEOCAT, Temperature from Ancillary Data at Retrieved Cloud Top Pressure Level',)
- units :
- ('K',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Particle Effective Radius two-channel retrieval using band 7(2.1um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from best points: not failed in any way, not marked for clear sky restoral',)
- units :
- ('micron',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_PCL(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Particle Effective Radius two-channel retrieval using band 7(2.1um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from points identified as either partly cloudy from 250m cloud mask test or 1km cloud edges',)
- units :
- ('micron',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_16(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Particle Effective Radius two-channel retrieval using band 6(1.6um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from best points: not failed in any way, not marked for clear sky restoral',)
- units :
- ('micron',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_16_PCL(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Particle Effective Radius two-channel retrieval using band 6(1.6um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from points identified as either partly cloudy from 250m cloud mask test or 1km cloud edges',)
- units :
- ('micron',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_37(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Particle Effective Radius two-channel retrieval using band 20(3.7um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from best points: not failed in any way, not marked for clear sky restoral',)
- units :
- ('micron',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_37_PCL(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Particle Effective Radius two-channel retrieval using band 20(3.7um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from points identified as either partly cloudy from 250m cloud mask test or 1km cloud edges',)
- units :
- ('micron',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_1621(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Particle Effective Radius two-channel retrieval using band 7(2.1um) and band 6(1.6um)from best points: not failed in any way, not marked for clear sky restoral',)
- units :
- ('micron',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_1621_PCL(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Particle Effective Radius two-channel retrieval using band 7(2.1um) and band 6(1.6um)from points identified as either partly cloudy from 250m cloud mask test or 1km cloud edges',)
- units :
- ('micron',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_Uncertainty(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Effective Particle Radius (from band 7(2.1um)) Relative Uncertainty (Percent)from both best points and points identified as cloud edge at 1km resolution or partly cloudy at 250m',)
- units :
- ('percent',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_Uncertainty_16(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Effective Particle Radius (from band 6(1.6um) Relative Uncertainty (Percent)from both best points and points identified as cloud edge at 1km resolution or partly cloudy at 250m',)
- units :
- ('percent',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_Uncertainty_37(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Effective Particle Radius (from band 20(3.7um)) Relative Uncertainty (Percent)from both best points and points identified as cloud edge at 1km resolution or partly cloudy at 250m',)
- units :
- ('percent',)
[2748620 values with dtype=int16]
- Cloud_Effective_Radius_Uncertainty_1621(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Effective Particle Radius Relative Uncertainty (Percent) using band 7(2.1um) and band 6(1.6um)from both best points and points identified as cloud edge at 1km resolution or partly cloudy at 250m',)
- units :
- ('percent',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness two-channel retrieval using band 7(2.1um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from best points: not failed in any way, not marked for clear sky restoral',)
- units :
- ('none',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_PCL(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness two-channel retrieval using band 7(2.1um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from points identified as either partly cloudy from 250m cloud mask test or 1km cloud edges',)
- units :
- ('none',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_16(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness two-channel retrieval using band 6(1.6um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from best points: not failed in any way, not marked for clear sky restoral',)
- units :
- ('none',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_16_PCL(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness two-channel retrieval using band 6(1.6um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from points identified as either partly cloudy from 250m cloud mask test or 1km cloud edges',)
- units :
- ('none',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_37(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness two-channel retrieval using band 20(3.7um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from best points: not failed in any way, not marked for clear sky restoral',)
- units :
- ('none',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_37_PCL(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness two-channel retrieval using band 20(3.7um) and either band 1(0.65um), 2(0.86um), or 5(1.2um) (specified in Quality_Assurance_1km)from points identified as either partly cloudy from 250m cloud mask test or 1km cloud edges',)
- units :
- ('none',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_1621(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness two-channel retrieval using band 7(2.1um) and band 6(1.6um)from best points: not failed in any way, not marked for clear sky restoral',)
- units :
- ('none',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_1621_PCL(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness two-channel retrieval using band 7(2.1um) and band 6(1.6um)from points identified as either partly cloudy from 250m cloud mask test or 1km cloud edges',)
- units :
- ('none',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_Uncertainty(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness Relative Uncertainty (Percent)from both best points and points identified as cloud edge at 1km resolution or partly cloudy at 250m based on the Cloud_Optical_Thickness and Cloud_Effective_Radius results',)
- units :
- ('percent',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_Uncertainty_16(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness Relative Uncertainty (Percent)from both best points and points identified as cloud edge at 1km resolution or partly cloudy at 250m based on the Cloud_Optical_Thickness_16 and Cloud_Effective_Radius_16 results',)
- units :
- ('percent',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_Uncertainty_37(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness Relative Uncertainty (Percent)from both best points and points identified as cloud edge at 1km resolution or partly cloudy at 250m based on the Cloud_Optical_Thickness_37 and Cloud_Effective_Radius_37 results',)
- units :
- ('percent',)
[2748620 values with dtype=int16]
- Cloud_Optical_Thickness_Uncertainty_1621(band, y, x)int16...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (-9999.0,)
- scales :
- (0.00999999977648258,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Optical Thickness Relative Uncertainty (Percent) using band 7(2.1um) and band 6(1.6um)from both best points and points identified as cloud edge at 1km resolution or partly cloudy at 250m',)
- units :
- ('percent',)
[2748620 values with dtype=int16]
- Cloud_Multi_Layer_Flag(band, y, x)uint8...
- transform :
- (1.0, 0.0, 0.0, 0.0, 1.0, 0.0)
- res :
- (1.0, -1.0)
- is_tiled :
- 0
- nodatavals :
- (0.0,)
- scales :
- (1.0,)
- offsets :
- (0.0,)
- descriptions :
- ('Cloud Multi Layer Identification From MODIS Shortwave Observations',)
- units :
- ('none',)
[2748620 values with dtype=uint8]