Commit 83a9b1e0 authored by Marcus Wirtz's avatar Marcus Wirtz
Browse files

[simulations] Warning for not supported source distances, improved plotting

parent c09fba8c
......@@ -487,6 +487,9 @@ class SourceBound:
"""
data = np.load(library_path, allow_pickle=True)
dis_bins, log10e_bins = data['distances'], data['log10e_bins']
if np.median(np.min(self.universe.distances, axis=1)) < np.min(dis_bins):
print("Warning: Distance binning of simulation starts too far outside (%s Mpc)! " % np.min(dis_bins))
print("Required would be: %.2fMpc." % np.median(np.min(self.universe.distances, axis=1)))
mask_out = dis_bins >= self.universe.rmax
# Assign distance indices for all simulated soures, shape: (self.nsets, self.universe.n_src)
dis_bin_idx = self.universe.distance_indices(dis_bins)
......@@ -640,8 +643,11 @@ class SourceBound:
cmap = plt.get_cmap('jet', len(src_idx))
cmap.set_over('k')
cmap.set_under('gray')
skymap.eventmap(self.crs['vecs'][:, idx], c=labels_p, cmap=cmap, cblabel='Source ID',
cticks=np.arange(-1, len(src_idx), 1), vmin=-0.5, vmax=len(src_idx)-0.5)
if len(src_idx) > 0:
skymap.eventmap(self.crs['vecs'][:, idx], c=labels_p, cmap=cmap, cblabel='Source ID',
cticks=np.arange(-1, len(src_idx), 1), vmin=-0.5, vmax=len(src_idx)-0.5)
else:
skymap.eventmap(self.crs['vecs'][:, idx], c='gray')
lon_src, lat_src = coord.vec2ang(self.universe.sources[:, idx])
plt.scatter(-lon_src, lat_src, c='k', marker='*', s=2*ns)
ns = np.sort(ns)[::-1]
......
......@@ -41,7 +41,7 @@ def scatter(v, c=None, cblabel='log$_{10}$(Energy / eV)', opath=None, **kwargs):
kwargs.setdefault('s', 8)
if 'marker' not in kwargs:
kwargs.setdefault('lw', 0)
if c is not None:
if kwargs.get('cmap') is not None:
finite = np.isfinite(c)
vmin = kwargs.pop('vmin', smart_round(np.min(c[finite]), upper_border=False))
vmax = kwargs.pop('vmax', smart_round(np.max(c[finite]), upper_border=True))
......@@ -69,7 +69,7 @@ def scatter(v, c=None, cblabel='log$_{10}$(Energy / eV)', opath=None, **kwargs):
ax = fig.add_axes([0.1, 0.1, 0.85, 0.9], projection="hammer")
events = ax.scatter(lons, lats, c=c, **kwargs)
if c is not None:
if kwargs.get('cmap') is not None:
cbar = plt.colorbar(events, orientation='horizontal', shrink=0.85, pad=0.05,
aspect=30, cmap=kwargs.get('cmap'), ticks=cticks)
cbar.set_label(cblabel, fontsize=fontsize)
......
......@@ -289,7 +289,7 @@ class TestObservedBound(unittest.TestCase):
class TestSourceBound(unittest.TestCase):
def setUp(self):
self.nsets = 100
self.nsets = 120
self.ncrs = 1000
self.shape = (self.nsets, self.ncrs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment