Skip to content

Define a policy for default values #13

@rafaqz

Description

@rafaqz

Some functions here have long lists default values that are for a specific location:

latitude = 43.07305u"°", # latitude
days = [15, 46, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349], # days of year to simulate - TODO leap years
hours = collect(0.:1:24.), # hour of day for solrad
reference_height = 2u"m", # reference height of weather data (air temperature, wind speed, humidity)
depths = [0.0, 2.5, 5.0, 10.0, 15.0, 20.0, 30.0, 40.0, 50.0, 100.0, 200.0]u"cm", # soil nodes - keep spacing close near the surface
heights = [0.01]u"m", # air nodes for temperature, wind speed and humidity profile
# solar radiation
cmH2O = 1, # precipitable cm H2O in air column, 0.1 = very dry; 1 = moist air conditions; 2 = humid, tropical conditions (note this is for the whole atmospheric profile, not just near the ground)
ϵ = 0.0167238, # orbital eccentricity of Earth
ω = 2π / 365, # mean angular orbital velocity of Earth (radians/day)
se = 0.39784993, # precomputed solar elevation constant
d0_solrad = 80.0, # reference day for declination calculations
iuv = false, # if `true`, uses the full gamma-function model for diffuse radiation (expensive)
scattered = true, # if `false`, disables scattered light computations (faster)
amr = 25.0u"km", # mixing ratio height of the atmosphere
nmax = 111, # Maximum number of wavelength intervals
= DEFAULT_Iλ, # cector of wavelength bins (e.g. in `nm`)
OZ = DEFAULT_OZ, # ozone column depth table indexed by latitude band and month (size 19×12)
τR = DEFAULT_τR, # vector of optical depths per wavelength for Rayleigh scattering
τO = DEFAULT_τO, # vector of optical depths per wavelength for ozone
τA = DEFAULT_τA, # vector of optical depths per wavelength for aerosols
τW = DEFAULT_τW, # vector of optical depths per wavelength for water vapor
= DEFAULT_Sλ, # solar spectral irradiance per wavelength bin (e.g. in `mW * cm^-2 * nm^-1`)
FD = DEFAULT_FD, # interpolated functino of radiation scattered from the direct solar beam
FDQ = DEFAULT_FDQ, # interpolated function of radiation scattered from ground-reflected radiation
= DEFAULT_s̄, # a function of τR linked to molecular scattering in the UV range (< 360 nm)
# terrain
elevation = 226.0u"m", # elevation (m)
horizon_angles = fill(0.0u"°", 24), # enter the horizon angles (degrees) so that they go from 0 degrees azimuth (north) clockwise in 15 degree intervals
slope = 0.0u"°", # slope (degrees, range 0-90)
aspect = 0.0u"°", # aspect (degrees, 0 = North, range 0-360)
roughness_height = 0.004u"m", # heat transfer roughness height
zh = 0u"m", # heat transfer roughness height
d0 = 0u"m", # zero plane displacement correction factor
# soil thermal parameters
soil_mineral_conductivity = 1.25u"W/m/K", # soil minerals thermal conductivity
soil_mineral_density = 2.560u"Mg/m^3", # soil minerals density
soil_mineral_heat_capacity = 870.0u"J/kg/K", # soil minerals specific heat
soil_bulk_density = 2.56u"Mg/m^3", # dry soil bulk density
soil_saturation_moisture = 0.26u"m^3/m^3", # volumetric water content at saturation (0.1 bar matric potential)
# soil moisture model soil parameters
air_entry_water_potential = fill(0.7, length(depths) * 2 - 2)u"J/kg", #air entry potential
saturated_hydraulic_conductivity = fill(0.0058, length(depths) * 2 - 2)u"kg*s/m^3", #saturated conductivity
Campbells_b_parameter = fill(1.7, length(depths) * 2 - 2), #soil 'b' parameter
soil_bulk_density2 = fill(soil_bulk_density, length(depths) * 2 - 2)u"Mg/m^3", # soil bulk density
soil_mineral_density2 = fill(soil_mineral_density, length(depths) * 2 - 2)u"Mg/m^3", # soil mineral density
# soil moisture plant parameters
root_density = [0, 0, 8.2, 8.0, 7.8, 7.4, 7.1, 6.4, 5.8, 4.8, 4.0, 1.8, 0.9, 0.6, 0.8, 0.4, 0.4, 0, 0] * 1e4u"m/m^3", # root density at each node (from Campell 1985 Soil Physics with Basic, p. 131)
root_resistance = 2.5e+10u"m^3/kg/s", # resistance per unit length of root
stomatal_closure_potential = -1500.0u"J/kg", # critical leaf water potential for stomatal closure
leaf_resistance = 2.0e6u"m^4/kg/s", # resistance per unit length of leaf
stomatal_stability_parameter = 10.0, # stability parameter, -
root_radius = 0.001u"m", # root radius, m
# soil moisture simulation controls
moist_error = 1e-6u"kg/m^2/s", # maximum overall mass balance error allowed
moist_count = 500, # maximum iterations of soil moisture algorithm
moist_step = 360.0u"s", # time step over which to simulate soil moisture (< = 1 hour)
maxpool = 1.0e4u"kg/m^2", # maximum depth of pooling water
# daily environmental vectors
albedos = fill(0.1, length(days)), # substrate albedo (decimal %)
shades = fill(0.0, length(days)), # % shade cast by vegetation
pctwets = fill(0.0, length(days)), # % surface wetness
sles = fill(0.96, length(days)), # - surface emissivity
daily_rainfall = ([28, 28.2, 54.6, 79.7, 81.3, 100.1, 101.3, 102.5, 89.7, 62.4, 54.9, 41.2])u"kg/m^2",
air_temperature_min = ([-14.3, -12.1, -5.1, 1.2, 6.9, 12.3, 15.2, 13.6, 8.9, 3, -3.2, -10.6] * 1.0)u"°C",
air_temperature_max = ([-3.2, 0.1, 6.8, 14.6, 21.3, 26.4, 29, 27.7, 23.3, 16.6, 7.8, -0.4] * 1.0)u"°C",
wind_min = ([4.9, 4.8, 5.2, 5.3, 4.6, 4.3, 3.8, 3.7, 4, 4.6, 4.9, 4.8] * 0.1)u"m/s",
wind_max = ([4.9, 4.8, 5.2, 5.3, 4.6, 4.3, 3.8, 3.7, 4, 4.6, 4.9, 4.8] * 1.0)u"m/s",
humidity_min = [50.2, 48.4, 48.7, 40.8, 40, 42.1, 45.5, 47.3, 47.6, 45, 51.3, 52.8],
humidity_max = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],
cloud_min = [50.3, 47, 48.2, 47.5, 40.9, 35.7, 34.1, 36.6, 42.6, 48.4, 61.1, 60.1],
cloud_max = [50.3, 47, 48.2, 47.5, 40.9, 35.7, 34.1, 36.6, 42.6, 48.4, 61.1, 60.1],
minima_times = [0, 0, 1, 1], # time of minima for air temp, wind, humidity and cloud cover (h), air & wind mins relative to sunrise, humidity and cloud cover mins relative to solar noon
maxima_times = [1, 1, 0, 0], # time of maxima for air temp, wind, humidity and cloud cover (h), air temp & wind maxs relative to solar noon, humidity and cloud cover maxs relative to sunrise
deep_soil_temperatures = fill(7.741666u"°C", length(days)),
# hourly weather vectors
air_temperatures = nothing,
humidities = nothing,
wind_speeds = nothing,
solar_radiation = nothing,
cloud_covers = nothing,
RAINs = nothing,
zenith_angles = nothing,
longwave_radiation = nothing,
# intial conditions
initial_soil_temperature = u"K".((fill(7.741667, length(depths)))u"°C"),
initial_soil_moisture = [0.42, 0.42, 0.42, 0.43, 0.44, 0.44, 0.43, 0.42, 0.41, 0.42, 0.42, 0.43],
leaf_area_index = fill(0.1, length(days)),
iterate_day = 3, # number of iterations per day
daily = false, # doing consecutive days?
runmoist = false, # run soil moisture algorithm?
spinup = false, # spin-up the first day by iterate_day iterations?

This is dangerous for real work, as missing one will silently give you bad answers.

Instead, I propose we define objects to hold and validate all of these keywords. In this example it would be a MicroclimateProblem or similar. Then if people want something to "just_work" they would call solve(example_microclimate(); kw...), where example_microclimate gives you a filled out MicroclimateProblem object. Then its explicit that its just an example, not real work.

For real work MicroclimateProblem would need keywords to be specified except where it makes sense to use global defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions