ufig package

Subpackages

Submodules

ufig.array_util module

Created on Dec 5, 2016

author: tomaszk

ufig.array_util.check_flag_bit(flags, flagbit)[source]
ufig.array_util.check_flag_bit_single(value, bit)[source]
ufig.array_util.clear_flag_bit_single(value, bit)[source]
ufig.array_util.rec_float64_to_float32(cat)[source]
ufig.array_util.set_flag_bit(flags, select, field)[source]
ufig.array_util.set_flag_bit_single(value, bit)[source]

ufig.coordinate_util module

Created on Jul 5, 2016 @author: Claudio Bruderer

ufig.coordinate_util.get_healpix_pixels(nside, w, size_x, size_y, margin=50, npoints=300, nest=False)[source]

For a given wcs-information of a tile find overlapping HEALPix pixels. These pixels are found, by setting up a grid of npoints x npoints points, finding the corresponding HEALPix pixels of these gridpoints and computing the unique pixel IDs.

Note: Pixels are in RING-ordering

Parameters:
  • nside – NSIDE of the HEALPix map

  • w – wcs-object containing all the relevant wcs-information

  • size_x – size of image in x-direction (pixel)

  • size_y – size of image in x-direction (pixel)

  • margin – Number of pixels margin to ensure that the whole tile is covered

  • npoints – Number of points in one dimension sampled

  • nest – whether the HEALPix map is ordered in the NESTED-format or not; default = False

Return pixels:

HEALPix pixels overlapping a given tile

ufig.coordinate_util.get_healpix_pixels_from_map(par)[source]

Returns the pixels of a boolean HEALPix map that are True. Also adapts the nside_sampling parameter if it is not set to the same value as the nside of the map.

ufig.coordinate_util.radec2pix(ra, dec, nside, **kwargs)[source]

Convert (RA, DEC) to HEALPix pixel number.

Parameters:
  • ra – RA coordinate (in degrees)

  • dec – DEC coordinate (in degrees)

  • nside – nside of HEALPix map

  • kwargs – additional keyword arguments for healpy.ang2pix-function; e.g. nest

Returns:

pixel number position lies in

ufig.coordinate_util.radec2thetaphi(ra, dec)[source]

Convert (RA, DEC) to (theta, phi).

Parameters:
  • ra – RA coordinate (in degrees)

  • dec – DEC coordinate (in degrees)

Returns:

Theta angle on the sphere following the HEALPix convention (in radians)

Returns:

Phi angle on the sphere following the HEALPix convention (in radians)

ufig.coordinate_util.radec2xy(w, ra, dec)[source]

Convert (RA, DEC) to (x, y).

Parameters:
  • w – wcs-object containing all the relevant wcs-information

  • ra – RA coordinate (in degrees)

  • dec – DEC coordinate (in degrees)

Returns:

x coordinate (in pixels)

Returns:

y coordinate (in pixels)

ufig.coordinate_util.thetaphi2pix(theta, phi, nside, **kwargs)[source]

Convert (RA, DEC) to HEALPix pixel number.

Parameters:
  • theta – Theta angle on the sphere following the HEALPix convention (in radians)

  • phi – Phi angle on the sphere following the HEALPix convention (in radians)

  • nside – nside of HEALPix map

  • kwargs – additional keyword arguments for healpy.ang2pix-function; e.g. nest

Returns:

pixel number position lies in

ufig.coordinate_util.thetaphi2radec(theta, phi)[source]

Convert (theta, phi) to (RA, DEC).

Parameters:
  • theta – Theta angle on the sphere following the HEALPix convention (in radians)

  • phi – Phi angle on the sphere following the HEALPix convention (in radians)

Returns:

RA coordinate (in degrees)

Returns:

DEC coordinate (in degrees)

ufig.coordinate_util.thetaphi2xy(w, theta, phi)[source]

Convert (theta, phi) to (x, y).

Parameters:
  • w – wcs-object containing all the relevant wcs-information

  • theta – Theta angle on the sphere following the HEALPix convention (in radians)

  • phi – Phi angle on the sphere following the HEALPix convention (in radians)

Returns:

x coordinate (in pixels)

Returns:

y coordinate (in pixels)

ufig.coordinate_util.tile_in_skycoords(pixscale, ra0, dec0, crpix_ra, crpix_dec)[source]

Maps a pixel tile onto the sky. The tile, which has pixels with width pixscale, is defined around a center point (ra0, dec0). The projection employed is a tangent plane gnonomic projection.

