You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by le...@apache.org on 2018/08/01 05:28:09 UTC
[1/4] climate git commit: include absolute bias
Repository: climate
Updated Branches:
refs/heads/master 7cdaa7c0c -> cf3ef6015
include absolute bias
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/4fd7d491
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/4fd7d491
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/4fd7d491
Branch: refs/heads/master
Commit: 4fd7d4916f12757434fe4494940aac064ca24852
Parents: 3a80408
Author: Prateek Chanda <pr...@gmail.com>
Authored: Sat Jun 23 22:25:12 2018 +0530
Committer: GitHub <no...@github.com>
Committed: Sat Jun 23 22:25:12 2018 +0530
----------------------------------------------------------------------
ocw/metrics.py | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/4fd7d491/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index 3a6477e..b266012 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -281,6 +281,29 @@ def calc_bias(target_array, reference_array, average_over_time=False):
return ma.average(bias, axis=0)
else:
return bias
+
+
+def calc_absbias(target_array, reference_array, average_over_time=False):
+ ''' Calculate absolute difference between two arrays
+
+ :param target_array: an array to be evaluated, as model output
+ :type target_array: :class:'numpy.ma.core.MaskedArray'
+
+ :param reference_array: an array of reference dataset
+ :type reference_array: :class:'numpy.ma.core.MaskedArray'
+
+ :param average_over_time: if True, calculated bias is averaged for the axis=0
+ :type average_over_time: 'bool'
+
+ :returns: Absolute Biases array of the target dataset
+ :rtype: :class:'numpy.ma.core.MaskedArray'
+ '''
+
+ bias = abs(target_array - reference_array)
+ if average_over_time:
+ return ma.average(bias, axis=0)
+ else:
+ return bias
def calc_stddev(array, axis=None):
[3/4] climate git commit: Add a unit test for Absolute Bias
Posted by le...@apache.org.
Add a unit test for Absolute Bias
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/03075741
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/03075741
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/03075741
Branch: refs/heads/master
Commit: 0307574133ff50d8f7f019cf867aa8a2fa2c6bd1
Parents: 8104a2b
Author: Prateek Chanda <pr...@gmail.com>
Authored: Wed Jun 27 07:33:51 2018 +0530
Committer: GitHub <no...@github.com>
Committed: Wed Jun 27 07:33:51 2018 +0530
----------------------------------------------------------------------
ocw/tests/test_metrics.py | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/03075741/ocw/tests/test_metrics.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_metrics.py b/ocw/tests/test_metrics.py
index ac786e5..2257112 100644
--- a/ocw/tests/test_metrics.py
+++ b/ocw/tests/test_metrics.py
@@ -66,6 +66,46 @@ class TestBias(unittest.TestCase):
expected_result.fill(-300)
np.testing.assert_array_equal(self.bias.run(
self.target_dataset, self.reference_dataset), expected_result)
+
+
+class TestAbsoluteBias(unittest.TestCase):
+ '''Test the metrics.Bias metric.'''
+
+ def setUp(self):
+ self.bias = metrics.AbsoluteBias()
+ # Initialize reference dataset
+ self.reference_lat = np.array([10, 12, 14, 16, 18])
+ self.reference_lon = np.array([100, 102, 104, 106, 108])
+ self.reference_time = np.array(
+ [dt.datetime(2000, x, 1) for x in range(1, 13)])
+ flat_array = np.array(range(300))
+ self.reference_value = flat_array.reshape(12, 5, 5)
+ self.reference_variable = 'prec'
+ self.reference_dataset = Dataset(self.reference_lat,
+ self.reference_lon,
+ self.reference_time,
+ self.reference_value,
+ self.reference_variable)
+ # Initialize target dataset
+ self.target_lat = np.array([1, 2, 4, 6, 8])
+ self.target_lon = np.array([10, 12, 14, 16, 18])
+ self.target_time = np.array(
+ [dt.datetime(2001, x, 1) for x in range(1, 13)])
+ flat_array = np.array(range(300, 600))
+ self.target_value = flat_array.reshape(12, 5, 5)
+ self.target_variable = 'tasmax'
+ self.target_dataset = Dataset(self.target_lat,
+ self.target_lon,
+ self.target_time,
+ self.target_value,
+ self.target_variable)
+
+ def test_function_run(self):
+ '''Test bias function between reference dataset and target dataset.'''
+ expected_result = np.zeros((12, 5, 5), dtype=np.int)
+ expected_result.fill(300)
+ np.testing.assert_array_equal(self.bias.run(
+ self.target_dataset, self.reference_dataset), expected_result)
class TestSpatialPatternTaylorDiagram(unittest.TestCase):
[2/4] climate git commit: Add a new class for Absolute Bias involving
the function
Posted by le...@apache.org.
Add a new class for Absolute Bias involving the function
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/8104a2b2
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/8104a2b2
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/8104a2b2
Branch: refs/heads/master
Commit: 8104a2b24f1cf04c299d27276fc500650089eac2
Parents: 4fd7d49
Author: Prateek Chanda <pr...@gmail.com>
Authored: Wed Jun 27 07:15:46 2018 +0530
Committer: GitHub <no...@github.com>
Committed: Wed Jun 27 07:15:46 2018 +0530
----------------------------------------------------------------------
ocw/metrics.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/8104a2b2/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index b266012..199ab16 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -89,6 +89,28 @@ class Bias(BinaryMetric):
:rtype: :class:`numpy.ndarray`
'''
return calc_bias(target_dataset.values, ref_dataset.values)
+
+
+class AbsoluteBias(BinaryMetric):
+ '''Calculate the absolute bias between a reference and target dataset.'''
+
+ def run(self, ref_dataset, target_dataset):
+ '''Calculate the absolute bias between a reference and target dataset.
+
+ .. note::
+ Overrides BinaryMetric.run()
+
+ :param ref_dataset: The reference dataset to use in this metric run.
+ :type ref_dataset: :class:`dataset.Dataset`
+
+ :param target_dataset: The target dataset to evaluate against the
+ reference dataset in this metric run.
+ :type target_dataset: :class:`dataset.Dataset`
+
+ :returns: The absolute difference between the reference and target datasets.
+ :rtype: :class:`numpy.ndarray`
+ '''
+ return calc_absbias(target_dataset.values, ref_dataset.values)
class SpatialPatternTaylorDiagram(BinaryMetric):
[4/4] climate git commit: Merge branch 'patch-2' of
https://github.com/prateekiiest/climate
Posted by le...@apache.org.
Merge branch 'patch-2' of https://github.com/prateekiiest/climate
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/cf3ef601
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/cf3ef601
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/cf3ef601
Branch: refs/heads/master
Commit: cf3ef6015833d476a2d0317e39874aa7413d70fd
Parents: 7cdaa7c 0307574
Author: Lewis John McGibbney <le...@gmail.com>
Authored: Tue Jul 31 22:28:04 2018 -0700
Committer: Lewis John McGibbney <le...@gmail.com>
Committed: Tue Jul 31 22:28:04 2018 -0700
----------------------------------------------------------------------
ocw/metrics.py | 45 ++++++++++++++++++++++++++++++++++++++++++
ocw/tests/test_metrics.py | 40 +++++++++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+)
----------------------------------------------------------------------