def _helper(vals): bd_xform = xform.LinearBandDataXform(*vals) lca_xform = xform.SameLCXform(bd_xform) lc = lca_xform.apply(lcb) new_lc = lca + lc length = new_lc.connect_the_dots() return length
def test_plot_arclen_res(): glc1 = sim.TestLC.make_easy_gauss() glc2 = sim.TestLC.make_hard_gauss() xform1 = xform.LinearBandDataXform(200, 0, 1, 1) lcxf = xform.SameLCXform(xform1) vis.plot_arclen_res(glc1, glc2, lcxf)
def lc_xform(self, time: float) -> xform.SameLCXform: band_xform = RandomSubsampler( min_rate=self.min_rate, max_rate=self.max_rate, preserve_time=time, preserve_time_radius=self.preserve_time_radius, rng=self.rng) return xform.SameLCXform(band_xform)
def opt_alignment( lca: lightcurve._LC, lcb: lightcurve._LC, ivals=None, constraints=None, method='Nelder-Mead', options=None, vb=True, ) -> xform.LCXform: """ Minimizes the arclength between two lightcurves after merging :param lca: First lightcurve. :param lcb: Lightcurve to try merging in :param ivals: initial values to try :param constraints: Not sure how these work, feel free to give it a try though! :param method: Only Nelder_Mead is tested as of now :param options: Only maxiter is included right now :param vb: Boolean verbose :return: best xform """ if constraints is None: constraints = [] if options is None: options = {'maxiter': 10000} if ivals is None: ivals = np.array([0, 0, 1, 1]) if method != 'Nelder-Mead': def pos_dil(xf: xform.LinearBandDataXform): return min(xf._dilate_time, xf._dilate_flux) constraints += [{'type': 'ineq', 'fun': pos_dil}] else: constraints = None # don't know if this way of handling constraints actually works -- untested! def _helper(vals): bd_xform = xform.LinearBandDataXform(*vals) lca_xform = xform.SameLCXform(bd_xform) lc = lca_xform.apply(lcb) new_lc = lca + lc length = new_lc.connect_the_dots() return length # could make this a probability by taking chi^2 error relative to # connect_the_dots original, but it didn't work better in the sandbox # notebook res = spo.minimize(_helper, ivals, constraints=constraints, method=method, options=options) if vb: print(res) res_xform = xform.SameLCXform(xform.LinearBandDataXform(*res.x)) return res_xform
def test_arclen(): glc = sim.TestLC.make_hard_gauss() aff = xform.SameLCXform(xform.LinearBandDataXform(50, 1, 1.5, 1)) glc2 = aff.apply(glc) aff2 = summ.opt_alignment(glc, glc2, vb=False, options={'maxiter': 10}) del aff2 # unused
def make_positive_pair(self, lc: lightcurve._LC) -> FullPositivesPair: time = float(self.rng.choice(lc.all_times_unique())) xf = self.make_xform() lc_xf = xform.SameLCXform(xf) transformed = lc_xf.apply(lc) time_transformed: float = xf.apply_time(time) return FullPositivesPair(lca=lc, time_a=time, lcb=transformed, time_b=time_transformed)