target.collection#

This module defines collection objects for grouping and operating on multiple targets or transients simultaneously.

skysurvey.target.collection.targets_from_collection(transientcollection)[source]#

Get targets from a transient collection.

skysurvey.target.collection.broadcast_mapping(value, ntargets)[source]#

Broadcast a value to a given number of targets.

Parameters:
  • value (array or scalar) – Input value to broadcast. If the input has more than one dimension, broadcasting is applied along the first axis.

  • ntargets (int) – Number of targets to broadcast the value to.

Returns:

Broadcasted array of shape:

  • (ntargets,) if value is 1D or scalar

  • (ntargets, N) if value is 2D or higher, where N is the size of the last dimension of value.

Return type:

ndarray

class skysurvey.target.collection.TargetCollection(targets=None)[source]#

Bases: object

A collection of targets.

Parameters:
  • targets (list, optional) – A list of targets. The default is None.

  • _COLLECTION_OF (type, optional) – The type of target in the collection. The default is Target.

  • _TEMPLATES (list, optional) – A list of templates. The default is [].

as_targets()[source]#

Convert the collection into a list of same-template targets.

call_down(which, margs=None, allow_call=True, **kwargs)[source]#

Call a method on each target in the collection.

set_targets(targets)[source]#

Set the targets in the collection.

get_model_parameters(entry, key, default=None)[source]#

Get the model parameters for each target in the collection.

get_data(keys='_KIND', colname='kind')[source]#

Get a concatenated dataframe of the data from each target.

get_target_template(index, as_model=False, set_magabs=False)[source]#

Get the template for a given target.

Parameters:
  • index (int) – Index of a target (see self.data.index) to set the template parameters to that of the target.

  • as_model (bool, optional) – should this return the sncosmo.Model (True) or the skysurvey.Template (for info sncosmo.Model => skysurvey.Template.sncosmo_model)

  • set_magabs (bool, optional) – should the peal magnitude of the template be set to magabs ?

  • **kwargs – Goes to seld.template.get() and passed to sncosmo.Model.

Returns:

An instance of the template (or its associated sncosmo.Model). (see as_model)

Return type:

skysurvey.Template or sncosmo.Model

show_lightcurve(band, index, params=None, ax=None, fig=None, colors=None, time_range=[-20, 50], npoints=500, zp=25, zpsys='ab', format_time=True, t0_format='mjd', in_mag=False, invert_mag=True, **kwargs)[source]#

Show the lightcurve of a given target.

Parameters:
  • band (str) – The band to show.

  • index (int) – The index of the target.

  • params (dict, optional) – Parameters to pass to get_target_template. The default is {}.

  • ax (matplotlib.axes.Axes, optional) – The axes to plot on. The default is None.

  • fig (matplotlib.figure.Figure, optional) – The figure to plot on. The default is None.

  • colors (list, optional) – A list of colors to use. The default is None.

  • time_range (list, optional) – The time range to plot. The default is [-20, 50].

  • npoints (int, optional) – The number of points to plot. The default is 500.

  • zp (float, optional) – The zero point to use. The default is 25.

  • zpsys (str, optional) – The zero point system to use. The default is “ab”.

  • format_time (bool, optional) – Whether to format the time axis. The default is True.

  • t0_format (str, optional) – The format of the time axis. The default is “mjd”.

  • in_mag (bool, optional) – Whether to plot in magnitudes. The default is False.

  • invert_mag (bool, optional) – Whether to invert the magnitude axis. The default is True.

  • **kwargs – Additional keyword arguments to pass to template.show_lightcurve.

Returns:

The figure containing the plot.

Return type:

matplotlib.figure.Figure

to_transient(keys=None, **kwargs)[source]#

Convert the collection to a Transient object.

property targets#

The list of targets in the collection.

property data#

The data of the collection.

property ntargets#

The number of targets in the collection.

property target_ids#

The IDs of the targets in the collection.

property models#

The models of the targets in the collection.

property template#

A shortcut to self.templates for self-consistency.

property templates#

The templates of the targets in the collection.

property template_names#
class skysurvey.target.collection.TransientCollection(targets=None)[source]#

Bases: TargetCollection

A collection of transients.

Parameters:
  • targets (list, optional) – A list of targets. The default is None.

  • _COLLECTION_OF (type, optional) – The type of transient in the collection. The default is Transient.

