def plot_displacements(ax, features1, features2, delta_info, num=False, projection=None, mode='com', bg=None, beam=True, cmap=None, **kwargs): """Display displacements of features on a map. If bg is not set and features1 and features2 are both SegmentedImage, a two color map, one color for the segments of each SegmentedImage, will be used as bg. Parameters ---------- ax : :class:`matplotlib.axes.Axes` features1 : :class:`wise.features.FeaturesGroup` The features of the first epoch. features2 : :class:`wise.features.FeaturesGroup` The features of the second epoch. delta_info : :class:`wise.features.DeltaInformation` An object containing the displacements information. num : bool, optional Whatever to optionally annotate the segments with there ids. projection : :class:`libwise.imgutils.Projection`, optional mode : str, optional Coord mode for the location of the features: 'lm', 'com' or 'cos'. bg : :class:`libwise.imgutils.Image`, optional The image to be used as background map. beam : bool, optional Whatever to optionally display the beam of the image. Default is True. cmap : :class:`matplotlib.cm.ColorMap` or str, optional A color map for the background map. **kwargs: Additional arguments to be passed to :func:`plot_displacement_vector` .. _tags: plt_matching """ alpha = 0.8 if isinstance(features1, wds.SegmentedImages): projection = plotutils.get_projection(features1.get_img(), projection) if bg is None: data = ((features1.get_labels() > 1) * 2 + (features2.get_labels() > 1) * 4).astype(np.int8) bg = imgutils.Image.from_image(features1.get_img(), data) alpha = 0.5 else: assert bg is not None assert projection is not None contour = False cmap = plotutils.get_cmap(cmap) plotutils.imshow_image(ax, bg, projection=projection, beam=beam, title=False, alpha=0.8, cmap=cmap) if num: plot_segmentid(ax, features1) plot_features(ax, features1, mode=mode, c=plotutils.blue, alpha=0.8) plot_features(ax, features2, mode=mode, c=plotutils.orange, alpha=0.8) plot_displacement_vector(ax, delta_info, mode=mode, fc='k', ec='k', **kwargs) plot_segments_contour(ax, features1, colors=plotutils.dblue) plot_segments_contour(ax, features2, colors=plotutils.red)
def preview_detection_stack(ctx, stack_detection_name, count_threshold=0, ms_set=None, date_filter=None, show_regions=[]): ''' Plot detection in stack''' stack = plotutils.FigureStack() stack_img, img_snr, img_count = load_detection_stack_image(ctx, stack_detection_name, preprocess=True) img_snr.data[img_count.data < count_threshold] = 0 img_count.data[img_count.data < count_threshold] = 0 prj = ctx.get_projection(stack_img) fig, ax = stack.add_subplots("Stack image") plotutils.imshow_image(ax, stack_img, projection=prj) for region in show_regions: plotutils.plot_region(ax, region, prj, text=True) fig, ax1 = stack.add_subplots("Stack detection SNR") plotutils.imshow_image(ax1, img_snr, projection=prj, cmap=plotutils.get_cmap('jet')) for region in show_regions: plotutils.plot_region(ax1, region, prj, text=True) fig, ax2 = stack.add_subplots("Stack detection count") plotutils.imshow_image(ax2, img_count, projection=prj, cmap=plotutils.get_cmap('jet')) for region in show_regions: plotutils.plot_region(ax2, region, prj, text=True) if ms_set is not None: colorbar_setting = plotutils.ColorbarSetting(cmap='jet', ticks_locator=mdates.AutoDateLocator(), ticks_formatter=mdates.DateFormatter('%m/%y')) def feature_filter(feature): if img_snr.data[tuple(feature.get_coord())] == 0: return False if date_filter is not None and not date_filter(feature.get_epoch()): return False return True ms_set = wds.MultiScaleImageSet.from_file(os.path.join(ctx.get_data_dir(), j), feature_filter=feature_filter) plot_ms_set_map(ax1, None, ms_set, prj, colorbar_setting=colorbar_setting) plot_ms_set_map(ax2, None, ms_set, prj, colorbar_setting=colorbar_setting) add_features_tooltip(stack, ax1, ms_set.features_iter(), projection=prj, epoch=True, tol=1) add_features_tooltip(stack, ax2, ms_set.features_iter(), projection=prj, epoch=True, tol=1) stack.show()
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')