-
Notifications
You must be signed in to change notification settings - Fork 0
Fix computation of Stratigraphic Column #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
deposition is net sed scc? So should not substract disintegration one more time?
test showing the exported sc does not equal to sac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From all of this, it is still not clear to me where the error is!
examples/model/alcap/run.jl
Outdated
@@ -11,7 +11,7 @@ using CarboKitten.Export: data_export, CSV | |||
const PATH = "data/output" | |||
|
|||
# ~/~ begin <<docs/src/model-alcap.md#alcap-example-input>>[init] | |||
const TAG = "alcap-example" | |||
const TAG = "alcap-example-deposition_only" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't change existing files like this. It will break other stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't copy paste files with their Entangled annotations intact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, what are you trying to achieve?
test/Testexport.jl
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A unit test should stand on its own legs. Here you depend on some previous simulation having been run.
The error is not in writing out the CSV, so don't test for that. There are two ways to go about this:
- run a small simulation with HDF5 output (make it 1d) and write the output to a temporary directory (see
CarboKitten.jl/test/ExportSpec.jl
Lines 90 to 108 in b6a5036
mktempdir() do path spec = CSV(GRID_LOCATIONS1, :sediment_accumulation_curve => joinpath(path, "sac.csv"), :age_depth_model => joinpath(path, "adm.csv"), :stratigraphic_column => joinpath(path, "sc.csv"), :water_depth => joinpath(path, "wd.csv"), :metadata => joinpath(path, "metadata.toml")) data_export(spec, HEADER1, DATA1) for f in values(spec.output_files) @test isfile(f) end metadata = TOML.parsefile(spec.output_files[:metadata]) @test IdDict(Symbol(k) => v for (k, v) in metadata["files"]) == spec.output_files @test length(metadata["locations"]) == 3 adm = read_csv(spec.output_files[:age_depth_model], DataFrame) rename!(adm, (n => split(n)[1] for n in names(adm))...) @test adm == ustrip(extract_sac(HEADER1, DATA1, GRID_LOCATIONS1) |> age_depth_model) end - find a way of isolating the problem without running a full model, or having the output in memory.
If you like, you can make the stratigraphic_column
function more testable by creating a version that only takes deposition
and disintegration
, and not the header
and data
instances that come from reading HDF5 files.
test/Testexport.jl
Outdated
sc1_f1 = data.var"sc1_f1 [m]" | ||
sc1_f2 = data.var"sc1_f2 [m]" | ||
sc1_f3 = data.var"sc1_f3 [m]" | ||
sum(sc1_f1+sc1_f2+sc1_f3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sum
statement doesn't do anything
test/Testexport.jl
Outdated
data2 = CSV.read("$(PATH)/$(TAG)_sac.csv", DataFrame) | ||
sac1 = data2.var"sac1 [m]"[end] | ||
|
||
@test sum(sc1_f1+sc1_f2+sc1_f3) ≈ sac1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these quantities were never meant to be equal.
From what I understand, the stratigraphic column gives you the amount and type of sediment for each time step (basically: production corrected for later erosion), whereas the sediment accumulation curve is an integral quantity (slight modification of the age depth model).
See
Line 174 in b6a5036
age_depth_model(sac::Vector{T}) where {T} = sac |> reverse |> accumulate(min) |> reverse |
test/Testexport.jl
Outdated
sac1 = data2.var"sac1 [m]"[end] | ||
|
||
@test sum(sc1_f1+sc1_f2+sc1_f3) ≈ sac1 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is to be a unit test, it should be encapsulated in a @testset
block as follows:
@testset "CarboKitten.Export.stratigraphic_column" begin
...
end
…simultaneously and warns when inconsistencies occur
pushed with assertions. It fails at : |
You should use |
Does it still fail? If so, what does the data look like and when does it fail? |
still fails, but not complaining any assertion this time. |
@xyl96 Ok, in principle now we have a self-contained test, but it doesn't suffice as a unit test, because it takes a few minutes to run, and it doesn't hone in on the problem at hand. We only need a single column of the generated data. What I would do:
|
the example of test and code to plot is here: examples\StraDiscrep_test\TestSCdiscrep.jl |
No description provided.