nwaylib package#

Submodules#

nwaylib.bayesdistance module#

Probabilistic Cross-Identification of Astronomical Sources

Reference: Budavari & Szalay (2008), ApJ, 679:301-309 Authors: Johannes Buchner (C) 2013-2020 Authors: Tamas Budavari (C) 2012

nwaylib.bayesdistance.log_posterior(prior, log_bf)[source]#

Returns log10 posterior probability normalised against alternative hypothesis that the sources are unrelated (Budavari+08)

nwaylib.bayesdistance.posterior(prior, log_bf)[source]#

Returns posterior probability normalised against alternative hypothesis that the sources are unrelated (Budavari+08)

nwaylib.bayesdistance.unnormalised_log_posterior(prior, log_bf, ncat)[source]#

Returns posterior probability (without normalisation against alternatives)

nwaylib.bayesdistance.log_bf2(psi, s1, s2)[source]#

log10 of the 2-way Bayes factor, see eq.(16) psi separation s1 and s2=accuracy of coordinates

nwaylib.bayesdistance.log_bf3(p12, p23, p31, s1, s2, s3)[source]#

log10 of the 3-way Bayes factor, see eq.(17)

nwaylib.bayesdistance.log_bf(p, s)[source]#

log10 of the multi-way Bayes factor, see eq.(18)

p: separations matrix (NxN matrix of arrays) s: errors (list of N arrays)

nwaylib.bayesdistance.assert_possemdef(M)[source]#

Check that the 2x2 matrix M is positive semi-definite, vectorized

nwaylib.bayesdistance.matrix_add(A, B)[source]#

2D matrix addition, vectorized

nwaylib.bayesdistance.matrix_multiply(A, B)[source]#

2D matrix multiplication, vectorized

nwaylib.bayesdistance.matrix_invert(A)[source]#

invert a matrix A, vectorized

nwaylib.bayesdistance.matrix_det(A)[source]#

2D matrix determinant, vectorized

nwaylib.bayesdistance.apply_vector_right(A, b)[source]#

multiply 2D vector with 2D matrix, vectorized

nwaylib.bayesdistance.apply_vector_left(a, B)[source]#

multiply 2D matrix with 2D vector, vectorized

nwaylib.bayesdistance.vector_multiply(a, b)[source]#

multiply two vectors, vectorized

nwaylib.bayesdistance.vector_normalised(v)[source]#
nwaylib.bayesdistance.apply_vABv(v, A, B)[source]#

compute v^T A B v, vectorized

nwaylib.bayesdistance.make_covmatrix(sigma_x, sigma_y, rho=0)[source]#

create covariance matrix from given standard deviations and normalised correlation rho, vectorized

nwaylib.bayesdistance.make_invcovmatrix(sigma_x, sigma_y, rho=0)[source]#

create inverse covariance matrix from given standard deviations and normalised correlation rho, vectorized

nwaylib.bayesdistance.convert_from_ellipse(a, b, phi)[source]#

create covariance parameters from ellipse major axis a, minor axis b and angle phi; vectorized

as in Pineau+16, eq 8-10, for example.

nwaylib.bayesdistance.log_bf_elliptical(separations_ra, separations_dec, pos_errors)[source]#

log10 of the multi-way Bayes factor, see eq.(18)

separations_ra: RA separations matrix (NxN matrix of arrays) separations_dec: DEC separations matrix (NxN matrix of arrays) pos_errors: errors (list of (N,3) arrays) giving sigma_RA, sigma_DEC, rho

nwaylib.checkupdates module#

nwaylib.checkupdates.checkupdates(current_version=None)[source]#

Check for program updates on PyPI

If you want to disable this, create a file I_will_check_for_NWAY_updates_myself_thank_you in your working directory.

nwaylib.fastskymatch module#

Functions for finding pairs within a certain search distance “err”.

Very fast method based on hashing.

nwaylib.fastskymatch.dist(apos, bpos)[source]#

Angular separation (in degrees) between two points on a sphere. http://en.wikipedia.org/wiki/Great-circle_distance

nwaylib.fastskymatch.dist3d(apos, bpos)[source]#

Angular separation in ra & dec between two points on a sphere.

nwaylib.fastskymatch.get_tablekeys(table, name, tablename='')[source]#
nwaylib.fastskymatch.get_healpix_resolution_degrees(nside)[source]#
nwaylib.fastskymatch.match_multiple(tables, table_names, err, fits_formats, logger, circular=True, pairwise_errs=[])[source]#

