stdpipe.templates module

stdpipe.templates.get_hips_image(hips, ra=None, dec=None, width=None, height=None, fov=None, wcs=None, shape=None, header=None, asinh=None, normalize=True, upscale=False, get_header=True, verbose=False)[source]

Load an image from any HiPS survey using the CDS hips2fits service.

The pixel grid may be specified by center coordinates and field of view, or by passing a WCS solution or FITS header directly.

Parameters:
hipsstr

HiPS survey identifier. See https://aladin.u-strasbg.fr/hips/list for the full list.

rafloat, optional

Image center Right Ascension in degrees.

decfloat, optional

Image center Declination in degrees.

widthint, optional

Image width in pixels.

heightint, optional

Image height in pixels.

fovfloat, optional

Field of view (angular size) in degrees.

wcsastropy.wcs.WCS, optional

WCS defining the pixel grid; supersedes ra, dec, fov.

shapetuple of int, optional

Image shape (height, width); alternative to width / height.

headerastropy.io.fits.Header, optional

Header containing image dimensions and WCS; alternative to providing them explicitly.

asinhbool or None, optional

Whether the survey uses non-linear asinh flux scaling. Auto-detected for Pan-STARRS surveys; set to False to override.

normalizebool, optional

If True, pseudo-normalize the image so that background mean ≈ 100 and background RMS ≈ 10.

upscalebool or int, optional

If set, request an upscaled image then downscale before returning. Useful for Pan-STARRS to reduce asinh photometric errors at coarse pixel scales.

get_headerbool, optional

If True, also return the FITS header alongside the image.

verbosebool or callable, optional

Whether to show verbose messages. May be boolean or a print-like callable.

Returns:
ndarray or tuple or None

Image projected onto the requested pixel grid, or (image, header) if get_header=True, or None on failure.

stdpipe.templates.dilate_mask(mask, dilate=5)[source]

Dilate binary mask with a given kernel size

stdpipe.templates.mask_template(tmpl, cat=None, cat_saturation_mag=None, cat_col_mag='rmag', cat_col_mag_err='e_rmag', cat_col_ra='RAJ2000', cat_col_dec='DEJ2000', cat_sr=0.0002777777777777778, mask_nans=True, mask_masked=True, mask_photometric=False, aper=2, sn=5, wcs=None, dilate=5, verbose=False, _tmpdir=None)[source]

Apply masking heuristics to a template image.

The following masking steps are applied (where enabled):

  1. NaN pixels are masked if mask_nans=True.

  2. If cat is provided and wcs is set:

    • Stars brighter than cat_saturation_mag have their central pixel masked.

    • Stars with masked or NaN magnitudes are masked if mask_masked=True.

    • Photometrically saturated stars are masked if mask_photometric=True.

  3. The mask is optionally dilated by dilate pixels.

Parameters:
tmplndarray

Template image array.

catastropy.table.Table, optional

Reference catalogue for catalogue-based masking.

cat_saturation_magfloat, optional

Stars brighter than this magnitude have their central pixel masked.

cat_col_magstr, optional

Catalogue column name for magnitude.

cat_col_mag_errstr, optional

Catalogue column name for magnitude error.

cat_col_rastr, optional

Catalogue column name for Right Ascension.

cat_col_decstr, optional

Catalogue column name for Declination.

cat_srfloat, optional

Catalogue matching radius in degrees.

mask_nansbool, optional

If True, mask NaN pixels in the template.

mask_maskedbool, optional

If True, mask catalogue stars whose magnitudes are masked or NaN.

mask_photometricbool, optional

If True, apply photometric-based masking to identify saturated stars.

aperfloat, optional

Aperture radius (pixels) for photometry in photometric masking.

snfloat, optional

Minimum S/N for star detection in photometric masking.

wcsastropy.wcs.WCS, optional

WCS of the template image.

dilateint, optional

Dilation kernel size in pixels for expanding masked regions.

verbosebool or callable, optional

Whether to show verbose messages. May be boolean or a print-like callable.

_tmpdirstr, optional

Directory for temporary files created during photometric masking.

Returns:
ndarray of bool

Boolean mask for the template image (True = masked).

stdpipe.templates.point_in_ps1(ra, dec)[source]

Whether the sky point is covered by Pan-STARRS, rough estimation

stdpipe.templates.point_in_ls(ra, dec)[source]

