-
Notifications
You must be signed in to change notification settings - Fork 24
missing region border in plots #110
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
Conversation
- added kwargs to plot_basemap to apply 'fast' projection and central latitude - added 'fast' as an option to the plot_args of plot_spatial_dataset and plot_catalog - updated docstrings
Codecov Report
@@ Coverage Diff @@
## master #110 +/- ##
=======================================
Coverage 53.25% 53.25%
=======================================
Files 19 19
Lines 3091 3091
Branches 445 445
=======================================
Hits 1646 1646
Misses 1352 1352
Partials 93 93 Continue to review full report at Codecov.
|
|
||
Returns: | ||
:class:`matplotlib.pyplot.ax` object | ||
|
||
""" | ||
if ax is None: | ||
fig = pyplot.figure() | ||
ax = fig.add_subplot(111, projection=ccrs.PlateCarree(central_longitude=0.0)) | ||
ax = fig.add_subplot(111, projection=projection) | ||
if apprx: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add & projection == ccrs.PlateCarree()
? (not needed if you are sure that plot_basemap()
will never be called by a user)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default arg is projection=ccrs.PlateCarree. I believe its good as Bill left it, to accept different projections. Also the default platecarree looks good, for quick plotting without worrying about projections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think plot_basemap
will probably be called by other users especially if they are trying to plot catalogs on top of forecasts or other data sets. is there a downside to letting users choose projections in the plot_basemap
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is: the 'fast'/apprx "projection" works by rescaling the axes. This rescaling is incompatible with any other "true" (non-PlateCaree) projection, which should be caught by adding & projection == ccrs.PlateCarree()
to the if statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats a good point. in the other functions i handled that case by forcing projection=ccrs.PlateCarree()
. for example, in plot_catalog()
. not sure why i didn't do that in basemap. also, if the user chooses the fast option, we should force PlateCarree().
now that im thinking about it, there are some other parameters that might lose continuity between these cartopy enhanced calls, eg, extent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In func plot_basemap
, line
Line 587 in a604a98
if set_global: |
else
is missing:
else:
ax.set_extent(extents=extent, crs=ccrs.PlateCarree())
so plot_basemap
can define the extent, and do not waste downloading time of unneeded basemaps
|
||
Returns: | ||
:class:`matplotlib.pyplot.ax` object | ||
|
||
""" | ||
if ax is None: | ||
fig = pyplot.figure() | ||
ax = fig.add_subplot(111, projection=ccrs.PlateCarree(central_longitude=0.0)) | ||
ax = fig.add_subplot(111, projection=projection) | ||
if apprx: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default arg is projection=ccrs.PlateCarree. I believe its good as Bill left it, to accept different projections. Also the default platecarree looks good, for quick plotting without worrying about projections.
2780d2c
to
a604a98
Compare
I did a failed commit, reversed it, and the test with jma_catalog_reader is not working anymore (don't understand why really). Sorry the mess. |
no worries @pabloitu. i think it is something to do with obspy and nothing that you did. it seems to be failing on an imported docstring. see below.
|
if set_global: | ||
ax.set_global() | ||
else: | ||
ax.set_extent(extents=extent, crs=ccrs.PlateCarree()) # Defined extent always in lat/lon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the crs
here be projection
and not ccrs.PlateCarree()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs: "Set the extent (x0, x1, y0, y1) of the map in the given coordinate system. [scitools.org.uk/cartopy/docs/...]. By default (crs=None
), it would take over the projection of the axis (i.e. projection
), but since the extent will be - in our case - (always?) specified in the same coordinate system as the original data (i.e. PlateCaree()), it is good as is.
See also stackoverflow.com.
csep/utils/plots.py
Outdated
if apprx: | ||
# Re-aspect plot (only for plain matplotlib plots, or when using PlateCarree) | ||
LATKM = 110.574 | ||
ax.set_aspect(1 / (LATKM / 111.320 * numpy.cos(numpy.deg2rad(central_latitude)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that it can be simplified:
ax.set_aspect(111.320 * numpy.cos(numpy.deg2rad(central_latitude)) / LATKM)
Btw: here a reference for why/how this works: stackoverflow.com/a/1253545. I use it essentially for every geographic operation because it allows to go from lat-lon to relative distances in km in a very concise way.
So all in all, you may revise this section to:
# Set plot aspect according to local longitude-to-latitude length ratio
# (only compatible with plain PlateCarree "projection")
LATKM = 110.574 # length of a ° of latitude [km] [https://stackoverflow.com/a/1253545]
ax.set_aspect(111.320 * numpy.cos(numpy.deg2rad(central_latitude)) / LATKM)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn. The simplification is wrong; it should be:
ax.set_aspect(111.320 / LATKM / numpy.cos(numpy.deg2rad(central_latitude)))
added missing else statement to handle set_global flag in plot_basemap
heres an example for these different options. import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from csep.utils.plots import plot_basemap Plot using
|
im merging this pr |
Uh oh!
There was an error while loading. Please reload this page.