Skip to content

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

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft

Fix computation of Stratigraphic Column #109

wants to merge 18 commits into from

Conversation

jhidding
Copy link
Member

No description provided.

Liu added 4 commits March 4, 2025 17:21
deposition is net sed scc? So should not substract disintegration one more time?
test showing the exported sc does not equal to sac
@jhidding jhidding linked an issue Mar 10, 2025 that may be closed by this pull request
Copy link
Member Author

@jhidding jhidding left a 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!

@@ -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"
Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Member Author

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:

  1. run a small simulation with HDF5 output (make it 1d) and write the output to a temporary directory (see
    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
    for an example).
  2. 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.

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)
Copy link
Member Author

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

data2 = CSV.read("$(PATH)/$(TAG)_sac.csv", DataFrame)
sac1 = data2.var"sac1 [m]"[end]

@test sum(sc1_f1+sc1_f2+sc1_f3) ≈ sac1
Copy link
Member Author

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

age_depth_model(sac::Vector{T}) where {T} = sac |> reverse |> accumulate(min) |> reverse
to see how ADM and SAC are related.

sac1 = data2.var"sac1 [m]"[end]

@test sum(sc1_f1+sc1_f2+sc1_f3) ≈ sac1
end
Copy link
Member Author

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

@xyl96
Copy link
Contributor

xyl96 commented Apr 9, 2025

pushed with assertions. It fails at : sum(sc[ts_down, :]) + sum(acc) == sum(previous_sc). Where previous_sc is sc[ts_down,:] before acc substraction.

@jhidding
Copy link
Member Author

You should use isapprox or unicode there. These are floating-point values.

@jhidding
Copy link
Member Author

Does it still fail? If so, what does the data look like and when does it fail?

@xyl96
Copy link
Contributor

xyl96 commented Apr 14, 2025

still fails, but not complaining any assertion this time.

@EmiliaJarochowska
Copy link
Member

EmiliaJarochowska commented May 14, 2025

I'm trying to figure out where we are with this problem. @jhidding are you satisfied with the test proposed by @xyl96 ?

@jhidding
Copy link
Member Author

@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:

  • find a column where the discrepancy is high, preferably in a single facies.
  • plot both the disintegration and the the deposition as a function of time.
  • is there anything that strikes you as odd? Try to create some artificial curves that still show the same problem.
  • reproduce the issue with only a given disintegration, deposition and the stratigraphic_column function.

@xyl96
Copy link
Contributor

xyl96 commented Jun 10, 2025

the example of test and code to plot is here: examples\StraDiscrep_test\TestSCdiscrep.jl

@EmiliaJarochowska
Copy link
Member

My understanding is now that @xyl96 should abandon ship and only move the useful parts of the code to #139 and then sink this branch and PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit test for stratigraphy column
3 participants