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

Fixed dh issue by modifying get_bbox() #175

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions csep/core/forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ def plot(self, ax=None, show=False, log=True, extent=None, set_global=False, plo
axes: matplotlib.Axes.axes
"""
# no mutable function arguments
dh = round(self.region.dh, 5)
if self.start_time is None or self.end_time is None:
time = 'forecast period'
else:
Expand All @@ -451,12 +450,12 @@ def plot(self, ax=None, show=False, log=True, extent=None, set_global=False, plo

# this call requires internet connection and basemap
if log:
plot_args.setdefault('clabel', f'log10 M{self.min_magnitude}+ rate per {str(dh)}° x {str(dh)}° per {time}')
plot_args.setdefault('clabel', f'log10 M{self.min_magnitude}+ rate per cell per {time}')
with numpy.errstate(divide='ignore'):
ax = plot_spatial_dataset(numpy.log10(self.spatial_counts(cartesian=True)), self.region, ax=ax,
show=show, extent=extent, set_global=set_global, plot_args=plot_args)
else:
plot_args.setdefault('clabel', f'M{self.min_magnitude}+ rate per {str(dh)}° x {str(dh)}° per {time}')
plot_args.setdefault('clabel', f'M{self.min_magnitude}+ rate per cell per {time}')
ax = plot_spatial_dataset(self.spatial_counts(cartesian=True), self.region, ax=ax,show=show, extent=extent,
set_global=set_global, plot_args=plot_args)
return ax
Expand Down
3 changes: 1 addition & 2 deletions csep/core/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def get_cartesian(self, data):

def get_bbox(self):
""" Returns rectangular bounding box around region. """
return (self.xs.min(), self.xs.max(), self.ys.min(), self.ys.max())
return (self.xs.min(), self.xs.max()+self.dh, self.ys.min(), self.ys.max()+self.dh)

def midpoints(self):
""" Returns midpoints of rectangular polygons in region """
Expand Down Expand Up @@ -970,7 +970,6 @@ def __init__(self, polygons, quadkeys, bounds, name='QuadtreeGrid2d', mask=None)
# self.xs = xs
# self.ys = ys
# self.idx_map = a
self.dh = 0.5 #Temporary use, until 'dh' is removed from plot_spatial_datasets() of forecast.plot.

@property
def num_nodes(self):
Expand Down
6 changes: 2 additions & 4 deletions csep/utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def plot_spatial_dataset(gridded, region, ax=None, show=False, extent=None, set_
# Get spatial information for plotting
bbox = region.get_bbox()
if extent is None and not set_global:
extent = [bbox[0], bbox[1], bbox[2] + region.dh, bbox[3] + region.dh]
extent = [bbox[0], bbox[1], bbox[2], bbox[3]]

# Retrieve plot arguments
plot_args = plot_args or {}
Expand Down Expand Up @@ -930,9 +930,7 @@ def plot_spatial_dataset(gridded, region, ax=None, show=False, extent=None, set_
cmap = matplotlib.colors.ListedColormap(cmap_tup)

## Plot spatial dataset
lons, lats = numpy.meshgrid(numpy.append(region.xs, region.xs[-1] + region.dh),
numpy.append(region.ys, region.ys[-1] + region.dh))

lons, lats = numpy.meshgrid(numpy.append(region.xs, bbox[1]), numpy.append(region.ys, bbox[3]))
im = ax.pcolor(lons, lats, gridded, cmap=cmap, alpha=alpha, snap=True, transform=ccrs.PlateCarree())
im.set_clim(clim)

Expand Down