MicroLIA.training_set

Created on Thu Jun 28 20:30:11 2018

@author: danielgodinez

Module Contents

Functions

create(→ Tuple[numpy.ndarray, numpy.ndarray])

Creates a training dataset using adaptive cadence.

load_all(→ Tuple[numpy.ndarray, numpy.ndarray])

Function to load already simulated lightcurves. The subdirectories in the path

plot(→ None)

Plots a simulated lightcurve from the lightcurves.fits file.

MicroLIA.training_set.create(timestamps: Union[List[numpy.typing.ArrayLike], numpy.typing.ArrayLike], load_microlensing: Optional[Union[str, List[numpy.typing.ArrayLike]]] = None, min_mag: float = 14, max_mag: float = 21, noise: Optional[collections.abc.Callable[[numpy.typing.ArrayLike], Tuple[numpy.typing.ArrayLike, numpy.typing.ArrayLike]]] = None, zp: float = 24, exptime: float = 60, n_class: int = 500, ml_n1: int = 7, cv_n1: int = 7, cv_n2: int = 1, t0_dist: Optional[Union[Tuple[float, float], numpy.typing.ArrayLike]] = None, u0_dist: Optional[Union[Tuple[float, float], numpy.typing.ArrayLike]] = None, tE_dist: Optional[Union[Tuple[float, float], numpy.typing.ArrayLike]] = None, filename: Optional[str] = None, apply_weights: bool = True, save_file: bool = True) Tuple[numpy.ndarray, numpy.ndarray][source]

Creates a training dataset using adaptive cadence. Simulates each class n_class times, adding errors from a noise model either defined using the create_noise function, or Gaussian by default.

Note: To input your own microlensing lightcurves, you can set the load_microlensing parameter, which takes the path to a directory containing the lightcurve text files (3 columns: time,mag,magerr).

Instead of a path, another valid input is a 3-dimensional array or list. This will be parsed one element at a time along the 0th axis. Example:

>>> lightcurves = []
>>> lightcurve_1 = np.c_[time1, mag1, magerr1]
>>> lightcurve_2 = np.c_[time2, mag2, magerr2]
>>>
>>> lightcurves.append(lightcurve_1)
>>> lightcurves.append(lightcurve_2)
>>>
>>> create(timestamps, load_microlensing=lightcurves)

Parameters:

timestampslist

Times at which to simulate the different lightcurves. Must be an array/list containing all possible timestamps combinations, stored as lists.

load_microlensingstr, list, optional

Either a 3-dimensional array containing the lightcurves, or the path to a folder containing the lightcurve text files. Data is asummed to be in following columns: time, mag, magerr. Defaults to None, in which case the microlensing lightcurves are simulated.

min_magfloat, optional

Minimum baseline magnitude for simulating lightcurves. Defaults to 14.

max_magfloat, optional

Maximum baseline magnitude for simulating lightcurves. Defaults to 21.

noisefunction, optional

Noise model, must be a function of flux, can be created using the create_noise function. If None it defaults to Gaussian noise. Defaults to None.

zpfloat

The zero point of the observing instrument, will be used when generating the noise model. Defaults to 24.

exptimefloat

Exposure time in seconds, will be used to generate the noise model. Defaults to 60.

n_classint, optional

The amount of lightcurve (per class) to simulate. Defaults to 500.

ml_n1int, optional

The mininum number of measurements that should be within the microlensing signal when simulating the lightcurves. Defaults to 7.

cv_n1int, optional

The mininum number of measurements that should be within at least one CV outburst when simulating the lightcurves. Defaults to 7.

cv_n2int, optional

The mininum number of measurements that should be within the rise or drop of at least one CV outburst when simulating the lightcurves. Defaults to 1.

t0_dist: array, tuple, optional

An array or tuple containing two values, the minimum and maximum value (in that order) to consider when simulating the microlensing events (in days), as this t0 parameter will be selected using a random uniform distribution according to these bounds. Defaults to None, which will compute an appropriate t0 according to the range of the input timestamps.

u0_dist: array, optional

