def gather_results(outfile, pointing_indices, ndays, gmags, template_indices):
    if not os.path.exists(outfile):
        raise ValueError("Cannot gather results from {0}".format(outfile))
    results = NumpyCache(outfile)
    brd = np.broadcast(pointing_indices, ndays, gmags, template_indices)
    results = np.array([results.get_row(key) for key in brd])
    return results.reshape(brd.shape + results.shape[-1:])
def gather_results(outfile, pointing_indices, ndays, gmags, template_indices):
    if not os.path.exists(outfile):
        raise ValueError("Cannot gather results from {0}".format(outfile))
    results = NumpyCache(outfile)
    brd = np.broadcast(pointing_indices, ndays, gmags, template_indices)
    results = np.array([results.get_row(key) for key in brd])
    return results.reshape(brd.shape + results.shape[-1:])
def compute_and_save_periods(Model,
                             outfile,
                             pointing_indices,
                             ndays,
                             gmags,
                             template_indices,
                             model_args=None,
                             model_kwds=None,
                             Nperiods=5,
                             save_every=5,
                             parallel=True,
                             client=None,
                             num_results=None):
    """Function to compute periods and save the results"""
    cache = NumpyCache(outfile)
    keys = list(np.broadcast(pointing_indices, ndays, gmags, template_indices))

    if num_results is not None:
        keys = keys[:num_results]

    # Define a function which, given a key, computes the desired periods.
    def find_periods(key,
                     Nperiods=Nperiods,
                     Model=Model,
                     LSSTsims=LSSTsims,
                     model_args=model_args,
                     model_kwds=model_kwds):
        import numpy as np
        lsstsim = LSSTsims()
        t, y, dy, filts = lsstsim.generate_lc(*key, random_state=0)

        model = Model(*(model_args or ()), **(model_kwds or {}))
        model.optimizer.period_range = (0.2, 1.2)
        model.optimizer.verbose = 0
        model.fit(t, y, dy, filts)

        try:
            periods = model.find_best_periods(Nperiods)
        except np.linalg.LinAlgError:
            periods = np.nan + np.zeros(Nperiods)
        except ValueError:
            periods = np.nan + np.zeros(Nperiods)
        return key, periods

    results = compute_parallel(cache,
                               find_periods,
                               keys,
                               save_every=save_every,
                               parallel=parallel,
                               client=client)

    if num_results is not None:
        return results
    else:
        return gather_results(outfile, pointing_indices, ndays, gmags,
                              template_indices)
def compute_and_save_periods(rrlyrae,
                             Model,
                             outfile,
                             model_args=None,
                             model_kwds=None,
                             Nperiods=5,
                             save_every=5,
                             parallel=True,
                             client=None,
                             num_results=None):
    """Function to compute periods and save the results"""
    cache = NumpyCache(outfile)
    lcids = rrlyrae.ids
    if num_results is not None:
        lcids = lcids[:num_results]

    # Define a function which, given an lcid, computes the desired periods.
    def find_periods(lcid,
                     Nperiods=Nperiods,
                     rrlyrae=rrlyrae,
                     Model=Model,
                     model_args=model_args,
                     model_kwds=model_kwds):
        t, y, dy, filts = rrlyrae.get_lightcurve(lcid)
        model = Model(*(model_args or ()), **(model_kwds or {}))
        model.optimizer.period_range = (0.2, 1.2)
        model.optimizer.verbose = 0
        model.fit(t, y, dy, filts)
        return lcid, model.find_best_periods(Nperiods)

    return compute_parallel(cache,
                            find_periods,
                            lcids,
                            save_every=save_every,
                            parallel=parallel,
                            client=client)
def gather_results(outfile, ids):
    if not os.path.exists(outfile):
        raise ValueError("Cannot gather results from {0}".format(outfile))
    results = NumpyCache(outfile)
    return np.array([results.get_row(lcid) for lcid in ids])
def gather_results(outfile, ids):
    if not os.path.exists(outfile):
        raise ValueError("Cannot gather results from {0}".format(outfile))
    results = NumpyCache(outfile)
    return np.array([results.get_row(lcid) for lcid in ids])