clevar.catalog module

@file catalog.py The ClCatalog and improved Astropy table classes

class clevar.catalog.Catalog(name, tags=None, labels=None, unique_id=False, default_tags=None, mt_hist=None, **kwargs)[source]

Bases: clevar.catalog.TagData

Parent object to handle catalogs.

Variables
  • ~Catalog.name (str) – ClCatalog name

  • ~Catalog.data (ClData) – Main catalog data (ex: id, ra, dec, z). Fixed values. Matching data (mt_self, mt_other, mt_cross, mt_multi_self, mt_multi_other)

  • ~Catalog.id_dict (dict) – Dictionary of indicies given the cluster id

  • ~Catalog.size (int) – Number of objects in the catalog

  • ~Catalog.tags (LoweCaseDict) – Tag for main quantities used in matching and plots (ex: id, ra, dec, z)

  • ~Catalog.labels (LowerCaseDict) – Labels of data columns for plots

  • ~Catalog.mt_hist (list) – Recorded steps of matching

add_ftpt_coverfrac(ftpt, aperture, aperture_unit, window='flat', cosmo=None, colname=None)[source]

Computes and adds a cover fraction value. It considers zmax and detection fraction when available in the footprint.

Parameters
  • ftpt (clevar.mask.Footprint object) – Footprint used to compute the coverfration

  • ftpt_other (clevar.mask.Footprint object) – Footprint of the other catalog

  • raduis (float) – Radial aperture to compute the coverfraction

  • aperture_unit (float) – Unit of radial aperture

  • window (str) – Window to weight corverfrac. Options are: flat, nfw2D (with flat core)

  • cosmo (clevar.Cosmology object) – Cosmology object for when aperture has physical units. Required if nfw2D window used.

  • colname (str, None) – Name of coverfrac column.

add_ftpt_masks(ftpt_self, ftpt_other)[source]

Add masks based on the cluster position relative to both footprints. It also considers zmax values on the footprint if available.

Parameters
  • ftpt_self (clevar.mask.Footprint object) – Footprint of this catalog

  • ftpt_other (clevar.mask.Footprint object) – Footprint of the other catalog

cross_match()[source]

Makes cross matches, requires unique matches to be done first.

get_matching_mask(matching_type)[source]
property id_dict
ids2inds(ids, missing=None)[source]

Returns the indicies of objects given an id list.

Parameters
  • ids (list) – List of object ids

  • missing (None) – Value added to position of missing id.

load_footprint_quantities(filename)[source]

Load matching results to catalogs

Parameters

filename (str) – Name of file with matching results

load_match(filename)[source]

Load matching results to catalogs

Parameters

filename (str) – Name of file with matching results

property mt_hist
classmethod read(filename, name, tags=None, labels=None, full=False)[source]

Read catalog from fits file. If full=False, only columns in tags are read.

Parameters
  • filename (str) – Input file.

  • name (str, None) – Catalog name, if none reads from file.

  • tags (LoweCaseDict, None) – Tags for table (required if full=False).

  • labels (dict, None) – Labels of data columns for plots.

  • full (bool) – Reads all columns of the catalog

classmethod read_full(filename)[source]

Read fits file catalog saved by clevar with all information. The catalog must contain name information.

Parameters

filename (str) – Input file.

remove_multiple_duplicates()[source]

Removes duplicates in multiple match columns

save_footprint_quantities(filename, overwrite=False)[source]

Saves the matching results of one catalog

Parameters
  • filename (str) – Name of file

  • overwrite (bool) – Overwrite saved files

save_match(filename, overwrite=False)[source]

Saves the matching results of one catalog

Parameters
  • filename (str) – Name of file

  • overwrite (bool) – Overwrite saved files

show_mt_hist(line_max_size=100)[source]
tag_column(colname, coltag, skip_warn=False)[source]

Tag column

Parameters
  • colname (str) – Name of column

  • coltag (str) – Tag for column

  • skip_warn (bool) – Skip overwriting warning

write(filename, add_header=True, overwrite=False)[source]

Write catalog.

Parameters
  • filename (str) – Name of file

  • add_header (bool) – Saves catalog name and labels.

  • overwrite (bool) – Overwrite saved files

class clevar.catalog.ClCatalog(name, tags=None, labels=None, radius_unit=None, members=None, **kwargs)[source]

Bases: clevar.catalog.Catalog

Object to handle cluster catalogs.