Parameters:
  • pixscale – Pixelscale of the image

  • size_x – size of image in x-direction (pixel)

  • size_y – size of image in x-direction (pixel)

  • ra0 – Right ascension of the center of the tile

  • dec0 – Declination of the center of the tile

  • crpix_ra – RA axis reference pixel (x-axis)

  • crpix_dec – DEC axis reference pixel (y-axis)

Return wcs_trans:

wcs-object containing all the relevant wcs-transformation information

ufig.coordinate_util.wcs_from_parameters(par)[source]

Creates an astropy WCS objects from the parameters in stored in the context. This is a wrapper for tile_in_skycoords to avoid code duplicates when getting crpix_ra and crpix_dec. :param par: parameters, type: ivy.utils.struct.Struct :return: wcs object created by tile_in_skycoords

ufig.coordinate_util.xy2pix(w, x, y, nside, **kwargs)[source]

Convert (RA, DEC) to HEALPix pixel number.

Parameters:
  • w – wcs-object containing all the relevant wcs-information

  • x – x coordinate (in pixels)

  • y – y coordinate (in pixels)

  • nside – nside of HEALPix map

  • kwargs – additional keyword arguments for healpy.ang2pix-function; e.g. nest

Returns:

pixel number position lies in

ufig.coordinate_util.xy2radec(w, x, y)[source]

Convert (x, y) to (RA, DEC).

Parameters:
  • w – wcs-object containing all the relevant wcs-information

  • x – x coordinate (in pixels)

  • y – y coordinate (in pixels)

Returns:

RA coordinate (in degrees)

Returns:

DEC coordinate (in degrees)

ufig.coordinate_util.xy2thetaphi(w, x, y)[source]

Convert (x, y) to (theta, phi).

Parameters:
  • w – wcs-object containing all the relevant wcs-information

  • x – x coordinate (in pixels)

  • y – y coordinate (in pixels)

Returns:

Theta angle on the sphere following the HEALPix convention (in radians)

Returns:

Phi angle on the sphere following the HEALPix convention (in radians)

ufig.io_util module

Created on Nov 3, 2015

author: jakeret

ufig.io_util.get_abs_path(file_name, root_path='res/maps/', is_file=True, package_name='ufig')[source]

Resolves the absolute path for a file or a directory.

In case the input is treated as a file (is_file=True), the function tries the following steps: 1) if file_name is already an absolute path, then just return it 2) if root_path is an absolute path the path is simply concatenated 3) checking in the ufig package structure 4) using DarkSkySync

In case the input should be treated as a directory (is_file=False), the function tries the following steps: 1) if file_name is already an absolute path, then just return it 2) if root_path is an absolute path the path is simply concatenated 3) checking in the ufig package structure

Returns path:

local absolute path to the file or directory if possible

ufig.io_util.get_local_abs_path(path)[source]
ufig.io_util.load_from_hdf5(file_name, hdf5_keys, hdf5_path='', root_path='res/maps/')[source]

Load data stored in a HDF5-file.

Parameters:
  • file_name – Name of the file.

  • hdf5_keys – Keys of arrays to be loaded.

  • hdf5_path – Path within HDF5-file appended to all keys.

  • root_path – Relative or absolute root path.

Returns:

Loaded arrays.

ufig.io_util.load_hpmap(file_name, root_path, ext=1)[source]

Loads a healpix map and returns it in the ring-scheme

Parameters:
  • file_name – name of the file

  • root_path – relative root path

  • ext – Extension of Healpix-maps (by default = 1)

ufig.io_util.load_image(file_name, size_x, size_y, root_path='res/maps/', ext=0, **kwargs)[source]

Loads an image from stored in a fits file

Parameters:
  • file_name – name of the file

  • size_x – max x size

  • size_y – max y size

  • root_path – relative root path

  • ext – fits extention

ufig.io_util.load_image_chunks(file_name, ext=0, dtype=<class 'numpy.float64'>, n_pix_per_row=100)[source]
ufig.io_util.write_hpmap(maps, file_path, **kwargs)[source]

Writes Healpix maps ensuring a format that can be loaded easily with fits.getdata() and displayed properly with Aladin.

Parameters:
  • maps – 1 or 3 (given as a list) Healpix maps

  • file_path – path where maps need to be stored

ufig.mask_utils module

Created on Feb 5, 2019 author: Joerg Herbel

ufig.mask_utils.decimal_integer_to_binary(n_bits, arr_decimal, dtype_out)[source]

Transform a one-dimensional array of decimal integers into its binary representation. Returns an array with the shape (len(arr_decimal), n_bits). To reconstruct arr_decimal[i], one would perform the operation

