coscon.toast_helper module

class coscon.toast_helper.AvesBands(data: Dict[str, float | int | str], validate_schema: bool = True)[source]

Bases: GenericDictStructure

a class describing the bands of Aves.

data: Dict[str, float | int | str]
schema: ClassVar[dict] = {<class 'str'>: {'NET': Or(<class 'float'>, <class 'numpy.float64'>), 'alpha': Or(<class 'float'>, <class 'int'>, <class 'numpy.float64'>, <class 'numpy.int64'>), 'bandpass': <class 'str'>, 'bandwidth': Or(<class 'float'>, <class 'int'>, <class 'numpy.float64'>, <class 'numpy.int64'>), 'center': Or(<class 'float'>, <class 'numpy.float64'>), 'fknee': Or(<class 'float'>, <class 'numpy.float64'>), 'fmin': Or(<class 'float'>, <class 'numpy.float64'>), 'fwhm': Or(<class 'float'>, <class 'numpy.float64'>)}}
class coscon.toast_helper.AvesDetectors(data: Dict[str, str | float | int | np.ndarray | None], validate_schema: bool = True)[source]

Bases: GenericFocalPlane

a class describing the detectors of Aves.

similar to FakeFocalPlane

data: Dict[str, str | float | int | np.ndarray | None]
plot(x_min: float | None = None, x_max: float | None = None, y_min: float | None = None, y_max: float | None = None, width: float | None = None, bleed: float | None = None, fontname: str = 'TeX Gyre Schola', wire: bool = False, wire_TB: bool = False, wire_connectionstyle: str | None = None)[source]

Plot the detectors in Azimuthal equidistant projection with orientation.

For wire_connectionstyle, use ‘arc3’ to draw straight-line. See more in https://matplotlib.org/stable/gallery/userdemo/connectionstyle_demo.html#sphx-glr-gallery-userdemo-connectionstyle-demo-py

schema: ClassVar[dict] = {<class 'str'>: {'UID': Or(<class 'int'>, <class 'numpy.int64'>), 'band': <class 'str'>, 'fwhm': Or(<class 'float'>, <class 'numpy.float64'>), 'orient': And(<class 'str'>, <function <lambda>>), 'pixel': <class 'str'>, 'pixtype': <class 'str'>, 'pol': And(<class 'str'>, <function <lambda>>), 'quat': And(<class 'numpy.ndarray'>, <function <lambda>>), 'wafer': <class 'str'>, Optional('handed'): Or(None, And(<class 'str'>, <function <lambda>>))}}
class coscon.toast_helper.AvesHardware(data: 'Dict[str, dict]', validate_schema: 'bool' = True)[source]

Bases: GenericDictStructure

data: Dict[str, dict]
property dataframe: DataFrame[source]

DataFrame representation of the hardware

property dataframe_with_azimuthal_equidistant_projection_with_orientation: DataFrame[source]

DataFrame representation of the hardware

classmethod from_dataframe(df: DataFrame, validate_schema=True)[source]

Create Hardware from a dataframe representation

reorder_QUAB(validate_schema: bool = False) → AvesHardware[source]

Reorder detector orient & handed in alternate pixel order.

In the following orders:

QA QA UA UA QB QB UB UB …

reorder_TB(pixels: List[int], TB_anti_alignment: bool = False, TB_alternate_anti_alignment: bool = False, validate_schema: bool = False) → AvesHardware[source]

Reorder pixels according its integer assignment

Parameters:

TB_anti_alignment (bool) – if True, assume TB pixels ordering BTTBBTTBBT.. else BTBTBTBT…

reorder_TB_from_csv(path: Path, TB_anti_alignment: bool = False, TB_alternate_anti_alignment: bool = False, validate_schema: bool = False) → AvesHardware[source]

Reorder pixels according its integer assignment

Parameters:
  • path (Path) – a csv or txt file that has the pixel numbers per line

  • TB_anti_alignment (bool) – if True, assume TB pixels ordering BTTBBTTBBT.. else BTBTBTBT…

schema: ClassVar[dict] = {<class 'str'>: {'bands': <class 'dict'>, 'detectors': <class 'dict'>, 'pixels': <class 'dict'>, 'telescopes': <class 'dict'>, 'wafers': <class 'dict'>}}
property size: int
class coscon.toast_helper.AvesPixels(data: Dict[str, float | List[str]], validate_schema: bool = True)[source]

Bases: GenericDictStructure

a class describing the pixels of Aves.

