Skip to content

Commit 054fe62

Browse files
authored
fix: drop DIMENSION_LIST, CLASS and NAME attributes (#86)
1 parent 6f1b9d8 commit 054fe62

File tree

6 files changed

+210
-112
lines changed

6 files changed

+210
-112
lines changed

icesat2_toolkit/io/ATL03.py

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
u"""
3-
ATL03.py (12/2022)
3+
ATL03.py (11/2023)
44
Read ICESat-2 ATL03 and ATL09 data files to calculate average segment surfaces
55
ATL03 datasets: Global Geolocated Photons
66
ATL09 datasets: Atmospheric Characteristics
@@ -15,6 +15,7 @@
1515
https://www.h5py.org/
1616
1717
UPDATE HISTORY:
18+
Updated 11/2023: drop DIMENSION_LIST, CLASS and NAME attributes
1819
Updated 12/2022: place some imports behind try/except statements
1920
refactor ICESat-2 data product read programs under io
2021
Updated 04/2022: updated docstrings to numpy documentation format
@@ -127,27 +128,32 @@ def read_granule(FILENAME, ATTRIBUTES=False, **kwargs):
127128
IS2_atl03_attrs[gtx]['geophys_corr'] = {}
128129
# Global Group Attributes
129130
for att_name,att_val in fileID[gtx].attrs.items():
130-
IS2_atl03_attrs[gtx][att_name] = att_val
131+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
132+
IS2_atl03_attrs[gtx][att_name] = att_val
131133
# ICESat-2 Measurement Group
132134
for key,val in fileID[gtx]['heights'].items():
133135
IS2_atl03_attrs[gtx]['heights'][key] = {}
134136
for att_name,att_val in val.attrs.items():
135-
IS2_atl03_attrs[gtx]['heights'][key][att_name]=att_val
137+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
138+
IS2_atl03_attrs[gtx]['heights'][key][att_name]=att_val
136139
# ICESat-2 Geolocation Group
137140
for key,val in fileID[gtx]['geolocation'].items():
138141
IS2_atl03_attrs[gtx]['geolocation'][key] = {}
139142
for att_name,att_val in val.attrs.items():
140-
IS2_atl03_attrs[gtx]['geolocation'][key][att_name]=att_val
143+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
144+
IS2_atl03_attrs[gtx]['geolocation'][key][att_name]=att_val
141145
# ICESat-2 Background Photon Rate Group
142146
for key,val in fileID[gtx]['bckgrd_atlas'].items():
143147
IS2_atl03_attrs[gtx]['bckgrd_atlas'][key] = {}
144148
for att_name,att_val in val.attrs.items():
145-
IS2_atl03_attrs[gtx]['bckgrd_atlas'][key][att_name]=att_val
149+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
150+
IS2_atl03_attrs[gtx]['bckgrd_atlas'][key][att_name]=att_val
146151
# ICESat-2 Geophysical Corrections Group
147152
for key,val in fileID[gtx]['geophys_corr'].items():
148153
IS2_atl03_attrs[gtx]['geophys_corr'][key] = {}
149154
for att_name,att_val in val.attrs.items():
150-
IS2_atl03_attrs[gtx]['geophys_corr'][key][att_name]=att_val
155+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
156+
IS2_atl03_attrs[gtx]['geophys_corr'][key][att_name]=att_val
151157

152158
# ICESat-2 spacecraft orientation at time
153159
IS2_atl03_mds['orbit_info'] = {}
@@ -158,11 +164,13 @@ def read_granule(FILENAME, ATTRIBUTES=False, **kwargs):
158164
if ATTRIBUTES:
159165
# Global Group Attributes
160166
for att_name,att_val in fileID['orbit_info'].attrs.items():
161-
IS2_atl03_attrs['orbit_info'][att_name] = att_val
167+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
168+
IS2_atl03_attrs['orbit_info'][att_name] = att_val
162169
# Variable Attributes
163170
IS2_atl03_attrs['orbit_info'][key] = {}
164171
for att_name,att_val in val.attrs.items():
165-
IS2_atl03_attrs['orbit_info'][key][att_name] = att_val
172+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
173+
IS2_atl03_attrs['orbit_info'][key][att_name] = att_val
166174

167175
# information ancillary to the data product
168176
# number of GPS seconds between the GPS epoch (1980-01-06T00:00:00Z UTC)
@@ -185,7 +193,8 @@ def read_granule(FILENAME, ATTRIBUTES=False, **kwargs):
185193
# Variable Attributes
186194
IS2_atl03_attrs['ancillary_data'][key] = {}
187195
for att_name,att_val in fileID['ancillary_data'][key].attrs.items():
188-
IS2_atl03_attrs['ancillary_data'][key][att_name] = att_val
196+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
197+
IS2_atl03_attrs['ancillary_data'][key][att_name] = att_val
189198

190199
# transmit-echo-path (tep) parameters
191200
IS2_atl03_mds['ancillary_data']['tep'] = {}
@@ -198,7 +207,8 @@ def read_granule(FILENAME, ATTRIBUTES=False, **kwargs):
198207
# Variable Attributes
199208
IS2_atl03_attrs['ancillary_data']['tep'][key] = {}
200209
for att_name,att_val in val.attrs.items():
201-
IS2_atl03_attrs['ancillary_data']['tep'][key][att_name] = att_val
210+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
211+
IS2_atl03_attrs['ancillary_data']['tep'][key][att_name] = att_val
202212

203213
# channel dead time and first photon bias derived from ATLAS calibration
204214
cal1,cal2 = ('ancillary_data','calibrations')
@@ -218,12 +228,14 @@ def read_granule(FILENAME, ATTRIBUTES=False, **kwargs):
218228
# Variable Attributes
219229
IS2_atl03_attrs[cal1][var][key] = {}
220230
for att_name,att_val in val.attrs.items():
221-
IS2_atl03_attrs[cal1][var][key][att_name] = att_val
231+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
232+
IS2_atl03_attrs[cal1][var][key][att_name] = att_val
222233
if isinstance(val, h5py.Group):
223234
for k,v in val.items():
224235
IS2_atl03_attrs[cal1][var][key][k] = {}
225236
for att_name,att_val in val.attrs.items():
226-
IS2_atl03_attrs[cal1][var][key][k][att_name]=att_val
237+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
238+
IS2_atl03_attrs[cal1][var][key][k][att_name]=att_val
227239

228240
# get ATLAS impulse response variables for the transmitter echo path (TEP)
229241
tep1,tep2 = ('atlas_impulse_response','tep_histogram')
@@ -239,21 +251,24 @@ def read_granule(FILENAME, ATTRIBUTES=False, **kwargs):
239251
if ATTRIBUTES:
240252
# Global Group Attributes
241253
for att_name,att_val in fileID[tep1][pce][tep2].attrs.items():
242-
IS2_atl03_attrs[tep1][pce][tep2][att_name] = att_val
254+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
255+
IS2_atl03_attrs[tep1][pce][tep2][att_name] = att_val
243256
# Variable Attributes
244257
IS2_atl03_attrs[tep1][pce][tep2][key] = {}
245258
for att_name,att_val in val.attrs.items():
246-
IS2_atl03_attrs[tep1][pce][tep2][key][att_name] = att_val
259+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
260+
IS2_atl03_attrs[tep1][pce][tep2][key][att_name] = att_val
247261

248262
# Global File Attributes
249263
if ATTRIBUTES:
250264
for att_name,att_val in fileID.attrs.items():
251-
IS2_atl03_attrs[att_name] = att_val
265+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
266+
IS2_atl03_attrs[att_name] = att_val
252267

253268
# Closing the HDF5 file
254269
fileID.close()
255270
# Return the datasets and variables
256-
return (IS2_atl03_mds,IS2_atl03_attrs,IS2_atl03_beams)
271+
return (IS2_atl03_mds, IS2_atl03_attrs, IS2_atl03_beams)
257272

258273
# PURPOSE: read ICESat-2 ATL09 HDF5 data file for specific variables
259274
def interpolate_ATL09(FILENAME, pfl, dtime, ATTRIBUTES=True, **kwargs):
@@ -311,22 +326,25 @@ def interpolate_ATL09(FILENAME, pfl, dtime, ATTRIBUTES=True, **kwargs):
311326
IS2_atl09_attrs[pfl] = dict(high_rate={})
312327
# Global Group Attributes
313328
for att_name,att_val in fileID[pfl].attrs.items():
314-
IS2_atl09_attrs[pfl][att_name] = att_val
329+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
330+
IS2_atl09_attrs[pfl][att_name] = att_val
315331
# Variable Attributes
316332
for key in high_rate_keys:
317333
IS2_atl09_attrs[pfl]['high_rate'][key] = {}
318334
for att_name,att_val in fileID[pfl]['high_rate'][key].attrs.items():
319-
IS2_atl09_attrs[pfl]['high_rate'][key][att_name] = att_val
335+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
336+
IS2_atl09_attrs[pfl]['high_rate'][key][att_name] = att_val
320337

321338
# Global File Attributes
322339
if ATTRIBUTES:
323340
for att_name,att_val in fileID.attrs.items():
324-
IS2_atl09_attrs[att_name] = att_val
341+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
342+
IS2_atl09_attrs[att_name] = att_val
325343

326344
# Closing the HDF5 file
327345
fileID.close()
328346
# Return the datasets and variables
329-
return (IS2_atl09_mds,IS2_atl09_attrs)
347+
return (IS2_atl09_mds, IS2_atl09_attrs)
330348

331349
# PURPOSE: find valid beam groups within ICESat-2 ATL03 HDF5 data files
332350
def find_beams(FILENAME, **kwargs):
@@ -425,11 +443,13 @@ def read_main(FILENAME, ATTRIBUTES=False, **kwargs):
425443
if ATTRIBUTES:
426444
# Global Group Attributes
427445
for att_name,att_val in fileID['orbit_info'].attrs.items():
428-
IS2_atl03_attrs['orbit_info'][att_name] = att_val
446+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
447+
IS2_atl03_attrs['orbit_info'][att_name] = att_val
429448
# Variable Attributes
430449
IS2_atl03_attrs['orbit_info'][key] = {}
431450
for att_name,att_val in val.attrs.items():
432-
IS2_atl03_attrs['orbit_info'][key][att_name] = att_val
451+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
452+
IS2_atl03_attrs['orbit_info'][key][att_name] = att_val
433453

434454
# information ancillary to the data product
435455
# number of GPS seconds between the GPS epoch (1980-01-06T00:00:00Z UTC)
@@ -452,7 +472,8 @@ def read_main(FILENAME, ATTRIBUTES=False, **kwargs):
452472
# Variable Attributes
453473
IS2_atl03_attrs['ancillary_data'][key] = {}
454474
for att_name,att_val in fileID['ancillary_data'][key].attrs.items():
455-
IS2_atl03_attrs['ancillary_data'][key][att_name] = att_val
475+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
476+
IS2_atl03_attrs['ancillary_data'][key][att_name] = att_val
456477

457478
# transmit-echo-path (tep) parameters
458479
IS2_atl03_mds['ancillary_data']['tep'] = {}
@@ -465,7 +486,8 @@ def read_main(FILENAME, ATTRIBUTES=False, **kwargs):
465486
# Variable Attributes
466487
IS2_atl03_attrs['ancillary_data']['tep'][key] = {}
467488
for att_name,att_val in val.attrs.items():
468-
IS2_atl03_attrs['ancillary_data']['tep'][key][att_name] = att_val
489+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
490+
IS2_atl03_attrs['ancillary_data']['tep'][key][att_name] = att_val
469491

470492
# channel dead time and first photon bias derived from ATLAS calibration
471493
cal1,cal2 = ('ancillary_data','calibrations')
@@ -485,12 +507,14 @@ def read_main(FILENAME, ATTRIBUTES=False, **kwargs):
485507
# Variable Attributes
486508
IS2_atl03_attrs[cal1][var][key] = {}
487509
for att_name,att_val in val.attrs.items():
488-
IS2_atl03_attrs[cal1][var][key][att_name] = att_val
510+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
511+
IS2_atl03_attrs[cal1][var][key][att_name] = att_val
489512
if isinstance(val, h5py.Group):
490513
for k,v in val.items():
491514
IS2_atl03_attrs[cal1][var][key][k] = {}
492515
for att_name,att_val in val.attrs.items():
493-
IS2_atl03_attrs[cal1][var][key][k][att_name]=att_val
516+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
517+
IS2_atl03_attrs[cal1][var][key][k][att_name]=att_val
494518

495519
# get ATLAS impulse response variables for the transmitter echo path (TEP)
496520
tep1,tep2 = ('atlas_impulse_response','tep_histogram')
@@ -506,21 +530,24 @@ def read_main(FILENAME, ATTRIBUTES=False, **kwargs):
506530
if ATTRIBUTES:
507531
# Global Group Attributes
508532
for att_name,att_val in fileID[tep1][pce][tep2].attrs.items():
509-
IS2_atl03_attrs[tep1][pce][tep2][att_name] = att_val
533+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
534+
IS2_atl03_attrs[tep1][pce][tep2][att_name] = att_val
510535
# Variable Attributes
511536
IS2_atl03_attrs[tep1][pce][tep2][key] = {}
512537
for att_name,att_val in val.attrs.items():
513-
IS2_atl03_attrs[tep1][pce][tep2][key][att_name] = att_val
538+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
539+
IS2_atl03_attrs[tep1][pce][tep2][key][att_name] = att_val
514540

515541
# Global File Attributes
516542
if ATTRIBUTES:
517543
for att_name,att_val in fileID.attrs.items():
518-
IS2_atl03_attrs[att_name] = att_val
544+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
545+
IS2_atl03_attrs[att_name] = att_val
519546

520547
# Closing the HDF5 file
521548
fileID.close()
522549
# Return the datasets and variables
523-
return (IS2_atl03_mds,IS2_atl03_attrs,IS2_atl03_beams)
550+
return (IS2_atl03_mds, IS2_atl03_attrs, IS2_atl03_beams)
524551

525552
# PURPOSE: read ICESat-2 ATL03 HDF5 data files for beam variables
526553
def read_beam(FILENAME, gtx, ATTRIBUTES=False, **kwargs):
@@ -595,29 +622,34 @@ def read_beam(FILENAME, gtx, ATTRIBUTES=False, **kwargs):
595622
IS2_atl03_attrs['Atlas_impulse_response'] = {}
596623
# Global Group Attributes
597624
for att_name,att_val in fileID[gtx].attrs.items():
598-
IS2_atl03_attrs[att_name] = att_val
625+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
626+
IS2_atl03_attrs[att_name] = att_val
599627
# ICESat-2 Measurement Group
600628
for key,val in fileID[gtx]['heights'].items():
601629
IS2_atl03_attrs['heights'][key] = {}
602630
for att_name,att_val in val.attrs.items():
603-
IS2_atl03_attrs['heights'][key][att_name]=att_val
631+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
632+
IS2_atl03_attrs['heights'][key][att_name]=att_val
604633
# ICESat-2 Geolocation Group
605634
for key,val in fileID[gtx]['geolocation'].items():
606635
IS2_atl03_attrs['geolocation'][key] = {}
607636
for att_name,att_val in val.attrs.items():
608-
IS2_atl03_attrs['geolocation'][key][att_name]=att_val
637+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
638+
IS2_atl03_attrs['geolocation'][key][att_name]=att_val
609639
# ICESat-2 Background Photon Rate Group
610640
for key,val in fileID[gtx]['bckgrd_atlas'].items():
611641
IS2_atl03_attrs['bckgrd_atlas'][key] = {}
612642
for att_name,att_val in val.attrs.items():
613-
IS2_atl03_attrs['bckgrd_atlas'][key][att_name]=att_val
643+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
644+
IS2_atl03_attrs['bckgrd_atlas'][key][att_name]=att_val
614645
# ICESat-2 Geophysical Corrections Group
615646
for key,val in fileID[gtx]['geophys_corr'].items():
616647
IS2_atl03_attrs['geophys_corr'][key] = {}
617648
for att_name,att_val in val.attrs.items():
618-
IS2_atl03_attrs['geophys_corr'][key][att_name]=att_val
649+
if att_name not in ('DIMENSION_LIST','CLASS','NAME'):
650+
IS2_atl03_attrs['geophys_corr'][key][att_name]=att_val
619651

620652
# Closing the HDF5 file
621653
fileID.close()
622654
# Return the datasets and variables
623-
return (IS2_atl03_mds,IS2_atl03_attrs)
655+
return (IS2_atl03_mds, IS2_atl03_attrs)

0 commit comments

Comments
 (0)