An array or tuple containing two values, the minimum and maximum value (in that order) to consider when simulating the microlensing events, as this u0 parameter will be selected using a random uniform distribution according to these bounds. Defaults to None, which will set these bounds to (0, 1).

te_dist: array, optional

An array containing the mean and standard deviation (in that order) to consider for this tE parameter during the microlensing simulations, as this value will be selected from a random normal distribution using the specified mean and standard deviation. Defaults to None which will apply a mean of 30 with a spread of 10 days.

apply_weights: bool

Whether to apply the photometric errors when calculating the features. Defaults to True. Note that this assumes that the erros are Gaussian and uncorrelated.

save_file: bool

If True the lightcurve.fits and all_features.txt files will be saved to the home directory. Defaults to True.

filename: str, optional

The name to be appended to the saved files, only applicable if save_file is set to True. files, only relevant if save_file=True. If no argument is input the files will be saved with the default names only. Defaults to None.

Returns:

data_xarray

2D array containing the statistical metrics of all simulated lightcurves.

data_yarray

1D array containing the class label of all simulated lightcurves.

lightcurvesFITS

All simulated lightcurves in a FITS file, sorted by class label and unique ID. Only saved if save_file=True.

all_featurestext file

A txt file containing all the features sorted by class label and unique ID. Only saved if save_file=True.

csvCSV file

A CSV file containing the training data present in the saved text file, which contains the feature names and can be input directly when creating the classifier. Only saved if save_file=True.

MicroLIA.training_set.load_all(path: str, convert: bool = True, zp: float = 24, filename: Optional[str] = None, apply_weights: bool = True, save_file: bool = True, skiprows: int = 0) Tuple[numpy.ndarray, numpy.ndarray][source]

Function to load already simulated lightcurves. The subdirectories in the path must contain the lightcurve text files for each class (columns: time,mag,magerr)

Note

If a file cannot be loaded with the standard numpy.loadtxt() function it will be printed and skipped, therefore no strings allowed, only the columns with the float numbers (nan ok)

Parameters:

pathstr

Path to the root directory containing the lightcurve subdirectories

convertbool

If True the magnitudes will be converted to flux using the input zeropoint. If the lightcurves are already in flux, set convert=False. Defaults to True.

zpfloat

The zero point of the observing instrument, will be used to calcualate the features. This is ignored used if convert=False. Defaults to 24.

filenamestr, optional

The name to be appended to the lightcurves.fits and the all_features.txt files, only relevant if save_file=True. If no argument is input the files will be saved with the default names only. Defaults to None.

apply_weightsbool

Whether to apply the photometric errors when calculating the features. Defaults to True. Note that this assumes that the erros are Gaussian and uncorrelated.

save_filebool

If True the lightcurve.fits and all_features.txt files will be saved to the home directory. Defaults to True.

skiprowsint

Used to exclude comments which may be present at the top of the data files. Defaults to 0 which skips no rows.

Returns:

data_xarray

2D array containing the statistical metrics of all simulated lightcurves.

data_yarray

1D array containing the class label of all simulated lightcurves.

lightcurvesFITS

All simulated lightcurves in a FITS file, sorted by class label and unique ID. Only saved if save_file=True.

all_featurestext file

A txt file containing all the features sorted by class label and unique ID. Only saved if save_file=True.

csvCSV file

A CSV file containing the training data present in the saved text file, which contains the feature names and can be input directly when creating the classifier. Only saved if save_file=True.

MicroLIA.training_set.plot(hdu: astropy.io.fits.HDUList, ID: Optional[int] = None, label: Optional[str] = None, savefig: bool = False) None[source]

Plots a simulated lightcurve from the lightcurves.fits file.

Parameters:
  • hdu (fits.HDUList) – The loaded lightcurves.fits file.

  • ID (int, optional) – The ID of the lightcurve to plot. Ignored if label is provided.

  • label (str, optional) – The class label of the lightcurve. A random example from this class will be plotted.

  • savefig (bool, optional) – If True, the figure will be saved to the working directory. Otherwise it will be shown interactively.

Return type:

None