Whether the sky point is covered by Legacy Survey, rough estimation

stdpipe.templates.find_skycells(ra, dec, sr, band='r', ext='image', survey='ps1', wcs=None, width=None, height=None)[source]

Find survey skycell URLs covering a sky region.

Parameters:
ra, dec, srfloat

Centre and radius (degrees) of the search region.

bandstr

Photometric band.

extstr

'image' or 'mask'.

surveystr

'ps1' or 'ls'.

wcs~astropy.wcs.WCS, optional

If provided together with width/height, used to reject cells that fall outside the actual rectangular image footprint (the default circular search can over-select for elongated or rotated fields).

width, heightint, optional

Image dimensions in pixels (required when wcs is given).

stdpipe.templates.fits_open_remote(url, **kwargs)[source]

Simple wrapper around astropy.io.fits.open() that handles cache corrution errors and downloads the image directly if necessary

stdpipe.templates.get_skycells(ra0, dec0, sr0, band='r', ext='image', survey='ps1', normalize=True, overwrite=False, wcs=None, width=None, height=None, _cachedir=None, _cache_downscale=1, _tmpdir=None, verbose=False)[source]

Get the list of filenames corresponding to skycells in the user-specified sky region. The cells are downloaded and stored to the specified cache location.

To get the masks, use ext='mask'.

Downloaded skycells are (optionally) normalized according to the parameters from their FITS headers.

stdpipe.templates.normalize_ps1_skycell(image, header, verbose=False)[source]

Normalize PanSTARRS skycell file according to its FITS header

stdpipe.templates.get_survey_image(band='r', ext='image', survey='ps1', wcs=None, shape=None, width=None, height=None, header=None, reproject='lanczos', extra=None, _cachedir=None, _cache_downscale=1, _tmpdir=None, _workdir=None, verbose=False, **kwargs)[source]

Download and reproject a Pan-STARRS or Legacy Survey image onto a WCS grid.

Pan-STARRS images are converted from asinh scaling to linear flux. Pan-STARRS mask bits: https://outerspace.stsci.edu/display/PANSTARRS/PS1+Pixel+flags+in+Image+Table+Data Legacy Survey mask bits: https://www.legacysurvey.org/dr10/bitmasks

Parameters:
bandstr, optional

Photometric band: 'g', 'r', 'i', 'z', or 'y'.

extstr, optional

Data type: 'image' or 'mask'.

surveystr, optional

Survey name: 'ps1' for Pan-STARRS or 'ls' for Legacy Survey.

wcsastropy.wcs.WCS, optional

Output WCS projection.

shapetuple of int, optional

Output image shape (height, width); alternative to width / height.

widthint, optional

Output image width in pixels.

heightint, optional

Output image height in pixels.

headerastropy.io.fits.Header, optional

Header containing WCS and image dimensions; alternative to providing them explicitly.

reprojectstr, optional

Reprojection method: 'lanczos' (default, pure-Python with flux conservation) or 'swarp' (external SWarp binary).

extradict, optional

Extra SWarp parameters (only used when reproject='swarp').

_cachedirstr, optional

Directory for caching downloaded sky cells between calls.

_cache_downscaleint, optional

Integer downscale factor for cached images.

_tmpdirstr, optional

Directory for temporary files.

_workdirstr, optional

If specified, temporary SWarp files are kept for debugging.

verbosebool or callable, optional

Whether to show verbose messages. May be boolean or a print-like callable.

**kwargs

Additional keyword arguments passed to the reprojection function.

Returns:
ndarray or None

Image reprojected onto the requested pixel grid, or None on failure.

stdpipe.templates.get_survey_image_and_mask(band='r', **kwargs)[source]

Download both the image and mask from Pan-STARRS or Legacy Survey.

Convenience wrapper that calls get_survey_image() twice.

Parameters:
bandstr, optional

Photometric band: 'g', 'r', 'i', 'z', or 'y'.

**kwargs

All other keyword arguments are passed to get_survey_image().

Returns:
tuple of ndarray

(image, mask) reprojected onto the requested pixel grid.

stdpipe.templates.get_ps1_image(band='r', **kwargs)[source]
stdpipe.templates.get_ps1_image_and_mask(band='r', **kwargs)[source]
stdpipe.templates.get_ls_image(band='r', **kwargs)[source]
stdpipe.templates.get_ls_image_and_mask(band='r', **kwargs)[source]