data: Dict[str, float | List[str]]
schema: ClassVar[dict] = {<class 'str'>: {'bands': And(<class 'list'>, <function <lambda>>), 'sizemm': <class 'float'>}}
class coscon.toast_helper.AvesTelescopes(data: Dict[str, float | List[str]], validate_schema: bool = True)[source]

Bases: GenericDictStructure

a class describing the telescopes of Aves.

data: Dict[str, float | List[str]]
schema: ClassVar[dict] = {<class 'str'>: {'platescale': Or(<class 'float'>, <class 'numpy.float64'>), 'wafers': And(<class 'list'>, <function <lambda>>), 'waferspace': Or(<class 'float'>, <class 'numpy.float64'>)}}
class coscon.toast_helper.AvesWafers(data: Dict[str, float | int | str | List[str] | None], validate_schema: bool = True)[source]

Bases: GenericDictStructure

a class describing the wafers of Aves.

data: Dict[str, float | int | str | List[str] | None]
schema: ClassVar[dict] = {<class 'str'>: {'npixel': Or(<class 'int'>, <class 'numpy.int64'>), 'pixels': And(<class 'list'>, <function <lambda>>), 'position': Or(<class 'int'>, <class 'numpy.int64'>), 'telescope': <class 'str'>, 'type': <class 'str'>, Optional('handed'): Or(None, <class 'float'>, <class 'int'>, <class 'numpy.float64'>, <class 'numpy.int64'>)}}
class coscon.toast_helper.CrosstalkMatrix(names: np.ndarray['S'], data: np.ndarray[np.float64], name: str | None = None, freq: np.ndarray[np.float64] | None = None)[source]

Bases: GenericMatrix

Crosstalk square matrix where column and row share the same names

compare_plot_diag(others: List[CrosstalkMatrix])[source]
compare_plot_nearest_neighbor(others: List[CrosstalkMatrix])[source]
property dataframe: DataFrame[source]
property dataframe_diag_only: DataFrame[source]
property dataframe_nearest_neighbor_only: DataFrame[source]
freq: np.ndarray[np.float64] | None = None
classmethod from_geometric(names: List[str] | np.ndarray, r: float = 0.01) → CrosstalkMatrix[source]

Generate a crosstalk matrix with coefficients in geometric series.

classmethod from_joshian_matrix(names: List[str] | np.ndarray, nearest: float, next_nearest: float, floor: float) → CrosstalkMatrix[source]

Generate a crosstalk matrix with structure based on Josh’s simple assumption

classmethod from_unique_matrix(names: List[str] | np.ndarray) → CrosstalkMatrix[source]

generate a crosstalk matrix with each entry to be unique.

Mainly for debug use to confirm the matrix multiplication is correct.

plot(annot: bool = True, figsize: Tuple[float, float] | None = None, log: bool = True)[source]
to_random_normal() → CrosstalkMatrix[source]

Generate a random normal matrix based on original matrix except for diagonal

with mean and std given by the original matrix.

class coscon.toast_helper.DictValueEqualsKey[source]

Bases: object

A fake dictionary where its values always equal their keys

class coscon.toast_helper.FakeFocalPlane(data: Dict[str, float | np.ndarray], validate_schema: bool = True)[source]

Bases: GenericFocalPlane

a class describing the output of fake_focalplane

data: Dict[str, float | np.ndarray]
plot(width: float = 4.0, height: float = 4.0, outfile: Path | None = None, facecolor: Dict[str, str | Tuple[float, float, float]] | None = None, polcolor: Dict[str, str | Tuple[float, float, float]] | None = None)[source]
schema: ClassVar[dict] = {<class 'str'>: {'NET': Or(<class 'float'>, <class 'numpy.float64'>), 'alpha': Or(<class 'float'>, <class 'numpy.float64'>), 'epsilon': Or(<class 'float'>, <class 'numpy.float64'>), 'fknee': Or(<class 'float'>, <class 'numpy.float64'>), 'fmin': Or(<class 'float'>, <class 'numpy.float64'>), 'fwhm_arcmin': Or(<class 'float'>, <class 'numpy.float64'>), 'quat': And(<class 'numpy.ndarray'>, <function <lambda>>), 'rate': Or(<class 'float'>, <class 'numpy.float64'>)}}
class coscon.toast_helper.GenericDictStructure(data: 'Dict[str, Any]', validate_schema: 'bool' = True)[source]

Bases: object

data: Dict[str, Any]
property dataframe: DataFrame[source]

