Print all MODIS C6 MYD03 SDS names and attributes in python 2.7

Published: March 30, 2017

DMCA.com Protection Status

Outputs of a code (see bottom of the page) written in python 2.7 to print all MODIS C6 MYD03 SDS names and attributes in python 2.7. All SDS infos (nd: number of dimensions, t: type, na: number of attributes):

Id name nd dimension t na
0 Latitude 2 [2030, 1354] 5 3
1 Longitude 2 [2030, 1354] 5 3
2 Scan Offset 2 [4060, 2708] 20 4
3 Track Offset 2 [4060, 2708] 20 4
4 Height Offset 2 [4060, 2708] 20 4
5 Height 2 [2030, 1354] 22 3
6 SensorZenith 2 [2030, 1354] 22 4
7 SensorAzimuth 2 [2030, 1354] 22 4
8 Range 2 [2030, 1354] 23 4
9 SolarZenith 2 [2030, 1354] 22 4
10 SolarAzimuth 2 [2030, 1354] 22 4
11 Land/SeaMask 2 [2030, 1354] 21 2
12 WaterPresent 2 [2030, 1354] 21 2
13 gflags 2 [2030, 1354] 21 1
14 Scan number 1 203 22 1
15 EV frames 1 203 23 1
16 SD frames 1 203 23 0
17 SV frames 1 203 23 0
18 EV start time 1 203 6 2
19 SD start time 1 203 6 2
20 SV start time 1 203 6 2
21 EV center time 1 203 6 2
22 Mirror side 1 203 23 2
23 SD Sun zenith 1 203 5 2
24 SD Sun azimuth 1 203 5 2
25 Moon Vector 2 [203, 3] 5 1
26 L1 scan quality 2 [203, 4] 24 1
27 Geo scan quality 2 [203, 4] 20 1
28 orb_pos 2 [203, 3] 6 3
29 orb_vel 2 [203, 3] 6 3
30 T_inst2ECR 3 [203, 3, 3] 6 2
31 attitude_angles 2 [203, 3] 6 5
32 sun_ref 2 [203, 3] 5 2
33 num_impulse 1 203 21 1
34 impulse_enc 2 [203, 25] 6 3
35 impulse_time 2 [203, 25] 6 3
36 Scan Type 2 [203, 10] 4 0
37 thermal_correction 2 [203, 3] 5 6
38 attitude_quality 2 [203, 1354] 25 15
39 ephemeris_quality 2 [203, 1354] 25 15
40 Focal_length 1 37 6 1
41 band_position 1 37 6 1
42 detector_space 1 37 6 1
43 detector_offsets 2 [37, 2] 6 3
44 T_offset 1 37 6 1
45 num_samples 1 37 23 0

Latitude

units degrees
_FillValue 999.0
valid_range [90.0, 90.0]

Longitude

units degrees
_FillValue 999.0
valid_range [180.0, 180.0]

Scan Offset

units km IFOV
_FillValue 128
scale_factor 0.006
valid_range [127, 127]

Track Offset

units km IFOV
_FillValue 128
scale_factor 0.006
valid_range [127, 127]

Height Offset

units km
_FillValue 128
scale_factor 0.006
valid_range [127, 127]

Height

units meters
_FillValue 32767
valid_range [400, 10000]

SensorZenith

units degrees
_FillValue 32767
scale_factor 0.01
valid_range [0, 18000]

SensorAzimuth

units degrees
_FillValue 32767
scale_factor 0.01
valid_range [18000, 18000]

Range

units meters
_FillValue 0
scale_factor 25.0
valid_range [27000, 65535]

SolarZenith

units degrees
_FillValue 32767
scale_factor 0.01
valid_range [0, 18000]

SolarAzimuth

units degrees
_FillValue 32767
scale_factor 0.01
valid_range [18000, 18000]

Land/SeaMask

_FillValue 221
valid_range [0, 7]

WaterPresent

_FillValue 255
valid_range [0, 8]

gflags

_FillValue 255

Scan number

_FillValue 0

EV frames

