velociraptor.observations.objects module¶
Objects for observational data plotting.
Tools for adding in extra (e.g. observational) data to plots.
Includes an object container and helper functions for creating and reading files.
-
velociraptor.observations.objects.save_cosmology(handle: h5py._hl.files.File, cosmology: astropy.cosmology.core.Cosmology)[source]¶ Save the (astropy) cosmology to a HDF5 dataset.
Parameters: - handle (h5py.File) – h5py file handle to save the cosmology to. This is performed by creating a cosmology group and setting attributes.
- cosmology (astropy.cosmology.Cosmology) – The Astropy cosmology instance to save to the HDF5 file. This is performed by extracting all of the key variables and saving them as either floating point numbers or strings.
Notes
This process can be reversed by using load_cosmology.
-
velociraptor.observations.objects.load_cosmology(handle: h5py._hl.files.File)[source]¶ Save the (astropy) cosmology to a HDF5 dataset.
Parameters: handle (h5py.File) – h5py file handle to read the cosmology from. Returns: Astropy cosmology instance extracted from the HDF5 file. Return type: astropy.cosmology.Cosmology
-
class
velociraptor.observations.objects.ObservationalData[source]¶ Bases:
objectObservational data object. Contains routines for both writing and reading HDF5 files containing the observations, as well as plotting.
-
name¶ Name of the observation for users to identifty
Type: str
-
x_units¶ Units for horizontal axes
Type: unyt_quantity
-
y_units¶ Units for vertical axes
Type: unyt_quantity
-
x¶ Horizontal data points
Type: unyt_array
-
y¶ Vertical data points
Type: unyt_array
-
x_scatter¶ Scatter in horizontal direction. Can be None, or an unyt_array of shape 1XN (symmetric) or 2XN (non-symmetric) such that it can be passed to plt.errorbar easily.
Type: Union[unyt_array, None]
-
y_scatter¶ Scatter in vertical direction. Can be None, or an unyt_array of shape 1XN (symmetric) or 2XN (non-symmetric) such that it can be passed to plt.errorbar easily.
Type: Union[unyt_array, None]
-
x_comoving¶ Whether or not the horizontal values are comoving (True) or physical (False)
Type: bool
-
y_comoving¶ Whether or not the vertical values are comoving (True) or physical (False)
Type: bool
-
x_description¶ Default label for horizontal axis (without units), also a description of the variable.
Type: str
-
y_description¶ Default label for horizontal axis (without units), also a description of the variable.
Type: str
-
filename¶ Filename that the data was read from, or was written to.
Type: str
-
comment¶ A free-text comment describing the data, including e.g. which cosmology and IMF it is calibrated to.
Type: str
-
citation¶ Short citation for data, e.g. Author et al. (Year) (Project), such as Baldry et al. (2012) (GAMA)
Type: str
-
bibcode¶ Bibcode for citation, this can be found on the NASA ADS.
Type: str
-
redshift¶ Redshift at which the data is collected at. If a range, use the mid-point.
Type: float
-
redshift_lower¶ Lowest redshift at which the data is collected at. Used to determine whether it should be plotted on a given figure.
Type: float
-
redshift_upper¶ Highest redshift at which the data is collected at. Used to determine whether it should be plotted on a given figure.
Type: float
-
plot_as¶ Whether the data should be plotted as points (typical for observations) or as a line (typical for simulation data). Allowed values:
- points
- line
Type: Union[str, None]
-
cosmology¶ Astropy cosmology that the data has been corrected to.
Type: Cosmology
-
plot_as= None
-
load(filename: str, prefix: Optional[str] = None)[source]¶ Loads the observations from file.
Parameters: - filename (str) – The filename to load the data from. Probably should end in .hdf5.
- prefix (str, optional) – An optional prefix to all fields that enables multiple
observational datasets to be saved in a single file. Not
for general use, only within
MultiRedshiftObservationalData. If a prefix is used, cosmology is not saved.
-
write(filename: str, prefix: Optional[str] = None)[source]¶ Writes the observations to file.
Parameters: - filename (str) – The filename to write the data to. Probably should end in .hdf5.
- prefix (str, optional) – An optional prefix to all fields that enables multiple
observational datasets to be saved in a single file. Not
for general use, only within
MultiRedshiftObservationalData. If a prefix is used, cosmology is not saved.
-
associate_x(array: unyt.array.unyt_array, scatter: Optional[unyt.array.unyt_array], comoving: bool, description: str)[source]¶ Associate an x quantity with this observational data instance.
Parameters: - array (unyt_array) – The array of (horizontal) data points, including units.
- scatter (Union[unyt_array, None]) – The array of scatter (1XN or 2XN) in the horizontal co-ordinates with associated units.
- comoving (bool) – Whether or not the horizontal values are comoving.
- description (str) – Short description of the data, e.g. Stellar Masses
-
associate_y(array: unyt.array.unyt_array, scatter: Optional[unyt.array.unyt_array], comoving: bool, description: str)[source]¶ Associate an y quantity with this observational data instance.
Parameters: - array (unyt_array) – The array of (vertical) data points, including units.
- scatter (Union[unyt_array, None]) – The array of scatter (1XN or 2XN) in the vertical co-ordinates with associated units.
- comoving (bool) – Whether or not the vertical values are comoving.
- description (str) – Short description of the data, e.g. Stellar Masses
-
associate_citation(citation: str, bibcode: str)[source]¶ Associate a citation with this observational data instance.
Parameters: - citation (str) – Short citation, formatted as follows: Author et al. (Year) (Project), e.g. Baldry et al. (2012) (GAMA)
- bibcode (str) – Bibcode for the paper the data was extracted from, available from the NASA ADS or publisher. E.g. 2012MNRAS.421..621B
-
associate_name(name: str)[source]¶ Associate a name with this observational data instance.
Parameters: name (str) – Short name to describe the dataset.
-
associate_comment(comment: str)[source]¶ Associate a comment with this observational data instance.
Parameters: comment (str) – A free-text comment describing the data, including e.g. which cosmology and IMF it is calibrated to.
-
associate_redshift(redshift: float, redshift_lower: Optional[float] = None, redshift_upper: Optional[float] = None)[source]¶ Associate the redshift that the observations were taken at with this observational data instance.
Parameters: - redshift (float) – Redshift at which the data is collected at. If a range, use the mid-point.
- redshift_lower (Optional[float]) – Lower bound for this set of observations. Used to determine if plotting is viable, and should always be present in the case where a multiple redshift dataset is used.
- redshift_upper (Optional[float]) – Upper bound for this set of observations. Used to determine if plotting is viable, and should always be present in the case where a multiple redshift dataset is used.
-
associate_plot_as(plot_as: str)[source]¶ Associate the ‘plot_as’ field - this should either be line or points.
Parameters: plot_as (str) – Either points or line
-
associate_cosmology(cosmology: astropy.cosmology.core.Cosmology)[source]¶ Associate a cosmology with this dataset that it has been corrected for. This should be an astropy cosmology instance.
Parameters: cosmology (astropy.cosmology.Cosmology) – Astropy cosmology instance describing what cosmology the data has been corrected to.
-
plot_on_axes(axes: matplotlib.axes._axes.Axes, errorbar_kwargs: Optional[dict] = None)[source]¶ Plot this set of observational data as an errorbar().
Parameters: - axes (plt.Axes) – The matplotlib axes to plot the data on. This will either plot the data as a line or a set of errorbar points, with the short citation (self.citation) being included in the legend automatically.
- errorbar_kwargs (dict) – Optional keyword arguments to pass to plt.errorbar.
-
-
class
velociraptor.observations.objects.MultiRedshiftObservationalData[source]¶ Bases:
objectMulti-redshift version of
ObservationalDataclass, which should be used instead of theObservationalDataclass for reading files, and writing multiple redshift files.Essentially, this contains multiple instances of
ObservationalData, and allows for multiple redshift data to be read transparently.-
code_version= '0.16.1'¶
-
maximum_number_of_returns= 1024¶
-
get_datasets_overlapping_with(redshifts: List[float] = [0.0, 1000.0]) → List[velociraptor.observations.objects.ObservationalData][source]¶ Gets individual redshift datasets overlapping with the specified redshift range. The check is performed inclusively, so if you ask for overlaps with [0.25, 0.75], and an observation has a redshift range of [0.75, 1.25], it will be included. Note that
maximum_number_of_returnsmodifies the behaviour of this function, and the maximum length of the returned list will be the same as that attribute.Parameters: redshifts (List[float]) – Redshifts to check for overlaps with. This defaults to the range [0.0, 1000.0], and hence should overlap with all reasonable datasets. Notes
You can access this ability in a slightly more user-friendly way using the
velociraptor.observations.load_observations()function.Datasets are returned in order of their scale-factor proximity to the centre of the range specified in
redshifts.
-
associate_dataset(dataset: velociraptor.observations.objects.ObservationalData)[source]¶ Associate an individual redshift dataset with this object.
Parameters: dataset (ObservationalData) – Instance of ObservationalData that may or may not be completed; comments are handled at the top level and are over-written. In total, citation,bibcode,name,comment, andcosmologyare shared.
-
associate_citation(citation: str, bibcode: str)[source]¶ Associate a citation with this observational data instance.
Parameters: - citation (str) – Short citation, formatted as follows: Author et al. (Year) (Project), e.g. Baldry et al. (2012) (GAMA)
- bibcode (str) – Bibcode for the paper the data was extracted from, available from the NASA ADS or publisher. E.g. 2012MNRAS.421..621B
-
associate_name(name: str)[source]¶ Associate a name with this observational data instance.
Parameters: name (str) – Short name to describe the dataset.
-
associate_comment(comment: str)[source]¶ Associate a comment with this observational data instance.
Parameters: comment (str) – A free-text comment describing the data, including e.g. which cosmology and IMF it is calibrated to.
-
associate_cosmology(cosmology: astropy.cosmology.core.Cosmology)[source]¶ Associate a cosmology with this dataset that it has been corrected for. This should be an astropy cosmology instance.
Parameters: cosmology (astropy.cosmology.Cosmology) – Astropy cosmology instance describing what cosmology the data has been corrected to.
-
associate_maximum_number_of_returns(maximum_number_of_returns: int)[source]¶ Associate a maximum number of returned datasets with this object. This number will give the maximum number of datasets that are returned in a call to
load_datasets. This is particularly useful in the case where you want to provide a large number of fits and only want to show a single curve on the figure.Parameters: maximum_number_of_returns (int) – The maximum number of datasets to plot simultaneously.
-