DataFrame representation of the focal plane

This has opposite key-ordering from the dict i.e. self.data[some_key][‘quat’] == self.dataframe[‘quat’][some_key] == self.dataframe.loc[some_key, ‘quat’]

dump(path: Path | str, overwrite: bool = False, compress: bool = None)[source]

Write hardware config to a TOML/YAML/JSON file.

classmethod load(path: Path | str)[source]

Read data from a TOML/YAML/JSON file.

schema: ClassVar[dict] = {}
validate()[source]
validate_schema: bool = True
class coscon.toast_helper.GenericFocalPlane(data: 'Dict[str, Any]', validate_schema: 'bool' = True)[source]

Bases: GenericDictStructure

property Quat: Quaternion[source]
property azimuthal_equidistant_projection_with_orientation: ndarray[floating][source]
property bleed: float[source]

Bleeding for plotting from FWHM.

property dataframe_with_azimuthal_equidistant_projection_with_orientation: DataFrame[source]
property dist_spherical_pairwise: ndarray[floating][source]

Pair-wise great circle distances between detector quaternions.

Assume input is a 1-dim array of quarternions (2d-array) and return pairwise distance in 1d-array, ordered in “row-major” and “j>i” directions. E.g. for 3 detectors, [(0, 1), (0, 2), (1, 2)] ordering.

iplot(scale: float = 1.0, height: int = 1000, width: int = 1000) → Figure[source]
property quat: ndarray[floating][source]
property x_max: float[source]
property x_min: float[source]
property y_max: float[source]
property y_min: float[source]
class coscon.toast_helper.GenericMatrix(names: np.ndarray['S'], data: np.ndarray[np.float64], name: str | None = None)[source]

Bases: object

Generic matrix that has row names in ASCII.

data: np.ndarray[np.float64]
dump(path: Path, compress_level: int = 9)[source]
classmethod load(path: Path, name: str | None)[source]
name: str | None = None
names: np.ndarray['S']
property names_str: List[str][source]

names in list of str

property shape: Tuple[int, ...]
property size: int
class coscon.toast_helper.NaiveTod(names: np.ndarray['S'], data: np.ndarray[np.float64], name: str | None = None)[source]

Bases: GenericMatrix

Naive TOD matrix that has all data in contiguous array

apply_crosstalk(crosstalk_matrix: CrosstalkMatrix) → NaiveTod[source]
property dataframe: DataFrame[source]
class coscon.toast_helper.SQUID(R_TES: float | np.ndarray[np.float64], r_s: float | np.ndarray[np.float64], L: float | np.ndarray[np.float64], L_com: float, C: np.ndarray[np.float64] | None = None, omega: np.ndarray[np.float64] | None = None)[source]

Bases: object

A model of the SQUID readout.

See fig. 4 in Montgomery2020.

Montgomery2020: Montgomery et al., “Performance and Characterization of the SPT-3G Digital Frequency Multiplexed Readout System Using an Improved Noise and Crosstalk Model.”

C: np.ndarray[np.float64] | None = None
L: float | np.ndarray[np.float64]
L_com: float
R_TES: float | np.ndarray[np.float64]
dataframe(include_omega: bool = False, include_freq: bool = False) → DataFrame[source]
property freq[source]
omega: np.ndarray[np.float64] | None = None
r_s: float | np.ndarray[np.float64]
to_crosstalk_matrix(names: List[str] | np.ndarray | None = None) → CrosstalkMatrix[source]

Compute the crosstalk matrix using Montgomery2020 approximations

to_crosstalk_matrix_exact(names: List[str] | np.ndarray | None = None) → CrosstalkMatrix[source]

Compute the crosstalk matrix using Montgomery2020 formulism without the approximations

to_dict(include_omega: bool = False, include_freq: bool = False) → dict[source]
coscon.toast_helper.fake_focalplane(samplerate: float = 20.0, epsilon: float = 0.0, net: float = 1.0, fmin: float = 0.0, alpha: float = 1.0, fknee: float = 0.05, fwhm: float = 30.0, npix: int = 7, fov: float = 3.0) → Dict[str, float | np.ndarray][source]

Create a set of fake detectors.

This generates 7 pixels (14 dets) in a hexagon layout at the boresight and with a made up polarization orientation.

This function is copied from TOAST workshop with the following license:

BSD 2-Clause License

Copyright (c) 2019, hpc4cmb All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

coscon.toast_helper.na_to_none(value)[source]

Convert pandas null value to None