qusp.target module¶
Provides support for working with BOSS targets.
In qusp, a target is identified by a unique plate-mjd-fiber. They are implemented as dictionaries and must have at least ‘plate’, ‘mjd’, and ‘fiber’ keys specified. The Target model is designed to be flexible, in that other attributes can be added to targets as needed.
Examples
Construct a target from a string identifier:
target = qusp.target.Target.from_string('plate-mjd-fiber')
Construct a target from a dictionary:
target = qusp.target.Target({'target':'plate-mjd-fiber'})
Read a target list along with ra, dec, and z columns:
targets = qusp.target.load_target_list(filename,
fields=[('ra', float, 1), ('dec', float, 2), ('z', float, 3)])
Save a target list along with z and sn fields:
qusp.target.save_target_list(filename, targets, fields=['z', 'sn'])
Iterate over combined spectra for a list targets:
for target, spectrum in qusp.target.get_combined_spectra(targets):
...
Iterate over plates for a list of targets:
for target, spplate in qusp.target.get_target_plates(targets):
spectrum = qusp.read_combined_spectrum(spplate, target)
...
-
class
qusp.target.
Target
(*args, **kwargs)¶ Bases:
dict
Represents a BOSS target.
Parameters: - args – Variable length argument list.
- kwargs – Arbitrary keyword arguments.
Raises: AssertionError
– if ‘target’ key is not specified-
classmethod
from_plate_mjd_fiber
(plate, mjd, fiber)¶ Returns a Target object constructed from plate, mjd, fiber.
Parameters: Returns: Target
object
-
classmethod
from_string
(target_string)¶ Returns a Target object constructed from a target string identifier.
Parameters: target_string (str) – a target string identifier. Returns: Target
object
-
to_string
()¶ Returns the standard plate-mjd-fiber string represntation of the target.
Returns: plate-mjd-fiber string represntation of target
-
qusp.target.
add_args
(parser)¶ Adds arguments to the provided command-line parser.
Parameters: parser (argparse.ArgumentParser) – an argument parser
-
qusp.target.
get_combined_spectra
(targets, paths=None, sort=True, verbose=False, tpcorr=None)¶ A generator that yields (target, spectrum) tuples for the provided list of targets. With sort=True, the targets will be sorted by plate-mjd-fiber to reduce the number of io operations.
Parameters: - targets (
Target
) – list ofTarget
objects to iterate through. - boss_path (str, optional) – path to boss data directory. Default is to look this up using env var.
- sort (bool, optional) – Whether or not to sort the provided targets by plate-mjd-fiber. Defaults to True.
- verbose (bool, optional) – Whether or not to print verbose output. Defaults to False.
Yields: The next tuple
(target, spectrum)
, wheretarget
is aTarget
andspectrum
is aqusp.spectrum.Spectrum
that corresponds to the target’s coadded spectrum.- targets (
-
qusp.target.
get_combined_spectrum
(target, paths=None)¶ Returns the coadded spectrum of the specified target.
Parameters: - target (
Target
) – a target - paths (
qusp.paths.Paths
, optional) – paths object that knows where the location of the boss data dir.
Returns: Coadded spectrum of the specified target.
- target (
-
qusp.target.
get_corrected_spectrum
(target, tpcorr, paths=None)¶ Returns the coadded spectrum of the specified target.
Parameters: - target (
Target
) – a target - tpcorr (hdf5 File object) – hdf5 file with throughput corrections
- paths (
qusp.paths.Paths
, optional) – paths object that knows where the location of the boss data dir.
Returns: Coadded spectrum of the specified target.
- target (
-
qusp.target.
get_lite_spectra
(targets)¶
-
qusp.target.
get_lite_spectrum
(target, paths=None)¶
-
qusp.target.
get_target_plates
(targets, boss_path=None, sort=True, verbose=False)¶ A generator that yields (target,spplate) tuples for the provided list of targets. With sort=True, the targets will be sorted by plate-mjd-fiber to reduce the number of io operations.
Parameters: - targets (
Target
) – list ofTarget
objects to iterate through. - boss_path (str, optional) – path to boss data directory. Default is to look this up using env var.
- sort (bool, optional) – Whether or not to sort the provided targets by plate-mjd-fiber. Defaults to True.
- verbose (bool, optional) – Whether or not to print verbose output. Defaults to False.
Yields: The next tuple
(target, spplate)
, wheretarget
is aTarget
andspplate
is the corresponding FITS file containing its coadded spectrum from the list of targets.- targets (
-
qusp.target.
load_target_list
(filename, fields=None, verbose=False)¶ Loads a target data from a text file.
The first column must be plate-mjd-fiber target identifier. Use the fields argument to specify additional columns to read. Must specify a (name, type, column index) tuple for each field.
Parameters: - filename (str) – The filename to load.
- fields (list, optional) – A list of columns to read, see example. Defaults to None.
- verbose (bool, optional) – Whether or not to print verbose output. Defaults to False.
Returns: list of
Target
objects.
-
qusp.target.
load_target_list_from_args
(args, fields=None)¶ Loads a target list from a text file specified using the default target arguments.
Parameters: - args (argparse.Namespace) – argparse argument namespace
- fields (list, optional) – A list of columns to read, see example. Defaults to None.
Returns: list of
Target
objects.
-
qusp.target.
save_target_list
(filename, targets, fields=None, verbose=False)¶ Writes a list of targets to the provided file.
By default, only the target plate-mjd-fiber is written to file. Use the fields argument to specify additional target fields to save.
Parameters: