Skymap¶
This module allows to easily plot arrival directions of events or healpy maps.
Module to visualize arrival directions or heatmaps on the sphere.
-
class
skymap.
PlotSkyPatch
(lon_roi, lat_roi, r_roi, ax=None, title=None, **kwargs)[source]¶ Bases:
object
Class to plot a close-up look of a region of interest (ROI) in the sky. To use this class you need to install the Basemap package: https://matplotlib.org/basemap/users/installing.html
from astrotools.skymap import PlotSkyPatch patch = PlotSkyPatch(lon0, lat0, r_roi, title='My Skypatch') mappable = patch.plot_crs("/path/to/cosmic_rays.CosmicRaysSets.npz", set_idx=0) patch.mark_roi() patch.plot_grid() patch.colorbar(mappable) patch.savefig("/tmp/test-skypatch.png")
-
colorbar
(mappable, cblabel='Energy [eV]', labelsize=12, ticks=None, **kwargs)[source]¶ Adds a colorbar to a mappable in matplotlib. Replaces matplotlib colorbar() function. Use e.g:
patch = PlotSkyPatch(…) mappable = patch.plot_crs(crs) patch.colorbar(mappable)
- Parameters
mappable – Mappable in matplotlib.
clabel – Label for the colorbar
ticks – Ticks for the colorbar (either array-like or integer for number of ticks)
kwargs – Keywords passed to matplotlib colorbar() function
-
mark_roi
(alpha=0.4, **kwargs)[source]¶ Marks the ROI by a circle ans shades cosmic rays outside the ROI.
- Parameters
kwargs – Passed to Basemaps tissot() function
-
mark_roi_center
(**kwargs)[source]¶ Mark the ROI center
- Parameters
kwargs – keywords for matplotlib.pyplot.plot() function
-
plot_crs
(crs, set_idx=0, zorder=0, cmap='viridis', **kwargs)[source]¶ Plot cosmic ray events in the sky.
- Parameters
crs – Either cosmic_rays.CosmicRaysBase or cosmic_rays.CosmicRaysSets object (or path) or dict object
set_idx – In case of CosmicRaysSets object, chose the respective set index
zorder – Usual matplotlib zorder keyword (order of plotting)
cmap – Matplotlib colormap object or string
-
plot_grid
(meridians=None, parallels=None, mer_labels=None, par_labels=None)[source]¶ Plot the longitude and latitude grid in the skypatch
-
-
skymap.
heatmap
(m, opath=None, label='entries', mask=None, maskcolor='white', tophat_smoothing=None, gaussian_smoothing=None, no_cb=False, **kwargs)[source]¶ Heatmap plot of binned data m. For exmaple usage see: cosmic_rays.plot_healpy_map()
- Parameters
m – Array with size npix for an arbitrary healpy nside.
opath – if not None, saves the figure to the given opath (no returns)
label – label for the colormap
mask – either boolean mask that paints certain pixels different or condition for m
maskcolor – which color to paint the mask
tophat_smoothing – if number: smooth map with tophat filter of that size in degree
tophat_smoothing – if number: smooth map with Gaussian filter of that size in degree
kwargs – additional named keyword arguments (non-listed keywords are passed to matplotlib.pcolormesh)
no_cb –
disables color bar
figsize: figure size as input for plt.figure()
cmap: colormap
vmin: Lower cut of the colorbar scale
vmax: Upper cut of the colorbar scale
cbticks: Ticks of the colorbar
mask_alpha: alpha value for maskcolor
fontsize: scale the general fontsize
xresolution: Scales the resolution of the plot (default: 800)
dark_grid: if True paints a dark grid (useful for bright maps)
gridcolor: Color of the grid.
gridalpha: Transparency value of the gridcolor.
tickcolor: Color of the ticks.
tickalpha: Transparency of the longitude ticks.
plane: plots ‘SGP’ or ‘GP’ or both (list) into plot
planecolor: color of plane
coord_system: default galactic (‘gal’) / equatorial (‘eq’)
- Returns
figure of the heatmap, colorbar
-
skymap.
plot_grid
(lon_ticks=None, lat_ticks=None, lon_grid=30, lat_grid=30, fontsize=26, **kwargs)[source]¶ Plot a grid on the skymap.
- Parameters
lon_ticks – Set the label ticks for the longitudes (default: [90, 0, -90]).
lat_ticks – Set the label ticks for the latitude (default: [-60, -30, 0, 30, 60]).
lon_grid – Distances between the grid lines in longitude in degrees (default: 30 deg).
lat_grid – Distances between the grid lines in latitude in degrees (default: 30 deg).
kwargs –
additional named keyword arguments
gridcolor: Color of the grid.
gridalpha: Transparency value of the gridcolor.
tickcolor: Color of the ticks.
tickalpha: Transparency of the longitude ticks.
-
skymap.
plot_plane
(planecolor=0.5, coord_system='gal', plane='SGP', zorder=- 10, **kwargs)[source]¶ Plot a the supergalactic plane onto skymap.
- Parameters
planecolor – color of plane
coord_system – default galactic (‘gal’) / equatorial (‘eq’)
plane – plots ‘SGP’ or ‘GAL’ or both (list) into plot
kwargs – additional named keyword arguments passed to plt.plot()
zorder – which layer to plot the plane (-10 for behind, +10 for before everything else)
-
skymap.
plot_tissot
(vec_c, r, res=0.01, **kwargs)[source]¶ Plot a circle onto skymap.
- Parameters
vec_c – vector pointing to the center of the circle
r – radius of the circle
res – resolution of the circle approximation (in radian)
kwargs – additional named keyword arguments passed to plt.plot()
-
skymap.
scatter
(v, c=None, cblabel='log$_{10}$(Energy / eV)', opath=None, fig=None, **kwargs)[source]¶ Scatter plot of events with arrival directions x,y,z and colorcoded energies.
- Parameters
v – array of shape (3, n) pointing into directions of the events
c – quantity that is supposed to occur in colorbar, e.g. energy of the cosmic rays
cblabel – colorbar label
opath – if not None, saves the figure to the given opath (no returns)
fig – figure to plot in, creates new figure if None
kwargs –
additional named keyword arguments
figsize: figure size as input for plt.figure()
cmap: colormap
cbar: if True includes a colobar
cticks: sets ticks of colormap
mask_alpha: alpha value for maskcolor
fontsize: scale the general fontsize
dark_grid: if True paints a dark grid (useful for bright maps)
gridcolor: Color of the grid.
gridalpha: Transparency value of the gridcolor.
tickcolor: Color of the ticks.
tickalpha: Transparency of the longitude ticks.
plane: plots ‘SGP’ or ‘GP’ or both (list) into plot
planecolor: color of plane
coord_system: default galactic (‘gal’) / equatorial (‘eq’)
- Returns
figure, axis of the scatter plot
-
skymap.
smart_round
(v, order=2, upper_border=True)[source]¶ Rounds a value v such that it can be used e.g. for colorbars
- Parameters
- Returns
rounded value
- Return type
This function has been tested on the following numbers (with all upper_border presented here):
:linenos: >> from astrotools.skymap import smart_round >> smart_round(100000), smart_round(100000, upper_border=False) 100000.0, 100000.0 >> smart_round(100001), smart_round(100001, upper_border=False) 101000.0, 100000.0 >> smart_round(-100001), smart_round(-100001, upper_border=False) -100000.0, -100000.0 >> smart_round(2.23), smart_round(2.23, upper_border=False) 2.23, 2.23 >> smart_round(2.230), smart_round(2.230, upper_border=False) 2.23, 2.23 >> smart_round(2.231), smart_round(2.231, upper_border=False) 2.24, 2.23 >> smart_round(-2.230), smart_round(-2.230, upper_border=False) -2.23, -2.23 >> smart_round(-2.231), smart_round(-2.231, upper_border=False) -2.23, -2.24 >> smart_round(0.930001), smart_round(0.930001, upper_border=False) 0.94, 0.93 >> smart_round(-0.930001), smart_round(-0.930001, upper_border=False) -0.93, -0.94