popsynth.population module

class popsynth.population.Population(luminosities: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], distances: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], known_distances: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], known_distance_idx: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], unknown_distance_idx: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], fluxes: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], flux_obs: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], selection: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], flux_sigma: float, r_max: float, n_model: int, lf_params: Dict[str, Any], spatial_params: Optional[Dict[str, Any]] = None, model_spaces: Optional[Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]] = None, seed: int = 1234, name: Optional[str] = None, spatial_form: Optional[Dict[str, Any]] = None, lf_form: Optional[Dict[str, Any]] = None, auxiliary_quantities: Optional[SecondaryStorage] = None, truth: Dict[str, float] = {}, graph: Optional[Dict[str, Any]] = None, theta=None, phi=None, pop_synth: Optional[Dict[str, Any]] = None, probability: Optional[ndarray] = None)[source]

Bases: object

__init__(luminosities: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], distances: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], known_distances: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], known_distance_idx: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], unknown_distance_idx: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], fluxes: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], flux_obs: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], selection: Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], flux_sigma: float, r_max: float, n_model: int, lf_params: Dict[str, Any], spatial_params: Optional[Dict[str, Any]] = None, model_spaces: Optional[Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]] = None, seed: int = 1234, name: Optional[str] = None, spatial_form: Optional[Dict[str, Any]] = None, lf_form: Optional[Dict[str, Any]] = None, auxiliary_quantities: Optional[SecondaryStorage] = None, truth: Dict[str, float] = {}, graph: Optional[Dict[str, Any]] = None, theta=None, phi=None, pop_synth: Optional[Dict[str, Any]] = None, probability: Optional[ndarray] = None) None[source]

A population container for all the properties of the population.

Parameters
  • luminosities (ArrayLike) – The luminosities

  • distances (ArrayLike) – The distances

  • known_distances (ArrayLike) – The known distances

  • known_distance_idx (ArrayLike) – The index of the known distances

  • unknown_distance_idx (ArrayLike) – The index of the unknown distances

  • fluxes (ArrayLike) – The latent fluxes

  • flux_obs (ArrayLike) – The observed fluxes

  • selection (ArrayLike) – The selection vector

  • flux_sigma (float) – The uncertainty on the observed flux

  • r_max (float) – The maximum distance of the survey

  • n_model (int) – Number of models

  • lf_params (Dict[str, Any]) – Luminosity function parameters

  • spatial_params (Optional[Dict[str, Any]]) – Spatial distribution parameters

  • model_spaces (ArrayLike) – Model spaces

  • seed (int) – Random seed

  • name (str) – Name of the population

  • spatial_form (Optional[Dict[str, Any]]) – Form of the spatial distribution

  • lf_form (Optional[Dict[str, Any]]) – Form of the luminosity function

  • auxiliary_quantities (Optional[Dict[str, Any]]) – Dict of auxiliary quantities

  • truth (Dict[str, float]) – Dict of true values

  • graph (Optional[Dict[str, Any]]) – Graph of generative model

  • theta – Theta

  • phi – Phi

  • pop_synth (Optional[Dict[str, Any]]) – Population synth

property graph

The networkx graph of the population

Returns

property probability: Optional[SimulatedVariable]
property pop_synth: Dict[str, Any]

Dictionary population synth used to create this population

property truth

The simulated truth parameters

property flux_sigma: float

The simulated flux sigma

property theta: SimulatedVariable

The polar angle of the objects

property phi: SimulatedVariable

The phi angle of the objects

property dec: SimulatedVariable

The declination of the objects

property ra: SimulatedVariable

The right ascension of the objects

property luminosities: SimulatedVariable

the luminosities of the objects

Returns

property luminosities_latent: ndarray

The true luminosities of the objects. These are always latent as one cannot directly observe them.

property distances: SimulatedVariable

The distances to the objects

property known_distances: ndarray

The observed distances

property selection: ndarray

The selection vector

property fluxes: SimulatedVariable

the fluxes of the objects

Returns

property fluxes_latent: ndarray

The latent fluxes of the objects

property fluxes_observed: ndarray

All of the observed fluxes, i.e., scattered with error

property selected_fluxes_observed: ndarray

The selected obs fluxes

property selected_fluxes_latent: ndarray

The selected latent fluxes

property selected_distances: ndarray

The selected distances. Note, this is different than the KNOWN distances.

property hidden_fluxes_observed: ndarray

The observed fluxes that are hidden by the selection

property hidden_distances: ndarray

The distances that are hidden by the selection

property hidden_fluxes_latent: ndarray

The latent fluxes that are hidden by the selection

property hard_cut: bool
property distance_probability: float
property luminosity_parameters
property n_objects: int

The number of objects in the population

property n_detections: int

The number of DETECTED objects in the population

property n_non_detections: int

The number of NON-DETECTED objects in the population

property has_detections: bool

If the population has detections

property spatial_parameters

spatial parameters

Returns

to_stan_data() dict[source]

Create Stan input

writeto(file_name: str) None[source]

Write population to an HDF5 file

Parameters

file_name (str) – Name of the file

addto(file_name: str, group_name: str) None[source]

Write population to a group in an existing HDF5 file.

Parameters
  • file_name (str) – Name of the file

  • group_name (str) – Name of the group

_writeto(f)[source]

Write to an HDF5 file or group.

Parameters

f – h5py file or group handle

classmethod from_file(file_name: str)[source]

Load a population from a file.

Parameters

file_name (str) – Name of the file

classmethod from_group(file_name: str, group_name: str)[source]

Load a population from a group in a file.

Parameters
  • file_name (str) – Name of the file

  • group_name (str) – Name of the group

classmethod _loadfrom(f)[source]

Load from and HDF5 file or group.

Parameters

f – h5py file or group handle

to_sub_population(observed: bool = True) Population[source]

Create a population that is down selected from either the observed or unobserved population

Parameters

observed (bool) – Extract the observed or unobserved object

Returns

A new population object

Return type

Population

display()[source]

Display the simulation parameters.

display_true_fluxes(ax=None, flux_color='#8F2727', **kwargs)[source]

Display the fluxes.

Parameters
  • ax – Axis on which to plot

  • flux_color – Color of fluxes

display_obs_fluxes(ax=None, flux_color='#8F2727', **kwargs)[source]

Display the observed fluxes.

Parameters
  • ax – Axis on which to plot

  • flux_color – Color of fluxes

display_fluxes(ax=None, true_color='#dec3c3', obs_color='#8F2727', arrow_color='k', with_arrows=True, **kwargs)[source]

Display the fluxes.

Parameters
  • ax – Axis on which to plot

  • true_color – Color of true values

  • obs_color – Color of obs values

  • arrow_color – Color of arrows

  • with_arrows – If True, display arrows

display_luminosities(ax=None, true_color='#dec3c3', obs_color='#8F2727', **kwargs)[source]

Display the luminosities

Parameters
  • ax – Axis on which to plot

  • true_color – Color of true values

  • obs_color – Color of obs values

display_obs_fluxes_sphere(cmap='magma', distance_transform=None, use_log=False, background_color='white', show=True, **kwargs)[source]
display_hidden_fluxes_sphere(cmap='magma', distance_transform=None, use_log=False, background_color='white', show=True, **kwargs)[source]
display_flux_sphere(seen_cmap='Reds', unseen_cmap='Blues', distance_transform=None, use_log=False, background_color='white', **kwargs)[source]
display_distances(ax=None)[source]

Display the distances

Parameters

ax – Axis on which to plot