photometric_database.microlensing_label_per_time_step_database¶
Code for representing a dataset of lightcurves for binary classification with a single label per time step.
Module Contents¶
-
class
MicrolensingLabelPerTimeStepDatabase[source]¶ Bases:
photometric_database.lightcurve_database.LightcurveDatabaseA representation of a dataset of lightcurves for binary classification with a single label per time step.
-
generate_datasets(self, positive_data_directory: str, negative_data_directory: str, meta_data_file_path: str)[source]¶ Generates the training and validation datasets.
Parameters: - positive_data_directory – The path to the directory containing the positive example files.
- negative_data_directory – The path to the directory containing the negative example files.
- meta_data_file_path – The path to the microlensing meta data file.
Returns: The training and validation datasets.
-
training_preprocessing(self, example_path_tensor: tf.Tensor)[source]¶ Loads and preprocesses the data for training.
Parameters: example_path_tensor – The tensor containing the path to the example to load. Returns: The example and its corresponding label.
-
evaluation_preprocessing(self, example_path_tensor: tf.Tensor)[source]¶ Loads and preprocesses the data for evaluation.
Parameters: example_path_tensor – The tensor containing the path to the example to load. Returns: The example and its corresponding label.
-
general_preprocessing(self, example_path_tensor: tf.Tensor)[source]¶ Loads and preprocesses the data =.
Parameters: example_path_tensor – The tensor containing the path to the example to load. Returns: The example and its corresponding label.
-
static
load_microlensing_meta_data(meta_data_file_path: str)[source]¶ Loads a microlensing meta data file into a Pandas data frame.
Parameters: meta_data_file_path – The path to the original meta data CSV. Returns: The meta data frame.
-
static
einstein_normalized_separation_in_direction_of_motion(observation_time: np.float32, minimum_separation_time: np.float32, einstein_crossing_time: np.float32)[source]¶ Gets the einstein normalized separation of the source relative to the minimum separation position due to motion. This will be the separation perpendicular to the line between the minimum separation position and the lens. Broadcasts for arrays times. \(u_v = 2 \dfrac{t-t_0}{t_E}\)
Parameters: - observation_time – \(t\), current time of the observation.
- minimum_separation_time – \(t_0\), the time the minimum separation between source and lens occurs at.
- einstein_crossing_time – \(t_E\), the time it would take the source to cross the center of the Einstein ring
Returns: \(u_v\), the separation in the direction of source motion.
-
calculate_magnification(self, observation_time: np.float32, minimum_separation_time: np.float32, minimum_einstein_separation: np.float32, einstein_crossing_time: np.float32)[source]¶ Calculates the magnification of a microlensing event for a given time step. Broadcasts for arrays of times. Allows an infinite magnification in cases where the separation is zero. With \(u\) as the einstein normalized separation, does .. math:
u_v = 2 \dfrac{t-t_0}{t_E} u = \sqrt{u_0^2 + u_v^2} A = \dfrac{u^2 + 2}{u \sqrt{u^2 + 4}}
Parameters: - observation_time – \(t\), current time of the observation.
- minimum_separation_time – \(t_0\), the time the minimum separation between source and lens occurs at.
- minimum_einstein_separation – \(u_0\), the minimum einstein normalized separation.
- einstein_crossing_time – \(t_E\), the time it would take the source to cross the center of the Einstein ring
Returns: \(A\), the magnification for the passed time step(s).
-
get_meta_data_for_lightcurve_file_path(self, lightcurve_file_path: Union[str, Path], meta_data_frame: pd.DataFrame)[source]¶ Gets the meta data for a lightcurve based on the file name from the meta data frame.
Parameters: - lightcurve_file_path – The lightcurve file path.
- meta_data_frame – The meta data frame.
Returns: The lightcurve meta data.
-
check_if_meta_data_exists_for_lightcurve_file_path(self, lightcurve_file_path: Union[str, Path], meta_data_frame: pd.DataFrame)[source]¶ Gets the meta data for a lightcurve based on the file name from the meta data frame.
Parameters: - lightcurve_file_path – The lightcurve file path.
- meta_data_frame – The meta data frame.
Returns: The lightcurve meta data.
-
is_positive(self, example_path)[source]¶ Checks if an example contains a microlensing event or not.
Parameters: example_path – The path to the example to check. Returns: Whether or not the example contains a microlensing event.
-
static
get_meta_data_frame_for_lightcurve_file_path(lightcurve_file_path: Union[str, Path], meta_data_frame: pd.DataFrame)[source]¶ Gets the meta data frame containing all rows for a lightcurve based on the file name from the meta data frame.
Parameters: - lightcurve_file_path – The lightcurve file path.
- meta_data_frame – The meta data frame.
Returns: The lightcurve meta data frame.
-
magnification_threshold_label_for_lightcurve_meta_data(self, observation_times: np.float32, lightcurve_meta_data: pd.Series, threshold: float)[source]¶ Gets the binary per time step label for a lightcurve based on a microlensing magnification threshold.
Parameters: - observation_times – The observation times to calculate magnifications of.
- lightcurve_meta_data – The microlensing meta data for magnifications to be based off.
- threshold – The magnification threshold required for a time step to be labeled positive.
Returns: The label containing a binary value per time step.
-
make_uniform_length_requiring_positive(self, example: np.ndarray, label: np.ndarray, length: Union[int, None] = None, required_length_multiple_base: Union[int, None] = None)[source]¶ Extracts a random segment from an example of the length specified. For examples with a positive label, the segment is required to include at least 1 positive time step. Examples shorter than the specified length will be repeated to fit the length.
Parameters: - example – The example to extract a segment from.
- label – The label whose matching segment should be extracted.
- length – The length to make the example.
- required_length_multiple_base – An optional base which the length is rounded to.
Returns: The extracted segment and corresponding label.
-
calculate_magnifications_for_lightcurve_meta_data(self, times: np.float32, lightcurve_microlensing_meta_data: pd.Series)[source]¶ Calculates the magnification values for a given set of times based on the meta data of a specific lightcurve.
Parameters: - times – The observation times to calculate magnifications for.
- lightcurve_microlensing_meta_data – The microlensing meta data for magnifications to be based off.
Returns: An array of the magnification of each time.
-
remove_file_paths_with_no_meta_data(self, file_paths: List[Path], meta_data_frame: pd.DataFrame)[source]¶ Filters file paths on whether or not the meta data frame contains an entry for them.
Parameters: - file_paths – The file paths to be filtered.
- meta_data_frame – The meta data frame.
Returns: The filtered file paths containing only paths which appear in the meta data frame.
-