BCReader
This module coordinates reading of boundary conditions from NetCDF files, as well as regridding calls and temporal interpolations from monthly to daily intervals.
BCReader API
ClimaCoupler.BCReader.BCFileInfo
— TypeBCFileInfo
Stores information specific to each boundary condition from a file and each variable.
Inputs:
- bcfile_dir::b # directory of the BC file
- comms_ctx::X # communication context used for MPI
- hdoutfileroot::S # filename root for regridded data
- varname::V # name of the variable
- all_dates::D # vector of all dates contained in the original data file
- monthly_fields::C # tuple of the two monthly fields, that will be used for the daily interpolation
- scaling_function::O # function that scales, offsets or transforms the raw variable
- land_fraction::M # fraction with 1 = 100% land, 0 = 100% ocean and/or sea-ice
- segment_idx::Vector{Int} # index of the monthly data in the file
- segmentidx0::Vector{Int} # `segmentidx` of the file data that is closest to date0
- segment_length::Vector{Int} # length of each month segment (used in the daily interpolation)
- interpolate_daily::Bool # switch to trigger daily interpolation
- mono::Bool # flag for monotone remapping of input data
ClimaCoupler.BCReader.bcfile_info_init
— Functionbcfile_info_init(
FT,
bcfile_dir,
datafile_rll,
varname,
boundary_space,
comms_ctx;
interpolate_daily = false,
segment_idx0 = nothing,
scaling_function = no_scaling,
land_fraction = nothing,
date0 = nothing,
mono = true,
)
Regrids from lat-lon grid to cgll grid, saving the output in a new file, and returns the info packaged in a single struct.
Arguments
FT
: [DataType] Float type.bcfile_dir
: [String] directory the BC file is stored in.datafile_rll
: [String] file containing data to regrid.varname
: [String] name of the variable to be regridded.boundary_space
: [Spaces.AbstractSpace] the space to which we are mapping.comms_ctx
: [ClimaComms.AbstractCommsContext] context used for this operation.interpolate_daily
: [Bool] switch to trigger daily interpolation.segment_idx0
: [Vector{Int}] reference date which, after initialization, refers to the the first file date index used minus 1 (segment_idx[1] - 1)scaling function
: [Function] scales, offsets or transformsvarname
.land_fraction
: [CC.Fields.field] fraction with 1 = land, 0 = ocean / sea-ice.date0
: [Dates.DateTime] start date of the file data.mono
: [Bool] flag for monotone remapping ofdatafile_rll
.
Returns
BCFileInfo
ClimaCoupler.BCReader.update_midmonth_data!
— Functionupdate_midmonth_data!(date, bcf_info::BCFileInfo{FT}) where {FT}
Extracts boundary condition data from regridded (to model grid) NetCDF files. The times for which data is extracted depends on the specifications in the bcf_info
struct).
Arguments
date
: [Dates.DateTime] start date for data.bcf_info
: [BCFileInfo] containing boundary condition data.
ClimaCoupler.BCReader.next_date_in_file
— Functionnext_date_in_file(bcf_info)
Returns the next date stored in the file bcfile_info
struct after the current date index given by segment_idx
. Note: this function does not update segment_idx
, so repeated calls will return the same value unless segment_idx
is modified elsewhere in between.
Arguments
bcf_info
: [BCFileInfo] containing the date information.
Returns
- Dates.DateTime
ClimaCoupler.BCReader.interpolate_midmonth_to_daily
— Functioninterpolate_midmonth_to_daily(date, bcf_info::BCFileInfo{FT}) where {FT}
Interpolates linearly between two Fields
in the bcf_info
struct, or returns the first Field if interpolation is switched off.
Arguments
date
: [Dates.DateTime] start date for data.bcf_info
: [BCFileInfo] contains fields to be interpolated.
Returns
- CC.Fields.field
BCReader Internal Functions
ClimaCoupler.BCReader.no_scaling
— Functionno_scaling(field, bcf_info)
Remap the values of a field
onto the space of the bcf_info
's land_fraction without scaling.
Arguments
field
: [CC.Fields.Field] contains the values to be remapped.bcf_info
: [BCFileInfo] contains a land_fraction to remap onto the space of.
ClimaCoupler.BCReader.interpol
— Functioninterpol(f1::FT, f2::FT, Δt_tt1::FT, Δt_t2t1::FT)
Performs linear interpolation of f
at time t
within a segment Δt_t2t1 = (t2 - t1)
, of fields f1
and f2
, with t2 > t1
.
Arguments
f1
: [FT] first value to be interpolated (f(t1) = f1
).f2
: [FT] second value to be interpolated.Δt_tt1
: [FT] time betweent1
and somet
(Δt_tt1 = (t - t1)
).Δt_t2t1
: [FT] time betweent1
andt2
.
Returns
- FT