Skip to content

Commit

Permalink
Merge #280
Browse files Browse the repository at this point in the history
280: Read albedo from file over time (v2) r=juliasloan25 a=juliasloan25



Co-authored-by: Julia Sloan <jsloan@caltech.edu>
  • Loading branch information
bors[bot] and juliasloan25 authored Aug 11, 2023
2 parents d1c96be + 24a6d0b commit 81af155
Show file tree
Hide file tree
Showing 14 changed files with 791 additions and 214 deletions.
5 changes: 3 additions & 2 deletions docs/src/APIs/Bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CurrentModule = ClimaLSM.Bucket

```@docs
ClimaLSM.Bucket.BucketModelParameters
ClimaLSM.Bucket.BulkAlbedoMap
ClimaLSM.Bucket.BulkAlbedoStatic
ClimaLSM.Bucket.BulkAlbedoTemporal
ClimaLSM.Bucket.BulkAlbedoFunction
ClimaLSM.Bucket.BucketModel
```
Expand All @@ -29,5 +30,5 @@ ClimaLSM.Bucket.update_soil_albedo
## Artifact Path Functions

```@docs
ClimaLSM.Bucket.cesm2_land_albedo_dataset_path
ClimaLSM.Bucket.cesm2_albedo_dataset_path
```
6 changes: 3 additions & 3 deletions docs/tutorials/Bucket/bucket_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ earth_param_set = create_lsm_parameters(FT);
# Define our `BulkAlbedoFunction` model using a constant surface and snow albedo:
# The surface albedo is a function of coordinates, which would be
# (x,y) on a plane, and (lat,lon) on a sphere. Another albedo
# option is to specify a `BulkAlbedoMap`, which uses a NetCDF
# file to read in surface albedo. This option only applies when coordinates
# are (lat,lon).
# option is to specify a `BulkAlbedoStatic` or `BulkAlbedoFunction`,
# which uses a NetCDF file to read in surface albedo.
# These options only applies when coordinates are (lat,lon).
α_sfc = (coordinate_point) -> FT(0.2);
α_snow = FT(0.8);
albedo = BulkAlbedoFunction{FT}(α_snow, α_sfc);
Expand Down
20 changes: 10 additions & 10 deletions src/shared_utilities/FileReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ data packaged into a single struct.
- `input_file` # NCDataset file containing data to regrid.
- `varname` # name of the variable to be regridded.
- `date_ref` # reference date to coordinate start of the simulation
- `t_start` # start time of the simulation (relative to `date_ref`)
- `t_start` # start time of the simulation relative to `date_ref` (date_start = date_ref + t_start)
- `surface_space` # the space to which we are mapping.
- `mono` # flag for monotone remapping of `input_file`.
Expand Down Expand Up @@ -197,7 +197,7 @@ in this range of time.
# Arguments
- `prescribed_data` # containing parameter value data.
- `date` # start date for data.
- `date` # current date to read in data for.
- `space` # space we're remapping the data onto.
"""
function read_data_fields!(
Expand Down Expand Up @@ -317,8 +317,7 @@ next_date_in_file(prescribed_data::PrescribedData) =
"""
interpolate_data(prescribed_data::PrescribedData, date::Union{DateTime, DateTimeNoLeap}, space::Spaces.AbstractSpace)
Interpolates linearly between two `Fields` in the `prescribed_data` struct,
or returns the first Field if interpolation is switched off.
Interpolates linearly between two `Fields` in the `prescribed_data` struct.
# Arguments
- `prescribed_data` # contains fields to be interpolated.
Expand All @@ -334,20 +333,21 @@ function interpolate_data(
space::Spaces.AbstractSpace,
)
FT = Spaces.undertype(space)
# Interpolate if the time period between dates is nonzero
if prescribed_data.file_state.segment_length[1] > FT(0)
(; segment_length, date_idx, data_fields) = prescribed_data.file_state
(; all_dates) = prescribed_data.file_info
(; segment_length, date_idx, data_fields) = prescribed_data.file_state
(; all_dates) = prescribed_data.file_info

# Interpolate if the time period between dates is nonzero
if segment_length[1] > FT(0) && date != all_dates[Int(date_idx[1])]
Δt_tt1 = FT((date - all_dates[Int(date_idx[1])]).value)
return interpol.(
data_fields[1],
data_fields[2],
FT((date - all_dates[Int(date_idx[1])]).value),
Δt_tt1,
FT(segment_length[1]),
)
# Otherwise use the data at the first date
else
return prescribed_data.file_state.data_fields[1]
return data_fields[1]
end
end

Expand Down
3 changes: 2 additions & 1 deletion src/shared_utilities/Regridder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ function regrid_netcdf_to_field(
infile,
varname,
boundary_space;
date_idx = 1,
outfile_root = string(varname, "_cgll"),
mono = true,
)
Expand All @@ -330,7 +331,7 @@ function regrid_netcdf_to_field(
field = read_from_hdf5(
REGRID_DIR,
outfile_root,
file_dates[1],
file_dates[date_idx],
varname,
comms_ctx,
)
Expand Down
Loading

0 comments on commit 81af155

Please sign in to comment.