Skip to content

Commit

Permalink
aggregate script now deals with case if no restarted_from attribute e…
Browse files Browse the repository at this point in the history
…xists
  • Loading branch information
scrasmussen committed Apr 9, 2024
1 parent 522d9ab commit de71135
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions helpers/aggregate_parallel_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

pool = None

no_restarted_from_s = 'No restarted_from Attribute'

# This should be an input, this is the search string that is assumed to match
# the output files to be aggregated.
prefix = 'icar_out_'
Expand Down Expand Up @@ -193,13 +195,16 @@ def get_restart_from_date(file_date):
file_date (str): The date used to construct the filename.
Returns:
str or None: The value of the 'restarted_from' attribute if the run was restarted, otherwise None.
str: The date from the 'restarted_from' attribute if the run was restarted, otherwise
'No restarted_from Attribute' or 'Not Restarted'
'''
out_filename = prefix + '000001_' + file_date + '.nc'
ds = xr.open_dataset(out_filename)
restarted_from = ds.attrs['restarted_from']
if restarted_from == 'Not Restarted':
return None
try:
restarted_from = ds.attrs['restarted_from']
except:
restarted_from = no_restarted_from_s

return restarted_from


Expand Down Expand Up @@ -227,9 +232,12 @@ def aggregate_prep():
agg_files.sort()

# if output files not from a restarted run, remove all existing aggregated files
if not restarted_from:
if restarted_from == 'Not Restarted':
print("Outputted files not from restart run, removing all aggregated files")
remove_from_file = agg_files[0]
elif restarted_from == no_restarted_from_s:
print("Output files do not have 'restarted_from' attribute, removing all aggregated files")
remove_from_file = agg_files[0]
else:
# delete every aggregated file from restarted_from date on
print("Recreating aggregated files from", restarted_from, "onward")
Expand Down
2 changes: 1 addition & 1 deletion src/io/output_h.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module output_interface
character(len=kMAX_DIM_LENGTH) :: dimensions(kMAX_DIMENSIONS)
character(len=kMAX_NAME_LENGTH) :: time_units
! global attribute restarted_from
! values: 2000-01-01_00:00:00 or None
! values: 2000-01-01_00:00:00 or "Not Restarted"
character(len=20) :: restarted_from

contains
Expand Down

0 comments on commit de71135

Please sign in to comment.