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

listGroup returns nested dictionary #19

Closed
rwegener2 opened this issue Dec 13, 2023 · 1 comment
Closed

listGroup returns nested dictionary #19

rwegener2 opened this issue Dec 13, 2023 · 1 comment

Comments

@rwegener2
Copy link
Collaborator

Description

When given a path to a specific variable, listGroup returns a dictionary with an extra level of nesting.

Code

from h5coro import h5coro, s3driver
import earthaccess

auth = earthaccess.login()
s3_creds = auth.get_s3_credentials(daac='NSIDC')

my_bucket = 'nsidc-cumulus-prod-protected'
path_to_hdf5_file = 'ATLAS/ATL03/006/2019/11/30/ATL03_20191130112041_09860505_006_01.h5'
# path_to_hdf5_file = 'ATLAS/ATL03/006/2018/10/17/ATL03_20181017222812_02950102_006_02.h5'

h5obj = h5coro.H5Coro(f'{my_bucket}/{path_to_hdf5_file}', s3driver.S3Driver,
                     credentials=s3_creds)

info = h5obj.listGroup('gt1l/heights/h_ph', w_attr=True, w_inspect=True)

# We expect the following print statement to return just a string of the long name
# returns a dictionary instead
info['long_name']

Result

Excepted output: 'Photon WGS84 Height'
Actual output:

{'__metadata__': {"type": <class 'numpy.float32'>, "dims": [2926335]},
 'description': 'Height of each received photon, relative to the WGS-84 ellipsoid including the geophysical corrections noted in Section 6. Please note that neither the geoid, ocean tide nor the dynamic atmosphere (DAC) corrections are applied to the ellipsoidal heights.',
 'contentType': 'physicalMeasurement',
 'source': 'ATL03g ATBD, Section 3.4',
 'long_name': 'Photon WGS84 Height',
 'standard_name': 'height',
 'units': 'meters',
 'coordinates': 'delta_time lat_ph lon_ph',
 'DIMENSION_LIST': None}
jpswinski added a commit that referenced this issue Dec 13, 2023
…e when inspecting attributes of a group; Fix for #20 - per the suggestion, the listGroup always returns a tuple of variables and attributes
@jpswinski
Copy link
Member

The listGroup function, when inspecting each of the variables in the specified group, was treating the attributes in the group like they were variables. The result was that the code was reading expecting it to have its own attributes (which it of course doesn't). The commit shown above fixed the issue by breaking out attributes of a group from the variables of a group. For the attributes, instead of calling the inspectVariable function, the readAttribute function is correctly called.

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