arr_decimal[i] = np.sum(2**np.arange(n_bits) * arr_binary[i])

This means that this binary representation is reversed with respect to what is normally used. For example, normally,

1100 = 1 * 2**3 + 1 * 2**2 + 0 * 2**1 + 0 * 2**0.

However, here we have

1100 = 1 * 2**0 + 1 * 2**1 + 0 * 2**2 + 0 * 2**3.

ATTENTION: THIS FUNCTION MODIFIES ARR_DECIMAL IN PLACE!

ufig.mask_utils.get_binary_mask_dtype(n_bits)[source]
ufig.mask_utils.pixel_mask_to_catalog_mask(pixel_mask, cat, off_mask_radius)[source]
ufig.mask_utils.pixel_mask_to_ucat_catalog_mask(pixel_mask, cat, off_mask_radius, r50_offset=5)[source]
ufig.mask_utils.select_off_mask(xs, ys, rs, mask)[source]
ufig.mask_utils.set_masked_pixels(pixel_mask, maskbits_keep, n_bits)[source]

Set pixels which are masked according to input bits. This function modifies pixel_mask in-place.

Parameters:
  • pixel_mask – mask

  • maskbits_keep – mask bits to keep

  • n_bits

Returns:

mask with only bits to keep switched on (same shape as input mask)

ufig.rendering_util module

Created on Jul 31, 2017 @author: Joerg Herbel

ufig.rendering_util.add_photon(image, x, y, dx, dy)[source]

Add one photon to image.

Parameters:
  • image – image

  • x – centroid x-position

  • y – centroid y-position

  • dx – x-coordinate sampled from light profile

  • dy – y-coordinate sampled from light profile

Returns:

ufig.rendering_util.compute_ellip_matrices(size, e1, e2)[source]

size can either be the PSF fwhm or the intrinsic galaxy r50

ufig.rendering_util.compute_flexion_tensors(fwhm, f1, f2, g1, g2)[source]
ufig.rendering_util.compute_kurtoses(fwhm, kurtoses, beta)[source]
ufig.rendering_util.distribute_photons_psf_profiles(nphot, n_profiles, flux_ratio)[source]
ufig.rendering_util.draw_photon_gal(rng_buffer, sin_table, cos_table, gammaprecision, gammaprecisionhigh, intrinsic_sersic_l, intrinsic_sersic_b, intrinsic_table, rng, ellip_matrix)[source]
ufig.rendering_util.draw_photon_psf(rng_buffer, sin_table, cos_table, alpha_by_fwhm, beta_power, rng, ellip_matrix, flexion_tensor, kurtosis, flexion_suppression, kurtosis_suppression, dx_offset, dy_offset)[source]
ufig.rendering_util.draw_photon_psf_radial(rng_buffer, sin_table, cos_table, rng, alpha_by_fwhm, beta_power)[source]
ufig.rendering_util.execute_threaded(func, n_threads, *args)[source]
ufig.rendering_util.integrate_pixel_psf(alpha_sq, beta, r50, e1, e2, dx_offset, dy_offset, nphot, min_x, max_x, min_y, max_y, offset_x, offset_y, mean)[source]
ufig.rendering_util.moffat_cdf_factors(psf_beta)[source]
ufig.rendering_util.psf_flexion_suppression(beta, flexion_suppression)[source]
ufig.rendering_util.psf_kurtosis_suppression(beta)[source]
ufig.rendering_util.rng_buffer()[source]
ufig.rendering_util.sin_cos_table()[source]
ufig.rendering_util.split_array(arr, n_split)[source]

ufig.run_util module

Created on Sep 30, 2016 @author: Joerg Herbel

ufig.run_util.run_ufig_from_config(config, **kwargs)[source]

Run UFig using an (importable) configuration file. Additional parameters can be provided as keyword arguments.

Parameters:
  • config – Importable configuration file.

  • kwargs – Additional parameter values.

Returns:

Ivy-context created by UFig

ufig.sampling_util module

Created on Mar 6, 2018 author: Joerg Herbel

class ufig.sampling_util.Catalog[source]

Bases: object

ufig.sampling_util.sample_position_uniform(numobj, w, pixel_index, nside)[source]

Sample a Healpix pixel uniformly

Parameters:
  • numobj – Number of uniform samples

  • w – wcs-object containing all the relevant wcs-information

  • pixel_index – Index of the Healpix pixels sampled

  • nside – NSIDE of the Healpix map

Returns:

Uniformly drawn x-coordinate (in pixels)

Returns:

Uniformly drawn y-coordinate (in pixels)

