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

Calculate rolling time-series of ice volume displacement over subglacial lakes #216

Merged
merged 7 commits into from
Dec 20, 2020

Conversation

weiji14
Copy link
Owner

@weiji14 weiji14 commented Dec 17, 2020

Multiply lake area by mean height displacement to get ice volume displacement! Sounds easy, but try implementing it in a robust way with pint units and standard deviation uncertainties too! This PR extends the work done in #212.

crossover_anomaly_whillans_ix_2018-10-14_2020-09-30 cascade_whillans_ice_stream

TODO:

  • Implement function for calculating ice volume displacement (a90b92a)
  • Include the rolling mean height anomaly line in crossover plots (4c5daf0)
  • Add a behavioural driven development test to parallelize the calculation of several lake volume changes (85f74a7, 24acc1c)
  • Make a plot overlaying ice volume displacement of several lakes at once (1872ad0)

References:

  • Kim, B.-H., Lee, C.-K., Seo, K.-W., Lee, W. S., & Scambos, T. A. (2016). Active subglacial lakes and channelized water flow beneath the Kamb Ice Stream. The Cryosphere, 10(6), 2971–2980. https://doi.org/10.5194/tc-10-2971-2016
  • Siegfried, M. R., Fricker, H. A., Carter, S. P., & Tulaczyk, S. (2016). Episodic ice velocity fluctuations triggered by a subglacial flood in West Antarctica. Geophysical Research Letters, 43(6), 2640–2648. https://doi.org/10.1002/2016GL067758

Math looks easy on paper until you try to implement it robustly, and this ice volume displacement calculation is one such example! We estimate ice volume displacement by multiplying lake area by the height anomaly, following Kim et al., 2016 and Siegfried et al., 2016. The height anomaly is a rolling mean elevation calculated with a window size of 91 days (1 ICESat-2 cycle), minus the first elevation at time=0. The cool thing about this function is that pint units are used, with standard deviation uncertainties included! Added one quick and dirty doctest for this function just to keep things simple.
@weiji14 weiji14 added the enhancement ✨ New feature or request label Dec 17, 2020
@weiji14 weiji14 added this to the v0.4.0 milestone Dec 17, 2020
@weiji14 weiji14 self-assigned this Dec 17, 2020
Fixing some inconsistencies in the use of "normalized" height, should be height "anomalies" instead. The df_th (time and height dataframe) is now sorted by time prior to running any processing operations, so the crossover height anomaly over time plots should all start right at 0 now. Still need to work on adding the one sigma uncertainty error bars, and find a way to parallelize the whole script on many lakes.
Chucking lots of code from atlxi_xover.py into our Behavioural Driven Development integration test suite. Not very DRY, but will refactor later. Should work by running `poetry run pytest --verbose --doctest-modules -k anomalies -n 2 deepicedrain/`. Dropped all the lake_ids from all the examples in subglacial_lakes.feature as they're listed in atlas_catalog.yaml now, one source of truth! Also made the `df_lake` function into a reusable fixture in conftest.py, setting it up for shaing across the test_subglacial_lakes_*.py tests.
One local dask cluster client to run them all! Also a minor tweak to the boolean 'draining' variable.
Like, actually calculate and save (!!) ice volume displacement (dvol), so that we can aggregrate the dvol values from several lakes into one plot later on, or share the data with other people. Both the nominal values and standard deviations are saved, though this requires the pint and uncertainties package. Also did some hacking to ensure pint unit registries are the same to avoid a "ValueError: Cannot operate with Quantity and Quantity of different registries."
@weiji14 weiji14 force-pushed the ice_volume_displacement branch from e56fe76 to cbb88f8 Compare December 20, 2020 05:32
Ice volume displacements (a proxy for subglacial lake volume discharge) did not seem right, and it's because the geographical subsetting was done using a bounding box rather than an actual polygon. Using geopandas (CPU-based) for this since there's only a few hundred points involved. Also decided I might as well randomly commit an enhancement to the point_in_polygon_gpu code, with a new poly_limit parameter for conserving GPU memory.
Not to be confused with waterfall plots, nor anything really. This is still a fairly basic graph showing an inferred cascade of Whillans 7 -> Whillans IX -> Subglacial Lake Whillans -> Whillans 12. The numbers don't quite sum up perfectly on the chart, so I might need to look at a few more adjacent lakes. This should do for now though!
@weiji14 weiji14 marked this pull request as ready for review December 20, 2020 08:59
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 20, 2020

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 1.99%.

Quality metrics Before After Change
Complexity 4.85 ⭐ 5.40 ⭐ 0.55 👎
Method Length 118.64 🙂 131.21 😞 12.57 👎
Working memory 19.04 ⛔ 20.41 ⛔ 1.37 👎
Quality 47.46% 😞 45.47% 😞 -1.99% 👎
Other metrics Before After Change
Lines 963 1216 253
Changed files Quality Before Quality After Quality Change
atlxi_xover.py 25.95% 😞 24.50% ⛔ -1.45% 👎
deepicedrain/init.py 78.39% ⭐ 78.24% ⭐ -0.15% 👎
deepicedrain/lake_algorithms.py 74.84% 🙂 54.57% 🙂 -20.27% 👎
deepicedrain/spatiotemporal.py 56.89% 🙂 56.62% 🙂 -0.27% 👎
deepicedrain/tests/conftest.py 99.67% ⭐ 61.52% 🙂 -38.15% 👎
deepicedrain/tests/test_subglacial_lake_animation.py 56.55% 🙂 59.37% 🙂 2.82% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
deepicedrain/spatiotemporal.py spatiotemporal_cube 6 ⭐ 267 ⛔ 21 ⛔ 35.68% 😞 Try splitting into smaller methods. Extract out complex expressions
deepicedrain/tests/test_subglacial_lake_animation.py visualize_grid_in_3D 1 ⭐ 201 😞 29 ⛔ 41.96% 😞 Try splitting into smaller methods. Extract out complex expressions
deepicedrain/lake_algorithms.py ice_volume_over_time 6 ⭐ 215 ⛔ 16 ⛔ 42.40% 😞 Try splitting into smaller methods. Extract out complex expressions
deepicedrain/spatiotemporal.py point_in_polygon_gpu 4 ⭐ 175 😞 18 ⛔ 45.64% 😞 Try splitting into smaller methods. Extract out complex expressions
deepicedrain/tests/conftest.py lake_altimetry_data 1 ⭐ 218 ⛔ 15 😞 48.26% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

@weiji14 weiji14 merged commit 7683721 into master Dec 20, 2020
@weiji14 weiji14 deleted the ice_volume_displacement branch December 20, 2020 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant