From 02fee8ad49cd9fdfbe99aaf458394692aa2b3d5a Mon Sep 17 00:00:00 2001 From: Valeria Barra Date: Tue, 16 May 2023 09:34:08 -0700 Subject: [PATCH] Update to Insolation v0.5.0 and apply API changes --- Project.toml | 2 +- docs/tutorials/Bucket/bucket_tutorial.jl | 13 ++++-- .../LSM/ozark/ozark_met_drivers_FLUXNET.jl | 2 +- experiments/Manifest.toml | 46 +++++++++---------- experiments/Project.toml | 2 +- experiments/Standalone/Soil/evaporation.jl | 7 ++- src/SharedUtilities/drivers.jl | 13 ++++-- src/Vegetation/Canopy.jl | 24 +++++----- test/Bucket/albedo_map_bucket.jl | 2 +- test/Bucket/snow_bucket_tests.jl | 2 +- test/Bucket/soil_bucket_tests.jl | 2 +- test/Project.toml | 2 +- test/Soil/climate_drivers.jl | 7 ++- test/Vegetation/canopy_model.jl | 2 +- test/Vegetation/plant_hydraulics_test.jl | 2 +- 15 files changed, 75 insertions(+), 53 deletions(-) diff --git a/Project.toml b/Project.toml index 268011d8f8..aa554f0b8b 100644 --- a/Project.toml +++ b/Project.toml @@ -28,7 +28,7 @@ ClimaComms = "0.3, 0.4" ClimaCore = "0.10" ClimaCoreTempestRemap = "0.3.5, 0.3.6, 0.3.7" DocStringExtensions = "0.8, 0.9" -Insolation = "0.3, 0.4" +Insolation = "0.3, 0.4, 0.5" IntervalSets = "0.5, 0.6, 0.7" JLD2 = "0.4" NCDatasets = "0.11, 0.12" diff --git a/docs/tutorials/Bucket/bucket_tutorial.jl b/docs/tutorials/Bucket/bucket_tutorial.jl index e158611d13..2b829fc2d3 100644 --- a/docs/tutorials/Bucket/bucket_tutorial.jl +++ b/docs/tutorials/Bucket/bucket_tutorial.jl @@ -51,7 +51,7 @@ # `` # `` -# G_{undersnow} = (R_n+ SHF + LHF)_{snow} - F_{intosnow} +# G_{undersnow} = (R_n+ SHF + LHF)_{snow} - F_{intosnow} # `` # `` @@ -89,7 +89,7 @@ # Turbulent surface fluxes of sensible heat, latent heat, and water vapor # (`SHF, LHF, E`) are computed using Monin-Obukhov theory; `SW↓` and `LW↓` # are the downward fluxes in short and long wavelength bands. We use the same -# roughness lengths for snow and soil. +# roughness lengths for snow and soil. # Note that with the exception of precipitation and downwelling radiation, # all fluxes are defined # such that positive is towards the atmosphere. @@ -216,7 +216,12 @@ bucket_domain = # Here we define the model drivers, starting with downward radiation. SW_d = (t) -> eltype(t)(300); LW_d = (t) -> eltype(t)(300); -bucket_rad = PrescribedRadiativeFluxes(FT, SW_d, LW_d; orbital_data=Insolation.OrbitalData()); +bucket_rad = PrescribedRadiativeFluxes( + FT, + SW_d, + LW_d; + orbital_data = Insolation.OrbitalData(Insolation.datadir()), +); # Prescribed atmospheric variables @@ -267,7 +272,7 @@ ClimaLSM.auxiliary_vars(model) p.bucket |> propertynames -# Next is to set initial conditions. +# Next is to set initial conditions. Y.bucket.T .= FT(270); Y.bucket.W .= FT(0.05); Y.bucket.Ws .= FT(0.0); diff --git a/experiments/LSM/ozark/ozark_met_drivers_FLUXNET.jl b/experiments/LSM/ozark/ozark_met_drivers_FLUXNET.jl index 4c16e473f8..763bf024c2 100644 --- a/experiments/LSM/ozark/ozark_met_drivers_FLUXNET.jl +++ b/experiments/LSM/ozark/ozark_met_drivers_FLUXNET.jl @@ -132,7 +132,7 @@ radiation = ClimaLSM.PrescribedRadiativeFluxes( SW_IN_spline, LW_IN_spline; θs = zenith_angle, - orbital_data = Insolation.OrbitalData(), + orbital_data = Insolation.OrbitalData(Insolation.datadir()), ) transpiration = DiagnosticTranspiration{FT}() diff --git a/experiments/Manifest.toml b/experiments/Manifest.toml index 311d7590cc..0dcc080b20 100644 --- a/experiments/Manifest.toml +++ b/experiments/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.8.5" manifest_format = "2.0" -project_hash = "20a85d7704f440a4911503c3b3f770cd3502e33f" +project_hash = "10798c79f173aef69e4f91905c65279be50e9e83" [[deps.AbstractFFTs]] deps = ["ChainRulesCore", "LinearAlgebra"] @@ -12,9 +12,9 @@ version = "1.3.1" [[deps.Adapt]] deps = ["LinearAlgebra", "Requires"] -git-tree-sha1 = "cc37d689f599e8df4f464b2fa3870ff7db7492ef" +git-tree-sha1 = "76289dc51920fdc6e0013c872ba9551d54961c24" uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -version = "3.6.1" +version = "3.6.2" [[deps.ArgTools]] uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" @@ -134,9 +134,9 @@ version = "0.1.2" [[deps.CLIMAParameters]] deps = ["DocStringExtensions", "TOML", "Test"] -git-tree-sha1 = "8e805f83a13d1452e66e8baf04977e0df053238a" +git-tree-sha1 = "5b8fe32b112461953359a7b4cfea42d10058eee3" uuid = "6eacf6c3-8458-43b9-ae03-caf5306d3d53" -version = "0.7.3" +version = "0.7.4" [[deps.CPUSummary]] deps = ["CpuId", "IfElse", "Static"] @@ -310,9 +310,9 @@ uuid = "7445602f-e544-4518-8976-18f8e8ae6cdb" version = "0.2.2" [[deps.DataAPI]] -git-tree-sha1 = "e8119c1a33d267e16108be441a287a6981ba1630" +git-tree-sha1 = "8da84edb865b0b5b0100c0666a9bc9a0b71c553c" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.14.0" +version = "1.15.0" [[deps.DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] @@ -387,9 +387,9 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" [[deps.Distributions]] deps = ["ChainRulesCore", "DensityInterface", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsAPI", "StatsBase", "StatsFuns", "Test"] -git-tree-sha1 = "eead66061583b6807652281c0fbf291d7a9dc497" +git-tree-sha1 = "4f59fe4eb1308011bd33b390369cbad74e46eea4" uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" -version = "0.25.90" +version = "0.25.92" [[deps.DocStringExtensions]] deps = ["LibGit2"] @@ -639,9 +639,9 @@ version = "1.12.2+2" [[deps.HTTP]] deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"] -git-tree-sha1 = "ae9629d4485489d905e5da801eb314c2a2550cd7" +git-tree-sha1 = "41f7dfb2b20e7e8bf64f6b6fae98f4d2df027b06" uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "1.9.0" +version = "1.9.4" [[deps.HarfBuzz_jll]] deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"] @@ -673,9 +673,9 @@ version = "0.1.3" [[deps.Insolation]] deps = ["ArtifactWrappers", "Dates", "DelimitedFiles", "Interpolations"] -git-tree-sha1 = "6dc12da34ec01ff85424bb22889cff37d2aa3f10" +git-tree-sha1 = "44d6196470e8e74ad9d251fc9ecda2fbe21f67f6" uuid = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8" -version = "0.4.1" +version = "0.5.0" [[deps.IntelOpenMP_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -1145,10 +1145,10 @@ uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" version = "0.12.3" [[deps.Parsers]] -deps = ["Dates", "SnoopPrecompile"] -git-tree-sha1 = "478ac6c952fddd4399e71d4779797c538d0ff2bf" +deps = ["Dates", "PrecompileTools", "UUIDs"] +git-tree-sha1 = "a5aef8d4a6e8d81f171b2bd4be5265b01384c74c" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "2.5.8" +version = "2.5.10" [[deps.Pipe]] git-tree-sha1 = "6842804e7867b115ca9de748a0cf6b364523c16d" @@ -1186,9 +1186,9 @@ version = "1.3.5" [[deps.Plots]] deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "JLFzf", "JSON", "LaTeXStrings", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "PrecompileTools", "Preferences", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "RelocatableFolders", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs", "UnicodeFun", "Unzip"] -git-tree-sha1 = "6c7f47fd112001fc95ea1569c2757dffd9e81328" +git-tree-sha1 = "d03ef538114b38f89d66776f2d8fdc0280f90621" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" -version = "1.38.11" +version = "1.38.12" [[deps.Polyester]] deps = ["ArrayInterface", "BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "ManualMemory", "PolyesterWeave", "Requires", "Static", "StrideArraysCore", "ThreadingUtilities"] @@ -1340,10 +1340,10 @@ uuid = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74" version = "0.3.5" [[deps.Rotations]] -deps = ["LinearAlgebra", "Quaternions", "Random", "StaticArrays", "Statistics"] -git-tree-sha1 = "72a6abdcd088764878b473102df7c09bbc0548de" +deps = ["LinearAlgebra", "Quaternions", "Random", "StaticArrays"] +git-tree-sha1 = "54ccb4dbab4b1f69beb255a2c0ca5f65a9c82f08" uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc" -version = "1.4.0" +version = "1.5.1" [[deps.SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" @@ -1441,9 +1441,9 @@ version = "0.7.8" [[deps.StaticArrays]] deps = ["LinearAlgebra", "Random", "StaticArraysCore", "Statistics"] -git-tree-sha1 = "c262c8e978048c2b095be1672c9bee55b4619521" +git-tree-sha1 = "8982b3607a212b070a5e46eea83eb62b4744ae12" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.5.24" +version = "1.5.25" [[deps.StaticArraysCore]] git-tree-sha1 = "6b7ba252635a5eff6a0b0664a41ee140a1c9e72a" diff --git a/experiments/Project.toml b/experiments/Project.toml index f2e914d35b..80bc698908 100644 --- a/experiments/Project.toml +++ b/experiments/Project.toml @@ -19,6 +19,6 @@ Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c" [compat] ClimaCore = "0.10" -Insolation = "0.3, 0.4" +Insolation = "0.3, 0.4, 0.5" SciMLBase = "<1.51" julia = "1.8" diff --git a/experiments/Standalone/Soil/evaporation.jl b/experiments/Standalone/Soil/evaporation.jl index c46fc034a9..9a44659675 100644 --- a/experiments/Standalone/Soil/evaporation.jl +++ b/experiments/Standalone/Soil/evaporation.jl @@ -50,7 +50,12 @@ z_0b = 1e-5 SW_d = (t) -> eltype(t)(0) LW_d = (t) -> eltype(t)(301.15^4 * 5.67e-8) -radiation = PrescribedRadiativeFluxes(FT, SW_d, LW_d; orbital_data=Insolation.OrbitalData()) +radiation = PrescribedRadiativeFluxes( + FT, + SW_d, + LW_d; + orbital_data = Insolation.OrbitalData(Insolation.datadir()), +) # Atmos T_air = 301.15 rh = 0.38 diff --git a/src/SharedUtilities/drivers.jl b/src/SharedUtilities/drivers.jl index 9246c31151..a2fdda44f3 100644 --- a/src/SharedUtilities/drivers.jl +++ b/src/SharedUtilities/drivers.jl @@ -132,7 +132,7 @@ end ) where {FT <: AbstractFloat} Computes the turbulent surface flux terms at the ground for a standalone simulation, -including turbulent energy fluxes as well as the water vapor flux +including turbulent energy fluxes as well as the water vapor flux (in units of m^3/m^2/s of water). Positive fluxes indicate flow from the ground to the atmosphere. @@ -240,14 +240,21 @@ end Container for the prescribed radiation functions needed to drive land models in standalone mode. $(DocStringExtensions.FIELDS) """ -struct PrescribedRadiativeFluxes{FT, SW, LW, T} <: AbstractRadiativeDrivers{FT} +struct PrescribedRadiativeFluxes{FT, SW, LW, T, OD} <: + AbstractRadiativeDrivers{FT} "Downward shortwave radiation function of time (W/m^2): positive indicates towards surface" SW_d::SW "Downward longwave radiation function of time (W/m^2): positive indicates towards surface" LW_d::LW "Sun zenith angle, in radians" θs::T - function PrescribedRadiativeFluxes(FT, SW_d, LW_d; θs = nothing, orbital_data) + function PrescribedRadiativeFluxes( + FT, + SW_d, + LW_d; + θs = nothing, + orbital_data, + ) args = (SW_d, LW_d, θs, orbital_data) @assert !isnothing(orbital_data) return new{FT, typeof.(args)...}(args...) diff --git a/src/Vegetation/Canopy.jl b/src/Vegetation/Canopy.jl index e33ef7dcd6..e198f1780d 100644 --- a/src/Vegetation/Canopy.jl +++ b/src/Vegetation/Canopy.jl @@ -56,11 +56,11 @@ end """ CanopyModel{FT, RM, PM, SM, PHM, A, R, PS, D} <: AbstractModel{FT} -The model struct for the canopy, which contains +The model struct for the canopy, which contains - the canopy model domain (a point for site-level simulations, or an extended surface (plane/spherical surface) for regional or global simulations. - subcomponent model type for radiative transfer. This is of type -`AbstractRadiationModel` and currently only the `BeerLambertModel` is +`AbstractRadiationModel` and currently only the `BeerLambertModel` is supported. - subcomponent model type for photosynthesis. This is of type `AbstractPhotosynthesisModel`, and currently only the `FarquharModel` @@ -74,10 +74,10 @@ prognostically solves Richards equation in the plant is available. - canopy model parameters, which include parameters that are shared between canopy model components or those needed to compute boundary fluxes. -- The atmospheric conditions, which are either prescribed +- The atmospheric conditions, which are either prescribed (of type `PrescribedAtmosphere`) or computed via a coupled simulation (of type `CoupledAtmosphere`). -- The radiative flux conditions, which are either prescribed +- The radiative flux conditions, which are either prescribed (of type `PrescribedRadiativeFluxes`) or computed via a coupled simulation (of type `CoupledRadiativeFluxes`). @@ -318,7 +318,7 @@ is better for performance as it saves looping over the state vector multiple times. The other sub-components rely heavily on each other, -so the version of the `CanopyModel` with these subcomponents +so the version of the `CanopyModel` with these subcomponents has a single update_aux! function, given here. """ function ClimaLSM.make_update_aux( @@ -448,7 +448,7 @@ end """ make_rhs(canopy::CanopyModel) -Creates and returns the rhs! for the `CanopyModel`. +Creates and returns the rhs! for the `CanopyModel`. This allows for prognostic variables in each canopy component. """ @@ -476,7 +476,7 @@ end Computes canopy transpiration using Monin-Obukhov Surface Theory, the prescribed atmospheric conditions, and the canopy conductance. -Please note that in the future the SurfaceFluxes.jl code will compute +Please note that in the future the SurfaceFluxes.jl code will compute fluxes taking into account the canopy conductance, so that what is returned by `surface_fluxes` is correct. At present, it does not, so we are adjusting for it after the fact here in both ET and LHF. @@ -520,7 +520,7 @@ end """ ClimaLSM.surface_temperature(model::CanopyModel, Y, p, t) -A helper function which returns the surface temperature for the canopy +A helper function which returns the surface temperature for the canopy model, which is stored in the aux state. """ function ClimaLSM.surface_temperature(model::CanopyModel, Y, p, t) @@ -530,7 +530,7 @@ end """ ClimaLSM.surface_height(model::CanopyModel, Y, _...) -A helper function which returns the surface height for the canopy +A helper function which returns the surface height for the canopy model, which is stored in the parameter struct. """ function ClimaLSM.surface_height(model::CanopyModel, _...) @@ -540,7 +540,7 @@ end """ ClimaLSM.surface_specific_humidity(model::CanopyModel, Y, p) -A helper function which returns the surface specific humidity for the canopy +A helper function which returns the surface specific humidity for the canopy model, which is stored in the aux state. """ function ClimaLSM.surface_specific_humidity( @@ -562,8 +562,8 @@ end """ ClimaLSM.surface_air_density(model::CanopyModel, Y, p) - -A helper function which computes and returns the surface air density for the canopy + +A helper function which computes and returns the surface air density for the canopy model. """ function ClimaLSM.surface_air_density( diff --git a/test/Bucket/albedo_map_bucket.jl b/test/Bucket/albedo_map_bucket.jl index 0834d43a70..f44524d6a4 100644 --- a/test/Bucket/albedo_map_bucket.jl +++ b/test/Bucket/albedo_map_bucket.jl @@ -51,7 +51,7 @@ include(joinpath(pkgdir(ClimaLSM), "parameters", "create_parameters.jl")) npolynomial = 2, ), ] - orbital_data=Insolation.OrbitalData() + orbital_data = Insolation.OrbitalData(Insolation.datadir()) for bucket_domain in bucket_domains diff --git a/test/Bucket/snow_bucket_tests.jl b/test/Bucket/snow_bucket_tests.jl index 8dc712ff20..4987ad67f0 100644 --- a/test/Bucket/snow_bucket_tests.jl +++ b/test/Bucket/snow_bucket_tests.jl @@ -56,7 +56,7 @@ bucket_domains = [ ), ] init_temp(z::FT, value::FT) where {FT} = FT(value) -orbital_data = Insolation.OrbitalData() +orbital_data = Insolation.OrbitalData(Insolation.datadir()) for bucket_domain in bucket_domains @testset "Conservation of water and energy" begin diff --git a/test/Bucket/soil_bucket_tests.jl b/test/Bucket/soil_bucket_tests.jl index 8d312cf35c..d3acff840e 100644 --- a/test/Bucket/soil_bucket_tests.jl +++ b/test/Bucket/soil_bucket_tests.jl @@ -53,7 +53,7 @@ bucket_domains = [ npolynomial = 1, ), ] -orbital_data=Insolation.OrbitalData() +orbital_data = Insolation.OrbitalData(Insolation.datadir()) init_temp(z::FT, value::FT) where {FT} = FT(value) for bucket_domain in bucket_domains @testset "Zero flux RHS" begin diff --git a/test/Project.toml b/test/Project.toml index ec5645958a..db66db2b3a 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -17,7 +17,7 @@ Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c" CLIMAParameters = "0.7" ClimaComms = "0.3, 0.4" ClimaCore = "0.10" -Insolation = "0.3, 0.4" +Insolation = "0.3, 0.4, 0.5" NLsolve = "4.5" StaticArrays = "1.5" SurfaceFluxes = "0.5, 0.6" diff --git a/test/Soil/climate_drivers.jl b/test/Soil/climate_drivers.jl index e3bb4757c9..d84a41da21 100644 --- a/test/Soil/climate_drivers.jl +++ b/test/Soil/climate_drivers.jl @@ -58,7 +58,12 @@ include(joinpath(pkgdir(ClimaLSM), "parameters", "create_parameters.jl")) # Radiation SW_d = (t) -> eltype(t)(500) LW_d = (t) -> eltype(t)(5.67e-8 * 280.0^4.0) - radiation = PrescribedRadiativeFluxes(FT, SW_d, LW_d; orbital_data=Insolation.OrbitalData()) + radiation = PrescribedRadiativeFluxes( + FT, + SW_d, + LW_d; + orbital_data = Insolation.OrbitalData(Insolation.datadir()), + ) # Atmos precip = (t) -> eltype(t)(1e-8) T_atmos = (t) -> eltype(t)(285.0) diff --git a/test/Vegetation/canopy_model.jl b/test/Vegetation/canopy_model.jl index 1069775d2f..8b088366b2 100644 --- a/test/Vegetation/canopy_model.jl +++ b/test/Vegetation/canopy_model.jl @@ -99,7 +99,7 @@ include(joinpath(pkgdir(ClimaLSM), "parameters", "create_parameters.jl")) shortwave_radiation, longwave_radiation; θs = zenith_angle, - orbital_data = Insolation.OrbitalData(), + orbital_data = Insolation.OrbitalData(Insolation.datadir()), ) # Plant Hydraulics diff --git a/test/Vegetation/plant_hydraulics_test.jl b/test/Vegetation/plant_hydraulics_test.jl index c42d951f75..35901f002a 100644 --- a/test/Vegetation/plant_hydraulics_test.jl +++ b/test/Vegetation/plant_hydraulics_test.jl @@ -103,7 +103,7 @@ domains = [ shortwave_radiation, longwave_radiation; θs = zenith_angle, - orbital_data = Insolation.OrbitalData(), + orbital_data = Insolation.OrbitalData(Insolation.datadir()), ) for domain in domains # Parameters are the same as the ones used in the Ozark tutorial