ufig.se_moment_util module

ufig.se_moment_util.get_se_cols(cat)[source]
ufig.se_moment_util.moments_to_distortion(x2, y2, xy)[source]

Convert SExtractor second moments to ellipticity parameters.

Parameters:
  • x2 – Second moments in x-direction (X2WIN_IMAGE from SExtractor)

  • y2 – Second moments in y-direction (Y2WIN_IMAGE from SExtractor

  • xy – Cross moments (XYWIN_IMAGE from SExtractor)

Returns:

e1, e2, r50: Ellipticity components and effective radius

ufig.sysmaps_util module

Created on Nov 16, 2016 author: Tomasz Kacprzak

ufig.sysmaps_util.chi_mean_combination_lowmem(par)[source]

This creates a CHI-MEAN detection image, as is done by the DES pipeline, see https://iopscience.iop.org/article/10.3847/1538-4365/aab4f5/pdf (DOI: 10.3847/1538-4365/aab4f5), appendix B.

Copy of chi_mean_combination made to run with low memory

Parameters:

images_and_weights – iterable yielding images with weights to be combined

Returns:

chi-mean detection image

ufig.sysmaps_util.chi_mean_loop(detect_image, n_contribute, arange_mu)[source]
ufig.sysmaps_util.get_detection_image(par)[source]

Constructs the detection image for SExtractor. In case of a single-band detection image, simply writes the weight map of the detection band to a fits file. For multi-band detection, the function computes the CHI-MEAN combination of the detection band images and their weights. :param par: ctx.parameters :return: path to detection image (fits), path to detection weights (fits or ‘NONE’),

weight type of detection image for SExtractor, either according to input parameters (single-band) or ‘NONE’ (multi-band detection image)

ufig.sysmaps_util.get_hdf_location_bgrms(par, band=None)[source]

Get the filename and dataset for the background noise map

Parameters:
  • par – ctx().parameters structure

  • band – which band to use (if None, use the single-band parameter values)

Returns:

filepath, dataset: path and dataset index in hdf file

ufig.sysmaps_util.get_hdf_location_exptime(par, band=None)[source]

Get the filename and dataset for the exposure time map

Parameters:
  • par – ctx().parameters structure

  • band – which band to use (if None, use the single-band parameter values)

Returns:

filepath, dataset: path and dataset index in hdf file

ufig.sysmaps_util.get_hdf_location_gain(par, band=None)[source]

Get the filename and dataset for the background noise map

Parameters:
  • par – ctx().parameters structure

  • band – which band to use (if None, use the single-band parameter values)

Returns:

filepath, dataset: path and dataset index in hdf file

ufig.sysmaps_util.get_hdf_location_invvar(par, band=None)[source]

Get the filename and dataset for the inverse variance map

Parameters:
  • par – ctx().parameters structure

  • band – which band to use (if None, use the single-band parameter values)

Returns:

filepath, dataset: path and dataset index in hdf file

ufig.sysmaps_util.get_path_temp_sextractor_weight(par, band)[source]

Constructs the path to the temporary fits-file with the weights for SExtractor

Parameters:
  • par – ctx.parameters

  • band – filter band

Returns:

path

ufig.sysmaps_util.stack_detect_image(detect_image, n_contribute, image, weights)[source]
ufig.sysmaps_util.write_temp_sextractor_weight(par, path_out, band=None, dtype=<class 'numpy.float32'>)[source]

Reads out the weight map (inverse variance) from hdf5 and writes it to fits, s.t. it can be used by SExtractor

Parameters:
  • par – ctx.parameters

  • path_out – path where weight map will be stored

  • band – filter band

ufig.sysmaps_util.write_temp_sextractor_weights(par, dirpath_temp, overwrite_photo=True, overwrite_det=True, dtype=<class 'numpy.float32'>)[source]

Write fits weight maps for SExtractor in the temp folder.

Parameters:
  • par – ctx().parameters structure

  • dirpath_temp – temp dir where to write files

  • overwrite_photo – if to overwrite photometry weight if exists

  • overwrite_det – if to overwrite detection weight if exists

Returns:

filepath_fits_photometry, filepath_fits_detection: paths to decompressed weights

ufig.workflow_util module

Created on Jun 15, 2016 author: Joerg Herbel

class ufig.workflow_util.FiltersStopCriteria[source]

Bases: StopCriteria

Stopping criteria for ivy-loops which makes the loop iterate over all filters in ctx.parameters.filters. It also sets the variable ctx.current_filter according to the current loop iteration.

is_stop()[source]

Module contents