vasca.utils

Utilities for VASCA

Module Contents

Functions

otype2ogroup

Returns object group for a given object type. Allows adding the default value of unkown type is asked.

get_col_cycler

Helper function to get matplotlib color cycler mathcing the colors defined in dd_ogrp2col

add_ogrp

Helper function to add ogrp_id column to tables

get_var_stat

Calculate variability parameters

freq2period

period2freq

run_LombScargle

Calculate Lomb Scargle periodogram

query_vizier_sed

Query VizieR Photometry tool around a given position.

sel_sources

Helper function to redo cuts, should be revisited/obsolete once table selection is rewritten

sel_sources_nuv_only

Helper function to redo cuts, should be revisited/obsolete once table selection is rewritten

select_obs_filter

Helper function to select rows or columns ob the passed obs_filter_id in a table

get_flat_table

Helper function to flatten tables when observation ID dependent entries are vectorized

flux2mag

Converts flux in Jy into AB magnitudes

mag2flux

Converts AB magnitudes to flux in Jansky

flux2mag_np

Flux to magnitude for numpy arrays only for secondary_axis in matplotlib

mag2flux_np

Magnitude to flux for numpy arrays only for secondary_axis in matplotlib

mjd2yr

Convert MJD to Time object

yr2mjd

Convert time in jyear format to MJD

get_field_id

Return VASCA field id, which also includes observatory and filter identifier. The first 3 characters characterize the observatory and filter. Afterwards the observatory field ID is attached.

extr_value

Computes the extremum value in a list of numeric lists.

get_hist_bins

Generates an array of bin edges for creating a histogram with specified bin size.

sky_sep2d

computes 2D distances between all possible pairs of coordinates that are closer together than the separation limit (default: 180 -> all-sky)

get_time_delta

Get time difference in seconds between visits

get_time_delta_mean

Get mean time difference in seconds between visits

table_to_array

Converts an astropy Table object into a regular numpy ndarray. Caveat: All table columns must have the same type.

get_cutout

Wrapper function to create a Cutout2D from a BaseField input.

get_cutout_bounds

Returns SkyCoord object defining a rectangular cutout with upperight and lower left pixels in coordinate system of out_frame.

get_cutout_mask

Returns a bool array to mask a coordinate dataset for given cutout bounds.

add_rg_src_id

Helper function, adds “rg_src_id” based on “rg_fd_id” and “fd_src_id” from the passed reference table.

nb_fig

Helper function for plotting in Jupyter notebooks. Wraps matplotlib.pylplot.subplots.

binned_stat

Compute a binned statistic for one or more sets of data.

tgalex_to_astrotime

Converts a GALEX time stamp to astropy.time.Time object with unix format and UTC scale. GALEX time is equal to UNIX time - 315964800.

galex_obs_info

Collects information form a light curve dataset (e.g. fetched using gPhoton.gAperture) and returns a pandas.DataFrame. The data frame contains columns for exposure time, observation gap time as well as observation start and stop date

timeit

Decorator to track total processing time (work in progress).

marker_set

Returns a list of n Matplotlib markers for use in plots. The list is generated by selecting markers from a curated set of markers supporting separate edge and face colors. By default, a set of markers are excluded, which can be overridden by providing the exclude argument.

color_palette

Return a palette of n colors from the matplotlib registry and additional qualitative palettes adopted from seaborn.

name2id

Generates a 32-bit or 64-bit integer from a string input.

get_config

Setup pipeline configuration file from yaml

get_lc_from_gphoton_npfile

Get light curve from gphoton numpy files

Data

API

vasca.utils.dd_filter2id = None
vasca.utils.dd_id2filter = 'dict(...)'
vasca.utils.dd_filter2wavelength = None
vasca.utils.dd_obs_id_add = None
vasca.utils.dd_ogrp2otypes = None
vasca.utils.dd_otype2ogroup = 'dict(...)'
vasca.utils.otype2ogroup(otype)[source]

Returns object group for a given object type. Allows adding the default value of unkown type is asked.

otype: str

Object type

str

Object group

vasca.utils.dd_ogrp2col = None
vasca.utils.get_col_cycler(ll_ogrp)[source]

Helper function to get matplotlib color cycler mathcing the colors defined in dd_ogrp2col

ll_ogrp: list

Return colors for passed object groups

