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

Bugfix: negative precip #181

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 19 additions & 0 deletions helpers/aggregate_parallel_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ def agg_file(first_file, verbose=True):
print(outputfile)
data_set.to_netcdf(outputfile)

# removing the last aggregated file to fix negative precip
def remove_last_two_aggregated_files(file_search):
# switch from looking for every ranks output to every aggregated file
aggregated_file_search = file_search.replace("_*", "-*")
last_file_search = aggregated_file_search.format(ens="[1-2][0-9][0-9][0-9]")
sorted_aggregated_files = sorted(glob.glob(last_file_search))

# if list is not empty, remove last two files
if sorted_aggregated_files:
last_aggregated_file = sorted_aggregated_files.pop()
os.remove(last_aggregated_file)
print("removed last aggregated file", last_aggregated_file)
if sorted_aggregated_files:
last_aggregated_file = sorted_aggregated_files.pop()
os.remove(last_aggregated_file)
print("removed second to last aggregated file", last_aggregated_file)

def main(file_search = "icar_out_{ens}_*"):
first_files = glob.glob(file_search.format(ens="000001"))
first_files.sort()
Expand All @@ -167,6 +184,8 @@ def main(file_search = "icar_out_{ens}_*"):
# would map_async be faster for some reason? I assume map is still parallel.
# pool.map(agg_file, first_files)

remove_last_two_aggregated_files(file_search)

for f in first_files:
agg_file(f)

Expand Down
10 changes: 8 additions & 2 deletions src/io/output_obj.f90
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ module subroutine save_file(this, filename, current_step, time)

if (.not.this%is_initialized) call this%init()

err = 0
! open file
this%filename = filename
err = nf90_open(filename, NF90_WRITE, this%ncfile_id)
if (err /= NF90_NOERR) then
! if hour of the day is 0 file will never be opened but clobbered if it exists, otherwise open file
if (time%hour /= 0) then
err = nf90_open(filename, NF90_WRITE, this%ncfile_id)
end if

! create new file if error opening or first output of the day
if (err /= NF90_NOERR .or. (time%hour == 0)) then
call check( nf90_create(filename, NF90_CLOBBER, this%ncfile_id), "Opening:"//trim(filename))
this%creating=.True.
else
Expand Down
Loading