popsynth.population_synth module

class popsynth.population_synth.PopulationSynth(spatial_distribution: SpatialDistribution, luminosity_distribution: Optional[LuminosityDistribution] = None, seed: int = 1234)[source]

Bases: object

__init__(spatial_distribution: SpatialDistribution, luminosity_distribution: Optional[LuminosityDistribution] = None, seed: int = 1234)[source]

Basic and generic population synth. One specifies the spatial and luminosity distribution OR derived luminosity distribution and everything is setup.

Parameters
  • spatial_distribution (SpatialDistribution) – The spatial distribution to sample locations from

  • luminosity_distribution (LuminosityDistribution) – The optional luminosity distribution

  • seed (int) – Random seed

clean(reset: bool = False)[source]

Clean the auxiliary samplers, selections, etc from the population synth

Parameters

reset (bool) – If True, reset any attached distributions and samplers

write_to(file_name: str) None[source]

Write the population synth to a YAML file.

Parameters

file_name (str) – the file name of the output YAML

to_dict() Dict[str, Any][source]

Convert the population synth to a dictionary

Returns

Popsynth dict

Return type

Dict[str, Any]

classmethod from_dict(input: Dict[str, Any]) PopulationSynth[source]

Build a PopulationSynth object from a dictionary

Parameters

input (Dict[str, Any]) – the dictionary from which to build

Returns

Popsynth object

Return type

PopulationSynth

classmethod from_file(file_name: str) PopulationSynth[source]

read the population in from a yaml file

Parameters

file_name – the file name of the population synth

property spatial_distribution: SpatialDistribution
property luminosity_distribution: Optional[LuminosityDistribution]
add_model_space(name, start, stop, log=True)[source]

Add a model space for stan generated quantities

Parameters
  • name – Name that Stan will use

  • start – Start of the grid

  • stop – Stop of the grid

  • log – Use log10 or not

add_auxiliary_sampler(auxiliary_sampler: Union[DerivedLumAuxSampler, AuxiliarySampler])[source]

Add an auxiliary sampler or derived luminosity sampler to the population synth.

Parameters

auxiliary_sampler (Union[DerivedLumAuxSampler, AuxiliarySampler]) – The auxiliary_sampler

add_observed_quantity(auxiliary_sampler: Union[DerivedLumAuxSampler, AuxiliarySampler])[source]

Add an auxiliary sampler or derived luminosity sampler to the population synth

Parameters

auxiliary_sampler (Union[DerivedLumAuxSampler, AuxiliarySampler]) – The auxiliary_sampler

set_distance_selection(selector: SelectionProbability) None[source]

Set the selection type for the distance.

Parameters

selector (SelectionProbability) – The selector

set_flux_selection(selector: SelectionProbability) None[source]

Set the selection type for the flux

Parameters

selector (SelectionProbability) – The selector

add_spatial_selector(spatial_selector: SelectionProbability) None[source]

Add a spatial selector into the mix

Parameters

spatial_selector (SelectionProbability) – The spatial selector

property name: str
draw_log10_fobs(f, f_sigma, size=1) ndarray[source]

Draw the log10 of the the fluxes.

draw_log_fobs(f, f_sigma, size=1) ndarray[source]

Draw the log10 of the the fluxes.

draw_survey(flux_sigma: Optional[float] = None, log10_flux_draw: bool = True, n_samples: Optional[int] = None, normalize: bool = False) Population[source]

Draw the total survey and return a Population object.

This will sample all attached distributions and apply selection functions.

If a value of flux_sigma is given, the log10 observed fluxes are sampled with measurement error.

Parameters
  • flux_sigma (Optional[float]) – The homoskedastic sigma for the flux in log10 space

  • log10_flux_draw (bool) – if True, fluxes are drawn in log space

Returns

a Population object

Return type

Population

display() None[source]

Display the simulation parameters.

property graph
_build_graph()[source]

Builds the graph for all the samplers.