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

How to link segmentations based on lon and lat coordinates? #98

Open
zxdawn opened this issue Mar 25, 2022 · 7 comments
Open

How to link segmentations based on lon and lat coordinates? #98

zxdawn opened this issue Mar 25, 2022 · 7 comments
Labels
enhancement Addition of new features, or improved functionality of existing features question Queries about using tobac or how the code works
Milestone

Comments

@zxdawn
Copy link
Collaborator

zxdawn commented Mar 25, 2022

I see @JuliaKukulies has added the lon/lat support (#65), is it possible to link the 2D segmentations with different shapes? Let's assume we have two segmentations: seg1 (y:200, x: 100) and seg2 (y: 190, x: 120). Both of them have 2D lon and lat coordinates. If we can utilize the lon/lat coordinates with segmentation info together. that would be awesome!

@zxdawn zxdawn added the question Queries about using tobac or how the code works label Mar 25, 2022
@freemansw1 freemansw1 added the enhancement Addition of new features, or improved functionality of existing features label Mar 25, 2022
@freemansw1 freemansw1 self-assigned this Mar 25, 2022
@freemansw1 freemansw1 added this to the Version 1.5 milestone Mar 25, 2022
@freemansw1
Copy link
Member

We have some code here that we've been working on to do basically that. It's close but not yet ready for a PR. Hopefully, we can get this in for v1.4 or v1.5.

@w-k-jones
Copy link
Member

Transferring detected features and segmentations across different grids is definitely a feature on the radar for tobac v2.0. This sounds like a subset of that situation, where it's only applied to two lat/lon grids (rather than grids on different coordinates). A couple of questions to see how complex this is:

  • Do the lat/lon grids share the same points and grid spacing as each other. I.e. are the offset from each other but overlapping?
  • Do they occupy the same spatial extent, but the grid spacing is different?

There are two approaches to this I've considered. The first, more direct approach is simply to regrid from one grid to the other. This is pretty straightforward, but more computationally intensive and slightly less satisfactory, particularly if you want to preserve resolution. The second approach is to turn each segmentation mask into a set of geometric objects that contain each of the segmented features, which could then be mapped to any other grid without having the regrid the data on the second grid itself

@zxdawn
Copy link
Collaborator Author

zxdawn commented Mar 26, 2022

@w-k-jones Thanks for the idea. For polar-orbiting satellite data, the lon/lat, spacing, and spatial extent are all different. Here's an example. I guess I can use geopandas to convert segmentations into geometric objects, but how to map it to another grid?

image
image

@w-k-jones
Copy link
Member

w-k-jones commented Mar 26, 2022

Here's a quick mock-up of what I'm thinking:

remap_mask_example

The idea is that it's much easier to map a geopandas/shapely boundary formed from a set of points from one coordinate system to a different coordinate system than it is an entire grid (this isn't even necessary if they're both in lat/lon coords). Then you just need to check which pixels on the new grid are within the boundary of segmentation on the old grid, giving you the mask in the new grid.

This is fairly straightforward for 2d, but I'm not sure if there are any libraries which could do the same for 3d data

@freemansw1
Copy link
Member

Ah- I see what the two of you are thinking. I misunderstood the original question. We don't have code that does that yet here. What we have is code that allows one to take feature detection output from one grid (with lat/lons) and use that to seed watershedding on a different grid (with lats/lons).

I think what the two of you are discussing is very interesting and I agree with @w-k-jones that it would be great to get something like that into v2.x.

@freemansw1 freemansw1 removed their assignment Mar 26, 2022
@zxdawn
Copy link
Collaborator Author

zxdawn commented Mar 26, 2022

@w-k-jones Thanks for the detailed explanation. I make a simple draft to accomplish your idea by pyresample:

The orange grid contains the mask and I get the mask in another grid (blue one) by resampling the blue grid to the mask points (lon/lat) of the orange grid.
image

Core code:

from pyresample import kd_tree
from pyresample.geometry import SwathDefinition

# orange grid
swath_to_map = SwathDefinition(lons=lon_to_map, lats=lat_to_map)
# blue grid
swath = SwathDefinition(lons=swath_lon, lats=swath_lat)

result = kd_tree.resample_nearest(swath_to_map,
                                  np.full((len(lon_to_map)), 1), # assign mask to 1
                                  swath,
                                  radius_of_influence=5000,
                                  epsilon=0.5)

@freemansw1 freemansw1 modified the milestones: Version 1.5, Version 2.0 Mar 26, 2022
@zxdawn
Copy link
Collaborator Author

zxdawn commented Mar 26, 2022

Note that pyresample can deal with both swath and grid data. It means that the model data, GEO, and polar-orbiting satellite observations can be all supported! The radius_of_influence can be the input from users or the auto-calculated space which has been added by @JuliaKukulies.

I suppose this solution can't deal with 3d data ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Addition of new features, or improved functionality of existing features question Queries about using tobac or how the code works
Projects
None yet
Development

No branches or pull requests

3 participants