def plot_ms_set_map(ax, img, ms_set, projection, mode='com', color_style='date', colorbar_setting=None, map_cmap='jet', **kwargs): """Display all features of ms_set on a map. Parameters ---------- ax : :class:`matplotlib.axes.Axes` img : Image An image to be used as background map. ms_set : :class:`wise.wds.MultiScaleImageSet` An object containing all the features to be displayed. projection : :class:`libwise.imgutils.Projection` mode : str, optional Coord mode for the location of the features: 'lm', 'com' or 'cos'. color_style : str, optional 'scale': display one color per scale. 'date': color correspond to the epoch. colorbar_setting : :class:`libwise.ColorbarSetting, optional Settings for the color bar if color_style is 'date'. map_cmap : :class:`matplotlib.cm.ColorMap` or str, optional **kwargs : Additional arguments to be passed to :func:`libwise.plotutils.imshow_image`. .. _tags: plt_detection """ if colorbar_setting is None and color_style == 'date': colorbar_setting = plotutils.ColorbarSetting(ticks_locator=mdates.AutoDateLocator(), ticks_formatter=mdates.DateFormatter('%m/%y')) epochs = ms_set.get_epochs() intensities = [k.get_intensity() for k in ms_set.features_iter()] int_norm = plotutils.Normalize(min(intensities), max(intensities)) marker_select = plotutils.MarkerSelector() epochs_map = plotutils.build_epochs_mappable(epochs, colorbar_setting.get_cmap()) if img is not None: plotutils.imshow_image(ax, img, projection=projection, title=False, cmap=plotutils.get_cmap(map_cmap), **kwargs) color_fct = None if color_style == 'date': color_fct = lambda f: epochs_map.to_rgba(f.get_epoch()) colorbar_setting.add_colorbar(epochs_map, ax) elif color_style is 'scale': pass for ms_segments in ms_set: for segments in ms_segments: # if segments.get_scale() != 2: # continue s = 10 * segments.get_scale() marker = marker_select.get(segments.get_scale()) # s = 500 * int_norm(segments.get_intensities()) # s = 200 plot_features(ax, segments, mode=mode, color_fct=color_fct, s=s, alpha=0.7, marker=marker)
def plot_links_map(ax, img, projection, links, color_style='link', mode='com', colorbar_setting=None, map_cmap='jet', vector_width=4, link_id_label=False, num_bbox=None, ang_vel_arrows=False, ang_vel_unit=u.mas / u.year, pix_per_ang_vel_unit=1, **kwargs): """Display features links on a map. Parameters ---------- ax : :class:`matplotlib.axes.Axes` img : Image An image to be used as background map. projection : :class:`libwise.imgutils.Projection` links : a list of :class:`wise.matcher.FeaturesLink` color_style : str, optional 'link': one color per link. 'date': map the features epochs to a color. any color string: use one color for each displacements vectors. function: a function that take a feature as argument and return a color. mode : str, optional Coord mode for the location of the features: 'lm', 'com' or 'cos'. colorbar_setting : ColorBar, optional Settings for the color bar if color_style is 'date'. map_cmap : :class:`matplotlib.cm.ColorMap` or str, optional vector_width : int, optional Width of the displacements vector arrows. Default is 4. link_id_label : bool, optional Annotate the links with there ids. num_bbox : dict, optional **kwargs: Additional arguments to be passed to :func:`libwise.plotutils.imshow_image`. .. _tags: plt_matching """ color_fct = None if color_style == 'date': all_epochs = matcher.get_all_epochs(links) epochs_map = plotutils.build_epochs_mappable(all_epochs, colorbar_setting.get_cmap()) if colorbar_setting is None: colorbar_setting = plotutils.ColorbarSetting(ticks_locator=mdates.AutoDateLocator(), ticks_formatter=mdates.DateFormatter('%m/%y')) colorbar_setting.add_colorbar(epochs_map, ax) color_fct = lambda f: epochs_map.to_rgba(f.get_epoch()) elif color_style is not 'link' and isinstance(color_style, str): color_fct = lambda f: color_style elif nputils.is_callable(color_style): color_fct = color_style plotutils.imshow_image(ax, img, projection=projection, title=False, cmap=plotutils.get_cmap(map_cmap), **kwargs) for link in links: delta_info = link.get_delta_info(measured_delta=False) if ang_vel_arrows: plot_velocity_vector(ax, delta_info, projection, ang_vel_unit, pix_per_ang_vel_unit, color_fct=color_fct, mode=mode, lw=0.5, fc=link.get_color(), ec='k', alpha=0.9, zorder=link.size(), width=vector_width) else: plot_displacement_vector(ax, delta_info, color_fct=color_fct, mode=mode, lw=0.5, fc=link.get_color(), ec='k', alpha=0.9, zorder=link.size(), width=vector_width) # y, x = link.get_features()[int(np.random.normal(s / 2, s / 4))].get_coord() if link_id_label: y, x = link.last().get_coord() if num_bbox is None: props = dict(boxstyle='round', facecolor='wheat', alpha=0.7, edgecolor=link.get_color(), lw=1.5) ax.text(x, y, link.get_id(), bbox=num_bbox, zorder=200, size='small')