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

Improve concatenation of netCDF files with simulation pickup #3818

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions src/OutputWriters/netcdf_output_writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -444,16 +444,16 @@ function NetCDFOutputWriter(model, outputs;
dimensions = Dict(),
overwrite_existing = nothing,
deflatelevel = 0,
part = 1,
josuemtzmo marked this conversation as resolved.
Show resolved Hide resolved
file_splitting = NoFileSplitting(),
verbose = false)
mkpath(dir)
filename = auto_extension(filename, ".nc")
filepath = joinpath(dir, filename)

initialize!(file_splitting, model)
update_file_splitting_schedule!(file_splitting, filepath)

part, filepath = is_output_splitted!(file_splitting, filepath, overwrite_existing)

if isnothing(overwrite_existing)
if isfile(filepath)
overwrite_existing = false
Expand Down Expand Up @@ -739,7 +739,7 @@ function initialize_nc_file!(filepath,
grid,
model)

mode = overwrite_existing ? "c" : "a"
mode = overwrite_existing || !isfile(filepath) ? "c" : "a"

# Add useful metadata
global_attributes["date"] = "This file was generated on $(now())."
Expand Down
17 changes: 17 additions & 0 deletions src/OutputWriters/output_writer_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ function update_file_splitting_schedule!(schedule::FileSizeLimit, filepath)
return nothing
end

# Update schedule based on user input
is_output_splitted!(schedule, filepath) = nothing

function is_output_splitted!(schedule::TimeInterval, filepath, overwrite_existing)
Copy link
Member

@ali-ramadhan ali-ramadhan Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my only comment is that I find this function name confusing. is_output_splitted! suggests it will return a boolean true or false, but it actually modifies a schedule and returns a part number and a filepath?

folder = dirname(filepath)
filename = first(split(basename(filepath),"."))*"_part"
josuemtzmo marked this conversation as resolved.
Show resolved Hide resolved
existing_files = filter(startswith(filename), readdir(folder))
if existing_files |> length > 0 && !overwrite_existing
josuemtzmo marked this conversation as resolved.
Show resolved Hide resolved
@warn "Split files found, Mode will be set to append to existing file:"*
joinpath(folder, last(existing_files))
schedule.actuations = length(existing_files) - 1
josuemtzmo marked this conversation as resolved.
Show resolved Hide resolved
return Int(length(existing_files)), joinpath(folder, last(existing_files))
josuemtzmo marked this conversation as resolved.
Show resolved Hide resolved
end
return 1, filepath
end


"""
ext(ow)

Expand Down
1 change: 0 additions & 1 deletion src/Utils/schedules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ end
function (schedule::TimeInterval)(model)
t = model.clock.time
t★ = next_actuation_time(schedule)

if t >= t★
if schedule.actuations < typemax(Int)
schedule.actuations += 1
Expand Down