computes the cartesian product of all possible matches, limited to a maximum distance of err (in degrees).

tables: input FITS table table_names: names of the tables fits_formats: FITS data type of the columns of each table

returns results: cartesian product of all possible matches (smaller than err) cat_columns: table with separation distances in arcsec header: which columns were used in each table for RA/DEC

nwaylib.fastskymatch.wraptable2fits(cat_columns, extname)[source]#
nwaylib.fastskymatch.array2fits(table, extname)[source]#

nwaylib.logger module#

class nwaylib.logger.FakeProgressBar(*args)[source]#

Bases: object

start()[source]#
increment()[source]#
finish()[source]#
class nwaylib.logger.NullOutputLogger[source]#

Bases: object

log(*msg)[source]#
warn(msg)[source]#
progress(*args, **kwargs)[source]#
class nwaylib.logger.NormalLogger[source]#

Bases: object

log(msg)[source]#
warn(msg)[source]#
progress(ndigits=6, *args, **kwargs)[source]#

nwaylib.magnitudeweights module#

Computes adaptively binned histograms of two distributions.

Provides smooth biasing functions and plots them.

This is not specific for magnitudes, it can be any provided property.

nwaylib.magnitudeweights.ratio(hist_sel, hist_all)[source]#

ratio between the two histograms. Minor offsets to avoid zero and inf.

nwaylib.magnitudeweights.fraction(bin_mag, hist_sel, hist_all)[source]#

fraction of selected

nwaylib.magnitudeweights.plot_fit(bin_mag, hist_sel, hist_all, func, name)[source]#

Plotting

nwaylib.magnitudeweights.fitfunc_histogram(bin_mag, hist_sel, hist_all)[source]#

creates the biasing functions

nwaylib.magnitudeweights.adaptive_histograms(mag_all, mag_sel, weights=None)[source]#

creates the histograms for the two columns in an adaptive way (based on mag_sel) with the same binning.

nwaylib.progress module#

nwaylib.progress.bar(**kwargs)[source]#

Module contents#

Multiway association between astrometric catalogues

exception nwaylib.UndersampledException[source]#

Bases: Exception

exception nwaylib.EmptyResultException[source]#

Bases: Exception

nwaylib.nway_match(match_tables, match_radius, prior_completeness, mag_include_radius=None, mag_exclude_radius=None, magauto_post_single_minvalue=0.9, prob_ratio_secondary=0.5, min_prob=0.0, consider_unrelated_associations=True, store_mag_hists=True, logger=<nwaylib.logger.NormalLogger object>)[source]#
match_tables: list of catalogues, each a dict with entries:
  • name (short catalog name, no spaces, used in output columns)

  • ra (RA in degrees)

  • dec (dec in degrees)

  • error (positional error in arcsec)

  • area (sky area covered by the catalogue in square degrees)

  • mags (list of additional columns to consider as priors)

  • magnames (short name for each entry in mags, used in output columns)

  • maghists (list of prior information for each entry in mags) use None to automatically build a histogram of target/non-target sources. Otherwise, supply the histogram manually: bins_lo, bins_hi, hist_sel, hist_all.

match_radius: maximum radius in arcsec to consider.

More distant counterparts are cut off. Set to a very large value, e.g. 5 times the largest positional error. Setting to larger values does not change the result, but setting to smaller values improves performance.

prior_completeness: expected fraction of sources in the primary catalogue

that are expected to have a counterpart (e.g., 90%). If an array is passed, completeness for each catalog. First entry has to be 1.

mag_include_radius:

search radius for building the magnitude histogram of target sources. If None (default), the Bayesian posterior is used

mag_exclude_radius:

exclusion radius for building the magnitude histogram of field sources. If None (default), mag_include_radius is used

magauto_post_single_minvalue:

minimum posterior probability (default: 0.9) for the magnitude histogram of secure target sources. Used in the Bayesian procedure.

prob_ratio_secondary: for each primary catalogue entry, the most probable associations is marked with match_flag=1. Comparably good solutions receive match_flag=2 (all others are match_flag=0). The prob_ratio_secondary parameter controls the lowest probability ratio p(secondary)/p(primary) still considered comparable.

min_prob: Minimum probability for truncating the output table.

default: 0 (no truncation)

consider_unrelated_associations: Correction for missing sources in

partial assocations. Keep to True.

store_mag_hists: Write constructed mag hists to file (filename based on table name and mags).

logger: NormalLogger for stderr output and progress bars, NullOutputLogger if silent