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

Add capability for user-defined parameter sets, with an example #172

Closed
wants to merge 11 commits into from

Conversation

glwagner
Copy link
Member

@glwagner glwagner commented Dec 5, 2023

This PR tweaks the internal API for defining parameter sets to support user-defined parameters. This is important, because it will allow users to invoke functions in Thermodynamics.jl without requiring the full suite of parameters in ThermodynamicsParameters. For example, if one is only interested in computing density as a function of temperature, pressure, and (total) specific humidity, then they only require the universal gas constant and the molar masses of air and water.

Next, this PR adds an example which illustrates such a parameter set, called ConstitutiveParameters. It culminates in this plot:

image

which uses sea level data derived from the JRA55 reanalysis (subsampled to make the dataset smaller), showing the primary dependence of density on temperature, secondary dependence on pressure, and teritiary dependence on specific humidity for the typical conditions of the Earth's atmosphere at sea level.

Currently, there are no examples, so this PR introduces the first one. I'd be happy to turn the example into something that appears in the documentation via Literate (the example is very close to that form already).

@glwagner
Copy link
Member Author

glwagner commented Dec 5, 2023

I guess this PR depends on #171, but that can be removed.

docs/src/Formulation.md Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we literate it and add it in the docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what I asked about in the original post

@glwagner glwagner mentioned this pull request Dec 12, 2023
1 task
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.93%. Comparing base (46f51af) to head (6ec15d1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #172   +/-   ##
=======================================
  Coverage   90.93%   90.93%           
=======================================
  Files          10       10           
  Lines        1180     1180           
=======================================
  Hits         1073     1073           
  Misses        107      107           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

For more information see [reference docs].
"""
function ConstitutiveParameters(FT = Float64;
gas_constant = 8.3144598,
Copy link
Member

Choose a reason for hiding this comment

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

I had some discussions a while back with SEs asking if the parameters constructors should come with default values. The feedback I got was leaning towards not having the defaults, unless it is really beneficial to the structure of the code.

From what I understood the defaults should live in a toml file. - I don't have any opinions on this personally. More of a question of convention and how much we want to stick to it in different examples

Copy link
Member Author

@glwagner glwagner Jan 24, 2024

Choose a reason for hiding this comment

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

This is a "classroom example" that illustrates some thermodynamic calculations. I think we want to include examples like this in the docs as well to form a link between theromdynamic theory explained in the docs and functions that one calls to make thermodynamic calculations.

This example is not intended to illustrate how to use this package within an Earth system model. So, I understand the validity of the argument to avoid defaults in parameter structs that are designed for use in ClimaAtmos.

However, this parameter struct is not for ClimaAtmos or an Earth system model --- it's just for this small example. For this use case, it's nice to have the defaults here so that we can read this file and understand what the code is doing. The same applies for code snippets embedded in the documentation, I think.

Copy link
Member

@trontrytel trontrytel left a comment

Choose a reason for hiding this comment

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

+1 on turning it into a documentation page

@charleskawczynski
Copy link
Member

Can you rebase this PR @glwagner? I’d definitely like these changes

@charleskawczynski
Copy link
Member

@glwagner, can you re-open this on branch off the main branch? (not the fork), I wasn't able to rebase it

@glwagner
Copy link
Member Author

glwagner commented Feb 2, 2024

I can do that.

@glwagner glwagner added the Launch Buildkite Add label to launch Buildkite label Mar 5, 2024
@glwagner
Copy link
Member Author

glwagner commented Mar 5, 2024

@charleskawczynski I think we just need to run the formatter

colorrange = prange,
colormap = pmap,
alpha = 0.1,
)
Copy link
Member Author

Choose a reason for hiding this comment

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

@charleskawczynski what are the rules about function arguments on one line vs many lines?

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to clean this up if possible within the rules that the formatter dictates (perhaps its not possible)

Copy link
Contributor

@navidcy navidcy Mar 5, 2024

Choose a reason for hiding this comment

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

The join_lines_based_on_source might be relevant? You might need to set this to true.

Copy link
Member

Choose a reason for hiding this comment

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

If you want local custom formatting, you can do

#! format: off
custom formatted code
#! format: on

Copy link
Member

Choose a reason for hiding this comment

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

Sometimes I find this very handy

@glwagner
Copy link
Member Author

glwagner commented Mar 5, 2024

@charleskawczynski looks like the buildkite isn't running even though I added the "Launch buildkite" label

@charleskawczynski charleskawczynski added Launch Buildkite Add label to launch Buildkite and removed Launch Buildkite Add label to launch Buildkite labels Mar 5, 2024
@charleskawczynski
Copy link
Member

@charleskawczynski looks like the buildkite isn't running even though I added the "Launch buildkite" label

Let me try. If it works, I'll see if I can update your privileges.

@charleskawczynski
Copy link
Member

@glwagner, maybe because it's a PR from a fork? Ah, or the branch needs to be rebased (so that it picks up the latest buildkite config).

@glwagner
Copy link
Member Author

glwagner commented Mar 6, 2024

Superceded by #210

@glwagner glwagner closed this Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Launch Buildkite Add label to launch Buildkite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants