ocean-transport / floater

For working with lagrangian float data
http://floater.readthedocs.io
15 stars 17 forks source link

allow FloatSet to accept a land mask #13

Closed rabernat closed 7 years ago

rabernat commented 8 years ago

We would like to do something like

fs = generators.FloatSet((140,150), (45,55), dx=0.25, dy=0.25)
fs.get_hexmesh(mask=some_mask)

This would blank out the regions where there is land and reduce memory usage, especially for global simulations.

nathanieltarshish commented 8 years ago

If I understand correctly, the spacing dx, dy of floats in the Floatset is in general different than the spacing of the tracer cell (or velocity cell) grid points used in the advection simulation.
This means that we cannot pass get_hexmesh just the simple mask (boolean array) taken without adjustment from the velocity field data or bathymetry file, for example.

Should we expect the user to "interpolate" their mask to a finer spatial resolution before passing it to get_hexmesh ? Or should we build this functionality into get_hexmesh and include optional arguments for information about the mask's grid geometry/structure ? To the tune of

fs.get_hexmesh(mask=some_mask, mask_lat = some_1D_array, mask_lon = some_1D_array)

nathanieltarshish commented 8 years ago

Here is a jupyter notebook walkthrough of a potential method to remove floater particles in masked regions. The method uses nearest neighbor searching on a k-d tree of the masked grid data.

rabernat commented 8 years ago

@nathanieltarshish: great to see you are digging into this. Apologies for not communicating earlier--I am visiting my family in Vermont and am mostly taking the week off.

Your KDtree approach seems pretty sophisticated. One comment on the code: I would rewrite the geo_to_xyz and xyz_to_geo functions using numpy so that they vectorize. That will speed things up a lot. (We generally avoid importing from math in scientific code, as numpy versions of math routines are all faster.)

I would try implementing this within the generators module. Do you know how to make a pull request on this repository? Once you open a PR, we can discuss the specifics of your implementation.

nathanieltarshish commented 8 years ago

@rabernat Thanks for taking a look and the feedback. Very good to know about speed differences between numpy and math. In general, I am interested in any optimization suggestions you have and learning better science coding practices. I will rewrite those functions and try to incorporate it into generators. Yes, I think I should be able to submit a PR on this repo.

Enjoy the break! I will be working on this throughout the week, but of course, no pressure to get back to me while you're away.

nathanieltarshish commented 8 years ago

@rabernat In PR #14, I vectorized the algorithm and incorporated it into the generators module as a new function: get_hexcoords. I created this function independent of get_hexmesh since I did not find the np.meshgrid structure to be very compatible with the masked float coordinate set. I tested the function out on a few sample masks here. Looks like it does an overall okay job, but errs on the side of including a few inland floats around the coasts.

rabernat commented 7 years ago

Closed by #14