def process(self, inputs): """Reads the light curve of a particular Kepler ID.""" kep_id = inputs["kepler_id"] all_time = None all_flux = None filenames = kepler_io.kepler_filenames( base_dir=self.kepler_data_dir, kep_id=kep_id, long_cadence=self.long_cadence, quarters=self.quarters, injected_group=self.injected_group) if filenames: try: all_time, all_flux = kepler_io.read_kepler_light_curve( filenames, light_curve_extension=self.extension, scramble_type=self.scramble_type, invert=self.invert_light_curves) except (IOError, ValueError) as e: raise ValueError("Kepler ID: {}, {}".format(kep_id, e)) else: Metrics.counter(self.__class__.__name__, "no-fits-%s" % kep_id).inc() raw_lc = light_curve_pb2.RawLightCurve() for time, flux in zip(all_time, all_flux): raw_lc.segments.add(time=time, flux=flux) inputs["raw_light_curve"] = raw_lc yield inputs
def testReadKeplerLightCurve(self): filenames = [ os.path.join(self.data_dir, "0114/011442793/kplr011442793-{}_llc.fits".format(q)) for q in ["2009350155506", "2010009091648", "2010174085026"] ] all_time, all_flux = kepler_io.read_kepler_light_curve(filenames) self.assertLen(all_time, 3) self.assertLen(all_flux, 3) self.assertLen(all_time[0], 4134) self.assertLen(all_flux[0], 4134) self.assertLen(all_time[1], 1008) self.assertLen(all_flux[1], 1008) self.assertLen(all_time[2], 4486) self.assertLen(all_flux[2], 4486) for time, flux in zip(all_time, all_flux): self.assertTrue(np.isfinite(time).all()) self.assertTrue(np.isfinite(flux).all())
def testReadKeplerLightCurveScrambled(self): filenames = [ os.path.join(self.data_dir, "0114/011442793/kplr011442793-{}_llc.fits".format(q)) for q in ["2009350155506", "2010009091648", "2010174085026"] ] all_time, all_flux = kepler_io.read_kepler_light_curve( filenames, scramble_type="SCR1") self.assertLen(all_time, 3) self.assertLen(all_flux, 3) # Arrays are shorter than above due to separation of time and flux NaNs. self.assertLen(all_time[0], 4344) self.assertLen(all_flux[0], 4344) self.assertLen(all_time[1], 4041) self.assertLen(all_flux[1], 4041) self.assertLen(all_time[2], 1008) self.assertLen(all_flux[2], 1008) for time, flux in zip(all_time, all_flux): self.assertTrue(np.isfinite(time).all()) self.assertTrue(np.isfinite(flux).all())
def read_light_curve(kepid, kepler_data_dir): """Reads a Kepler light curve. Args: kepid: Kepler id of the target star. kepler_data_dir: Base directory containing Kepler data. See kepler_io.kepler_filenames(). Returns: all_time: A list of numpy arrays; the time values of the raw light curve. all_flux: A list of numpy arrays corresponding to the time arrays in all_time. Raises: IOError: If the light curve files for this Kepler ID cannot be found. """ # Read the Kepler light curve. file_names = kepler_io.kepler_filenames(kepler_data_dir, kepid) if not file_names: raise IOError( "Failed to find .fits files in {} for Kepler ID {}".format( kepler_data_dir, kepid)) return kepler_io.read_kepler_light_curve(file_names)