Skip to content

Commit 9980b78

Browse files
committed
use t_start/end
1 parent 75872f8 commit 9980b78

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

artifacts/artifact_funcs.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ function artifact_data(datapath_full, name)
7171
end
7272

7373
"""
74-
artifact_data(datapath_full, name, datapath_trunc, date0, time_start, time_end, comms_ctx)
74+
artifact_data(datapath_full, name, datapath_trunc, date0, t_start, t_end, comms_ctx)
7575
7676
Truncates given data set, and constructs a new dataset containing only the dates needed and stores it in datapath_trunc
7777
"""
78-
function artifact_data(datapath_full, name, datapath_trunc, date0, time_start, time_end, comms_ctx)
78+
function artifact_data(datapath_full, name, datapath_trunc, date0, t_start, t_end, comms_ctx)
7979
datafile = joinpath(datapath_full, string(name, ".nc"))
80-
datafile_truncated =
81-
Regridder.truncate_dataset(datafile, name, datapath_trunc, date0, time_start, time_end, comms_ctx)
80+
datafile_truncated = Regridder.truncate_dataset(datafile, name, datapath_trunc, date0, t_start, t_end, comms_ctx)
8281
return datafile_truncated
8382
end

src/Regridder.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ function cgll2latlonz(field; DIR = "cgll2latlonz_dir", nlat = 360, nlon = 720, c
638638
end
639639

640640
"""
641-
truncate_dataset(datafile, name, datapath_trunc, date0, time_start, time_end, comms_ctx)
641+
truncate_dataset(datafile, name, datapath_trunc, date0, t_start, t_end, comms_ctx)
642642
643643
Truncates given data set, and constructs a new dataset containing only the dates that are used in the simulation
644644
"""
@@ -647,12 +647,12 @@ function truncate_dataset(
647647
name,
648648
datapath_trunc,
649649
date0,
650-
time_start,
651-
time_end,
650+
t_start,
651+
t_end,
652652
comms_ctx::ClimaComms.AbstractCommsContext,
653653
)
654-
date_start = date0 + Dates.Second(time_start)
655-
date_end = date0 + Dates.Second(time_start + time_end)
654+
date_start = date0 + Dates.Second(t_start)
655+
date_end = date0 + Dates.Second(t_start + t_end)
656656

657657
file_name = replace(string(name, "_truncated_data_", string(date_start), string(date_end), ".nc"), r":" => "")
658658
datafile_truncated = joinpath(datapath_trunc, file_name)

test/regridder_tests.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,40 +312,40 @@ for FT in (Float32, Float64)
312312
end
313313
end
314314
end
315-
# test dataset truncation
315+
# test dataset truncation
316316
@testset "test dataset truncation" begin
317-
# Get the original dataset set up
317+
# Get the original dataset set up
318318
include(joinpath(pkgdir(ClimaCoupler), "artifacts", "artifact_funcs.jl"))
319319
sst_data_all = joinpath(sst_dataset_path(), "sst.nc")
320320
ds = NCDatasets.NCDataset(sst_data_all, "r")
321321
dates = ds["time"][:]
322322
first_date = dates[1]
323323
last_date = last(dates)
324324

325-
# set up comms_ctx
325+
# set up comms_ctx
326326
device = ClimaComms.device()
327327
comms_ctx = ClimaComms.context(device)
328328
ClimaComms.init(comms_ctx)
329329

330-
# make path for truncated datasets
330+
# make path for truncated datasets
331331
COUPLER_OUTPUT_DIR = joinpath("experiments", "AMIP", "output", "tests")
332332
mkpath(COUPLER_OUTPUT_DIR)
333333

334334
REGRID_DIR = joinpath(COUPLER_OUTPUT_DIR, "regrid_tmp", "")
335335
mkpath(REGRID_DIR)
336336

337-
# values for the truncations
338-
time_start = 0.0
339-
time_end = 1.728e6
337+
# values for the truncations
338+
t_start = 0.0
339+
t_end = 1.728e6
340340
date0test = ["18690101", "18700101", "19790228", "20220301", "20230101"]
341341
for date in date0test
342342
date0 = Dates.DateTime(date, Dates.dateformat"yyyymmdd")
343-
sst_data = Regridder.truncate_dataset(sst_data_all, "test", REGRID_DIR, date0, time_start, time_end, comms_ctx)
343+
sst_data = Regridder.truncate_dataset(sst_data_all, "test", REGRID_DIR, date0, t_start, t_end, comms_ctx)
344344
ds_truncated = NCDatasets.NCDataset(sst_data, "r")
345345
new_dates = ds_truncated["time"][:]
346346

347-
date_start = date0 + Dates.Second(time_start)
348-
date_end = date0 + Dates.Second(time_start + time_end)
347+
date_start = date0 + Dates.Second(t_start)
348+
date_end = date0 + Dates.Second(t_start + t_end)
349349

350350
# start date is before the first date of datafile
351351
if date_start < first_date
@@ -359,10 +359,10 @@ end
359359
@test new_dates[2] >= date_start
360360
end
361361

362-
# end date is before the first date of datafile
362+
# end date is before the first date of datafile
363363
if date_end < first_date
364364
@test last(new_dates) == first_date
365-
# end date is after the last date of datafile
365+
# end date is after the last date of datafile
366366
elseif date_end > last_date
367367
@test last(new_dates) == last_date
368368
# end date is within the bounds of datafile
@@ -371,7 +371,7 @@ end
371371
@test new_dates[length(new_dates) - 1] <= date_end
372372
end
373373

374-
# check that truncation is indexing correctly
374+
# check that truncation is indexing correctly
375375
all_data = ds["SST"][:, :, :]
376376
new_data = ds_truncated["SST"][:, :, :]
377377
(start_id, end_id) = Regridder.find_idx_bounding_dates(dates, date_start, date_end)

0 commit comments

Comments
 (0)