Skip to content

Commit

Permalink
Add option to shift ObsDataSources to end of month
Browse files Browse the repository at this point in the history
This helps with comparing with our model because observations are
typically defined on the 15th, but our model is defined at the end of
the month. Since we always find the closest data available, this can
lead to comparisons across months.
  • Loading branch information
Sbozzolo committed Aug 15, 2024
1 parent f1fa9b9 commit 5465e61
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion experiments/ClimaEarth/user_io/leaderboard/data_sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ struct ObsDataSource

"""The NCDataset associated to the file"""
ncdataset::NCDatasets.NCDataset

"""Shift dates so that they are at the end of month?"""
shift_to_end_of_month::Bool
end

function ObsDataSource(;
Expand All @@ -33,11 +36,21 @@ function ObsDataSource(;
lon_name = "lon",
lat_name = "lat",
preprocess_data_fn = identity,
shift_to_end_of_month = true,
)

ncdataset = NCDatasets.NCDataset(path)

return ObsDataSource(path, var_name, time_name, lon_name, lat_name, preprocess_data_fn, ncdataset)
return ObsDataSource(
path,
var_name,
time_name,
lon_name,
lat_name,
preprocess_data_fn,
ncdataset,
shift_to_end_of_month,
)
end

"""
Expand Down
4 changes: 4 additions & 0 deletions experiments/ClimaEarth/user_io/leaderboard/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ function find_and_resample(

available_times = obs.ncdataset[observed_data.time_name]

if observed_data.shift_to_end_of_month
available_times = endofmonth.(available_times)
end

time_index = ClimaAnalysis.Utils.nearest_index(available_times, date)

# NOTE: We are hardcoding that the time index is the last one and that there are three
Expand Down

0 comments on commit 5465e61

Please sign in to comment.