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

Issue 36 bugfix #74

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nsidc/metgen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def process(config_filename, env, write_cnm, number):
except Exception as e:
print("\nUnable to process data: " + str(e))
exit(1)
click.echo(f'Processed granules using the configuration file {config}')
click.echo(f'Processed granules using the configuration file {config_filename}')

if __name__ == "__main__":
cli()
38 changes: 19 additions & 19 deletions src/nsidc/metgen/metgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def process(configuration):
# * Parallelize the operations
configuration.show()
print()

print('--------------------------------------------------')

valid, errors = config.validate(configuration)
if not valid:
print("The configuration is invalid:")
Expand All @@ -108,8 +110,10 @@ def process(configuration):
raise Exception('Invalid configuration')

granules = granule_paths(Path(configuration.data_dir))
print(f'Found {len(granules.items())} granules to process')
if (configuration.number > 0 and configuration.number < len(granules)):
print(f'Found {len(granules)} granules to process')
if configuration.number < 1 or configuration.number >= len(granules):
print('Processing all available granules')
else:
print(f'Processing the first {configuration.number} granule(s)')
granules = granules[:configuration.number]
print()
Expand All @@ -122,10 +126,8 @@ def process(configuration):
cnms_template = cnms_body_template()
processed_count = 0

for producer_granule_id, granule_files in granules.items():
print()
for producer_granule_id, granule_files in granules:
print('--------------------------------------------------')
print()
print(f'Processing {producer_granule_id}...')

# Add producer_granule_id and information from CMR.
Expand All @@ -152,20 +154,18 @@ def process(configuration):
print(f'Processed {processed_count} source files')

def granule_paths(data_dir):
granules = {}

# This sets up a data structure to associate a "producer granule id" with
# one or more files identified as part of the same granule. We still need
# code to identify the common basename for the cases where more than one
# file exists per granule (or the case where an ancillary file is associated
# with the granule), and to add the correct "type" of the file. See the CNM
# spec for a list of types. At the moment the assumption is one (netCDF!) file
# per granule, with a type of "data," plus a metadata (UMM-G) file.
producer_granule_ids = [os.path.basename(i) for i in data_dir.glob('*.nc')]
for pgid in producer_granule_ids:
granules[pgid] = {'data': [os.path.join(data_dir, pgid)]}

return granules
# Returns a list of tuples containing the "producer granule id" and a dict
# containing the key 'data' with a list of one or more files identified as
# part of the same granule. We still need code to identify the common
# basename for the cases where more than one file exists per granule (or
# the case where an ancillary file is associated with the granule), and to
# add the correct "type" of the file. See the CNM spec for a list of types.
# At the moment the assumption is one (netCDF!) file per granule, with a
# type of "data," plus a metadata (UMM-G) file.
producer_granule_ids = [os.path.basename(f) for f in data_dir.glob('*.nc')]
granule_data_files = [{ 'data': [f] } for f in data_dir.glob('*.nc')]

return list(zip(producer_granule_ids, granule_data_files))

def find_or_create_ummg(mapping, data_file_paths, ummg_path, all_existing_ummg):
"""
Expand Down