-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add functions to fit and convert IAM models #1827
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
Changes from 1 commit
9816a3f
dacc1f0
fc968af
441d8cc
77641d0
d7cbf5e
b4dcecf
6d054f4
21a66ee
b4714a4
96de7d9
de20629
91f811e
e4d4cdc
3789890
2efa830
c5c2d09
af65bc0
d505ac9
109e20e
554d862
e8d83b6
ee9c686
e95993d
991e962
484cb5a
47ebdac
317fb35
3996cab
ba87f7e
ac4e717
529e512
6b211fd
3fc2c00
a9f9b74
ac160b8
536cb9f
2882912
9bb36b5
753d72b
fc1316c
935443b
c9f697d
88a9dfc
8ace9d6
3475bf4
f216d94
cb4cb05
ed35731
fdcc952
9b1cfd8
d78265a
38bfb58
04121de
69cd00a
520a74e
e5cd24b
6ce34e4
743931d
fe9a39c
d56cbcf
2a0b815
4e165a0
d3d8cfd
313386c
b0e45dd
32aa64a
8df7bf6
6250182
74c2e54
f9c8888
79af432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -951,8 +951,8 @@ def _get_model(model_name): | |
try: | ||
model = model_dict[model_name] | ||
except KeyError: | ||
raise NotImplementedError(f"The {model_name} model has not been \ | ||
implemented") | ||
raise NotImplementedError(f"The {model_name} model has not been " | ||
"implemented") | ||
|
||
return model | ||
|
||
|
@@ -962,9 +962,9 @@ def _check_params(model_name, params): | |
# belong to the model | ||
exp_params = _IAM_MODEL_PARAMS[model_name] | ||
if set(params.keys()) != exp_params: | ||
raise ValueError(f"The {model_name} model was expecting to be passed \ | ||
{', '.join(list(exp_params))}, but \ | ||
was handed {', '.join(list(params.keys()))}") | ||
raise ValueError(f"The {model_name} model was expecting to be passed " | ||
"{', '.join(list(exp_params))}, but " | ||
"was handed {', '.join(list(params.keys()))}") | ||
|
||
|
||
def _sin_weight(aoi): | ||
|
@@ -1106,8 +1106,8 @@ def _min_scipy(): | |
return False | ||
|
||
|
||
def convert(source_name, source_params, target_name, weight=None, fix_n=True, | ||
xtol=None): | ||
def convert(source_name, source_params, target_name, weight=_sin_weight, | ||
fix_n=True, xtol=None): | ||
""" | ||
Convert a source IAM model to a target IAM model. | ||
cwhanse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
@@ -1134,9 +1134,9 @@ def convert(source_name, source_params, target_name, weight=None, fix_n=True, | |
``'physical'``. | ||
|
||
weight : function, optional | ||
A single-argument function of AOI that calculates weights for the | ||
residuals between models. Must return a float or an array-like object. | ||
The default weight function is :math:`f(aoi) = 1 - sin(aoi)`. | ||
A single-argument function of AOI (degrees) that calculates weights for | ||
the residuals between models. Must return a float or an array-like | ||
object. The default weight function is :math:`f(aoi) = 1 - sin(aoi)`. | ||
|
||
fix_n : bool, default True | ||
A flag to determine which method is used when converting from the | ||
|
@@ -1174,9 +1174,11 @@ def convert(source_name, source_params, target_name, weight=None, fix_n=True, | |
|
||
.. math:: | ||
|
||
\sum_{\\theta=0}^{90} weight \\left(\\theta \\right) \\times | ||
\\sum_{\\theta=0}^{90} weight \\left(\\theta \\right) \\times | ||
\\| source \\left(\\theta \\right) - target \\left(\\theta \\right) \\| | ||
|
||
|
||
The sum is over :math:`\\theta = 0, 1, 2, ..., 90`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite true; the code actually uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to code to Ready to merge from my point of view. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pedantic nitpick: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a nit, rather, that's the intent, because it feels natural to step by 1.0000000000000... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it feels natural to step by unity. I was trying to point out that the current code (
8000
|
||
|
||
References | ||
---------- | ||
.. [1] Jones, A. R., Hansen, C. W., Anderson, K. S. Parameter estimation | ||
|
@@ -1195,10 +1197,6 @@ def convert(source_name, source_params, target_name, weight=None, fix_n=True, | |
source = _get_model(source_name) | ||
target = _get_model(target_name) | ||
|
||
# if no options were passed in, we will use the default arguments | ||
if weight is None: | ||
weight = _sin_weight | ||
|
||
aoi = np.linspace(0, 90, 100) | ||
_check_params(source_name, source_params) | ||
source_iam = source(aoi, **source_params) | ||
|
@@ -1233,7 +1231,7 @@ def residual_function(target_param): | |
return {} | ||
|
||
|
||
def fit(measured_aoi, measured_iam, model_name, weight=None, xtol=None): | ||
def fit(measured_aoi, measured_iam, model_name, weight=_sin_weight, xtol=None): | ||
""" | ||
Find model parameters that best fit the data. | ||
|
||
|
@@ -1251,9 +1249,9 @@ def fit(measured_aoi, measured_iam, model_name, weight=None, xtol=None): | |
or ``'physical'``. | ||
|
||
weight : function, optional | ||
A single-argument function of AOI that calculates weights for the | ||
residuals between models. Must return a float or an array-like object. | ||
The default weight function is :math:`f(aoi) = 1 - sin(aoi)`. | ||
A single-argument function of AOI (degrees) that calculates weights for | ||
the residuals between models. Must return a float or an array-like | ||
object. The default weight function is :math:`f(aoi) = 1 - sin(aoi)`. | ||
|
||
xtol : float, optional | ||
Passed to scipy.optimize.minimize. | ||
|
@@ -1284,8 +1282,11 @@ def fit(measured_aoi, measured_iam, model_name, weight=None, xtol=None): | |
|
||
.. math:: | ||
|
||
\sum_{measured AOI} weight \\left( AOI \\right) \\times | ||
\\| measured IAM \\left( AOI \\right) - model \\left( AOI \\right) \\| | ||
\\sum_{AOI} weight \\left( AOI \\right) \\times | ||
\\| IAM \\left( AOI \\right) - model \\left( AOI \\right) \\| | ||
|
||
The sum is over ``measured_aoi`` and :math:`IAM \\left( AOI \\right)` | ||
is ``measured_IAM``. | ||
|
||
See Also | ||
-------- | ||
|
@@ -1298,10 +1299,6 @@ def fit(measured_aoi, measured_iam, model_name, weight=None, xtol=None): | |
|
||
target = _get_model(model_name) | ||
|
||
# if no options were passed in, we will use the default arguments | ||
if weight is None: | ||
weight = _sin_weight | ||
|
||
if model_name == "physical": | ||
bounds = [(0, 0.08), (1, 2)] | ||
guess = [0.002, 1+1e-08] | ||
|
Uh oh!
There was an error while loading. Please reload this page.