Variables
  • ~ClCatalog.name (str) – ClCatalog name

  • ~ClCatalog.data (ClData) – Main catalog data (ex: id, ra, dec, z). Fixed values. Mathing data (mt_self, mt_other, mt_cross, mt_multi_self, mt_multi_other)

  • ~ClCatalog.mt_input (object) – Contains the necessary inputs for the match (added by Match objects)

  • ~ClCatalog.size (int) – Number of objects in the catalog

  • ~ClCatalog.id_dict (dict) – Dictionary of indicies given the cluster id

  • ~ClCatalog.radius_unit (str, None) – Unit of the radius column

  • ~ClCatalog.tags (LoweCaseDict) – Tag for main quantities used in matching and plots (ex: id, ra, dec, z, mass,…)

  • ~ClCatalog.labels (LowerCaseDict) – Labels of data columns for plots

  • ~ClCatalog.members (MemCatalog) – Catalog of members associated to the clusters

  • ~ClCatalog.leftover_members (MemCatalog) – Catalog of members not associated to the clusters

Notes

Column names that automatically become tags: id, ra, dec, mass, z, radius, zmin, zmax, z_err

add_members(members_consistency=True, members_warning=True, members_catalog=None, **kwargs)[source]

Add members to clusters

Parameters
  • members_consistency (bool) – Require that all input members belong to this cluster catalog.

  • members_warning (bool) – Raise warning if members are do not belong to this cluster catalog, and save them in leftover_members attribute.

  • members_catalog (clevar.MemCatalog, None) – Members catalog if avaliable.

  • **kwargs (keyword arguments) – Arguments to initialize member catalog if members_catalog=None. For details, see: https://lsstdesc.org/clevar/compiled-examples/catalogs.html#adding-members-to-cluster-catalogs

raw()[source]

Get a copy of the catalog without members.

classmethod read(filename, name, tags=None, labels=None, radius_unit=None, full=False)[source]

Read catalog from fits file. If full=False, only columns in tags are read.

Parameters
  • filename (str) – Input file.

  • name (str, None) – Catalog name, if none reads from file.

  • tags (LoweCaseDict, None) – Tags for table (required if full=False).

  • labels (dict, None) – Labels of data columns for plots.

  • radius_unit (str, None) – Unit of the radius column (default read from file).

  • full (bool) – Reads all columns of the catalog

read_members(filename, tags=None, labels=None, members_consistency=True, members_warning=True, full=False)[source]

Read members catalog from fits file.

Parameters
  • filename (str) – Input file.

  • tags (LoweCaseDict, None) – Tags for member table.

  • labels (dict, None) – Labels of data columns for plots.

  • members_consistency (bool) – Require that all input members belong to this cluster catalog.

  • members_warning (bool) – Raise warning if members are do not belong to this cluster catalog, and save them in leftover_members attribute.

  • full (bool) – Reads all columns of the catalog

remove_members()[source]

Remove member catalogs.

class clevar.catalog.ClData(*args, **kwargs)[source]

Bases: astropy.table.table.Table

ClData: A data object. It behaves as an astropy table but case independent.

Variables
  • ~ClData.meta (dict) – Dictionary with metadata for this object

  • ~ClData.namedict (dict) – Dictionary for making ClData case insensitive

  • tables (Same as astropy) –

get(key, default=None)[source]

Return the column for key if key is in the dictionary, else default

property namedict
classmethod read(*args, **kwargs)[source]

Read and parse a data table and return as a Table.

This function provides the Table interface to the astropy unified I/O layer. This allows easily reading a file in many supported data formats using syntax such as:

>>> from astropy.table import Table
>>> dat = Table.read('table.dat', format='ascii')
>>> events = Table.read('events.fits', format='fits')

Get help on the available readers for Table using the``help()`` method:

>>> Table.read.help()  # Get help reading Table and list supported formats
>>> Table.read.help('fits')  # Get detailed help on Table FITS reader
>>> Table.read.list_formats()  # Print list of available formats

See also: https://docs.astropy.org/en/stable/io/unified.html

Parameters
  • *args (tuple, optional) – Positional arguments passed through to data reader. If supplied the first argument is typically the input filename.

  • format (str) – File format specifier.

  • units (list, dict, optional) – List or dict of units to apply to columns

  • descriptions (list, dict, optional) – List or dict of descriptions to apply to columns

  • **kwargs (dict, optional) – Keyword arguments passed through to data reader.

Returns

out – Table corresponding to file contents

Return type

~astropy.table.Table

Notes

The available built-in formats are:

Format

Read

Write

Auto-identify

Deprecated

ascii

Yes

Yes

No

ascii.aastex

Yes

Yes

No

ascii.basic

Yes

Yes

No

ascii.cds

Yes

No

No

ascii.commented_header

Yes

Yes

No

ascii.csv

Yes

Yes

Yes

ascii.daophot

Yes

No

No

ascii.ecsv

