-
Notifications
You must be signed in to change notification settings - Fork 365
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
Add ability to specify custom bounds to Projections #1888
base: main
Are you sure you want to change the base?
Conversation
Assuming people are comfortable with this, let me know if/where I should add documentation in the sphinx docs. |
If the pin for |
Obviously up to cartopy devs, but maybe in a future PR? |
There may be other places in the code that would likely benefit from that as well, so a separate PR would be a better fit for that. |
Currently this only helps with updating rectangular extents? Maybe this would be addressed by the Thoughts on if we should add |
I'm fine with adding this. Without knowing all of the edge cases, do you have an example of what you mean beyond that linked PR? I'm used to requesting bounds in X/Y projection coordinates. The issue(s) so are talking about only exist if someone provides lon/lat bounds, right? For example, non-eqc/geographic projections would have different transformed bounds depending on if you transformed (lon_min, lat_min) or (lon_min, lat_max). That's the concern, right?
Obviously not a cartopy maintainer so feel free to ignore me, but I personally would try to avoid |
Taking a step back here as I'm a little confused now. Do you truly want bounds on the Projection, or are you actually looking for bounds/extents on each of your swaths/images? I took a quick look at the pyresample docs and found this in a few places under the Cartopy section My concern in this case is that putting the bounds on Projection objects could lead to issues when adding multiple of these images to the same map because then the bounds of the map/axes would only be defined by one of the image projections. An alternative idea would be to subclass a feature or image source, such as LocatedImage or RasterSource, and then within Cartopy if someone calls Just a thought I had, I may be way off base and missing something pretty fundamental too... |
You aren't wrong and it has been a while since I originally wanted this type of interaction between pyresample and cartopy, so it is very possible I'm forgetting some of the use cases. Looking at an old SciPy tutorial I made for Satpy (which uses pyresample underneath), I have code snippets like this:
Full notebook: https://github.com/pytroll/tutorial-satpy-half-day/blob/main/notebooks/07_cartopy_geoviews.ipynb So I think the idea was that the user doesn't have to know extents. At least in use cases like this the extents on the map and the image data are the same thing; we're just viewing the image. Now of course looking at this with fresh eyes and more experience I could see someone wanting to say "I want to display this image but with a margin of 10km on each side" in which case the person would need to access the bounds of the
I'm not sure I understand what would be wrong with this. Plus it is fairly typical for our users to have all their data resampled to the same "area" already so the plotted data and the map projection are all the same (makes it so cartopy shouldn't have to resample or transform anything). The main thing here that I think I need to figure out is what is the cartopy analog for a pyresample AreaDefinition. An AreaDefinition is CRS + bounds/extents + shape. So maybe the new and preferred way of plotting pyresample results should be something like:
@mraspaud Do you have any opinion on this? I suppose the more generic use case for this feature is that some Projections won't have bounds so this keyword argument let's you, the knowledgeable user, define them. |
I would just like to mention the area_of_use.bounds attribute in pyproj CRSs that is used for epsg codes that have bounds. Could that be helpful? |
|
Rationale
See #813 for more info. The summary is that I (and others) want to be able to take an arbitrary pyproj CRS object with our own bounds and provide it to cartopy. Currently a
Projection
instance will try to use the static "area_of_use" provided by the PROJ/pyproj definition of a CRS. This is fine, but there are many cases where datasets only cover a specific region of a CRS. By allowing users to specify thebounds
for aProjection
you can reuse the same Projection instance in multiple locations without worrying about extents on the plot. This closely follows with the way that Pyresample users resample data and then plot various pieces of data sharing the same geolocation information.This also adds an optional
transform_bounds
keyword argument toProjection
as a convenience when the user wants to provide bounds in lon/lat degrees and have them transformed to CRS coordinates.Implications
The
bounds
andtransform_bounds
keyword arguments are optional so should not effect existing users at all. I would say "advanced" users seeking this feature will benefit.There may be cases for certain CRSes where the basic logic provided in Projection isn't good enough (I assume that's why some of the Projection subclasses exist, for example the _RectangularProjection and _CylindricalProjection classes). Having this new flexibility in the
Projection
class may make users think any projection can be provided to theProjection
class and maybe that isn't true. I honestly don't know all of the edge cases in cartopy.Partial Example
CC @snowman2