def _process_tce(feature_config): """Reads and process the input features of a Threshold Crossing Event. Args: feature_config: ConfigDict containing the feature configurations. Returns: A dictionary of processed light curve features. Raises: ValueError: If feature_config contains features other than 'global_view' and 'local_view'. """ if not {"global_view", "local_view"}.issuperset(feature_config.keys()): raise ValueError( "Only 'global_view' and 'local_view' features are supported.") # Read and process the light curve. all_time, all_flux = preprocess.read_light_curve(FLAGS.kepler_id, FLAGS.kepler_data_dir) time, flux = preprocess.process_light_curve(all_time, all_flux) time, flux = preprocess.phase_fold_and_sort_light_curve( time, flux, FLAGS.period, FLAGS.t0) # Generate the local and global views. features = {} if "global_view" in feature_config: global_view = preprocess.global_view(time, flux, FLAGS.period) # Add a batch dimension. features["global_view"] = np.expand_dims(global_view, 0) if "local_view" in feature_config: local_view = preprocess.local_view(time, flux, FLAGS.period, FLAGS.duration) # Add a batch dimension. features["local_view"] = np.expand_dims(local_view, 0) # Possibly save plots. if FLAGS.output_image_file: ncols = len(features) fig, axes = plt.subplots(1, ncols, figsize=(10 * ncols, 5), squeeze=False) for i, name in enumerate(sorted(features)): ax = axes[0][i] ax.plot(features[name][0], ".") ax.set_title(name) ax.set_xlabel("Bucketized Time (days)") ax.set_ylabel("Normalized Flux") fig.tight_layout() fig.savefig(FLAGS.output_image_file, bbox_inches="tight") return features
def _process_tce(tce): """Processes the light curve for a Kepler TCE and returns an Example proto. Args: tce: Row of the input TCE table. Returns: A tensorflow.train.Example proto containing TCE features. """ all_time, all_flux = preprocess.read_light_curve(tce.kepid, FLAGS.kepler_data_dir) time, flux = preprocess.process_light_curve(all_time, all_flux) return preprocess.generate_example_for_tce(time, flux, tce)