set_rates(float_or_func)[source]#

Call set_rate for each target in the collection.

update_model(rate_update=True, **kwargs)[source]#

Call update_model for each target in the collection.

get_rates(z, relative=False, **kwargs)[source]#

Get the rates for each target in the collection.

draw(size=None, zmin=None, zmax=None, tstart=None, tstop=None, nyears=None, inplace=True, shuffle=True, rng=None, **kwargs)[source]#

Draw the transients in the collection.

rngNone, int, (Bit)Generator, optional

= ignored if size is None = seed for the random number generator. (doc adapted from numpy’s np.random.default_rng docstring. See that documentation for details.) If None, an unpredictable entropy will be pulled from the OS. If an int, (>0), it will set the initial BitGenerator state. If a (Bit)Generator, it will be returned as a Generator unaltered.

class skysurvey.target.collection.CompositeTransient(targets=None)[source]#

Bases: TransientCollection

A composite transient.

Parameters:
  • targets (list, optional) – A list of targets. The default is None.

  • _COLLECTION_OF (type, optional) – The type of transient in the collection. The default is Transient.

  • _KIND (str, optional) – The kind of transient. The default is “unknown”.

  • _RATE (float, optional) – The rate of the transient. The default is 1e5.

  • _MAGABS (tuple, optional) – The absolute magnitude of the transient. The default is (-18, 1).

classmethod from_draw(size=None, model=None, templates=None, zmax=None, tstart=None, tstop=None, zmin=0, nyears=None, skyarea=None, rate=None, effect=None, **kwargs)[source]#

Load the instance from a random draw of targets given the model.

Parameters:
  • size (int, optional) – Number of target you want to sample. If None, 1 is assumed. Ignored if nyears is given. By default None.

  • model (dict, optional) – Defines how template parameters are drawn and how they are connected. The model will update the default cls._MODEL if any. If None, cls._MODEL is used as default. By default None.

  • templates (str, optional) – Name of the template (sncosmo.Model(source)). If None, cls._TEMPLATE is used as default. By default None.

  • zmax (float, optional) – Maximum redshift to be simulated. By default None.

  • tstart (float, str, optional) – Starting time of the simulation. If a string is given, it is converted to mjd. By default None.

  • tstop (float, str, optional) – Ending time of the simulation. If a string is given, it is converted to mjd. If tstart and nyears are both given, tstop will be overwritten by tstart + 365.25 * nyears. By default None.

  • zmin (float, optional) – Minimum redshift to be simulated. By default 0.

  • nyears (float, optional) –

    If given, nyears will set:

    • size: it will be the number of target expected up to zmax in the given number of years. This uses get_rate(zmax).

    • tstop: tstart + 365.25 * nyears

    By default None.

  • skyarea (None, str, geometry, optional) –

    Sky area to be considered.

    • str: ‘full’ (equivalent to None), [‘extra-galactic’, not implemented yet]

    • geometry: shapely.Geometry

    • None: full sky

    By default None.

  • rate (float, callable, optional) –

    If a float is given, it is assumed to be the number of targets per Gpc3. If a callable is given, it is supposed to be a function of z that returns the volumetric rate as a function of wavelength.

    By default None.

  • effect ([type], optional) – [description]. By default None.

  • **kwargs – Goes to self.draw().

Returns:

The loaded instance.

Return type:

CompositeTransient

See also

from_setting: loads an instance given model parameters (dict)

property targets#

The list of targets forming the composite transients.

property magabs#

The absolute magnitudes of the transients in the collection.

property rate#

The rate of the transients in the collection.

If float, it is assumed to be the volumetric rate in Gpc-3 / yr.

property ntargets#

The number of templates in the collection.

class skysurvey.target.collection.TSTransientCollection(targets=None)[source]#

Bases: TransientCollection

A collection of time-series transients.

Parameters:
  • targets (list, optional) – A list of targets. The default is None.

  • _COLLECTION_OF (type, optional) – The type of transient in the collection. The default is TSTransient.

classmethod from_draw(sources, size=None, nyears=None, rates=1000.0, magabs=None, magscatter=None, **kwargs)[source]#

Load the instance from a random draw of targets given the model.

classmethod from_sncosmo(sources, rates=1000.0, magabs=None, magscatter=None)[source]#

Load the instance from a list of sources (and relative rates).