Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhassell committed Jul 16, 2024
1 parent f3ad202 commit 8e5487f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions cf/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def histogram(*digitized, density=False):
>>> print(p)
Field: long_name=probability density function
---------------------------------------------
Data : long_name=probability density function(specific_humidity(10))
Data : long_name=probability density function(specific_humidity(10)) 1
Cell methods : latitude: longitude: point
Dimension coords: specific_humidity(10) = [0.01015, ..., 0.13885] 1
>>> print(p.data.round(2).array))
Expand Down Expand Up @@ -283,7 +283,7 @@ def histogram(*digitized, density=False):
>>> print(p)
Field: long_name=probability density function
---------------------------------------------
Data : long_name=probability density function(air_temperature(5), specific_humidity(10))
Data : long_name=probability density function(air_temperature(5), specific_humidity(10)) K-1
Cell methods : latitude: longitude: point
Dimension coords: air_temperature(5) = [257.05, ..., 288.25] K
: specific_humidity(10) = [0.01015, ..., 0.13885] 1
Expand Down Expand Up @@ -320,7 +320,6 @@ def histogram(*digitized, density=False):
# Convert counts to densities
out /= out.data.sum() * bin_measures

out.override_units(Units(), inplace=True)
out.del_property("standard_name", None)
out.set_property("long_name", "probability density function")

Expand Down
3 changes: 2 additions & 1 deletion cf/test/test_Maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def test_histogram(self):
h = cf.histogram(indices)
self.assertTrue((h.array == [9, 7, 9, 4, 5, 1, 1, 1, 2, 1]).all)
h = cf.histogram(indices, density=True)
self.assertEqual(h.Units, cf.Units("1"))
# Check that integral is 1
bin_measures = h.dimension_coordinate().cellsize
integral = (h * bin_measures).sum()
Expand All @@ -247,7 +248,7 @@ def test_histogram(self):
)

h = cf.histogram(indices, indices_t, density=True)
self.assertEqual(h.Units, cf.Units())
self.assertEqual(h.Units, cf.Units("K-1"))
# Check that integral is 1
bin_measures = h.dimension_coordinate("air_temperature").cellsize
bin_measures.outerproduct(
Expand Down

0 comments on commit 8e5487f

Please sign in to comment.