RAMjET

ramjet.photometric_database.lightcurve_database

Code for a base generalized database for photometric data to be subclassed.

Module Contents

Classes

LightcurveDatabase A base generalized database for photometric data to be subclassed.
class LightcurveDatabase(data_directory='data')[source]

Bases: abc.ABC

A base generalized database for photometric data to be subclassed.

window_shift :int

How much the window shifts for a windowed batch set.

Returns:The window shift size.
__init__(self, data_directory='data')[source]

Initialize self. See help(type(self)) for accurate signature.

static normalize_log_0_to_1(lightcurve: np.ndarray)[source]

Normalizes from 0 to 1 on the logarithm of the lightcurve.

static normalize_on_percentiles(array: np.ndarray)[source]

Normalizes an array using percentiles. The 10th percentile is normalized to -1, the 90th to 1.

static normalize_on_percentiles_with_errors(array: np.ndarray, array_errors: np.ndarray)[source]

Normalizes an array using percentiles. The 10th percentile is normalized to -1, the 90th to 1. Scales the errors by the corresponding scaling factor.

static shuffle_in_unison(a, b, seed=None)[source]

Shuffle two arrays in unison.

static remove_random_elements(lightcurve: np.ndarray, ratio: float = 0.01)[source]

Removes random values from the lightcurve.

get_ratio_enforced_dataset(self, positive_training_dataset: tf.data.Dataset, negative_training_dataset: tf.data.Dataset, positive_to_negative_data_ratio: float)[source]

Generates a dataset with an enforced data ratio.

static repeat_dataset_to_size(dataset: tf.data.Dataset, size: int)[source]

Repeats a dataset to make it a desired length.

make_uniform_length(self, example: np.ndarray, length: int, randomize: bool = True)[source]

Makes the example a specific length, by clipping those too large and repeating those too small.

static randomly_roll_elements(example: np.ndarray)[source]

Randomly rolls the elements.

get_training_and_validation_datasets_for_file_paths(self, example_paths: Union[Iterable[Path], Callable[[], Iterable[Path]]])[source]

Creates training and validation datasets from a list of all file paths. The database validation ratio is used to determine the size of the split.

Parameters:example_paths – The total list of file paths.
Returns:The training and validation datasets.
static extract_shuffled_chunk_and_remainder(array_to_extract_from: Union[List, np.ndarray], chunk_ratio: float, chunk_to_extract_index: int = 0)[source]

Shuffles an array, extracts a chunk of the data, and returns the chunk and remainder of the array.

Parameters:
  • array_to_extract_from – The array to process.
  • chunk_ratio – The number of equal size chunks to split the array into before extracting one.
  • chunk_to_extract_index – The index of the chunk to extract out of all chunks.
Returns:

The chunk which is extracted, and the remainder of the array excluding the chunk.

static flat_window_zipped_example_and_label_dataset(dataset: tf.data.Dataset, batch_size: int, window_shift: int)[source]

Takes a zipped example and label dataset and repeats examples in a windowed fashion of a given batch size. It is expected that the resulting dataset will subsequently be batched in some fashion by the given batch size.

Parameters:
  • dataset – The zipped example and label dataset.
  • batch_size – The size of the batches to produce.
  • window_shift – The shift of the moving window between batches.
Returns:

The flattened window dataset.

padded_window_dataset_for_zipped_example_and_label_dataset(self, dataset: tf.data.Dataset, batch_size: int, window_shift: int, padded_shapes: Tuple[List, List])[source]

Takes a zipped example and label dataset, and converts it to padded batches, where each batch uses overlapping examples based on a sliding window.

Parameters:
  • dataset – The zipped example and label dataset.
  • batch_size – The size of the batches to produce.
  • window_shift – The shift of the moving window between batches.
  • padded_shapes – The output padded shape.
Returns:

The padded window dataset.

window_dataset_for_zipped_example_and_label_dataset(self, dataset: tf.data.Dataset, batch_size: int, window_shift: int)[source]

Takes a zipped example and label dataset, and converts it to batches, where each batch uses overlapping examples based on a sliding window.

Parameters:
  • dataset – The zipped example and label dataset.
  • batch_size – The size of the batches to produce.
  • window_shift – The shift of the moving window between batches.
Returns:

The window dataset.

clear_data_directory(self)[source]

Empties the data directory.

create_data_directories(self)[source]

Creates the data directories to be used by the database.

static paths_dataset_from_list_or_generator_factory(list_or_generator_factory: Union[Iterable[Path], Callable[[], Iterable[Path]]])[source]

Produces a dataset from either the examples path list or example paths factory to strings.

Parameters:list_or_generator_factory – The list or generator factory.
Returns:The new path generator.
normalize_fluxes(self, light_curve: np.ndarray)[source]

Normalizes the flux channel of the light curve in-place.

Parameters:light_curve – The light curve whose flux channel should be normalized.
Returns:The light curve with the flux channel normalized.
build_light_curve_array(self, fluxes: np.ndarray, times: Union[np.ndarray, None] = None, flux_errors: Union[np.ndarray, None] = None)[source]

Builds the light curve array based on the components required for the specific database setup.

Parameters:
  • fluxes – The fluxes of the light curve.
  • times – The optional times of the light curve.
  • flux_errors – The optional flux errors of the light curve.
Returns:

The constructed light curve array.

preprocess_times(self, light_curve_array: np.ndarray)[source]

Preprocesses the times of the light curve.

Parameters:light_curve_array – The light curve array to preprocess.
Returns:The light curve array with the times preprocessed.
static calculate_time_differences(times: np.ndarray)[source]

Calculates the differences between an array of time, doubling up the first element to make the length the same.

Parameters:times – The times to difference.
Returns:The time differences.
preprocess_light_curve(self, light_curve: np.ndarray, evaluation_mode: bool = False)[source]

Preprocessing for the light curve.

Parameters:
  • light_curve – The light curve array to preprocess.
  • evaluation_mode – If the preprocessing should be consistent for evaluation.
Returns:

The preprocessed flux array.