-
Notifications
You must be signed in to change notification settings - Fork 105
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
Extrapolate from flowline #1490
Conversation
…area and thickness from the flowline
…area and thickness from the flowline
Maybe some collective knowledge will help ;-) |
write down if you have a look at it (it would be bad if there are two people working on it at the same time). I won't look at it this week but could try next week. |
I looked at the code and the most obvious runtime optimisation would be to avoid operations which loop over each pixel separately. import numpy as np
from scipy import interpolate
thick_fl = fl.thickness_m[dict(time=yr)]
surface_h_fl = fl.bed_h + thick_fl
# just make a linear interpolation between surface_h and thick_fl
sort_index = np.argsort(surface_h_fl)
tck = interpolate.splrep(surface_h_fl[sort_index],
thick_fl[sort_index],
k=1) # degree of the fitting, 1 is linear
# this function returns the ice thickness depending on the surface height
def lin_interpolate_h(surface_height):
return interpolate.splev(surface_height, tck)
# now vectorize so it can be used elementwise on a numpy array
vec_lin_interpolate_h = np.vectorize(lin_interpolate_h)
# get the first-order thickness, topo_smoothed is the map with the 2D surface heights of the current glacier
thick = vec_lin_interpolate_h(topo_smoothed) It also would need some safeguards during the interpolation to make sure there are no surface_h values along the flowline which are the same (in this case maybe one can use a mean thick of the two). And I am also not sure how effective I can try to implement this in the upcoming days, but before I can try to create a minimum python script which is a bit faster and makes it more fun for testing new things. Maybe @anoukvlug can help with this because I am not quite sure what in the notebook is testing and what is essentially needed. If a minimum script is not possible, we maybe could save intermediate steps to disk and start from there to increase the run time for testing (because if I understand correctly the goal is to optimise |
Yes - the other day I also had an even simpler idea for this, lets discuss all three of us tomorrow or another day maybe |
To add to my comment above, if we want to vectorize some functions for real, we could have a look at Numba https://numba.pydata.org/ ;) |
yes, although this should really just be the last step, done after the possible optimisations are done |
Two papers which might explain how the GloGEM model does the extrapolation (at least according to a text I just read):
Can someone skim them through and check how this is done there? |
I understand that they extrapolate the ice thickness change of individual elevation bands to the corresponding 2D pixels. The idea is that each oggm-flowline grid point has 2D pixels assigned. With this, the elevation change of the oggm-flowline could be extrapolated on the belonging 2D pixels. What I think is needed for this:
All these steps only need to be done once in a postprocessing step. In the end, we have for each 2D pixel the initial thickness, the glacier bed, the belonging grid point of the oggm-flowline, and the ranking inside the elevation band. The actual extrapolation could look like this:
I think the actual extrapolation could be quite fast in the end and could be done for any timestep without the need of computing preceding glacier states. Note: this method only works if the resulting glacier is smaller than the initial glacier. If we also want to be able to advance we need to think of connecting ice-free 2D pixels to the oggm-flowline in some way... |
I think I also understand what Anouk meant that one cannot preserve area and volume easily - do they mention this? |
No, they basically only mention the extrapolation in one sentence, with not much detail:
|
I think with the idea I had over the weekend it is possible to preserve area and volume per elevation band (first add/delete pixels to match the area, second add/remove delta volume evenly over remaining pixels without deleting any pixel) |
Thanks for all the ideas and feedback! I will now close this PR, as I just created a fresh one. |
This PR contains a notebook that shows an option for extrapolating the glacier covered area, simulated along the flowline again to a 2-D grid. In addition it re-distributes the ice thickness. The notebook is far from perfect. Some things to be addressed are the time it takes to run the notebook, which is extremely long, so suggestions regarding that are especially welcome. Also the resolution is still quite course, making it finer would be an option once the run time has decreased.
Generally speaking I'm looking for constructive feedback and discussing the different options. (This notebook isn't meant to be merged.)
This issue addresses #1448