Skip to content

Commit 74b950d

Browse files
authored
Plot catalogs into a spatial map (#64)
* - catalogs.py * - Fixed docstring of several plot functions - Added the option for plot_basemap, plot_catalog and plot_spatial_dataset to include own webservice link for raster image as argument. * Modifications in plot_catalog - Added simple functionality to scale scatter size by magnitudes exponentially, with a exponent base defined by user. Should work in all of the geographic extents. - Added wrapper for a decent Legend of magnitude size. Has functionality for the ticks wanted, legend location and the spacing between ticks. - Function was tested on California catalog, Europe catalog and Global catalog is pending still.. * - Finished docstrings of plot_catalog() - Fixed size_map function for scaling size with magnitude. Now works fine - Removed plot_catalog from tutorials - Added extra example in tutorials/plot_customizations, to get and plot a catalog, and customize it.
1 parent 862dabb commit 74b950d

File tree

5 files changed

+327
-65
lines changed

5 files changed

+327
-65
lines changed

csep/core/catalogs.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from csep.utils.log import LoggingMixin
2323
from csep.utils.readers import csep_ascii
2424
from csep.utils.file import get_file_extension
25-
25+
from csep.utils.plots import plot_catalog
2626

2727
class AbstractBaseCatalog(LoggingMixin):
2828
"""
@@ -453,6 +453,19 @@ def get_longitudes(self):
453453
"""
454454
return self.catalog['longitude']
455455

456+
def get_bbox(self):
457+
"""
458+
Returns bounding box of all events in the catalog
459+
460+
Returns:
461+
(numpy.array): [lon_min, lon_max, lat_min, lat_max]
462+
"""
463+
bbox = numpy.array([numpy.min(self.catalog['longitude']),
464+
numpy.max(self.catalog['longitude']),
465+
numpy.min(self.catalog['latitude']),
466+
numpy.max(self.catalog['latitude'])])
467+
return bbox
468+
456469
def get_depths(self):
457470
""" Returns depths of all events in catalog """
458471
return self.catalog['depth']
@@ -818,6 +831,29 @@ def p():
818831
else:
819832
return bval
820833

834+
def plot(self, ax=None, show=False, extent=None, set_global=False, plot_args=None):
835+
""" Plot catalog according to plate-carree projection
836+
837+
Args:
838+
ax (`matplotlib.pyplot.axes`): Previous axes onto which catalog can be drawn
839+
show (bool): if true, show the figure. this call is blocking.
840+
extent (list): Force an extent [lon_min, lon_max, lat_min, lat_max]
841+
plot_args (optional/dict): dictionary containing plotting arguments for making figures
842+
843+
Returns:
844+
axes: matplotlib.Axes.axes
845+
"""
846+
# no mutable function arguments
847+
848+
849+
plot_args = plot_args or {}
850+
plot_args.setdefault('figsize', (10, 10))
851+
plot_args.setdefault('title', self.name)
852+
853+
# this call requires internet connection and basemap
854+
ax = plot_catalog(self, ax=ax,show=show, extent=extent,
855+
set_global=set_global, plot_args=plot_args)
856+
return ax
821857

822858
class CSEPCatalog(AbstractBaseCatalog):
823859
"""

csep/core/forecasts.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ def load_ascii(cls, ascii_fname, start_date=None, end_date=None, name=None):
407407
gds = cls(start_date, end_date, magnitudes=mws, name=name, region=region, data=rates)
408408
return gds
409409

410-
def plot(self, show=False, log=True, extent=None, set_global=False, plot_args=None):
411-
""" Plot gridded forecast according to plate-carree proejction
410+
def plot(self, ax=None, show=False, log=True, extent=None, set_global=False, plot_args=None):
411+
""" Plot gridded forecast according to plate-carree projection
412412
413413
Args:
414414
show (bool): if true, show the figure. this call is blocking.
@@ -434,11 +434,11 @@ def plot(self, show=False, log=True, extent=None, set_global=False, plot_args=No
434434
if log:
435435
plot_args.setdefault('clabel', f'log10 M{self.min_magnitude}+ rate per {str(dh)}° x {str(dh)}° per {time}')
436436
with numpy.errstate(divide='ignore'):
437-
ax = plot_spatial_dataset(numpy.log10(self.spatial_counts(cartesian=True)), self.region, show=show,
438-
extent=extent, set_global=set_global, plot_args=plot_args)
437+
ax = plot_spatial_dataset(numpy.log10(self.spatial_counts(cartesian=True)), self.region, ax=ax,
438+
show=show, extent=extent, set_global=set_global, plot_args=plot_args)
439439
else:
440440
plot_args.setdefault('clabel', f'M{self.min_magnitude}+ rate per {str(dh)}° x {str(dh)}° per {time}')
441-
ax = plot_spatial_dataset(self.spatial_counts(cartesian=True), self.region, show=show, extent=extent,
441+
ax = plot_spatial_dataset(self.spatial_counts(cartesian=True), self.region, ax=ax,show=show, extent=extent,
442442
set_global=set_global, plot_args=plot_args)
443443
return ax
444444

0 commit comments

Comments
 (0)