def make_plot(args): """ Take the steps to make the plot. Parameters ---------- args: dict Command line arguments Returns ------- Nothing """ infile = './data/' + args['inputFile'] basename = 'PMmap-' + args['inputFile'].split('.')[0] default_proj = ccrs.PlateCarree() sky_proj = ccrs.Mollweide() backgr = plt.imread( '../star-trail-animation/sky-images/GaiaSky-colour-2k.png') nside = hp.order2nside(args['hplevel']) hpcol = 'healpix_{0}'.format(args['hplevel']) edr3data = Table.read(infile) alpha, delta = hp.pix2ang(nside, edr3data[hpcol], lonlat=True, nest=True) pmra = edr3data['avg_pmra'] pmdec = edr3data['avg_pmdec'] icrs = ICRS(ra=alpha * u.degree, dec=delta * u.degree, pm_ra_cosdec=pmra * u.mas / u.yr, pm_dec=pmdec * u.mas / u.yr) galactic = icrs.transform_to(Galactic) pmtot = np.sqrt(galactic.pm_l_cosb.value**2 + galactic.pm_b.value**2) fig = plt.figure(figsize=(16, 9), dpi=120, frameon=False, tight_layout={'pad': 0.01}) gs = GridSpec(1, 1, figure=fig) ax = fig.add_subplot(gs[0, 0], projection=sky_proj) ax.imshow(np.fliplr(backgr), transform=default_proj, zorder=-1, origin='upper') pmcmap = cm.viridis veccolor = plt.cm.get_cmap('tab10').colors[9] linecolor = plt.cm.get_cmap('tab10').colors[9] if args['quiver']: vscale = np.median(pmtot) / 10 ax.quiver(galactic.l.value, galactic.b.value, galactic.pm_l_cosb.value, galactic.pm_b.value, transform=default_proj, angles='xy', scale=vscale, scale_units='dots', color=veccolor, headwidth=1, headlength=3, headaxislength=2.5) else: if args['colourstreams']: ax.streamplot(galactic.l.value, galactic.b.value, galactic.pm_l_cosb.value, galactic.pm_b.value, transform=default_proj, linewidth=2.0, density=2, color=pmtot, cmap=pmcmap, maxlength=0.5, arrowsize=1, arrowstyle=ArrowStyle.Fancy(head_length=1.0, head_width=.4, tail_width=.4)) elif args['lwcode'] > 0: ax.streamplot(galactic.l.value, galactic.b.value, galactic.pm_l_cosb.value, galactic.pm_b.value, transform=default_proj, linewidth=args['lwcode'] * pmtot / np.median(pmtot), density=2, color=linecolor, maxlength=0.5, arrowsize=1, arrowstyle=ArrowStyle.Fancy(head_length=1.0, head_width=.4, tail_width=.4)) else: ax.streamplot(galactic.l.value, galactic.b.value, galactic.pm_l_cosb.value, galactic.pm_b.value, transform=default_proj, linewidth=1.5, density=2, color=linecolor, maxlength=0.5, arrowsize=1, arrowstyle=ArrowStyle.Fancy(head_length=1.0, head_width=.4, tail_width=.4)) ax.invert_xaxis() if args['pdfOutput']: plt.savefig(basename + '.pdf') elif args['pngOutput']: plt.savefig(basename + '.png') else: plt.show()
def plot_network(network, n_columns=1, n_regions=1, radius=None, ax=None, linewidth=2, cmap=None, clim=None): """This plot the columnar network""" from matplotlib.patches import ArrowStyle ax = plt.subplot() if ax is None else ax cmap = plt.get_cmap('bwr') if cmap is None else cmap clim = [-1, 1] if clim is None else clim # network is made of n_columns + entry node n_nodes = (len(network) // n_columns - 1) // n_regions init_pos = np.zeros((network.shape[0], 2)) x = np.linspace(-1, 1, n_regions) y = np.linspace(-1, 1, n_columns) if radius is None: radius = 1. / n_columns z = np.linspace(-np.pi / 2, 3 * np.pi / 2, n_nodes + 1)[:-1] z = np.transpose([np.cos(z), np.sin(z) + 1.]) for column, region, node in itertools.product(range(n_columns), range(n_regions), range(-1, n_nodes)): sel = select_nodes(n_columns, n_regions, n_nodes=n_nodes, column=column, region=region, node=node) if node == -1: first_node = np.diff(x[:2]) if len(x) > 1 else 1. init_pos[sel, 0] = -1 - first_node init_pos[sel, 1] = y[column] - 1 * radius else: init_pos[sel, 0] = x[region] + z[node, 0] * radius init_pos[sel, 1] = y[column] + z[node, 1] * radius arrow_style = ArrowStyle.Fancy(head_length=1., head_width=1.25, tail_width=.25) G, nodes, = plot_graph(network, iterations=0, edge_curve=True, directional=True, node_color='w', node_alpha=1., edge_color=cmap, negative_weights=True, init_pos=init_pos.T, ax=ax, final_pos=None, node_size=linewidth * 100, edge_width=linewidth, self_edge=1000, clim=clim, arrowstyle=arrow_style) nodes.set_linewidths(linewidth) ax.set_aspect('equal') ax.patch.set_visible(False) if n_columns > 1: ax.set_ylim([-.2, 1.2]) if n_regions > 1: ax.set_xlim([-.2, 1.2])
def make_plot(args): """ Take the steps to make the plot. Parameters ---------- args: array-like Command line arguments Returns ------- Nothing """ basename = 'PMmap-qso-galactic-aberration' gx = 5.04 gy = -0.10 gz = -0.29 if args['quiver']: hplevel = 3 else: hplevel = 5 nside = hp.order2nside(hplevel) npix = hp.nside2npix(nside) ahp = HEALPix(nside=nside, order='nested', frame=Galactic()) hpindices = np.arange(npix) skycoords = ahp.healpix_to_skycoord(hpindices) pm_l_cosb = -gx * np.sin(skycoords.l.to(u.rad)) + gy * np.cos( skycoords.l.to(u.rad)) pm_b = -gx * np.sin(skycoords.b.to(u.rad)) * np.cos(skycoords.l.to(u.rad)) \ - gy * np.sin(skycoords.b.to(u.rad)) * np.sin(skycoords.l.to(u.rad)) \ + gz * np.cos(skycoords.b.to(u.rad)) pmtot = np.sqrt(pm_l_cosb**2 + pm_b**2) backgr = plt.imread( '../star-trail-animation/sky-images/GaiaSky-colour-2k.png') default_proj = ccrs.PlateCarree() sky_proj = ccrs.Mollweide() fig = plt.figure(figsize=(16, 9), dpi=120, frameon=False, tight_layout={'pad': 0.01}) gs = GridSpec(1, 1, figure=fig) ax = fig.add_subplot(gs[0, 0], projection=sky_proj) ax.imshow(np.fliplr(backgr), transform=default_proj, zorder=-1, origin='upper') veccolor = plt.cm.get_cmap('tab10').colors[9] linecolor = plt.cm.get_cmap('tab10').colors[9] if args['quiver']: vscale = np.median(pmtot) / 50 ax.quiver(skycoords.l.value, skycoords.b.value, pm_l_cosb, pm_b, transform=default_proj, angles='xy', scale=vscale, scale_units='dots', color=veccolor, headwidth=4, headlength=4, headaxislength=3.5) else: if args['colourstreams']: ax.streamplot(skycoords.l.value, skycoords.b.value, pm_l_cosb, pm_b, transform=default_proj, linewidth=2.0, density=2, color=pmtot, cmap='viridis', maxlength=0.5, arrowsize=1, arrowstyle=ArrowStyle.Fancy(head_length=1.0, head_width=.4, tail_width=.4)) elif args['lwcode'] > 0: ax.streamplot(skycoords.l.value, skycoords.b.value, pm_l_cosb, pm_b, transform=default_proj, linewidth=args['lwcode'] * pmtot / np.median(pmtot), density=2, color=linecolor, maxlength=0.5, arrowsize=1, arrowstyle=ArrowStyle.Fancy(head_length=1.0, head_width=.4, tail_width=.4)) else: ax.streamplot(skycoords.l.value, skycoords.b.value, pm_l_cosb, pm_b, transform=default_proj, linewidth=1.5, density=2.5, color=linecolor, maxlength=0.5, arrowsize=1, arrowstyle=ArrowStyle.Fancy(head_length=1.0, head_width=.4, tail_width=.4)) # ax.gridlines() ax.invert_xaxis() if args['pdfOutput']: plt.savefig(basename + '.pdf') elif args['pngOutput']: plt.savefig(basename + '.png') else: plt.show()