Utils¶
Other support functions are documented bellow:
- hostphot.utils.adapt_aperture(objects, img_wcs, img_wcs2, flip=False)¶
Changes the aperture parameters to consider differences in WCS between surveys.
The values of
center
,a
andb
should in pixel units. DES images are flipped, so these need to be corrected withtheta -> -theta
, i.e. usingflip=True
.- Parameters:
objects (ndarray) – Objects with apertures.
img_wcs (WCS) – WCS of the image from where the objects were extracted.
img_wcs2 (WCS) – WCS used to adapt the apertures.
flip (bool, default
False
) – Whether to flip the orientation of the aperture. Only used for DES images.
- Returns:
objects_ (ndarray) – Objects with adapted apertures.
conv_factor (float) – Convertion factor between the resolutions of the images.
- hostphot.utils.calc_sky_unc(image, exptime)¶
Calculates the uncertainty of the image from the sky standard deviation, sigma-clipped STD.
- Parameters:
image (ndarray) – Image in a 2D numpy array.
exptime (float) – Exposure time of the image.
- Returns:
error – Estimated error of the image.
- Return type:
float
- hostphot.utils.check_HST_filters(filt)¶
Check whether the given filter is whithin the valid options for HST.
- Parameters:
filt (str) – Filter to use, e,g,
WFC3_UVIS_F225W
.
- hostphot.utils.check_filters_validity(filters, survey)¶
Check whether the given filters are whithin the valid options for the given survey.
- Parameters:
filters (str or list) – Filters to use, e,g,
griz
.survey (str) – Survey name: e.g.
PS1
,GALEX
.
- hostphot.utils.check_survey_validity(survey)¶
Check whether the given survey is whithin the valid options.
- Parameters:
survey (str) – Survey name: e.g.
PS1
,GALEX
.
- hostphot.utils.check_work_dir(wokrdir)¶
Checks if the working directory exists. If it does not, one is created.
- Parameters:
wokrdir (str) – Working directory path.
- hostphot.utils.clean_dir(directory)¶
Removes the directory if it is empty.
- Parameters:
directory (str) – Directory path.
- hostphot.utils.correct_HST_aperture(filt, ap_area, header)¶
Get the aperture correction for the given configuration.
- Parameters:
filt (str) – HST filter, e.g.
WFC3_UVIS_F225W
.ap_area (float) – Aperture area.
header (fits header) – Header of an image.
- Returns:
correction – Aperture correction (encircled energy fraction).
- Return type:
float
- hostphot.utils.extract_filter(filt, survey, version=None)¶
Extracts the transmission function for the filter.
- Parameters:
filt (str) – Filter to extract.
survey (str) – Survey of the filters.
version (str, default
None
) – Version of the filters to use. E.g. for the Legacy Survey as it uses DECam for the south and BASS+MzLS for the north.
- Returns:
wave (array) – Wavelength range of the filter.
transmission (array) – Transmission function.
- hostphot.utils.get_HST_err(filt, header)¶
Obtaines the error propagation from the zeropoint.
- Parameters:
filt (str) – HST filter, e.g.
WFC3_UVIS_F225W
.header (fits header) – Header of an image.
- Returns:
mag_err – Magnitude error on PHOTFLAM.
- Return type:
float
- hostphot.utils.get_image_exptime(header, survey)¶
Returns the exposure time from an image’s header.
- Parameters:
header (fits header) – Header of an image.
survey (str) – Survey name: e.g.
PS1
,GALEX
.
- Returns:
exptime – Exposure time in seconds.
- Return type:
float
- hostphot.utils.get_image_gain(header, survey)¶
Returns the gain from an image’s header.
Note: for
SDSS
this is assumed to be one as it should already be included.- Parameters:
header (fits header) – Header of an image.
survey (str) – Survey name: e.g.
PS1
,GALEX
.
- Returns:
gain – Gain value.
- Return type:
float
- hostphot.utils.get_image_readnoise(header, survey)¶
Returns the read noise from an image’s header. All values are per-pixel values.
Note: for
SDSS
this is assumed to be zero as it should already be included.- Parameters:
header (fits header) – Header of an image.
survey (str) – Survey name: e.g.
PS1
,GALEX
.
- Returns:
readnoise – Read noise value.
- Return type:
float
- hostphot.utils.get_survey_filters(survey)¶
Gets all the valid filters for the given survey.
- Parameters:
survey (str) – Survey name: e.g.
PS1
,GALEX
.- Returns:
filters – Filters for the given survey.
- Return type:
str
- hostphot.utils.integrate_filter(spectrum_wave, spectrum_flux, filter_wave, filter_response, response_type='photon')¶
Calcultes the flux density of an SED given a filter response.
- Parameters:
spectrum_wave (array) – Spectrum’s wavelength range.
spectrum_flux (array) – Spectrum’s flux density distribution.
filter_wave (array) – Filter’s wavelength range.
filter_response (array) – Filter’s response function.
response_type (str, default
photon
) – Filter’s response type. Eitherphoton
orenergy
.
- Returns:
flux_filter – Flux density.
- Return type:
float
- hostphot.utils.load_pickle(inputfile)¶
Loads a pickle file.
- Parameters:
inputfile (str) – Pickle file to load.
- Returns:
content – The content of the pickle file
- Return type:
any
- hostphot.utils.magnitude_calculation(flux, flux_err, survey, filt=None, ap_area=0.0, header=None, bkg_rms=0.0)¶
Calculates the calibrated magnitudes and errors.
Error propagation is included here, both for magnitudes and fluxes.
- Parameters:
flux (float) – Aperture flux.
survey (str) – Survey name: e.g.
PS1
,GALEX
.filt (str, default
None
) – Survey-specific filter.ap_area (float, default
0.0
) – Aperture area.header (fits header, default
None
) – Header of an image.bkg_rms (float, default
0.0
) – Background noise.invvar_map (ndarray) –
- Returns:
mag (float) – Apparent magnitude.
mag_err (float) – Apparent magnitude uncertainty.
flux (float) – Total flux.
flux_err (float) – Total uncertainty in flux.
zp (float) – Zeropoint.
- hostphot.utils.pixel2pixel(x1, y1, img_wcs1, img_wcs2)¶
Convert the pixel coordinates from one image to another.
- hostphot.utils.plot_fits(fits_file, ext=0)¶
Plots a fits file.
- Parameters:
fits_file (str or HDU.) – Path to fits file.
ext (int) – Extension index.
- hostphot.utils.plot_image(image_file)¶
Plots an image file.
E.g. ‘.png’ and ‘.jpg’ files.
- Parameters:
image_file (str) – Path to an image file.
- hostphot.utils.suppress_stdout()¶
Suppresses annoying outputs.
Useful with astroquery and aplpy packages.
- hostphot.utils.survey_pixel_scale(survey, filt=None)¶
Returns the pixel scale for a given survey.
- Parameters:
survey (str) – Survey name: e.g.
PS1
,GALEX
.filt (str, default
None
) – Filter to use by surveys that have different pixel scales for different filters (e.g. Spitzer’s IRAC and MIPS instruments).
- Returns:
pixel_scale – Pixel scale in units of arcsec/pixel.
- Return type:
float
- hostphot.utils.survey_zp(survey)¶
Returns the zero-point for a given survey.
Note: for
PS1
, an extra \(+2.5*np.log10(exptime)\) needs to be added afterwards.- Parameters:
survey (str) – Survey name: e.g.
PS1
,GALEX
.- Returns:
zp_dict – Zero-points for all the filters in the given survey. If the survey zero-point is different for each image, the string
header
is returned.- Return type:
dict or str
- hostphot.utils.uncertainty_calculation(flux, flux_err, survey, filt=None, ap_area=0.0, header=None, bkg_rms=0.0)¶
Calculates the uncertainty propagation.
- Parameters:
flux (float) – Aperture flux.
flux_err (float) – Aperture flux error.
survey (str) – Survey name: e.g.
PS1
,GALEX
.filt (str, default
None
) – Survey-specific filter.ap_area (float, default
0.0
) – Aperture area.header (fits header, default
None
) – Header of an image.bkg_rms (float, default
0.0
) – Background noise.
- Returns:
flux_err – Total uncertainty in flux units.
- Return type:
float