Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisRenchon committed Mar 15, 2024
1 parent fa3f0f1 commit da72c5b
Showing 1 changed file with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
export getoutput, make_output_df

"""
getoutput(variable::Symbol, variables::Symbol...; result = sv.saveval, depth = 1)
getoutput(sv, variable::Symbol, variables::Symbol...; result = sv.saveval, depth = 1)
Return a vector of FT corresponding to the variable of interest at all times.
By default, get output from sv.saveval, but user can specify e.g., result = sol.u
By default, get surface value, but user can specify depth for e.g., soil temperature
example 1:
julia> getoutput(sv, 1, :SW_out)
example 2:
julia> getoutput(sv, 1, :canopy, :conductance, :gs)
example 3:
julia> getoutput(sol, 1, :soil, :ϑ_l; result = sol.u)
"""
function getoutput(
sv,
sv, # or sol for prognostic variables
depth, # 1 is surface
variable::Symbol,
variables::Symbol...;
result = sv.saveval,
depth = 1,
result = sv.saveval, # or sol.u for prognostic variables
)
for v in (variable, variables...)
result = getproperty.(result, v)
end
return [parent(r)[depth] for r in result]
end
# example: getoutput(sv, :SW_out)
# example 2: getoutput(sv, :canopy, :conductance, :gs)
# example 3: getoutput(sol, :soil, :ϑ_l; result = sol.u, depth = 2)

"""
make_output_df(sv, inputs)
Expand All @@ -31,25 +37,39 @@ Return a dataframe containing climaland outputs
function make_output_df(sv, inputs; N_days = 60, N_spinup_days = 30)
# List of output that we want
output_list = (
(:SW_out,),
(:LW_out,),
(:canopy, :conductance, :gs),
(:canopy, :conductance, :transpiration),
(:canopy, :autotrophic_respiration, :Ra),
(:canopy, :photosynthesis, :GPP),
(:canopy, :hydraulics, ),
(:canopy, :hydraulics, :area_index, :leaf),
(:canopy, :energy, :lhf),
(:soil, :turbulent_fluxes, :shf),
(:soil, :turbulent_fluxes, :lhf),
(:soil, :T),
(:soil, :θ_l),
(:soil, :turbulent_fluxes, :vapor_flux),
(1, :SW_out,),
(1, :LW_out,),
(1, :canopy, :conductance, :gs),
(1, :canopy, :conductance, :transpiration),
(1, :canopy, :autotrophic_respiration, :Ra),
(1, :canopy, :photosynthesis, :GPP),
(1, :canopy, :hydraulics, ),
(1, :canopy, :hydraulics, :area_index, :leaf),
(1, :canopy, :energy, :lhf),
(1, :soil, :turbulent_fluxes, :shf),
(1, :soil, :turbulent_fluxes, :lhf),
((1:1:20), :soil, :T),
((1:1:20), :soil, :θ_l),
(1, :soil, :turbulent_fluxes, :vapor_flux),
)

output_vectors = [getoutput(sv, args...) for args in output_list]

# WIP WIP

depth = reduce(vcat, [
if isa(t[1], Integer) # Check for integers
[t[1]] # Wrap number in a single-element list
else
collect(t[1]) # Keep range or other non-number elements as-is
end
for t in output_list
])



# Extract the last symbol from each tuple for column names
column_names = [names[end] for names in output_list]
column_names = [Symbol(names[end], "_", depth) for names in output_list, depth in output_list[1]]
# Create a dictionary with simplified column names and corresponding vectors
data_dict = Dict(zip(column_names, output_vectors))
# Create a DataFrame from the dictionary
Expand Down

0 comments on commit da72c5b

Please sign in to comment.