Lightspeedpy API¶
- class lightspeedpy.DataSet(filenames, **kwargs)¶
Bases:
objectContains metadata relating to one contiguous LightSpeed observation. The data set is never loaded into memory, so many-GB observations can be treated.
There are three ways to initialize a
DataSet:Use
DataSet.from_first()to create a data set of all files in the captureUse
DataSet.from_dir()to create a data set out of all the files in a directoryUse the constructor and pass all the files you want to be in the data set as a parameter.
The default keyword arguments are the ones you passed when you created the
DataSet. You can override the defaults by passing new arguments here. You can also pass the following- Parameters:
filenames (list of str) – List of files to include
max_frames (int, optional) – Maximum number of frames to iterate through. Default: all the frames
use_bar (bool, optional) – Show a progress bar. Default: True.
cut_cr (bool, optional) – Cut cosmic rays. Default: True
cr_thresh (int, optional) – Cosmic ray cutting threshold. Default: 20
- apply_timing_offset(timing_offset=0)¶
Apply a timing offset to the data set. Now, a frame read at timing_offset will be treated as having time 0.
- Parameters:
timing_offset (float) – Time offset, in seconds
- bootstrap(seed)¶
Resamples the file names for use in bootstrapping. If you want to estimate uncertainties, redo your analysis with many
DataSet.bootstrap()’ed data sets and calculate the standard deviation of your results.Notes
You should never bootstrap a data set twice. Instead, you should always create a copy of the original data set with copy.deepcopy and then bootstrap the copy.
- display_filenames()¶
Print all the filenames in the data set
- from_dir(**kwargs)¶
Create a
DataSetfor all files in a directory. The default keyword arguments are the ones you passed when you created theDataSet. You can override the defaults by passing new arguments here. You can also pass the following- Parameters:
directory (str) – name of the directory
max_frames (int, optional) – Maximum number of frames to iterate through. Default: all the frames
use_bar (bool, optional) – Show a progress bar. Default: True.
cut_cr (bool, optional) – Cut cosmic rays. Default: True
cr_thresh (int, optional) – Cosmic ray cutting threshold. Default: 20
- from_first(min_index=None, max_index=None, **kwargs)¶
Create a
DataSetfor all files in a capture. The default keyword arguments are the ones you passed when you created theDataSet. You can override the defaults by passing new arguments here. You can also pass the following- Parameters:
filenames (list of str) – List of files to include
max_frames (int, optional) – Maximum number of frames to iterate through. Default: all the frames
use_bar (bool, optional) – Show a progress bar. Default: True.
cut_cr (bool, optional) – Cut cosmic rays. Default: True
cr_thresh (int, optional) – Cosmic ray cutting threshold. Default: 20
- iterator(**kwargs)¶
Create an iterator for iterating through all frames in a
DataSet.:param The default keyword arguments are the ones you passed when you created the
DataSet.: :param You can override the defaults by passing new arguments here. You can also pass the following: :param max_frames: Maximum number of frames to iterate through. Default: all the frames :type max_frames: int, optional :param use_bar: Show a progress bar. Default: True. :type use_bar: bool, optional :param cut_cr: Cut cosmic rays. Default: True :type cut_cr: bool, optional :param cr_thresh: Cosmic ray cutting threshold. Default: 20 :type cr_thresh: int, optionalNotes
for frame in data_set.iterator()is equivalent tofor frame in data_set.
- num_frames()¶
Counts the number of frames in the data set
- Returns:
The number of frames in the data set
- Return type:
int
- property pixel_properties¶
PixelProperties Pixel properties of the data set
- set_bias(bias)¶
Set the bias
- Parameters:
bias (DataSet or PixelProperties) – A
DataSetcontaining the bias observation, or thePixelPropertiesof the observation
- set_dark(dark_data_set)¶
Set the dark
- set_flat(flat_data_set)¶
Set the flat
- set_self_bias()¶
Estimate an observation from these data. This can only be done accurately for very fast readout of a faint source, where most of the pixels detect zero photons.
- class lightspeedpy.Ephemeris(parfile, data_set, observatory='LCO')¶
Bases:
objectClass to contain a PINT ephemeris and assign phases to lightspeed data. Ephemerides are saved in the lightspeedpy/tmp directory so that they don’t have to be recomputed.
- Parameters:
parfile (str) – File name of the PINT ephemeris file
data_set (DataSet) – The data set to create timestamps for
observatory (str, optional) – Observatory where Lightspeed was. Default: LCO
- get_phase(time)¶
Returns the phase (0 to 1) corresponding to a specific time
- class lightspeedpy.Frame(image, timestamp, duration, is_saturated)¶
Bases:
object- image¶
Contains the frame image in units of electrons. If darks and biases were set, they are already subtracted. If a dark was not set, it is assumed to be zero. If the bias is not set, it is assumed to be 199.5 ADU. The flat is not included, nor the QE.
- Type:
array-like
- timestamp¶
Time in seconds after camera start
- Type:
float
- duration¶
Frame time in seconds
- Type:
float
- class lightspeedpy.PixelProperties(bias, widths, params, source_data_set, dest_data_set)¶
Bases:
objectBiases and noise of each pixel in the data set. Use
PixelProperties.from_data()orPixelProperties.from_bias()to create it.- bias¶
Image of biases of each pixel
- Type:
array-like
- widths¶
Noises in each pixel, defined as the standard deviation of the Gaussian error approximation.
- Type:
array-like
- default()¶
Get the default pixel properties for a data set with no bias and not self-biased.
- from_bias(dest_data_set, max_frames=10000, use_pool=True)¶
Get the pixel properties of a bias data set
- get_prob(image, true_n, mask=None)¶
Get the probability for the observed counts to have been produced given a true source count.
- Parameters:
image (array-like) – Detected image (e.g. from frame.image)
true_n (int) – True number of counts
mask (array of bool, optional) – If you only wish to get probabilities for a subset of the full image, provide that subset as the iamge argument and supply the pixel mask here.
- Return type:
array-like
The probability for each pixel to have originated from the given true source count.
- load()¶
- save(filename, clobber)¶
Save the pixel properties to a file
- Parameters:
filename (str) – Name of the output file
- class lightspeedpy.Region(filename)¶
Bases:
objectClass to store DS9 regions.
Notes
All regions are assumed to be stored in ciao format.
All coordinates must be physical
- check_inside_absolute(x, y)¶
Return True if (x, y) is inside the region
- lightspeedpy.add_dataset_args(parser)¶
Add the standard lightspeedpy arguments to an argparse parser. These include input, output, bias, self-bias, flat, flat, frames, timing-offset, and clobber.
- Parameters:
parser (argparse parser) – Parser to which to add arguments
- lightspeedpy.get_dataset(args)¶
Get the
DataSetfrom an argparse parser, assuming the arguments correspond to those created bycli.add_dataset_args().- Parameters:
args (argparse args) – Command line arguments