matplotlib.cycler

vasca.utils.add_ogrp(tt, provenance='SIMBAD')[source]

Helper function to add ogrp_id column to tables

provenance: str

Where does object group definition come from, ‘SIMBAD’ or ‘GAIA’

None

vasca.utils.dd_spec_lines = None
vasca.utils.get_var_stat(vals, vals_err)[source]

Calculate variability parameters

vals: list of floats

Variable values

vals_err: list of floats

Variable errors

dict

Dictionary with weighted mean, chisquare, excess variance, etc.

vasca.utils.freq2period(ff)[source]
vasca.utils.period2freq(pp)[source]
vasca.utils.run_LombScargle(tt_lc, nbins_min=40, freq_range=[0.03, 2] / uu.d)[source]

Calculate Lomb Scargle periodogram

Parameters
tt_lc: astropy.table.Table

Table with the VASCA light curve

nbins_minint, optional

Minimum number of time bins to perform LombScargle.

freq_rangelist

Minimum and maximum Frequency. If None calculated automatically.

dict

Dictionary with LombScargle objects

vasca.utils.query_vizier_sed(ra, dec, radius=1.0)[source]

Query VizieR Photometry tool around a given position.

The VizieR photometry tool is here .. url:: http://vizier.u-strasbg.fr/vizier/sed/doc/

ra: float

Position RA in degrees in ICRS.

dec: float

Position RA in degrees in ICRS.

radius: float

Position matching radius in arseconds.

table: astropy.Table

VO table returned.

vasca.utils.sel_sources(tt_srcs)[source]

Helper function to redo cuts, should be revisited/obsolete once table selection is rewritten

tt_srcsastropy.table.Table

Source table

sel_vasca[bool]

Selected sources.

vasca.utils.sel_sources_nuv_only(tt_srcs)[source]

Helper function to redo cuts, should be revisited/obsolete once table selection is rewritten

tt_srcsastropy.table.Table

Source table

sel_vascalist of bool

Selected sources.

vasca.utils.select_obs_filter(tt_in, obs_filter_id)[source]

Helper function to select rows or columns ob the passed obs_filter_id in a table

tt_inastropy.table.Table

Input table

obs_filter_idTYPE

Observation filter ID Nr.

ttastropy.table.Table

Copy of the input table with only entries for the requested filter.

vasca.utils.get_flat_table(tt_in)[source]

Helper function to flatten tables when observation ID dependent entries are vectorized

tt_inastropy.table.Table

Input table

ttastropy.table.Table

Copy of the input table with a separate column for every observation filter dependent entry.

vasca.utils.flux2mag(flux, flux_err=None)[source]

Converts flux in Jy into AB magnitudes

fluxlist of astropy.Quantity or numpy array

Flux density array in micro Jy

flux_errlist of astropy.Quantity or numpy array

Flux error array in micro Jy. Default is none.

list of astropy.Quantity

AB magnitude array. If flux was zero or positive -1 is returned.

list of astropy.Quantity, optional

AB magnitude error array. If flux was zero or positive -1 is returned. If no flux errors are passed nothing is returned.

vasca.utils.mag2flux(mag, mag_err=None)[source]

Converts AB magnitudes to flux in Jansky

maglist of float

Array of AB magnitudes

astropy.Quantity

Flux in micro Jy

vasca.utils.flux2mag_np(flux)[source]

Flux to magnitude for numpy arrays only for secondary_axis in matplotlib

vasca.utils.mag2flux_np(mag)[source]

Magnitude to flux for numpy arrays only for secondary_axis in matplotlib

vasca.utils.mjd2yr(mjd)[source]

Convert MJD to Time object

vasca.utils.yr2mjd(jyr)[source]

Convert time in jyear format to MJD

vasca.utils.get_field_id(obs_field_id, observatory, obs_filter)[source]

Return VASCA field id, which also includes observatory and filter identifier. The first 3 characters characterize the observatory and filter. Afterwards the observatory field ID is attached.

obs_field_idint

Field ID for the given observatory.

observatorystr

Observatory name.

obs_filterTYPE

Observation filter.

str

Region field identifier.

vasca.utils.extr_value(inputlist, upper=False)[source]

Computes the extremum value in a list of numeric lists.

inputlistlist

A list of numeric lists.

upperbool, optional