Yes

Yes

Yes

ascii.fast_basic

Yes

Yes

No

ascii.fast_commented_header

Yes

Yes

No

ascii.fast_csv

Yes

Yes

No

ascii.fast_no_header

Yes

Yes

No

ascii.fast_rdb

Yes

Yes

No

ascii.fast_tab

Yes

Yes

No

ascii.fixed_width

Yes

Yes

No

ascii.fixed_width_no_header

Yes

Yes

No

ascii.fixed_width_two_line

Yes

Yes

No

ascii.html

Yes

Yes

Yes

ascii.ipac

Yes

Yes

No

ascii.latex

Yes

Yes

Yes

ascii.mrt

Yes

Yes

No

ascii.no_header

Yes

Yes

No

ascii.qdp

Yes

Yes

Yes

ascii.rdb

Yes

Yes

Yes

ascii.rst

Yes

Yes

No

ascii.sextractor

Yes

No

No

ascii.tab

Yes

Yes

No

asdf

Yes

Yes

Yes

fits

Yes

Yes

Yes

hdf5

Yes

Yes

Yes

pandas.csv

Yes

Yes

No

pandas.fwf

Yes

No

No

pandas.html

Yes

Yes

No

pandas.json

Yes

Yes

No

parquet

Yes

Yes

Yes

votable

Yes

Yes

Yes

aastex

Yes

Yes

No

Yes

cds

Yes

No

No

Yes

csv

Yes

Yes

No

Yes

daophot

Yes

No

No

Yes

html

Yes

Yes

No

Yes

ipac

Yes

Yes

No

Yes

latex

Yes

Yes

No

Yes

mrt

Yes

Yes

No

Yes

rdb

Yes

Yes

No

Yes

Deprecated format names like aastex will be removed in a future version. Use the full name (e.g. ascii.aastex) instead.

class clevar.catalog.MemCatalog(name, tags=None, labels=None, **kwargs)[source]

Bases: clevar.catalog.Catalog

Object to handle member catalogs.

Variables
  • ~MemCatalog.name (str) – ClCatalog name

  • ~MemCatalog.data (ClData) – Main catalog data (ex: id, id_cluster, pmem). Fixed values.

  • ~MemCatalog.mt_input (object) – Contains the necessary inputs for the match (added by Match objects)

  • ~MemCatalog.size (int) – Number of objects in the catalog

  • ~MemCatalog.id_dict (dict) – Dictionary of indicies given the member id

  • ~MemCatalog.id_dict_list (dict) – Dictionary of indicies given the member id, returns list allowing for repeated ids.

  • ~MemCatalog.tags (LoweCaseDict) – Tag for main quantities used in matching and plots (ex: id, id_cluster, ra, dec, z,…)

  • ~MemCatalog.labels (dict) – Labels of data columns for plots

Notes

Column names that automatically become tags: id, id_cluster, ra, dec, z, radius, pmem

property id_dict_list
class clevar.catalog.TagData(tags=None, default_tags=None, **kwargs)[source]

Bases: object

Parent object to implement tag to catalogs.

Variables
  • ~TagData.data (ClData) – Main catalog data (ex: id, ra, dec, z).

  • ~TagData.size (int) – Number of objects in the catalog

  • ~TagData.tags (LoweCaseDict) – Tag for main quantities used in matching and plots (ex: id, ra, dec, z)

  • ~TagData.default_tags (NameList) – List of keys that generate tags automatically.

  • ~TagData.colnames (NameList) – Names of columns in data.

property colnames
property data
property default_tags
get(key, default=None)[source]

Return the column for key if key is in the dictionary, else default

classmethod read(filename, tags=None, full=False)[source]

Read catalog from fits file. If full=False, only columns in tags are read.

Parameters
  • filename (str) – Input file.

  • tags (LoweCaseDict, None) – Tags for table (required if full=False).

  • full (bool) – Reads all columns of the catalog

classmethod read_full(filename)[source]

Read fits file catalog saved by clevar with all information. The catalog must contain name information.

Parameters

filename (str) – Input file.

property size
tag_column(colname, coltag, skip_warn=False)[source]

Tag column

Parameters
  • colname (str) – Name of column

  • coltag (str) – Tag for column

  • skip_warn (bool) – Skip overwriting warning

tag_columns(colnames, coltags)[source]

Tag columns

Parameters
  • colname (list) – Name of columns

  • coltag (list) – Tag for columns

property tags
write(filename, add_header=True, overwrite=False)[source]

Write catalog.

Parameters
  • filename (str) – Name of file

  • add_header (bool) – Saves catalog name and labels.

  • overwrite (bool) – Overwrite saved files