valid_range [0, 1400]

SD frames

SV frames

EV start time

units seconds
_FillValue 2000000000.0

SD start time

units seconds
_FillValue 2000000000.0

SV start time

units seconds
_FillValue 2000000000.0

EV center time

units seconds
_FillValue 2000000000.0

Mirror side

_FillValue 65535
valid_range [0, 1]

SD Sun zenith

units radians
_FillValue 9.96920996839e+36

SD Sun azimuth

units radians
_FillValue 9.96920996839e+36

Moon Vector

_FillValue 9.96920996839e+36

L1 scan quality

_FillValue 1

Geo scan quality

_FillValue 127

orb_pos

units meters
_FillValue 9.96920996839e+36
valid_range [7200000.0, 7200000.0]

orb_vel

units meters per second
_FillValue 9.96920996839e+36
valid_range [7600.0, 7600.0]

T_inst2ECR

_FillValue 9.96920996839e+36
valid_range [1.0, 1.0]

attitude_angles

units radians
_FillValue 9.96920996839e+36
pitch_element 1
roll_element 0
yaw_element 2

sun_ref

_FillValue 9.96920996839e+36
valid_range [1.0, 1.0]

num_impulse

valid_range [0, 25]

impulse_enc

units encoder pulses
_FillValue 9.96920996839e+36
valid_range [0.0, 16384.0]

impulse_time

units seconds
_FillValue 9.96920996839e+36
valid_range [0.0, 1.5]

Scan Type

thermal_correction

_FillValue 999.0
pitch_element 1
yaw_element 2
valid_range [180.0, 180.0]
roll_element 0
units degrees

attitude_quality

_FillValue 4096
interpolated_point 16384
overall 1
data_summary 2
yellow_limit_low 8
repaired_data_point 1024
quality_flag_problem 2048
short_gap_precedes 256
red_limit_low 4
long_gap_follows 64
yellow_limit_high 16
valid_range [0, 20139]
short_gap_follows 128
red_limit_high 32
long_gap_precedes 512

ephemeris_quality

_FillValue 4096
interpolated_point 16384
overall 1
data_summary 2
yellow_limit_low 8
repaired_data_point 1024
quality_flag_problem 2048
short_gap_precedes 256
red_limit_low 4
long_gap_follows 64
yellow_limit_high 16
valid_range [0, 18091]
short_gap_follows 128
red_limit_high 32
long_gap_precedes 512

Focal_length

units meters

band_position

units frame sample time

detector_space

units meters

detector_offsets

units meters
scandim 0
trackdim 1

T_offset

units frame sample time

num_samples

Code source:

#!/usr/bin/env python

from pyhdf.SD import SD, SDC

import pprint

file_name = 'MYD03.A2008190.1420.006.2012069052937.hdf'

file = SD(file_name, SDC.READ)

file_info = file.info()
print file_info  # number of sds and metadata

#----------------------------------------------------------------------------------------#
# print sds names

datasets_dic = file.datasets()

#for idx,sds in enumerate(datasets_dic.keys()):
#   print idx,sds

sds_dic = {}
for key, value in datasets_dic.iteritems():
    #print key, value, value[3]
    sds_dic[value[3]] = key

pprint.pprint( sds_dic )

#----------------------------------------------------------------------------------------#
# print SDS info

for i in range(file_info[0]):
    sds_obj = file.select(sds_dic[i])
    sds_info = sds_obj.info()
    print i, ' | ', sds_dic[i], \
             ' | ', sds_info[1] , \
             ' | ', sds_info[2] , \
             ' | ', sds_info[3] , \
             ' | ', sds_info[4]

#----------------------------------------------------------------------------------------#
# print SDS Attributes

for i in range(file_info[0]):
    sds_obj = file.select(sds_dic[i])
    sds_attributes = sds_obj.attributes()
    attributes = ''
    for key, value in sds_attributes.iteritems():
        attributes = attributes + key + ' ' + str(value) + '\n'
    print '#### ',  sds_dic[i]
    print
    print attributes.replace('-', '')
    print