Specifies whether to compute the maximum value. Defaults to False, which computes the minimum value.

float or None

The computed extremum value if the input list is not empty and contains valid numeric values. Returns None if the input list is empty or contains only NaN values.

>>> extr_value([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
1
>>> extr_value([[1, 2, 3], [4, 5, 6], [7, 8, 9]], upper=True)
9
>>> extr_value([[1, 2, 3], [4, 5], [6, 7, 8, 9]])
1
>>> extr_value([[1, 2, 3], [4, 5], [6, 7, 8, 9]], upper=True)
9
>>> extr_value([])
None
>>> extr_value([[], []])
None
>>> extr_value([[np.nan, np.nan], [np.nan, np.nan]])
None
>>> extr_value([[-1, 0, 1], [2, -3, 4], [5, -6, 7]])
-6
>>> extr_value([[-1, 0, 1], [2, -3, 4], [5, -6, 7]], upper=True)
7
vasca.utils.get_hist_bins(data, bin_size)[source]

Generates an array of bin edges for creating a histogram with specified bin size.

dataarray-like, list

The input data for which to generate the histogram bin edges. It can be either a 1D numpy array or a list of lists. If it’s a list of lists, each sub-list can have a different number of elements, and the bin edges will be determined based on the minimum and maximum values across all sub-lists (only one level of nesting is allowed)

bin_sizefloat

The desired width of each histogram bin.

numpy.ndarray

An array of bin edges that can be used for creating a histogram of the input data

ValueError

If the input data structure is not supported.

>>> data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> bin_size = 2
>>> get_hist_bins(data, bin_size)
array([ 1.,  3.,  5.,  7.,  9., 11.])
>>> data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> bin_size = 1
>>> get_hist_bins(data, bin_size)
array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])
>>> data = [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
>>> bin_size = 0.5
>>> get_hist_bins(data, bin_size)
array([1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5, 5. , 5.5, 6. , 6.5, 7. , 7.5,
      8. , 8.5, 9. , 9.5])
vasca.utils.sky_sep2d(coords, seperation_limit=180)[source]

computes 2D distances between all possible pairs of coordinates that are closer together than the separation limit (default: 180 -> all-sky)

if the all-sky case is set, the number of unique distance values is determined as follows: for the number of coordinates n = len(coords) a number of pairwise distances values N = 1/2 * (n-1)*n is returned

vasca.utils.get_time_delta(tt_visit_dates, unit=None)[source]

Get time difference in seconds between visits

vasca.utils.get_time_delta_mean(tt_visit_dates, unit=None, deviation=True)[source]

Get mean time difference in seconds between visits

vasca.utils.table_to_array(table)[source]

Converts an astropy Table object into a regular numpy ndarray. Caveat: All table columns must have the same type.

vasca.utils.get_cutout(field, position, size)[source]

Wrapper function to create a Cutout2D from a BaseField input.

fieldBaseField

Field data object from which the reference image data and corresponding WCS are used to create the cutout.

positiontuple, SkyCoord

The position of the cutout array’s center with respect to the data array. The position can be specified either as a (x, y) tuple of pixel coordinates or a SkyCoord, in which case wcs is a required input.

sizeastropy.units.Quantity

The size of the cutout array along each axis. For more inforamtion see documentaiont of Cutout2D.

Cutout2D

vasca.utils.get_cutout_bounds(cutout, out_frame='icrs')[source]

Returns SkyCoord object defining a rectangular cutout with upperight and lower left pixels in coordinate system of out_frame.

cutoutCutout2D

Cutout object from which to derive the bounds.

out_framestr, BaseCoordinateFrame class or instance, or :py:class:`~astropy.coordinates.SkyCoord instance, optional

Coordinate frame of returned SkyCoord object.

SkyCoord

vasca.utils.get_cutout_mask(tt_mcat, cutout_bounds, frame='icrs')[source]

Returns a bool array to mask a coordinate dataset for given cutout bounds.

tt_mcatTable

Table to be masked

cutout_bounds : SkyCoord

ndarray

vasca.utils.add_rg_src_id(tt_ref, tt_add)[source]

Helper function, adds “rg_src_id” based on “rg_fd_id” and “fd_src_id” from the passed reference table.

tt_refastropy.table.Table

Reference table has to contain “rg_src_id”, “rg_fd_id” and “fd_src_id”

tt_addastropy.table.Table

Table to add “rg_src_id”, has to contain “rg_src_id”, “rg_fd_id” and “fd_src_id”

None

vasca.utils.nb_fig(num=0, gr_size=None, **kwargs)[source]

Helper function for plotting in Jupyter notebooks. Wraps matplotlib.pylplot.subplots.

numint, str, optional

Figure number, i.e. name handle

gr_sizetuple, optional

Golden ratio size. Figure width in inches. The hight is calculated according to the golden ratio.

kwargs

Parameters passed to subplots

tuple

Tuple containg the figure and plot axis.

vasca.utils.binned_stat(x, values, statistic='mean', return_bin_edges=False, return_bin_idx=False, return_bin_centers=False, **bining_kwargs)[source]

Compute a binned statistic for one or more sets of data.

This wraps scipy.stats.binned_statistic in combination with numpy.histogram_bin_edges to support automatic & optimized calculation of the bin edges.

vasca.utils.tgalex_to_astrotime(galex_timestamp, output_format=None, verbose=False)[source]

Converts a GALEX time stamp to astropy.time.Time object with unix format and UTC scale. GALEX time is equal to UNIX time - 315964800.

galex_timestampfloat or vector of floats

The GALEX time epoch.

output_format{None, “iso”, “tt”}, optional

Specifies the time format/scale of the return value The default is None where the GALEX time stamp is converted and returned astropy.time.Time object with format=unix and scale=utc. Keywords “iso” and “tt” change return value to str using the astropy methods astropy.time.Time.iso and astropy.time.Time.tt respectively.

verbosebool, default False

Enable verbose printing to show format and scale if the converted time

astropy.time.Time or str

An astropy.time.Time object or str depending on output_format.

ValueError

Only floats or ints are supported for conversion

vasca.utils.galex_obs_info(lc, verbose=False)[source]

Collects information form a light curve dataset (e.g. fetched using gPhoton.gAperture) and returns a pandas.DataFrame. The data frame contains columns for exposure time, observation gap time as well as observation start and stop date

lcdictionary, data frame or astropy.Table

GALEX light curve dataset. Requires existence of keys/columns named “t0” (start) and “t1” (stop) each containing numerical arrays with the start/stop time in GALEX time format.

verbosebool, default False

Enable verbose printing

pandas.DataFrame

A data frame containing the timing meta data of GALEX observations in human readable formats.

vasca.utils.timeit(f)[source]

Decorator to track total processing time (work in progress).

vasca.utils.marker_set(n, exclude=None, exclude_default=True)[source]

Returns a list of n Matplotlib markers for use in plots. The list is generated by selecting markers from a curated set of markers supporting separate edge and face colors. By default, a set of markers are excluded, which can be overridden by providing the exclude argument.

nint

The number of markers to return.

excludestr, None, optional

A list of markers to exclude from the selection.

exclude_defaultbool, optional

Whether to exclude markers by default: [",", "8", "H"].

list

A list of n markers

vasca.utils.color_palette(name, n, show_in_notebook=False)[source]

Return a palette of n colors from the matplotlib registry and additional qualitative palettes adopted from seaborn.

For continuous palettes, evenly-spaced discrete samples are chosen while excluding the minimum and maximum value in the colormap to provide better contrast at the extremes.

For qualitative palettes (e.g. those from colorbrewer), exact values are indexed (rather than interpolated).

namestring

Name of the palette. This should be a named matplotlib colormap.

nint

Number of discrete colors in the palette.

show_in_notebookbool

Wether to show the returned colors in a juypter notebook

list of RGBA tuples

vasca.utils.name2id(name, bits=32)[source]

Generates a 32-bit or 64-bit integer from a string input.

namestr,

String input from which to generate the number

bitsint, optional

Bit-size of the output integer

int

ValueError

If bits is neither 32 or 64

vasca.utils.get_config(cfg_file)[source]

Setup pipeline configuration file from yaml

cfg_filestr

yaml configuration file name

vasca_cfgdict

VASCA pipeline configuration dictionary

vasca.utils.get_lc_from_gphoton_npfile(file_name, obs_filter)[source]

Get light curve from gphoton numpy files

file_name str

File name

obs_filter str

Obervation filter NUV or FUV

astropy.Table Light curve table