forked from ooici/coverage-model
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M117 / Issue ooici#155 - Reworked interface for external parameter re…
…ferences.
- Loading branch information
1 parent
c8296ba
commit 6cf4181
Showing
6 changed files
with
53 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
__author__ = 'casey' | ||
|
||
import numpy as np | ||
|
||
|
||
def linear_map(pval_callback, cov, external_param_name, time_segment): | ||
# TODO: Might not want to hard-code time | ||
x = pval_callback('time', time_segment).get_data()['time'] | ||
x_i = cov.get_parameter_values('time', time_segment=time_segment).get_data()['time'] | ||
y_i = cov.get_parameter_values(external_param_name, time_segment=time_segment).get_data()[external_param_name] | ||
|
||
|
||
# Where in x_i does x fit in? | ||
upper = np.searchsorted(x_i, x) | ||
# Clip values not in [1, N-1] | ||
upper = upper.clip(1, len(x_i)-1).astype(int) | ||
lower = upper - 1 | ||
|
||
# Linear interpolation | ||
w = (x - x_i[lower]) / (x_i[upper] - x_i[lower]) | ||
y = y_i[lower] * (1-w) + y_i[upper] * w | ||
return y |