-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #658 from slayoo/freezing
cleanups, null default for freezing spectrum, README update
- Loading branch information
Showing
16 changed files
with
142 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from .niemand_et_al_2012 import Niemand_et_al_2012 | ||
from .niemand_et_al_2012 import Niemand_et_al_2012 | ||
from .bigg_1953 import Bigg_1953 | ||
from .null import Null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import numpy as np | ||
from PySDM.physics import constants as const | ||
|
||
P_median = .5 | ||
DT_median = np.nan | ||
|
||
# TODO #599: there are two Bigg 1953 papers | ||
# TODO #599: relate DT to drop volume to A_insol? (the second paper!) | ||
|
||
|
||
class Bigg_1953: | ||
def __init__(self): | ||
assert np.isfinite(DT_median) | ||
|
||
@staticmethod | ||
def pdf(T, A_insol): | ||
A = np.log(1 - P_median) | ||
B = DT_median - const.T0 | ||
return - A * np.exp(A * np.exp(B + T) + B + T) | ||
|
||
@staticmethod | ||
def cdf(T, A_insol): | ||
return np.exp(np.log(1 - P_median) * np.exp(DT_median - (const.T0 - T))) | ||
|
||
@staticmethod | ||
def median(): | ||
return const.T0 - DT_median |
16 changes: 10 additions & 6 deletions
16
PySDM/physics/freezing_temperature_spectrum/niemand_et_al_2012.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
from PySDM.physics import constants as const, si | ||
from PySDM.physics import constants as const | ||
import numpy as np | ||
|
||
a = -0.517 | ||
b = 8.934 | ||
A_insol = const.pi * (1*si.um)**2 | ||
a = np.nan | ||
b = np.nan | ||
|
||
|
||
class Niemand_et_al_2012: | ||
def __str__(self): | ||
return 'Niemand et al. 2012' | ||
|
||
def __init__(self): | ||
assert np.isfinite(a) | ||
assert np.isfinite(b) | ||
|
||
@staticmethod | ||
def pdf(T): | ||
def pdf(T, A_insol): | ||
ns_T = np.exp(a * (T - const.T0) + b) | ||
return -A_insol * a * ns_T * np.exp(-A_insol * ns_T) | ||
|
||
@staticmethod | ||
def cdf(T): | ||
def cdf(T, A_insol): | ||
ns_T = np.exp(a * (T - const.T0) + b) | ||
return 1 - np.exp(-A_insol * ns_T) - np.exp(-A_insol*np.exp(-a * const.T0 + b)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Null: | ||
@staticmethod | ||
def cdf(T): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
c = np.inf | ||
unit = 1 / si.cm**2 / si.s | ||
|
||
|
||
class ABIFM: | ||
@staticmethod | ||
def _check(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
tests/unit_tests/initialisation/test_spectral_discretisation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 33 additions & 18 deletions
51
tests/unit_tests/physics/test_freezing_temperature_spectra.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
from PySDM.physics import Formulae, constants as const | ||
from matplotlib import pylab | ||
import numpy as np | ||
import pytest | ||
from matplotlib import pylab | ||
from PySDM.physics import Formulae, si, constants as const | ||
from PySDM.physics.freezing_temperature_spectrum import niemand_et_al_2012, bigg_1953 | ||
|
||
|
||
A = 1 * si.um**2 | ||
|
||
def test_freezing_temperature_spectra(plot=False): | ||
|
||
@pytest.mark.parametrize("model", ( | ||
'Niemand_et_al_2012', | ||
'Bigg_1953' | ||
)) | ||
def test_freezing_temperature_spectra(model, plot=False): | ||
# Arrange | ||
formulae = Formulae() | ||
bigg_1953.DT_median = 33 | ||
niemand_et_al_2012.a = -0.517 | ||
niemand_et_al_2012.b = 8.934 | ||
niemand_et_al_2012.A_insol = 1 * si.um ** 2 | ||
|
||
formulae = Formulae(freezing_temperature_spectrum=model) | ||
T = np.linspace(const.T0, const.T0 - 40, num=100) | ||
|
||
# Act | ||
pdf = formulae.freezing_temperature_spectrum.pdf(T) | ||
cdf = formulae.freezing_temperature_spectrum.cdf(T) | ||
pdf = formulae.freezing_temperature_spectrum.pdf(T, A) | ||
cdf = formulae.freezing_temperature_spectrum.cdf(T, A) | ||
|
||
# Plot | ||
pylab.plot(T, pdf, linestyle='-', marker='o', label='pdf') | ||
pdfax = pylab.gca() | ||
cdfax = pdfax.twinx() | ||
cdfax.plot(T, cdf, linestyle='--', marker='x', label='cdf') | ||
pylab.xlabel('T [K]') | ||
pylab.xlim(np.amax(T), np.amin(T)) | ||
pdfax.set_ylabel('pdf [K$^{-1}$]') | ||
cdfax.set_ylabel('cdf [1]') | ||
pylab.grid() | ||
pylab.title(model) | ||
if plot: | ||
pylab.plot(T, pdf, linestyle='-', marker='o', label='pdf') | ||
pdfax = pylab.gca() | ||
cdfax = pdfax.twinx() | ||
cdfax.plot(T, cdf, linestyle='--', marker='x', label='cdf') | ||
pylab.xlabel('T [K]') | ||
pylab.xlim(np.amax(T), np.amin(T)) | ||
pdfax.set_ylabel('pdf [K$^{-1}$]') | ||
cdfax.set_ylabel('cdf [1]') | ||
pylab.grid() | ||
pylab.show() | ||
|
||
# Assert | ||
dT = abs(T[1] - T[0]) | ||
np.testing.assert_approx_equal(np.sum(pdf * dT), 1) | ||
np.testing.assert_approx_equal(cdf[0]+1, 1) | ||
np.testing.assert_approx_equal(cdf[-1], 1) | ||
np.testing.assert_approx_equal(np.sum(pdf * dT), 1, significant=3) | ||
np.testing.assert_approx_equal(cdf[0]+1, 1, significant=3) | ||
np.testing.assert_approx_equal(cdf[-1], 1, significant=3) |