Skip to content
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

Overhaul of box model to use more of the Clima infrastructure + data assimilation example #164

Merged
merged 47 commits into from
Jan 31, 2024

Conversation

jagoosw
Copy link
Collaborator

@jagoosw jagoosw commented Jan 4, 2024

This PR now overhauls BoxModel to use the Clima infrastructure (and breaks the box model API in the process).

This is a simple data assimilation example. Although it's a fictitious case hopefully it shows how it could be used.

evolution.mp4

CC: https://github.com/orgs/OceanBioME/discussions/163

@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 4, 2024

I'm not sure its worth making this a regular example but it doesn't take too long to run

@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 4, 2024

Its also interesting to not how insensitive this model is/how made up the parameters can be as the "learned" values are quite different from the "truth" ones, but for this case replicate the data well. I guess for a real-life case this indicates you do need more varied data/scenarios.

@jagoosw jagoosw added the documentation Improvements or additions to documentation label Jan 4, 2024
@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 5, 2024

Hmm this is strange, the docs build normally when I run them manually on kelp


@inline PAR(t) = PAR⁰(t) * exp(- 0.2 * 10)

function model(initial_photosynthetic_slope,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code a little harder to read because this function is called model, but there is also an object below called model = BoxModel(...). For examples I think it's good to be abnormally verbose, both for understandability and because a lot of code will end up being based on the example, so it has an outsized influence on coding style in the community.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe following the style from other examples, e.g. simulation = Simulation(..., you could do boxmodel = BoxModel(....

Copy link
Collaborator

@glwagner glwagner Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd advocate changing the name of the function to precisely reflect either the action taken, or the values returned. Functions fall broadly into two categories: verbs (actions) and nouns (constructors --- technically, a constructor takes an action that results in the construction of an object, but our convention is to use "nouns" for constructors).

In this case the function runs a simulation and returns P, times. So I don't think that "model" is the right name for the function. Perhaps "run_box_simulation" or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good point, thank you!

I will change to something like run_box_simulation.

P = zeros(1093)

for (idx, t_idx) in enumerate(length(times)-1092:length(times))
P[idx] = file["values/$(times[t_idx])"].P
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the "time" have a field .P?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P is a property of a tuple of values saved as values/timestep index like how in FieldTimeSeries we have timeseries which then has timesteps and in each timeseries/time step index you get each tracer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the file address timeseries/iteration/name here?

Copy link
Collaborator Author

@jagoosw jagoosw Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I'll change that for consistency too

@jagoosw jagoosw changed the title Added data assimilation example Overhaul of box model to use more of the Clima infrastructure + data assimilaiton example Jan 11, 2024
@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 11, 2024

@glwagner I've made quite a few changes so that BoxModel is now an AbstractModel and reuses all of the stuff in Oceananigans for simulations etc. as far as possible.

I guess it might be more appropriate for the box model to not be part of this package as its not really specific to the BGC stuff at all but we can move in the future e.g. when the simulation stuff gets moved out of Oceananigans.

@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 11, 2024

I'm just testing the updates to the data assimilation example now but think it may be a bit expensive to be worth running for the docs. The box model stuff is a bit slower now, I would guess the most expensive bit is that now instead of just writing a bunch of numbers to the file its got to write fields.

docs/Project.toml Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
Project.toml Show resolved Hide resolved
@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 30, 2024

I've sorted the interpolations issue now @navidcy

@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 30, 2024

Also I think the warning is from the output writer trying to serialise the $\kappa$ function which it can't (CliMA/Oceananigans.jl#2245)

@navidcy
Copy link
Collaborator

navidcy commented Jan 31, 2024

Project.toml Show resolved Hide resolved
@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 31, 2024

Yay, it finally built and only took 15ish min longer to run. The example is here https://oceanbiome.github.io/OceanBioME.jl/previews/PR164/generated/data_assimilation/

Do we think this is worthwhile including?

@navidcy
Copy link
Collaborator

navidcy commented Jan 31, 2024

Sure. Why not. We can always improve it later.

@jagoosw
Copy link
Collaborator Author

jagoosw commented Jan 31, 2024

Great, I'll merge

@jagoosw jagoosw merged commit a006207 into main Jan 31, 2024
5 checks passed
@jagoosw jagoosw deleted the jsw/data-assimilaiton-example branch January 31, 2024 22:27
@navidcy navidcy restored the jsw/data-assimilaiton-example branch February 1, 2024 05:55
@navidcy navidcy deleted the jsw/data-assimilaiton-example branch February 1, 2024 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants