Skip to content

Commit 3337bf2

Browse files
authored
Fixed dh issue by modifying get_bbox() (#175)
* Fixed dh issue by modifying get_bbox() * deleting extra comments
1 parent 962dd6a commit 3337bf2

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

csep/core/forecasts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ def plot(self, ax=None, show=False, log=True, extent=None, set_global=False, plo
437437
axes: matplotlib.Axes.axes
438438
"""
439439
# no mutable function arguments
440-
dh = round(self.region.dh, 5)
441440
if self.start_time is None or self.end_time is None:
442441
time = 'forecast period'
443442
else:
@@ -451,12 +450,12 @@ def plot(self, ax=None, show=False, log=True, extent=None, set_global=False, plo
451450

452451
# this call requires internet connection and basemap
453452
if log:
454-
plot_args.setdefault('clabel', f'log10 M{self.min_magnitude}+ rate per {str(dh)}° x {str(dh)}° per {time}')
453+
plot_args.setdefault('clabel', f'log10 M{self.min_magnitude}+ rate per cell per {time}')
455454
with numpy.errstate(divide='ignore'):
456455
ax = plot_spatial_dataset(numpy.log10(self.spatial_counts(cartesian=True)), self.region, ax=ax,
457456
show=show, extent=extent, set_global=set_global, plot_args=plot_args)
458457
else:
459-
plot_args.setdefault('clabel', f'M{self.min_magnitude}+ rate per {str(dh)}° x {str(dh)}° per {time}')
458+
plot_args.setdefault('clabel', f'M{self.min_magnitude}+ rate per cell per {time}')
460459
ax = plot_spatial_dataset(self.spatial_counts(cartesian=True), self.region, ax=ax,show=show, extent=extent,
461460
set_global=set_global, plot_args=plot_args)
462461
return ax

csep/core/regions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def get_cartesian(self, data):
602602

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

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

975974
@property
976975
def num_nodes(self):

csep/utils/plots.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ def plot_spatial_dataset(gridded, region, ax=None, show=False, extent=None, set_
862862
# Get spatial information for plotting
863863
bbox = region.get_bbox()
864864
if extent is None and not set_global:
865-
extent = [bbox[0], bbox[1], bbox[2] + region.dh, bbox[3] + region.dh]
865+
extent = [bbox[0], bbox[1], bbox[2], bbox[3]]
866866

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

932932
## Plot spatial dataset
933-
lons, lats = numpy.meshgrid(numpy.append(region.xs, region.xs[-1] + region.dh),
934-
numpy.append(region.ys, region.ys[-1] + region.dh))
935-
933+
lons, lats = numpy.meshgrid(numpy.append(region.xs, bbox[1]), numpy.append(region.ys, bbox[3]))
936934
im = ax.pcolor(lons, lats, gridded, cmap=cmap, alpha=alpha, snap=True, transform=ccrs.PlateCarree())
937935
im.set_clim(clim)
938936

0 commit comments

Comments
 (0)