def do_plot(fig): nrows = 2 ax = fig.subplots(nrows=nrows, sharex=True) group = delta_info.get_features(wfeatures.DeltaInformation.DELTA_MATCH) if group.size() == 0: return x = np.array([k.get_coord()[1] for k in group]) delta = delta_info.get_deltas(group) deltay, deltax = delta.T expectedx, sigx, chi2x, dof, rmsx = plot_delta_info_1dim(ax[0], x, deltax, input_delta, axis=0) expectedy, sigy, chi2y, dof, rmsy = plot_delta_info_1dim(ax[1], x, deltay, input_delta, axis=1) if input_delta is not None: residual = nputils.l2norm(np.array([deltax, deltay]).T - np.array([expectedx, expectedy]).T) print "Chi2 X:", chi2x / dof, "RMS:", rmsx print "Chi2 Y:", chi2y / dof, "RMS:", rmsy print "Full RMS:", residual.std() ax[0].set_ylabel("$\Delta_x (px)$") ax[1].set_xlabel("$X (px)$") ax[1].set_ylabel("$\Delta_y (px)$") ax[1].set_xlim(min(x) - 5, max(x) + 5)
def plot_links_dfc(ax, projection, links, mode='com', num=False, num_bbox=None, **kwargs): """Plot features link on a distance from core vs epoch plot. Parameters ---------- ax : :class:`matplotlib.axes.Axes` projection : :class:`libwise.imgutils.Projection` links : a list of :class:`wise.matcher.FeaturesLink` mode : str, optional Coord mode for the location of the features: 'lm', 'com' or 'cos'. num : bool, optional Whatever to optionally annotate the links with there ids. num_bbox : dict, optional **kwargs : Additional arguments to be passed to :func:`matplotlib.pyplot.plot`. .. _tags: plt_matching """ dfc_fct_coord = lambda coord: nputils.l2norm(projection.p2s(p2i(coord))) dfc_fct = lambda feature: dfc_fct_coord(feature.get_coord(mode)) for link in links: delta_info = link.get_delta_info() if num is True: if num_bbox is None: num_bbox = dict(boxstyle='round', facecolor='wheat', alpha=0.7, edgecolor=link.get_color(), lw=1.5) # ax.text(link.get_first_epoch(), dfc_fct(link.first()), "%s, %s" % (link.get_id(), link.size())) ax.text(link.get_first_epoch(), dfc_fct(link.first()), link.get_id(), bbox=num_bbox, zorder=200, size='small') if 'c' not in kwargs: line_color = link.get_color() else: line_color = kwargs['c'] # plotutils.checkargs(kwargs, 'lw', 2.5) for epoch, related in link.get_relations(): link_feature = link.get(epoch) related_feature = related.get(epoch) ax.plot([epoch, epoch], [dfc_fct(link_feature), dfc_fct(related_feature)], color='k', marker='+') for feature1, feature2 in nputils.pairwise(link.get_features()): epoch1 = feature1.get_epoch() epoch2 = feature2.get_epoch() delta = delta_info.get_delta(feature1) dfc1 = dfc_fct(feature1) dfc2 = dfc_fct(feature2) # dfc2 = dfc_fct_coord(feature1.get_coord(mode) + delta) ax.plot([epoch1, epoch2], [dfc1, dfc2], color=line_color, **kwargs) ax.plot([epoch1], dfc1, ls='', marker='+', color='k')
def plot_velocity_vector(ax, delta_info, projection, ang_vel_unit, pix_per_unit, mode='com', color_fct=None, flag=wfeatures.DeltaInformation.DELTA_MATCH, **kwargs): features = delta_info.get_features(flag=flag) for i, feature in enumerate(features): coord = feature.get_coord(mode=mode) delta = delta_info.get_delta(feature) ang_vel = delta_info.get_full_delta(feature).get_angular_velocity(projection) ang_vel_pix = ang_vel.to(ang_vel_unit).value * pix_per_unit ang_vel_vect_pix = ang_vel_pix * delta / nputils.l2norm(delta) if color_fct is not None: kwargs['fc'] = color_fct(feature) plotutils.checkargs(kwargs, 'zorder', 3) plotutils.checkargs(kwargs, 'width', 3.5) patch = plt.Arrow(coord[1], coord[0], ang_vel_vect_pix[1], ang_vel_vect_pix[0], **kwargs) ax.add_patch(patch)
def add_delta_info(self, delta_info, match, projection, link_builder=None, coord_mode='com', scale=None, min_snr=2, max_snr=10): import pandas as pd features = delta_info.get_features(flag=wfeatures.DeltaInformation.DELTA_MATCH) cdf = self.add_features_group(features, projection, coord_mode=coord_mode, scale=scale, min_snr=min_snr, max_snr=max_snr) features = features.features idx = cdf.index sigma_pos = np.array([feature.get_coord_error() for feature in features]) deltas = delta_info.get_full_deltas(flag=wfeatures.DeltaInformation.DELTA_MATCH) if isinstance(features[0].get_epoch(), (float, int)): time = [delta.get_time() for delta in deltas] * u.second else: time = [delta.get_time().total_seconds() for delta in deltas] * u.second delta_pix = p2i(np.array([delta.get_delta() for delta in deltas])) coord1 = p2i(np.array([delta.get_feature().get_coord(mode=coord_mode) for delta in deltas])) coord2 = coord1 + delta_pix angular_sep, sep_pa = projection.angular_separation_pa(coord1, coord2) # angular_sep_error = projection.angular_separation(coord1, coord1 + np.array([np.sqrt(2) / 2] * 2)) if angular_sep.unit.is_equivalent(u.deg): ra_error1, dec_error1 = cdf[['ra_error', 'dec_error']].as_matrix().T ra_error2, dec_error2 = ra_error1, dec_error1 angular_sep_error_ra = np.sqrt(ra_error1 ** 2 + ra_error2 ** 2) * projection.get_unit() angular_sep_error_dec = np.sqrt(dec_error1 ** 2 + dec_error2 ** 2) * projection.get_unit() angular_velocity = (angular_sep / time).to(u.mas / u.year) angular_velocity_error_ra = (angular_sep_error_ra / time).to(u.mas / u.year) angular_velocity_error_dec = (angular_sep_error_dec / time).to(u.mas / u.year) angular_velocity_error = nputils.l2norm(np.array([angular_velocity_error_ra, angular_velocity_error_dec]).T) proper_sep = projection.proper_distance(coord1, coord2) if proper_sep.unit.is_equivalent(u.m): proper_velocity = (proper_sep / time).to(unit_c) angular_proper_ratio = proper_velocity / angular_velocity proper_velocity_error_ra = angular_velocity_error_ra * angular_proper_ratio proper_velocity_error_dec = angular_velocity_error_dec * angular_proper_ratio proper_velocity_error = nputils.l2norm(np.array([proper_velocity_error_ra, proper_velocity_error_dec]).T) if link_builder is not None: fetaure_id_mapping = link_builder.get_features_id_mapping() link_id = [fetaure_id_mapping.get(feature) for feature in features] self.df.loc[idx, 'link_id'] = pd.Series(link_id, index=idx) if match is not None: matching_features = [match.get_peer_of_one(feature) for feature in features] self.df.loc[idx, 'match'] = pd.Series(matching_features, index=idx) self.df.loc[idx, 'delta_ra'] = pd.Series(delta_pix.T[0], index=idx) self.df.loc[idx, 'delta_dec'] = pd.Series(delta_pix.T[1], index=idx) self.df.loc[idx, 'delta_time'] = pd.Series(time, index=idx) self.df.loc[idx, 'sep_pa'] = pd.Series(sep_pa, index=idx) self.df.loc[idx, 'angular_sep'] = pd.Series(angular_sep, index=idx) if angular_sep.unit.is_equivalent(u.deg): self.df.loc[idx, 'angular_velocity'] = pd.Series(angular_velocity, index=idx) self.df.loc[idx, 'angular_velocity_error'] = pd.Series(angular_velocity_error, index=idx) self.df.loc[idx, 'angular_velocity_error_ra'] = pd.Series(angular_velocity_error_ra, index=idx) self.df.loc[idx, 'angular_velocity_error_dec'] = pd.Series(angular_velocity_error_dec, index=idx) if proper_sep.unit.is_equivalent(u.m): self.df.loc[idx, 'proper_velocity'] = pd.Series(proper_velocity, index=idx) self.df.loc[idx, 'proper_velocity_error'] = pd.Series(proper_velocity_error, index=idx) self.df.loc[idx, 'proper_velocity_error_dec'] = pd.Series(proper_velocity_error_dec, index=idx) self.df.loc[idx, 'proper_velocity_error_ra'] = pd.Series(proper_velocity_error_ra, index=idx)