Skip to content
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

IMPRO-1917: Boolean output are now int8 from these plugins/CLIs: #1362

Merged
merged 4 commits into from
Nov 5, 2020

Conversation

MoseleyS
Copy link
Contributor

@MoseleyS MoseleyS commented Nov 3, 2020

  • CorrectLandSeaMask; generate-landmask-ancillary
  • PrecipPhaseProbability; precipphase
  • SignificantPhaseMask; phase-mask
  • calculate_sleet_prob - if inputs are int8

Testing:

  • Ran tests and they passed OK
  • Added new tests for the new feature(s)

- CorrectLandSeaMask; generate-landmask-ancillary
- PrecipPhaseProbability; precipphase
- SignificantPhaseMask; phase-mask
- calculate_sleet_prob - if inputs are int8
@MoseleyS MoseleyS self-assigned this Nov 3, 2020
@codecov
Copy link

codecov bot commented Nov 3, 2020

Codecov Report

Merging #1362 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1362      +/-   ##
==========================================
- Coverage   96.18%   96.18%   -0.01%     
==========================================
  Files          85       85              
  Lines        7285     7284       -1     
==========================================
- Hits         7007     7006       -1     
  Misses        278      278              
Impacted Files Coverage Δ
...hrometric_calculations/precip_phase_probability.py 97.95% <ø> (ø)
improver/calculate_sleet_prob.py 100.00% <100.00%> (ø)
...mprover/generate_ancillaries/generate_ancillary.py 90.24% <100.00%> (ø)
...ychrometric_calculations/significant_phase_mask.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1cebb4...27d83b6. Read the comment docs.

@MoseleyS MoseleyS requested a review from BelligerG November 3, 2020 17:02
BelligerG
BelligerG previously approved these changes Nov 4, 2020
Copy link
Contributor

@BelligerG BelligerG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Contributor

@cgsandford cgsandford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acceptance tests pass. Couple of minor comments.

ones = np.ones((prob_of_snow.shape), dtype="float32")
sleet_prob = ones - (prob_of_snow.data + prob_of_rain.data)
if np.any(sleet_prob < 0.0):
sleet_prob = 1 - (prob_of_snow.data + prob_of_rain.data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it a problem to cast probabilities to float32?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any reason to cast the ones here to float32 as int - float32 = float32 (it's also about twice as fast to do it this way)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris is right. By casting the ones as float32, the code was forcing the output to be at least float32 precision. Now it is determined by Numpy based on the highest precision of the snow and rain inputs. Other changes in this PR mean they will be int8, so the output here is int8 too. If they are float32 fractions, then the output here would be a float32 fraction too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK, I misunderstood. I thought the data coming in were float32 probabilities.

Could you update the docstring please to clarify that these are actually integer / boolean masks, not probabilities? Otherwise this is fine.

self.assertIsInstance(result, iris.cube.Cube)
self.assertEqual(result.name(), "probability_of_rain_at_surface")
self.assertEqual(result.units, Unit("1"))
self.assertArrayAlmostEqual(result.data, expected)
self.assertTrue(result.dtype == np.int8)

def test_unit_conversion(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are two more tests in this file whose datatypes need converting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved these meta-data tests into a function that is called from each test instead. This avoids repetition.

- Moves meta-data tests into a common function and uses it everywhere that the output are tested.
- Moves creation of expected data array template into setup function.
cgsandford
cgsandford previously approved these changes Nov 4, 2020
@MoseleyS MoseleyS merged commit f422bba into metoppv:master Nov 5, 2020
@MoseleyS MoseleyS deleted the impro-1917-int8-masks branch November 5, 2020 09:00
MoseleyS added a commit to MoseleyS/improver that referenced this pull request Nov 6, 2020
…phase-change-radius

* remotes/origin/master:
  IMPRO-1917: Boolean output are now int8 from these plugins/CLIs: (metoppv#1362)
  IMPRO-1815: reject float64 data in combine plugin (metoppv#1363)
MoseleyS added a commit to MoseleyS/improver that referenced this pull request Aug 22, 2024
…oppv#1362)

* Boolean output are now int8 from these plugins/CLIs:

- CorrectLandSeaMask; generate-landmask-ancillary
- PrecipPhaseProbability; precipphase
- SignificantPhaseMask; phase-mask
- calculate_sleet_prob - if inputs are int8

* Blackify

* Refactors test_PrecipPhaseProbability.py

- Moves meta-data tests into a common function and uses it everywhere that the output are tested.
- Moves creation of expected data array template into setup function.

* Makes doc-string clearer in calculate_sleet_prob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants