Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Given valid inputs, some functions return NaN #82

Open
FudgeMunkey opened this issue Nov 23, 2021 · 0 comments
Open

Given valid inputs, some functions return NaN #82

FudgeMunkey opened this issue Nov 23, 2021 · 0 comments

Comments

@FudgeMunkey
Copy link

FudgeMunkey commented Nov 23, 2021

Bug

I have been writing Property Based Tests for GSW using the Hypothesis framework. I have tried to provide reasonable inputs for these functions, however they can return NaN.

The following ranges were used:

Parameter Minimum Maximum
Salinity (g/kg) 0 42
Temperature (C) -2 40
Ice Temperature (C) -20 0
Sea Pressure (dbar) 0 11,000
Fractions 0 1
Density (kg/m^3) 1000 1060
Longitude -360 360
Latitude -90 90
Conductivity (mS/cm) 0 60

The following functions are affected:

  • CT_from_rho
  • SA_from_rho
  • SP_from_C
  • SP_from_SK
  • ice_fraction_to_freeze_seawater
  • melting_ice_SA_CT_ratio
  • melting_ice_SA_CT_ratio_poly
  • melting_ice_into_seawater
  • melting_seaice_SA_CT_ratio
  • melting_seaice_SA_CT_ratio_poly
  • melting_seaice_into_seawater
  • seaice_fraction_to_freeze_seawater
  • SA_freezing_from_CT
  • SA_freezing_from_CT_poly
  • SA_freezing_from_t
  • SA_freezing_from_t_poly
  • pressure_freezing_CT
  • SA_from_SP_Baltic
  • SP_from_SA_Baltic

Resources

I used these resources to generate the input ranges. If they are incorrect, please let me know and I can adjust my tests and rerun.

  1. Key Physical Variables in the Ocean: Temperature, Salinity, and Density (2010)
  2. Accurate polynomial expressions for the density and specific volume of seawater using the TEOS-10 standard
  3. Algorithms for Density, Potential Temperature, Conservative Temperature, and the Freezing Temperature of Seawater
  4. Three-stage vertical distribution of seawater conductivity
  5. Documentation

To Reproduce

I have added tests to this branch and added Hypothesis as a dependency to requirements-dev.txt. Clone the repo, checkout the branch, install the dependencies and run the tests using pytest as normal.

I have also listed falsifying examples for each of the functions below.

CT_from_rho(rho=1000.0, SA=0.0, p=0.0)
SA_from_rho(rho=1000.0, CT=0.0, p=30.794423499933114)
SP_from_C(C=0.0, t=9.990234375002293, p=0.0)
SP_from_SK(SK=0.0)
ice_fraction_to_freeze_seawater(SA=0.0, CT=0.0, p=0.0, t_Ih=0.0)
melting_ice_SA_CT_ratio(SA=0.0, CT=0.0, p=0.0, t_Ih=0.0)
melting_ice_SA_CT_ratio_poly(SA=0.0, CT=0.0, p=0.0, t_Ih=0.0)
melting_ice_into_seawater(SA=0.0, CT=0.0, p=0.0, w_Ih=0.0, t_Ih=0.0)
melting_seaice_SA_CT_ratio(SA=0.0, CT=0.0, p=0.0, SA_seaice=0.0, t_seaice=0.0)
melting_seaice_SA_CT_ratio_poly(SA=0.0, CT=0.0, p=0.0, SA_seaice=0.0, t_seaice=0.0)
melting_seaice_into_seawater(SA=0.0, CT=0.0, p=0.0, w_seaice=0.0, SA_seaice=0.0, t_seaice=0.0)
seaice_fraction_to_freeze_seawater(SA=0.0, CT=0.0, p=0.0, SA_seaice=0.0, t_seaice=0.0)
SA_freezing_from_CT(CT=0.0, p=23.199230114322237, saturation_fraction=0.3125777542779598)
SA_freezing_from_CT_poly(CT=0.0, p=23.19905520299171, saturation_fraction=0.3125777701890003)
SA_freezing_from_t(t=0.0, p=2.381246187626918, saturation_fraction=0.31252766369797685)
SA_freezing_from_t_poly(t=0.0, p=2.380903489457076, saturation_fraction=0.3125276948530216)
pressure_freezing_CT(SA=0.0, CT=0.017154556664884527, saturation_fraction=0.3125155482932987)
SA_from_SP_Baltic(SP=0.0, lon=0.0, lat=0.0)
SP_from_SA_Baltic(SA=0.0, lon=0.0, lat=0.0)

Please note that many of the parameters are 0.0 because Hypothesis tries to shrink falsifying examples. 17 of the 19 functions still fail if the salinity, pressure and fractions strategies are set to have a minimum value of 1 instead of 0.

  • SP_from_C does not fail anymore if Conductivity is at least ~0.1.
  • SP_from_SK does not fail anymore if SK is at least ~0.1.

Expected behaviour

I would expect the functions to always return some scalar value rather than NaN.

Environment

  • Ubuntu 20.04
  • Python 3.8.10
  • GSW 3.4.1.post1.dev1+gcede756.d20211122
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant