ztfimg package#
Base#
- class ztfimg.base.Image(data=None, header=None)#
Bases:
object
See also
from_filename
load the instance given a filename
from_data
load the instance given its data (and header)
- Attributes:
- SHAPE
data
data of the image ; numpy.array or dask.array
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filepath
If this method was loaded from a file, this is it’s filename.
filtername
Name of the image’s filter (from header)
header
header of the data.
meta
meta data for the instance, from the filename.
obsjd
Observation Julian date of the image (from header)
use_dask
are the data dasked (did you set use_dask=True)
Methods
from_data
(data[, header])Instanciate this class given data.
from_filename
(filename[, as_path, use_dask, ...])classmethod load an instance given an input file.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_data
([rebin, rebin_stat, data])get image data
get_header
([compute])get the current header
get_value
(key[, default, attr_ok])quick access to an image value.
has_data
()are data set ? (True means yes)
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
to_fits
(fileout[, overwrite])writes the image (data and header) into a fits file.
- SHAPE = None#
- classmethod from_filename(filename, as_path=True, use_dask=False, persist=False, dask_header=False, **kwargs)#
classmethod load an instance given an input file.
- Parameters:
filename (str) – fullpath or filename or the file to load. If a filename is given, set as_path=False, then ztfquery.get_file() will be called to grab the file for you (and download it if necessary)
as_path (bool) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
use_dask (bool, optional) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool, optional) – = only applied if use_dask=True = should we use dask’s persist() on data ?
dask_header (bool, optional) – should the header be dasked too (slows down a lot)
**kwargs (goes to __init__()) –
- Return type:
class instance
Examples
Load a ztf image you know the name of but not the full path.
>>> img = Image.from_filename("ztf_20220704387176_000695_zr_c11_o_q3_sciimg.fits", as_path=False, use_dask=False)
- classmethod from_data(data, header=None, **kwargs)#
Instanciate this class given data.
- Parameters:
data (numpy.array or dask.array]) – Data of the Image. this will automatically detect if the data are dasked.
header (fits.Header or dask.delayed) – Header of the image.
__init__ (**kwargs goes to) –
- Return type:
class instance
- to_fits(fileout, overwrite=True, **kwargs)#
writes the image (data and header) into a fits file.
- set_header(header)#
set self.header with the given header.
- set_data(data)#
Set the data to the instance
= It is unlikely you need to use that directly. =
- Parameters:
data (numpy.array, dask.array) – numpy or dask array with the same shape as cls.shape.
- Return type:
None
- Raises:
ValueError – This error is returned if the shape is not matching
See also
from_filename
loads the instance (data, header) given a filepath
from_data
loads the instance given data and header.
- get_data(rebin=None, rebin_stat='nanmean', data=None)#
get image data
- Parameters:
rebin (int, None) – Shall the data be rebinned by square of size rebin ? None means no rebinning. (see details in rebin_stat) rebin must be a multiple of the image shape. for instance if the input shape is (6160, 6144) rebin could be 2,4,8 or 16
rebin_stat (str) – = applies only if rebin is not None = numpy (dask.array) method used for rebinning the data. For instance, if rebin=4 and rebin_stat = median the median of a 4x4 pixel will be used to form a new pixel. The dimension of the final image will depend on rebin.
data (str) – If None, data=”data” assumed. Internal option to modify the data. This could be any attribure value of format (int/float) Leave to ‘data’ if you are not sure.
- Returns:
dask or numpy array, which shape will depend on rebin
- Return type:
2d array
- get_header(compute=True)#
get the current header
this is a shortcut to self.header
- Returns:
if compute is needed, this returns a pandas.Series for serialization issues
- Return type:
fits.Header or pandas.Series
- get_value(key, default=None, attr_ok=True)#
quick access to an image value.
This method looks for this key in: 1. image’s attributes 2. image’s meta 3. image’s header (using upper case).
- Parameters:
- Returns:
whatever is in the header key you queried.
- Return type:
- Raises:
AttributeError – If no header is set this returns is returned
- get_aperture(x, y, radius, data=None, bkgann=None, subpix=0, err=None, mask=None, as_dataframe=True, **kwargs)#
get the apeture photometry, base on sep.sum_circle()
- Parameters:
x (array) – coordinates of the centroid for the apertures. x and y are image pixel coordinates. numpy or dask array.
y (array) – coordinates of the centroid for the apertures. x and y are image pixel coordinates. numpy or dask array.
radius (float, list) – size (radius) of the aperture. This could be a list of radius.
data (2d-array, None) – if you want to apply the aperture photometry on this specific image, provide it. otherwhise,
data = self.get_data()
is usedbkgann (2d-array, None) – inner and outer radius of a “background annulus”. If supplied, the background is estimated by averaging unmasked pixels in this annulus.
subpix (int) – Subpixel sampling factor. 0 is the exact overlap calculation ; 5 is acceptable.
err (2d-array, None) – error image if you have it.
mask (2d-array, None) – mask image if you have it. Pixels within this mask will be ignored.
as_dataframe (bool) – return format. If As DataFrame, this will be a dataframe with 3xn-radius columns (f_0…f_i, f_0_e..f_i_e, f_0_f…f_i_f) standing for fluxes, errors, flags.
- Returns:
flux, error and flag for each coordinates and radius.
- Return type:
2d-array or dataframe
Examples
get the aperture photometry of random location in the image.
>>> import ztfimg >>> import numpy as np >>> img = ztfimg.Quadrant.from_filename("ztf_20220704387176_000695_zr_c11_o_q3_sciimg.fits", as_path=False, use_dask=False) >>> x = np.random.uniform(0, ztfimg.Quadrant.shape[1], size=400) >>> y = np.random.uniform(0, ztfimg.Quadrant.shape[0], size=400) >>> radius = np.linspace(1,5,10) >>> df = img.get_aperture(x,y, radius=radius[:,None], as_dataframe=True) >>> df.shape (400, 30) # 30 because 10 radius, so 10 flux, 10 errors, 10 flags
- show(ax=None, colorbar=True, cax=None, apply=None, data=None, vmin='1', vmax='99', rebin=None, savefile=None, dpi=150, **kwargs)#
Show the image data (imshow)
- Parameters:
ax (matplotlib.Axes, None) – provide the axes where the image should be drawn
colobar (bool) – should be colobar be added ?
cax (matplotlib.Axes, None) – = ignored if colobar=False = axes where the colorbar should be drawn
apply (str, None) – provide a numpy method that should be applied to the data prior been shown. For instance, apply=”log10”, then np.log10(data) will be shown.
data (2d-array, None) – if you want to plot this specific image, provide it. otherwhise,
data = self.get_data(rebin=rebin)
is shown.vmin (str, float) – minimum and maximum value for the colormap. string are interpreted as ‘percent of data’. float or int are understood as ‘use as such’
vmax (str, float) – minimum and maximum value for the colormap. string are interpreted as ‘percent of data’. float or int are understood as ‘use as such’
rebin (int, None) – by how much should the data be rebinned when accessed ? (see details in get_data())
savefile (str, None) – if you want to save the plot, provide here the path for that.
dpi (int) – = ignored if savefile is None = dpi of the stored image
- Return type:
matplotlib.Figure
See also
get_data
acess the image data
- property use_dask#
are the data dasked (did you set use_dask=True)
- property data#
data of the image ; numpy.array or dask.array
- has_data()#
are data set ? (True means yes)
- property header#
header of the data.
- shape = array(None, dtype=object)#
- property filename#
If this method was loaded from a file, this is it’s filename. None otherwise
- property filepath#
If this method was loaded from a file, this is it’s filename. None otherwise
- property filtername#
Name of the image’s filter (from header)
- property exptime#
Exposure time of the image (from header)
- property obsjd#
Observation Julian date of the image (from header)
- property meta#
meta data for the instance, from the filename.
- class ztfimg.base.Quadrant(data=None, header=None)#
Bases:
Image
See also
from_filename
load the instance given a filename
from_data
load the instance given its data (and header)
- Attributes:
ccdid
ccd id (from header)
data
data of the image ; numpy.array or dask.array
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filepath
If this method was loaded from a file, this is it’s filename.
filtername
Name of the image’s filter (from header)
header
header of the data.
meta
meta data for the instance, from the filename.
obsjd
Observation Julian date of the image (from header)
qid
quadrant id (from header)
rcid
rcid (from header)
use_dask
are the data dasked (did you set use_dask=True)
Methods
add_coord_to_catalog
(cat[, coord, ra, dec, ...])add the quadrant xy coordinates to a given catalog if possible.
compute
(**kwargs)computes all delayed attribute.
from_data
(data[, header])Instanciate this class given data.
from_filename
(filename[, as_path, use_dask, ...])classmethod load an instance given an input file.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_catalog
(name[, fieldcat, radius, ...])get a catalog for the image
get_ccd
([use_dask, as_path])get the ccd object containing this quadrant.
get_center
([system, reorder])get the center of the image
get_corners
([system, reorder])get the corners of the image.
get_data
([rebin, reorder])get image data
get_focalplane
([use_dask, as_path])get the full focal plane (64 quadrants making 16 CCDs) containing this quadrant
get_header
([compute])get the current header
get_value
(key[, default, attr_ok])quick access to an image value.
has_data
()are data set ? (True means yes)
persist
([attrnames])persist delayed attributes
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
to_fits
(fileout[, overwrite])writes the image (data and header) into a fits file.
- SHAPE = (3080, 3072)#
- get_ccd(use_dask=None, as_path=False, **kwargs)#
get the ccd object containing this quadrant. (see self._CCDCLASS)
- Parameters:
use_dask (bool, None) – should the ccd object be build using dask ? if None, the current instance use_dask is used.
as_path (bool) – should this assume that instance self.filename can be directly transformed ? False should be favored as it downloads the missing images if need.
self._CCDCLASS.from_single_filename() (**kwargs goes the) –
- Returns:
instance of self._CCDCLASS.
- Return type:
- get_focalplane(use_dask=None, as_path=False, **kwargs)#
get the full focal plane (64 quadrants making 16 CCDs) containing this quadrant
(see self._FocalPlaneCLASS)
- Parameters:
use_dask (bool, None) – should the ccd object be build using dask ? if None, the current instance use_dask is used.
as_path (bool) – should this assume that instance self.filename can be directly transformed ? False should be favored as it downloads the missing images if need.
self._FocalPlaneCLASS.from_single_filename() (**kwargs goes the) –
- Returns:
instance of self._FocalPlaneCLASS.
- Return type:
- get_data(rebin=None, reorder=True, **kwargs)#
get image data
- Parameters:
rebin (int, None) – Shall the data be rebinned by square of size rebin ? None means no rebinning. (see details in rebin_stat) rebin must be a multiple of the image shape. for instance if the input shape is (6160, 6144) rebin could be 2,4,8 or 16
reorder (bool) – Should the data be re-order to match the actual north-up. (leave to True if not sure)
rebin_stat (**kwargs goes to super.get_data() e.g.) –
- Returns:
numpy.array or dask.array
- Return type:
data
- get_catalog(name, fieldcat=False, radius=0.7, reorder=True, in_fov=False, use_dask=None, **kwargs)#
get a catalog for the image
- Parameters:
name (str) – name of a the catalog. - ps1 # available for fieldcat
fieldcat (bool) – is the catalog you are looking for a “field catalog” ? (see catalog.py). See list of available names in name parameter doc.
radius (float) – = ignored if fieldcat is True = radius [in degree] of the cone search centered on the quadrant position. radius=0.7 is slightly larger that half a diagonal.
reorder (bool) – when creating the x and y columns given the catalog ra, dec, should this assume x and y reordered position. reorder=True matches data from get_data() but not self.data. (leave to True if unsure).
in_fov (bool) – should entries outside the image footprint be droped ? (ignored if x and y column setting fails).
use_dask (bool) – should this return a dask.dataframe for the catalog ? If None, this will use self.use_dask.
download_vizier_catalog. (**kwargs goes to get_field_catalog or) –
- Returns:
catalog dataframe. The image x, y coordinates columns will be added using the radec_to_xy method. If not available, NaN will be set.
- Return type:
DataFrame
- add_coord_to_catalog(cat, coord='ij', ra='ra', dec='dec', reorder=True, in_fov=False)#
add the quadrant xy coordinates to a given catalog if possible.
This assume that radec_to_xy is implemented for this instance.
- Parameters:
cat (pandas.DataFrame or dask.dataframe) – catalog with at least the ra and dec keys.
ra (str) – R.A. entry of the input catalog
dec (str) – Dec entry of the input catalog
coord (str) – Coord to add to given catalogue. ‘ij’ or ‘xy’
reorder (bool) – when creating the x and y columns given the catalog ra, dec, should this assume x and y reordered position. reorder=True matches data from get_data() but not self.data. (leave to True if unsure).
in_fov (bool) – should entries outside the image footprint be droped ? (ignored if x and y column setting fails).
- Returns:
pandas or dask.
- Return type:
DataFrame
See also
get_catalog
get a catalog for this instance.
- get_center(system='xy', reorder=True)#
get the center of the image
- Parameters:
system (string) – coordinate system. - xy: image pixel coordinates - ij: ccd coordinates - radec: sky coordinates (in deg) - uv: camera coordinates (in arcsec)
reorder (bool) – should this provide the coordinates assuming normal ordering (+ra right, +dec up) (True) ? = leave True if unsure =
- Returns:
coordinates (see system)
- Return type:
2d-array
- get_corners(system='xy', reorder=True)#
get the corners of the image.
- Parameters:
system (str) – coordinate system. - xy: image pixel coordinates - ij: ccd coordinates - radec: sky coordinates (in deg) - uv: camera coordinates (in arcsec)
reorder (bool) – = ignored if system=’xy’ = should this provide the coordinates assuming normal ordering (+ra right, +dec up) (True) ? Leave default if unsure.
- Returns:
lower-left, lower-right, upper-right, upper-left
- Return type:
2d-array
- compute(**kwargs)#
computes all delayed attribute.
- Parameters:
attrnames (list) – list of attribute name this should be applied to. If None, all dasked attributes will be used.
delayed.compute(**kwargs) (**kwargs goes to) –
- Return type:
None
See also
persist
persists (some) delayed attributes
- persist(attrnames=None, **kwargs)#
persist delayed attributes
- Parameters:
attrnames (list) – list of attribute name this should be applied to. If None, all dasked attributes will be used.
delayed.persist(**kwargs) (**kwargs goes to) –
- Return type:
None
See also
compute
computes delayed attributes
- property qid#
quadrant id (from header)
- property ccdid#
ccd id (from header)
- property rcid#
rcid (from header)
- class ztfimg.base.CCD(quadrants=None, qids=None, data=None, header=None, pos_inverted=None, **kwargs)#
Bases:
Image
,_Collection_
CCD are collections for quadrants except if loaded from whole CCD data.
See also
from_filename
load the instance given a filename
from_filenames
load the image given the list of its four quadrant filenames
from_single_filename
build and load the instance given the filename of a single quadrant.
- Attributes:
ccdid
ccd id (from header)
collection_of
name of the collection elements.
data
the image data.
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filenames
list of the filename of the different quadrants constituing the data.
filepath
If this method was loaded from a file, this is it’s filename.
filepaths
list of the filepath of the different quadrants constituing the data.
filtername
Name of the image’s filter (from header)
header
header of the data.
meta
meta data for the instance, from the filename.
obsjd
Observation Julian date of the image (from header)
quadrants
dictionnary of the quadrants, keys are the quadrant id
use_dask
are the data dasked (did you set use_dask=True)
Methods
add_coord_to_catalog
(cat[, coord, ra, dec, ...])add the quadrant xy coordinates to a given catalog if possible.
call_quadrants
(what, *args, **kwargs)run the given input on quadrants
compute
(**kwargs)compute all dasked images = careful this may load a lot of data in memory =
from_data
(data[, header])Instanciate this class given data.
from_filename
(filename[, as_path, use_dask, ...])classmethod load an instance given an input file.
from_filenames
(filenames[, as_path, qids, ...])loads the instance from a list of the quadrant files.
from_quadrants
(quadrants[, qids])loads the instance given a list of four quadrants.
from_single_filename
(filename[, as_path, ...])given a single quadrant file, this fetchs the missing ones and loads the instance.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_catalog
(name[, fieldcat, in_fov, ...])get a catalog for the image.
get_center
([system, reorder])get the center of the image Note: this uses the 1st quadrant wcs solution if one is needed.
get_corners
([system, reorder])get the corners of the image.
get_data
([rebin, rebin_quadrant, ...])get (a copy of) the data
get_focalplane
([use_dask])get the full focal plane (64 quadrants making 16 CCDs) containing this quadrant
get_header
([compute])get the current header
get_quadrant
(qid)get a quadrant (
self.quadrants[qid]
)get_quadrantdata
([from_data, rebin, ...])get the quadrant's data.
get a DataFrame gathering the quadrants's header
get_value
(key[, default, attr_ok])quick access to an image value.
has_data
()are data set ? (True means yes)
has_quadrants
([logic])are (all/any, see option) quadrant loaded ?
load_data
(**kwargs)get the data from the quadrants and set it to data.
persist
(**kwargs)persist all dasked images = this loads data in your cluster's memory =
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
set_quadrant
(quadrant[, qid])set the quadrants to the instance.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
show_footprint
([values, ax, system, cmap, ...])illustrate the image footprint
to_fits
(fileout[, as_quadrants, overwrite])dump the data (and header if any) into the given fitsfile
to_quadrant_fits
(quadrantfiles[, overwrite, ...])dump the current image into 4 different files: one for each quadrants
- SHAPE = (6160, 6144)#
- classmethod from_single_filename(filename, as_path=True, use_dask=False, persist=False, **kwargs)#
given a single quadrant file, this fetchs the missing ones and loads the instance.
- Parameters:
filename (str) – filename of a single quadrant filename. This will look for the 3 missing to build the ccd.
as_path (bool -optional-) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
use_dask (bool, optional) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool, optional) – = only applied if use_dask=True = should we use dask’s persist() on data ?
_QUADRANTCLASS.from_filename (**kwargs goes to) –
- Return type:
class instance
Examples
>>> ccdimg = CCD.from_single_filename("ztf_20220704387176_000695_zr_c11_o_q3_sciimg.fits", as_path=False, use_dask=False)
See also
from_quadrants
loads the instance given a list of the four quadrants
from_filenames
loads the instance given the filename of the four quadrants
from_filename
loads the intance given a filename (assuming data are full-ccd shape)
- classmethod from_quadrants(quadrants, qids=None, **kwargs)#
loads the instance given a list of four quadrants.
- Parameters:
- Return type:
class instance
- Raises:
ValueError – this error is returned if you do not provide exactly 4 quadrants.
- classmethod from_filenames(filenames, as_path=True, qids=[1, 2, 3, 4], use_dask=False, persist=False, **kwargs)#
loads the instance from a list of the quadrant files.
- Parameters:
filanames (list of four str) – filenames for the four quadrants
as_path (bool) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
qids (list of int) – list of the qid for the input filenames
use_dask (bool) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool) – = only applied if use_dask=True = should we use dask’s persist() on data ?
_QUADRANTCLASS.from_filename (**kwargs goes to) –
- Return type:
class instance
- to_fits(fileout, as_quadrants=False, overwrite=True, **kwargs)#
dump the data (and header if any) into the given fitsfile
- Parameters:
fileout (str) – path to where the data should be stored. (fits file)
as_quadrant (bool) – should the data stored as 4 quadrant hdu images (True) or one larger image (as_quadrant=False)
overwrite (bool) – if fileout already exists, shall this overwrite it ?
writeto. (**kwargs goes to astropy.io.fits') –
- Return type:
output of astropy.io.fits.writeto
See also
to_quadrant_fits
store the data as quadrant fitsfile
- to_quadrant_fits(quadrantfiles, overwrite=True, from_data=True, **kwargs)#
dump the current image into 4 different files: one for each quadrants
- Parameters:
quadrantfiles (list of string) – list of the filenames for each of the quadrants
overwrite (bool) – if fileout already exists, shall this overwrite it ?
from_data (bool) – option of get_quadrantdata(). If both self.data exists and self.qudrants, should the data be taken from self.data (from_data=True) or from the individual quadrants (from_data=False) using
self.quadrants[i].get_data()
- Return type:
None
See also
to_fits
store the data as a unique fitsfile
get_quadrantdata
get a list of 2d-array (on per quadrant)
- load_data(**kwargs)#
get the data from the quadrants and set it to data.
- set_quadrant(quadrant, qid=None)#
set the quadrants to the instance.
= It is unlikely you need to use that directly. =
- Parameters:
quadrant (ztfimg.Quadrant) – attach a quadrant to the instance. will be added to
self.quadrants[qid]
qid (int, None) – quadrant id. If not provided, it will be taken from quadrant.qid.
- Return type:
None
See also
from_filenames
load the image given the list of its four quadrant filenames
from_single_filename
build and load the instance given the filename of a single quadrant.
- call_quadrants(what, *args, **kwargs)#
run the given input on quadrants
- get_quadrant(qid)#
get a quadrant (
self.quadrants[qid]
)
- get_focalplane(use_dask=None, **kwargs)#
get the full focal plane (64 quadrants making 16 CCDs) containing this quadrant
(see self._FocalPlaneCLASS)
- Parameters:
use_dask (bool, None) – should the ccd object be build using dask ? if None, the current instance use_dask is used.
as_path (bool) – should this assume that instance self.filename can be directly transformed ? False should be favored as it downloads the missing images if need.
self._FocalPlaneCLASS.from_single_filename() (**kwargs goes the) –
- Returns:
instance of self._FocalPlaneCLASS.
- Return type:
- get_quadrantheader()#
get a DataFrame gathering the quadrants’s header
- Returns:
on column per quadrant
- Return type:
DataFrame
- get_quadrantdata(from_data=False, rebin=None, rebin_stat='mean', reorder=True, **kwargs)#
get the quadrant’s data.
- Parameters:
from_data (bool) – if self.data exists, should the quadrant be taken from it (spliting it into 4 quadrants) ? if not, it will be taken from self.get_quadrant(i).get_data()
- rebin: int, None
Shall the data be rebinned by square of size rebin ? None means no rebinning. (see details in rebin_stat) rebin must be a multiple of the image shape. for instance if the input shape is (6160, 6144) rebin could be 2,4,8 or 16
- rebin_stat: str
= applies only if rebin is not None = numpy (dask.array) method used for rebinning the data. For instance, if rebin=4 and rebin_stat = median the median of a 4x4 pixel will be used to form a new pixel. The dimension of the final image will depend on rebin.
- reorder: bool
Should the data be re-order to match the actual north-up. (leave to True if not sure)
**kwargs goes to each quadrant’s get_data() (only if not from_data)
- Returns:
list of 2d-array.
- Return type:
3d-array
See also
get_data
access the image data.
- get_data(rebin=None, rebin_quadrant=None, rebin_stat='mean', rebuild=False, persist=False, **kwargs)#
get (a copy of) the data
- Parameters:
rebin (int, None) – Shall the data be rebinned by square of size rebin ? None means no rebinning. (see details in rebin_stat) rebin must be a multiple of the image shape. for instance if the input shape is (6160, 6144) rebin could be 2,4,8 or 16 = rebin is applied to the whole ccd image see rebin_quadrant for rebinning at the quadrant level =
rebin_quadrant (int, None) – rebinning (like rebin) but applied at the quadrant level (prior merging then as data)
rebin_stat (str) – = applies only if rebin is not None = numpy (dask.array) method used for rebinning the data. For instance, if rebin=4 and rebin_stat = median the median of a 4x4 pixel will be used to form a new pixel. The dimension of the final image will depend on rebin.
rebuild (bool) – if self.data exist and rebin_quadrant is None, then
self.data.copy()
will be used. If rebuild=True, then this will be re-build the data and ignore self.datapersist (bool) – = only applied if self.use_dask is True = should we use dask’s persist() on data ?
- Returns:
dask or numpy array
- Return type:
2d-array
See also
get_quadrantdata
get a list of all the individual quadrant data.
Examples
get the ccd image and rebin it by 4 >>> ccdimg.get_data(rebin=4).shape
- get_catalog(name, fieldcat=False, in_fov=False, drop_duplicate=True, sourcekey='Source', use_dask=None, **kwargs)#
get a catalog for the image.
This method calls down to the individual quadrant’s get_catalog and merge them while updating their x,y position to make x,y ccd pixels and not quadrant pixels.
- get_center(system='xy', reorder=True)#
get the center of the image Note: this uses the 1st quadrant wcs solution if one is needed.
- Parameters:
system (string) – coordinate system. # for ccds xy and ij are the same - xy / ij: image pixel coordinates - radec: sky coordinates (in deg) - uv: camera coordinates (in arcsec)
reorder (bool) – should this provide the coordinates assuming normal ordering (+ra right, +dec up) (True) ? = leave True if unsure =
- Returns:
coordinates (see system)
- Return type:
2d-array
- get_corners(system='xy', reorder=True)#
get the corners of the image. Note: this uses the 1st quadrant wcs solution if one is needed.
- Parameters:
- Returns:
lower-left, lower-right, upper-right, upper-left
- Return type:
2d-array
- add_coord_to_catalog(cat, coord='ij', ra='ra', dec='dec', reorder=True, in_fov=False)#
add the quadrant xy coordinates to a given catalog if possible.
This assume that radec_to_xy is implemented for this instance.
- Parameters:
cat (pandas.DataFrame or dask.dataframe) – catalog with at least the ra and dec keys.
ra (str) – R.A. entry of the input catalog
dec (str) – Dec entry of the input catalog
coord (str) – Coord to add to given catalogue. ‘ij’ or ‘xy’
reorder (bool) – when creating the x and y columns given the catalog ra, dec, should this assume x and y reordered position. reorder=True matches data from get_data() but not self.data. (leave to True if unsure).
in_fov (bool) – should entries outside the image footprint be droped ? (ignored if x and y column setting fails).
- Returns:
pandas or dask.
- Return type:
DataFrame
See also
get_catalog
get a catalog for this instance.
- show_footprint(values='qid', ax=None, system='ij', cmap='coolwarm', vmin=None, vmax=None, quadrant_id='qid', **kwargs)#
illustrate the image footprint
- Parameters:
values (str, None, array, dict, pandas.Series) –
values to be displaid as facecolor in the image. - str: understood as a quadrant properties
(using call_quadrants)
ax (matplotlib.Axes) – axes where to draw the plot
system (str) – coordinates system: - xy: quadrant - ij: ccd (favored) - uv: focalplane
cmap (str or matplotlib's cmap) – colormap
vmin – boundaries for the colormap
vmax – boundaries for the colormap
quadrant_id (str or None) – value indicated in the quadrants. None means no text written.
matplotlib.patches.Polygon (**kwargs goes to) –
- Return type:
fig
- property data#
the image data.
- property quadrants#
dictionnary of the quadrants, keys are the quadrant id
- has_quadrants(logic='all')#
are (all/any, see option) quadrant loaded ?
- qshape = array([3080, 3072])#
- property ccdid#
ccd id (from header)
- property filenames#
list of the filename of the different quadrants constituing the data.
- property filepaths#
list of the filepath of the different quadrants constituing the data.
- class ztfimg.base.FocalPlane(ccds=None, ccdids=None, data=None, header=None, **kwargs)#
Bases:
Image
,_Collection_
See also
from_filename
load the instance given a filename
from_filenames
load the image given the list of its quadrant filenames
from_single_filename
build and load the instance given the filename of a single quadrant.
- Attributes:
- SHAPE
ccds
dictionary of the ccds {ccdid:CCD, …}
collection_of
name of the collection elements.
data
data of the image ; numpy.array or dask.array
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filenames
list of the filename of the different quadrants constituing the data.
filepath
If this method was loaded from a file, this is it’s filename.
filepaths
list of the filename of the different quadrants constituing the data.
filtername
Name of the image’s filter (from header)
header
header of the data.
meta
meta data for the instance, from the filename.
obsjd
Observation Julian date of the image (from header)
use_dask
are the data dasked (did you set use_dask=True)
Methods
call_ccds
(what, *args, **kwargs)run the given input on ccds
call_quadrants
(what, *args, **kwargs)run the given input on quadrants
compute
(**kwargs)compute all dasked images = careful this may load a lot of data in memory =
from_data
(data[, header])Instanciate this class given data.
from_filename
(filename[, as_path, use_dask, ...])classmethod load an instance given an input file.
from_filenames
(filenames[, as_path, rcids, ...])loads the instance from a list of the quadrant files.
from_single_filename
(filename[, as_path, ...])given a single quadrant file, this fetchs the missing ones and loads the instance.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_ccd
(ccdid)get the ccd (self.ccds[ccdid])
get_data
([rebin, incl_gap, persist, ccd_coef])get data.
get_header
([compute])get the current header
get_quadrant
(rcid)get the quadrant (get the ccd and then get its quadrant
get_quadrantheader
([rcids])returns a DataFrame of the header quadrants (rcid)
get_value
(key[, default, attr_ok])quick access to an image value.
has_ccds
([logic])test if (any/all see option) ccds are loaded.
has_data
()are data set ? (True means yes)
persist
(**kwargs)persist all dasked images = this loads data in your cluster's memory =
set_ccd
(ccd[, ccdid])attach ccd images to the instance.
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
show_footprint
([values, ax, level, cmap, ...])illustrate the image footprint
to_fits
(fileout[, overwrite])writes the image (data and header) into a fits file.
- classmethod from_filenames(filenames, as_path=True, rcids=None, use_dask=False, persist=False, **kwargs)#
loads the instance from a list of the quadrant files.
- Parameters:
filanames (list of four str) – filenames for the four quadrants
as_path (bool) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
rcid (list of int) – list of the rcid (0->63) for the input filenames
use_dask (bool) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool) – = only applied if use_dask=True = should we use dask’s persist() on data ?
_CCDCLASS.from_filenames (**kwargs goes to) –
- Return type:
class instance
- classmethod from_single_filename(filename, as_path=True, use_dask=False, persist=False, **kwargs)#
given a single quadrant file, this fetchs the missing ones and loads the instance.
- Parameters:
filename (str) – filename of a single quadrant filename. This will look for the 3 missing to build the ccd.
as_path (bool -optional-) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
use_dask (bool, optional) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool, optional) – = only applied if use_dask=True = should we use dask’s persist() on data ?
_QUADRANTCLASS.from_filename() (**kwargs goes to _CCDCLASS.from_single_filename ->) –
- Return type:
class instance
Examples
>>> ccdimg = CCD.from_single_filename("ztf_20220704387176_000695_zr_c11_o_q3_sciimg.fits", as_path=False, use_dask=False)
- set_ccd(ccd, ccdid=None)#
attach ccd images to the instance.
- call_ccds(what, *args, **kwargs)#
run the given input on ccds
- call_quadrants(what, *args, **kwargs)#
run the given input on quadrants
- get_ccd(ccdid)#
get the ccd (self.ccds[ccdid])
- get_quadrant(rcid)#
get the quadrant (get the ccd and then get its quadrant
- get_quadrantheader(rcids='all')#
returns a DataFrame of the header quadrants (rcid)
- get_data(rebin=None, incl_gap=True, persist=False, ccd_coef=None, **kwargs)#
get data.
- show_footprint(values='id', ax=None, level='quadrant', cmap='coolwarm', vmin=None, vmax=None, incl_ids=True, in_deg=True, **kwargs)#
illustrate the image footprint
- Parameters:
values (str, None, array, dict, pandas.Series) –
values to be displaid as facecolor in the image. - str: understood as a level properties
(using call_quadrants or call_ccds) Special case: ‘id’ means: - ccdid if level=’ccd’ - rcid if level=’quadrant
- ax: matplotlib.Axes
axes where to draw the plot
- level: str
‘ccd’ (16) or ‘quadrant’ (64)
- cmap: str or matplotlib’s cmap
colormap
- vmin, vmax:
boundaries for the colormap
- incl_ids: bool
should the name of the (ccd or quadrant) id be shown ?
- in_deg: bool
should the footprint be shown in deg (True) or in arcsec (False) ? note: 1 pixel ~ 1 arcsec
**kwargs goes to matplotlib.patches.Polygon
- Return type:
fig
- property ccds#
CCD, …}
- Type:
dictionary of the ccds {ccdid
- has_ccds(logic='all')#
test if (any/all see option) ccds are loaded.
- property filenames#
list of the filename of the different quadrants constituing the data.
- property filepaths#
list of the filename of the different quadrants constituing the data.
- shape_full = array([24640, 24576])#
- shape = array([24640, 24576])#
- ccdshape = array([6160, 6144])#
- qshape = array([3080, 3072])#
Raw#
- class ztfimg.raw.RawQuadrant(data=None, header=None, overscan=None)#
Bases:
Quadrant
See also
from_filename
load the instance given a filename
from_data
load the instance given its data (and header)
- Attributes:
ccdid
ccd id (from header)
darkcurrent
Dark current [e-/s]
data
data of the image ; numpy.array or dask.array
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filepath
If this method was loaded from a file, this is it’s filename.
filtername
Name of the image’s filter (from header)
gain
gain [adu/e-]
header
header of the data.
meta
meta data for the instance, from the filename.
obsjd
Observation Julian date of the image (from header)
- overscan
qid
quadrant (amplifier of the ccd) id (1->4)
rcid
quadrant (within the focal plane) id (0->63)
readnoise
read-out noise [e-]
shape_overscan
shape of the raw overscan data
use_dask
are the data dasked (did you set use_dask=True)
Methods
add_coord_to_catalog
(cat[, coord, ra, dec, ...])add the quadrant xy coordinates to a given catalog if possible.
compute
(**kwargs)computes all delayed attribute.
from_data
(data[, header, overscan])Instanciate this class given data.
from_filefracday
(filefracday, rcid[, ...])load the instance given a filefracday and the rcid (ztf ID)
from_filename
(filename, qid[, as_path, ...])classmethod load an instance given an input file.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_catalog
(name[, fieldcat, radius, ...])get a catalog for the image
get_ccd
([use_dask, as_path])get the ccd object containing this quadrant.
get_center
([system, reorder])get the center of the image
get_corners
([system, reorder])get the corners of the image.
get_data
([corr_overscan, corr_nl, rebin, ...])get the image data.
hstack of data and oversan with amplifier at (0,0) resulting shape: (quad.SHAPE[0], quad.SHAPE[1]+quad.SHAPE_OVERSCAN[1])
get_focalplane
([use_dask, as_path])get the full focal plane (64 quadrants making 16 CCDs) containing this quadrant
get_header
([compute])get the current header
get_lastdata_firstoverscan
([n, ...])get the last data and the first overscan columns
looks in the raw.NONLINEARITY_TABLE the the entry corresponding to the quadrant's rcid and returns the a and b parameters.
get_overscan
([which, sigma_clipping, ...])- param which:
There are different format.
get_sciimage
([use_dask])get the Science image corresponding to this raw image
get_value
(key[, default, attr_ok])quick access to an image value.
has_data
()are data set ? (True means yes)
persist
([attrnames])persist delayed attributes
read_rawfile_header
(filepath, qid[, ...])reads the filename's header and returns it as a pandas.DataFrame
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
set_overscan
(overscan)set the overscan image.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
show_overscan
([ax, axs, axm, which, ...])display the overscan image.
to_fits
(fileout[, overwrite])writes the image (data and header) into a fits file.
- SHAPE_OVERSCAN = (3080, 30)#
- classmethod from_data(data, header=None, overscan=None, **kwargs)#
Instanciate this class given data.
- Parameters:
data (numpy.array or dask.array]) – Data of the Image. this will automatically detect if the data are dasked.
header (fits.Header or dask.delayed) – Header of the image.
overscan (2d-array) – overscan image.
__init__ (**kwargs goes to) –
- Return type:
class instance
- classmethod from_filename(filename, qid, as_path=True, use_dask=False, persist=False, dask_header=False, **kwargs)#
classmethod load an instance given an input file.
- Parameters:
filename (str) – fullpath or filename or the file to load. This must be a raw ccd file. If a filename is given, set as_path=False, then ztfquery.get_file() will be called to grab the file for you (and download it if necessary)
qid (int) – quadrant id. Which quadrant to load from the input raw image ?
as_path (bool) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
use_dask (bool) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool) – = only applied if use_dask=True = should we use dask’s persist() on data ?
dask_header (bool, optional) – should the header be dasked too (slows down a lot)
**kwargs (goes to __init__()) –
- Return type:
class instance
- classmethod from_filefracday(filefracday, rcid, use_dask=True, persist=False, **kwargs)#
load the instance given a filefracday and the rcid (ztf ID)
- Parameters:
filefracday (str) – ztf ID of the exposure (YYYYMMDDFFFFFF) like 20220704387176 ztfquery will fetch for the corresponding data.
rcid (int) – rcid of the given quadrant
use_dask (bool) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool) – = only applied if use_dask=True = should we use dask’s persist() on data ?
__init__ (**kwargs goes to from_filename ->) –
- Return type:
class instance
- static read_rawfile_header(filepath, qid, grab_imgkeys=True)#
reads the filename’s header and returns it as a pandas.DataFrame
- set_overscan(overscan)#
set the overscan image.
= It is unlikely you need to use that directly. =
- Parameters:
overscan (2d-array) – overscan 2d-image
- Return type:
None
- get_data_and_overscan()#
hstack of data and oversan with amplifier at (0,0) resulting shape: (quad.SHAPE[0], quad.SHAPE[1]+quad.SHAPE_OVERSCAN[1])
- get_data(corr_overscan=False, corr_nl=False, rebin=None, rebin_stat='nanmean', reorder=True, overscan_prop={}, **kwargs)#
get the image data.
returned data can be affected by different effects.
- Parameters:
corr_overscan (bool) – Should the data be corrected for overscan (if both corr_overscan and corr_nl are true, nl is applied first)
corr_nl (bool) – Should data be corrected for non-linearity
rebin (int, None) – Shall the data be rebinned by square of size rebin ? None means no rebinning. (see details in rebin_stat) rebin must be a multiple of the image shape. for instance if the input shape is (6160, 6144) rebin could be 2,4,8 or 16
rebin_stat (str) – = applies only if rebin is not None = numpy (dask.array) method used for rebinning the data. For instance, if rebin=4 and rebin_stat = median the median of a 4x4 pixel will be used to form a new pixel. The dimension of the final image will depend on rebin.
reorder (bool) – Should the data be re-order to match the actual north-up. (leave to True if not sure)
overscan_prop ([dict] -optional-) – kwargs going to get_overscan() - > e.g. userange=[10,20], stackstat=”nanmedian”, modeldegree=5,
- Returns:
numpy or dask array
- Return type:
2d-array
- get_nonlinearity_corr()#
looks in the raw.NONLINEARITY_TABLE the the entry corresponding to the quadrant’s rcid and returns the a and b parameters.
raw data should be corrected as such:
` data_corr = data/(a*data**2 + b*data +1) `
- Return type:
data
- get_overscan(which='data', sigma_clipping=3, userange=[5, 25], stackstat='nanmedian', modeldegree=3, specaxis=1, corr_overscan=False, corr_nl=False)#
- Parameters:
which (str) –
There are different format. - data and raw are 2d images:
’raw’ are the overscan as stored
- ’data’ re-order the data, that is, first overscan left and north up
matching get_data(reorder=True).
- could be:
- ’raw’: as stored |
most likely you want ‘data’ as it includes re-ordering i.e. [:,0] is the first overscan independently of the quadrant
’data’: raw re-ordered and within userange (if given).
’spec’: vertical or horizontal profile of the overscan
see stackstat (see specaxis). Clipping is applied at that time (if clipping=True) - ‘model’: polynomial model of spec
clipping (bool) – Should clipping be applied to remove the obvious flux excess. This clipping is made using median statistics (median and 3*nmad)
specaxis (int) – axis along which you are doing the median = Careful: after userange applyed = - axis: 1 (default) -> horizontal overscan data spectrum (~3000 pixels) - axis: 0 -> vertical stack of the overscan (~30 pixels) (see stackstat for stacking statistic (mean, median etc)
stackstat (str) – numpy method to use to converting data into spec
userange (2d-array) – = ignored is which != data or raw = start and end of overscan data to be considered.
corr_overscan (bool) – = only if which is raw or data = Should the data be corrected for overscan (if both corr_overscan and corr_nl are true, nl is applied first)
corr_nl (bool) – = only if which is raw or data = Should data be corrected for non-linearity
- Return type:
1 or 2d array (see which)
Examples
To get the raw overscan vertically stacked spectra, using mean statistic do: get_overscan(‘spec’, userange=None, specaxis=0, stackstat=’nanmean’)
- get_lastdata_firstoverscan(n=1, corr_overscan=False, corr_nl=False, **kwargs)#
get the last data and the first overscan columns
- get_sciimage(use_dask=None, **kwargs)#
get the Science image corresponding to this raw image
This uses ztfquery to parse the filename and set up the correct science image filename path.
- Parameters:
use_dask (bool or None) – if None, this will use self.use_dask.
ScienceQuadrant.from_filename (**kwargs goes to) –
- Return type:
- show_overscan(ax=None, axs=None, axm=None, which='data', colorbar=False, cax=None, **kwargs)#
display the overscan image.
- Return type:
fig
- property shape_overscan#
shape of the raw overscan data
- property overscan#
- property qid#
quadrant (amplifier of the ccd) id (1->4)
- property rcid#
quadrant (within the focal plane) id (0->63)
- property gain#
gain [adu/e-]
- property darkcurrent#
Dark current [e-/s]
- property readnoise#
read-out noise [e-]
- class ztfimg.raw.RawCCD(quadrants=None, qids=None, data=None, header=None, pos_inverted=None, **kwargs)#
Bases:
CCD
CCD are collections for quadrants except if loaded from whole CCD data.
See also
from_filename
load the instance given a filename
from_filenames
load the image given the list of its four quadrant filenames
from_single_filename
build and load the instance given the filename of a single quadrant.
- Attributes:
ccdid
ccd id (from header)
collection_of
name of the collection elements.
data
the image data.
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filenames
list of the filename of the different quadrants constituing the data.
filepath
If this method was loaded from a file, this is it’s filename.
filepaths
list of the filepath of the different quadrants constituing the data.
filtername
Name of the image’s filter (from header)
header
header of the data.
meta
meta data for the instance, from the filename.
obsjd
Observation Julian date of the image (from header)
quadrants
dictionnary of the quadrants, keys are the quadrant id
use_dask
are the data dasked (did you set use_dask=True)
Methods
add_coord_to_catalog
(cat[, coord, ra, dec, ...])add the quadrant xy coordinates to a given catalog if possible.
call_quadrants
(what, *args, **kwargs)run the given input on quadrants
compute
(**kwargs)compute all dasked images = careful this may load a lot of data in memory =
from_data
(data[, header])Instanciate this class given data.
from_filefracday
(filefracday, ccdid[, use_dask])load the instance given a filefracday and the ccidid (ztf ID)
from_filename
(filename[, as_path, use_dask, ...])load the instance from the raw filename.
from_filenames
(*args, **kwargs)rawccd data have a single file.
from_quadrants
(quadrants[, qids])loads the instance given a list of four quadrants.
from_single_filename
(*args, **kwargs)rawccd data have a single file.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_catalog
(name[, fieldcat, in_fov, ...])get a catalog for the image.
get_center
([system, reorder])get the center of the image Note: this uses the 1st quadrant wcs solution if one is needed.
get_corners
([system, reorder])get the corners of the image.
get_data
([rebin, rebin_quadrant, ...])get (a copy of) the data
get_focalplane
([use_dask])get the full focal plane (64 quadrants making 16 CCDs) containing this quadrant
get_header
([compute])get the current header
get_quadrant
(qid)get a quadrant (
self.quadrants[qid]
)get_quadrantdata
([from_data, rebin, ...])get the quadrant's data.
get_quadrantheader
()get a DataFrame gathering the quadrants's header
get_sciimage
([use_dask, qid, as_ccd])get the Science image corresponding to this raw image
get_value
(key[, default, attr_ok])quick access to an image value.
has_data
()are data set ? (True means yes)
has_quadrants
([logic])are (all/any, see option) quadrant loaded ?
load_data
(**kwargs)get the data from the quadrants and set it to data.
persist
(**kwargs)persist all dasked images = this loads data in your cluster's memory =
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
set_quadrant
(quadrant[, qid])set the quadrants to the instance.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
show_footprint
([values, ax, system, cmap, ...])illustrate the image footprint
to_fits
(fileout[, as_quadrants, overwrite])dump the data (and header if any) into the given fitsfile
to_quadrant_fits
(quadrantfiles[, overwrite, ...])dump the current image into 4 different files: one for each quadrants
- classmethod from_filename(filename, as_path=True, use_dask=False, persist=False, **kwargs)#
load the instance from the raw filename.
- Parameters:
filename (str) – fullpath or filename or the file to load. If a filename is given, set as_path=False, then ztfquery.get_file() will be called to grab the file for you (and download it if necessary)
as_path (bool) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
use_dask (bool, optional) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool, optional) – = only applied if use_dask=True = should we use dask’s persist() on data ?
**kwargs (goes to _QUADRANTCLASS.from_filename) –
- Return type:
class instance
Examples
Load a ztf image you know the name of but not the full path.
>>> rawccd = ztfimg.RawCCD.from_filename("ztf_20220704387176_000695_zr_c11_o.fits.fz", as_path=False)
- classmethod from_single_filename(*args, **kwargs)#
rawccd data have a single file.
See also
from_filename
load the instance given the raw filename
- classmethod from_filenames(*args, **kwargs)#
rawccd data have a single file.
See also
from_filename
load the instance given the raw filename
- classmethod from_filefracday(filefracday, ccdid, use_dask=True, **kwargs)#
load the instance given a filefracday and the ccidid (ztf ID)
- Parameters:
filefracday (str) – ztf ID of the exposure (YYYYMMDDFFFFFF) like 20220704387176 ztfquery will fetch for the corresponding data.
ccidid (int) – ccidid of the given ccd
use_dask (bool) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool) – = only applied if use_dask=True = should we use dask’s persist() on data ?
__init__ (**kwargs goes to from_filename ->) –
- Return type:
class instance
- get_sciimage(use_dask=None, qid=None, as_ccd=True, **kwargs)#
get the Science image corresponding to this raw image
This uses ztfquery to parse the filename and set up the correct science image filename path.
- Parameters:
- Return type:
- class ztfimg.raw.RawFocalPlane(ccds=None, ccdids=None, data=None, header=None, **kwargs)#
Bases:
FocalPlane
See also
from_filename
load the instance given a filename
from_filenames
load the image given the list of its quadrant filenames
from_single_filename
build and load the instance given the filename of a single quadrant.
- Attributes:
- SHAPE
ccds
dictionary of the ccds {ccdid:CCD, …}
collection_of
name of the collection elements.
data
data of the image ; numpy.array or dask.array
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filenames
list of the filename of the different quadrants constituing the data.
filepath
If this method was loaded from a file, this is it’s filename.
filepaths
list of the filename of the different quadrants constituing the data.
filtername
Name of the image’s filter (from header)
header
header of the data.
meta
meta data for the instance, from the filename.
obsjd
Observation Julian date of the image (from header)
use_dask
are the data dasked (did you set use_dask=True)
Methods
call_ccds
(what, *args, **kwargs)run the given input on ccds
call_quadrants
(what, *args, **kwargs)run the given input on quadrants
compute
(**kwargs)compute all dasked images = careful this may load a lot of data in memory =
from_data
(data[, header])Instanciate this class given data.
from_filefracday
(filefracday[, use_dask])load the instance given a filefracday and the ccidid (ztf ID)
from_filename
(filename[, as_path, use_dask, ...])classmethod load an instance given an input file.
from_filenames
(filenames[, as_path, ...])load the instance from the raw filename.
from_single_filename
(filename[, as_path, ...])given a single quadrant file, this fetchs the missing ones and loads the instance.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_ccd
(ccdid)get the ccd (self.ccds[ccdid])
get_data
([rebin, incl_gap, persist, ccd_coef])get data.
get_header
([compute])get the current header
get_quadrant
(rcid)get the quadrant (get the ccd and then get its quadrant
get_quadrantheader
([rcids])returns a DataFrame of the header quadrants (rcid)
get_value
(key[, default, attr_ok])quick access to an image value.
has_ccds
([logic])test if (any/all see option) ccds are loaded.
has_data
()are data set ? (True means yes)
persist
(**kwargs)persist all dasked images = this loads data in your cluster's memory =
set_ccd
(ccd[, ccdid])attach ccd images to the instance.
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
show_footprint
([values, ax, level, cmap, ...])illustrate the image footprint
to_fits
(fileout[, overwrite])writes the image (data and header) into a fits file.
- classmethod from_filenames(filenames, as_path=True, use_dask=False, persist=False, **kwargs)#
load the instance from the raw filename.
- Parameters:
filenames (list of str) – list of fullpath or filename or the ccd file to load. If a filename is given, set as_path=False, then ztfquery.get_file() will be called to grab the file for you (and download it if necessary)
as_path (bool) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
use_dask (bool, optional) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool, optional) – = only applied if use_dask=True = should we use dask’s persist() on data ?
**kwargs (goes to _CCDCLASS.from_filename) –
- Return type:
class instance
- classmethod from_filefracday(filefracday, use_dask=True, **kwargs)#
load the instance given a filefracday and the ccidid (ztf ID)
- Parameters:
filefracday (str) – ztf ID of the exposure (YYYYMMDDFFFFFF) like 20220704387176 ztfquery will fetch for the corresponding data.
use_dask (bool) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool) – = only applied if use_dask=True = should we use dask’s persist() on data ?
_CCDCLASS.from_filename (**kwargs goes to from_filenames ->) –
- Return type:
class instance
Science#
- class ztfimg.science.ScienceQuadrant(data=None, mask=None, header=None, meta=None)#
Bases:
Quadrant
,WCSHolder
,ComplexImage
Science Quadrant. You most likely want to load it using from_* class method
See also
from_filename
load the instance using a quadrant filename
- Attributes:
ccdid
id of the ccd (1->16)
data
data of the image ; numpy.array or dask.array
exptime
Exposure time of the image (from header)
fieldid
number of the field (from meta)
filefracday
id corresponding to the ‘fraction of the day’ (from meta)
filename
If this method was loaded from a file, this is it’s filename.
filepath
If this method was loaded from a file, this is it’s filename.
filterid
filter number (1: zg, 2: zr, 3:zi) see self.filtername
filtername
name of the filter (from self.meta)
header
header of the data.
mask
mask image.
meta
meta data for the instance, from the filename.
obsdate
observing date with the yyyy-mm-dd format.
obsjd
Observation Julian date of the image (from header)
pointing
requested telescope pointing [in degree]
qid
id of the quadrant (1->4)
rcid
id of the quadrant in the focal plane (from meta) (0->63)
use_dask
are the data dasked (did you set use_dask=True)
wcs
astropy wcs solution loaded from the header
Methods
add_coord_to_catalog
(cat[, coord, ra, dec, ...])add the quadrant xy coordinates to a given catalog if possible.
compute
(**kwargs)computes all delayed attribute.
from_data
(data[, header])Instanciate this class given data.
from_filename
(filename[, filename_mask, ...])- param filename:
name of the file.
get_aperture
(x0, y0, radius[, data, bkgann, ...])get the aperture (circular) photometry.
get_background
([method, data])get an estimation of the image's background
get_catalog
(name[, fieldcat, radius, ...])get a catalog for the image
get_ccd
([use_dask, as_path])get the ccd object containing this quadrant.
get_center
([system, reorder])get the center of the image
get_corners
([system, reorder])get the corners of the image.
get_data
([apply_mask, rm_bkgd, rebin, ...])get a copy of the data affected by background and/or masking.
get_focalplane
([use_dask, as_path])get the full focal plane (64 quadrants making 16 CCDs) containing this quadrant
get_header
([compute])get the current header
get_mask
([reorder, from_sources, tracks, ...])get a boolean mask (or associated flags).
get_noise
([method])get a noise image or value
get_psfcat
([show_progress, use_dask])get the psf photometry catalog generated by the ztf-pipeline
get_rawimage
([use_dask, which, as_path])get the raw image of the given science quadrant
get_sexcat
([as_table, show_progress, use_dask])get the sextractor photometry catalog generated by the ztf-pipeline (nested-aperture photometry catalog)
get_value
(key[, default, attr_ok])quick access to an image value.
has_data
()are data set ? (True means yes)
ij_to_radec
(i, j[, reorder, qid])get the (ra,dec) sky coordinates from the i,j ccd coordinates
ij_to_uv
(i, j[, reorder, qid])get the tangent plane coordinates from the i,j ccd coordinates
ij_to_xy
(i, j[, qid])converts ccd coordinates (i,j) into quadrant coordinates (x,y)
load_wcs
([header])loads the wcs solution from the header
persist
([attrnames])persist delayed attributes
radec_to_ij
(ra, dec[, reorder, qid])radec to ccd coordinates (i,j)
radec_to_uv
(ra, dec)radec to u, v (tangent plane projection in arcsec from pointing center)
radec_to_xy
(ra, dec[, reorder])get the (x,y) quadrant positions given the sky ra, dec [in deg] coordinates
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
set_mask
(mask)set the mask to this instance.
set_wcs
(wcs[, pointingkey])show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
to_fits
(fileout[, overwrite])writes the image (data and header) into a fits file.
uv_to_ij
(u, v[, reorder, qid])get the i,j ccd pixel coordinates given the tangent plane coordinates u, v
uv_to_radec
(u, v)get the ra, dec coordinates given the tangent plane coordinates u, v
uv_to_xy
(u, v[, reorder])get the x, y quadrant position given the tangent plane coordinates u, v
xy_to_ij
(x, y[, qid])converts quadrant coordinates (x,y) into ccd coordinates (i,j)
xy_to_radec
(x, y[, reorder])get sky ra, dec [in deg] coordinates given the (x,y) quadrant positions
xy_to_uv
(x, y[, reorder])w,y to u, v tangent plane projection (in arcsec from pointing center).
get_source_mask
has_wcs
set_pointing
- classmethod from_filename(filename, filename_mask=None, download=True, as_path=True, use_dask=False, persist=False, **kwargs)#
- Parameters:
filename (str) – name of the file. This could be a full path or a ztf filename. (see as_path option)
filename_mask (str) – name of the file containing the mask. This could be a full path or a ztf filename. (see as_path option). If None, filename_mask will be built based on filename.
download (bool) – Downloads the file (filename or filename_masl) if necessary.
as_path (bool) – Set to True if the filename [filename_mask] are path and not just ztf filename, hence bypassing
filename = ztfquery.io.get_file(filename)
use_dask (bool) – Shall this use dask to load the image data ?
persist (bool) – = ignored if use_dask=False = shall this run .persist() on data ?
= (**kwargs goes to ztfquery.io.get_file() = ignored if as_path=True) –
- Return type:
instance
- load_wcs(header=None)#
loads the wcs solution from the header
- Parameters:
header (fits.Header) – header containing the wcs information. If None, self.header will be used.
- get_rawimage(use_dask=None, which='quadrant', as_path=False, **kwargs)#
get the raw image of the given science quadrant
This uses ztfquery to fetch the raw image path and inputs it to RawQuadrant or RawCCD .from_filename method (see which)
- get_data(apply_mask=False, rm_bkgd=False, rebin=None, rebin_stat='nanmean', maskvalue=nan, zp=None, reorder=True, **kwargs)#
get a copy of the data affected by background and/or masking.
- Parameters:
apply_mask (bool, array) – Shall a default masking be applied (i.e. all bad pixels to nan) if an array is given, this will be the mask used.
rm_bkgd (bool, array, float) – Should the data be background subtracted ? if something else than a bool is given, it will be used as background
maskvalue (float) – Whick values should the masked out data have ?
**kwargs goes to super().get_data()
- Returns:
numpy or dask.
- Return type:
2d array
- get_source_mask(reorder=True, thresh=5, r=8)#
- get_aperture(x0, y0, radius, data=None, bkgann=None, subpix=0, system='xy', mask=None, err=None, as_dataframe=False, **kwargs)#
get the aperture (circular) photometry.
- Parameters:
x0 (1d-array) – Center coordinates and radius (radii) of aperture(s). (could be x,y, ra,dec or u,v ; see system)
y0 (1d-array) – Center coordinates and radius (radii) of aperture(s). (could be x,y, ra,dec or u,v ; see system)
radius (1d-array) – Center coordinates and radius (radii) of aperture(s). (could be x,y, ra,dec or u,v ; see system)
data (2d-array) – 2d image the aperture will be applied on. (self.data otherwise, see also which and dataprop)
bkgann (2d-array) – Length 2 tuple giving the inner and outer radius of a “background annulus”. If supplied, the background is estimated by averaging unmasked pixels in this annulus. If supplied, the inner and outer radii obey numpy broadcasting rules along with
x
,y
andr
.subpix (int) – Subpixel sampling factor. If 0, exact overlap is calculated. 5 is acceptable.
system (str) – In which system are the input x0, y0: - xy (ccd ) - radec (in deg, sky) - uv (focalplane)
dataprop (dict) – = ignored if data is given = kwargs for the get_data method using
data = self.get_data(**dataprop)
mask (2d-array) – mask image.
mask=self.get_mask()
used if Noneerr (2d-array) – error image.
mask=self.get_noise()
used if Noneas_dataframe ([bool]) – set the returned format. If as_dataFrame=True, this will be a dataframe with 3xn-radius columns (f_0…f_i, f_0_e..f_i_e, f_0_f…f_i_f) standing for fluxes, errors, flags.
super().get_aperture(**kwargs) (**kwargs goes to) –
- Returns:
array: with n the number of radius.
- Return type:
(3, n) array or pandas.DataFrame
- get_psfcat(show_progress=False, use_dask=None, **kwargs)#
get the psf photometry catalog generated by the ztf-pipeline
- get_sexcat(as_table=False, show_progress=False, use_dask=None, **kwargs)#
get the sextractor photometry catalog generated by the ztf-pipeline (nested-aperture photometry catalog)
- Parameters:
as_table (bool) – should the returned table be a pandas dataframe or an astropy table. careful, nested apertures (MAG_APER, FLUX_APER and associated errors are droped when using pandas.)
show_progress (bool) – option of io.get_file to display progress while downloading the data.
use_dask (bool) – should the catalog dataframe be as dask.dataframe ?
- Return type:
pandas.DataFrame or astropy.Table
- property wcs#
astropy wcs solution loaded from the header
- property filtername#
name of the filter (from self.meta)
- property filterid#
zr, 3:zi) see self.filtername
- Type:
filter number (1
- Type:
zg, 2
- property rcid#
id of the quadrant in the focal plane (from meta) (0->63)
- property ccdid#
id of the ccd (1->16)
- property qid#
id of the quadrant (1->4)
- property fieldid#
number of the field (from meta)
- property filefracday#
id corresponding to the ‘fraction of the day’ (from meta)
- property obsdate#
observing date with the yyyy-mm-dd format.
- class ztfimg.science.ScienceCCD(quadrants=None, qids=None, data=None, header=None, pos_inverted=None, **kwargs)#
Bases:
CCD
,ComplexImage
CCD are collections for quadrants except if loaded from whole CCD data.
See also
from_filename
load the instance given a filename
from_filenames
load the image given the list of its four quadrant filenames
from_single_filename
build and load the instance given the filename of a single quadrant.
- Attributes:
ccdid
ccd id (from header)
collection_of
name of the collection elements.
data
the image data.
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filenames
list of the filename of the different quadrants constituing the data.
filepath
If this method was loaded from a file, this is it’s filename.
filepaths
list of the filepath of the different quadrants constituing the data.
filtername
Name of the image’s filter (from header)
header
header of the data.
mask
mask image.
meta
pandas.dataframe concatenating meta data from the quadrants.
obsjd
Observation Julian date of the image (from header)
quadrants
dictionnary of the quadrants, keys are the quadrant id
use_dask
are the data dasked (did you set use_dask=True)
Methods
add_coord_to_catalog
(cat[, coord, ra, dec, ...])add the quadrant xy coordinates to a given catalog if possible.
call_quadrants
(what, *args, **kwargs)run the given input on quadrants
compute
(**kwargs)compute all dasked images = careful this may load a lot of data in memory =
from_data
(data[, header])Instanciate this class given data.
from_filename
(filename[, as_path, use_dask, ...])classmethod load an instance given an input file.
from_filenames
(filenames[, as_path, qids, ...])loads the instance from a list of the quadrant files.
from_quadrants
(quadrants[, qids])loads the instance given a list of four quadrants.
from_single_filename
(filename[, as_path, ...])given a single quadrant file, this fetchs the missing ones and loads the instance.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_background
([method, data])get an estimation of the image's background
get_catalog
(name[, fieldcat, in_fov, ...])get a catalog for the image.
get_center
([system, reorder])get the center of the image Note: this uses the 1st quadrant wcs solution if one is needed.
get_corners
([system, reorder])get the corners of the image.
get_data
([apply_mask, rm_bkgd, rebin, ...])- param rm_bkgd:
Should the data be background subtracted ?
get_focalplane
([use_dask])get the full focal plane (64 quadrants making 16 CCDs) containing this quadrant
get_header
([compute])get the current header
get_noise
([method])get a noise image or value
get_quadrant
(qid)get a quadrant (
self.quadrants[qid]
)get_quadrantdata
([from_data, rebin, ...])get the quadrant's data.
get_quadrantheader
()get a DataFrame gathering the quadrants's header
get_value
(key[, default, attr_ok])quick access to an image value.
has_data
()are data set ? (True means yes)
has_quadrants
([logic])are (all/any, see option) quadrant loaded ?
load_data
(**kwargs)get the data from the quadrants and set it to data.
persist
(**kwargs)persist all dasked images = this loads data in your cluster's memory =
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
set_mask
(mask)set the mask to this instance.
set_quadrant
(quadrant[, qid])set the quadrants to the instance.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
show_footprint
([values, ax, system, cmap, ...])illustrate the image footprint
to_fits
(fileout[, as_quadrants, overwrite])dump the data (and header if any) into the given fitsfile
to_quadrant_fits
(quadrantfiles[, overwrite, ...])dump the current image into 4 different files: one for each quadrants
get_mask
ij_to_radec
ij_to_xy_qid
radec_to_ij
- property meta#
pandas.dataframe concatenating meta data from the quadrants.
- get_mask(**kwargs)#
- get_data(apply_mask=False, rm_bkgd=False, rebin=None, rebin_stat='mean', maskvalue=nan, zp=None, **kwargs)#
- Parameters:
Should the data be background subtracted ? - False: no background subtraction - True: background subtraction at the ccd level - array:
if shape 4 x quadrant.shape, this mapped at the quadrant-level
if shape ccd.shape, this is applied at the ccd-level
- str:
quadrant: removed at the quandrant level (equiv to rm_bkgd=True)
ccd: removed at the ccd-level (equiv to rm_bkgd=ccd.get_background())
- rebin_stat: str
= applies only if rebin is not None = numpy (dask.array) method used for rebinning the data. For instance, if rebin=4 and rebin_stat = median the median of a 4x4 pixel will be used to form a new pixel. The dimension of the final image will depend on rebin.
- radec_to_ij(ra, dec, reorder=True)#
- ij_to_radec(i, j, reorder=True)#
- ij_to_xy_qid(i, j)#
- class ztfimg.science.ScienceFocalPlane(ccds=None, ccdids=None, data=None, header=None, **kwargs)#
Bases:
FocalPlane
- Attributes:
- SHAPE
ccds
dictionary of the ccds {ccdid:CCD, …}
collection_of
name of the collection elements.
data
data of the image ; numpy.array or dask.array
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filenames
list of the filename of the different quadrants constituing the data.
filepath
If this method was loaded from a file, this is it’s filename.
filepaths
list of the filename of the different quadrants constituing the data.
filtername
Name of the image’s filter (from header)
header
header of the data.
meta
pandas.dataframe concatenating meta data from the quadrants.
obsjd
Observation Julian date of the image (from header)
use_dask
are the data dasked (did you set use_dask=True)
Methods
call_ccds
(what, *args, **kwargs)run the given input on ccds
call_quadrants
(what, *args, **kwargs)run the given input on quadrants
compute
(**kwargs)compute all dasked images = careful this may load a lot of data in memory =
from_data
(data[, header])Instanciate this class given data.
from_filename
(filename[, as_path, use_dask, ...])classmethod load an instance given an input file.
from_filenames
(filenames[, as_path, rcids, ...])loads the instance from a list of the quadrant files.
from_single_filename
(filename[, as_path, ...])given a single quadrant file, this fetchs the missing ones and loads the instance.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_ccd
(ccdid)get the ccd (self.ccds[ccdid])
get_data
([rebin, incl_gap, persist, ccd_coef])get data.
get_files
([client, suffix, as_dask])fetch the files of the focal plane (using ztfquery.io.bulk_get_file)
get_header
([compute])get the current header
get_quadrant
(rcid)get the quadrant (get the ccd and then get its quadrant
get_quadrantheader
([rcids])returns a DataFrame of the header quadrants (rcid)
get_value
(key[, default, attr_ok])quick access to an image value.
has_ccds
([logic])test if (any/all see option) ccds are loaded.
has_data
()are data set ? (True means yes)
persist
(**kwargs)persist all dasked images = this loads data in your cluster's memory =
set_ccd
(ccd[, ccdid])attach ccd images to the instance.
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
show_footprint
([values, ax, level, cmap, ...])illustrate the image footprint
to_fits
(fileout[, overwrite])writes the image (data and header) into a fits file.
See also
from_filename
load the instance given a filename
from_filenames
load the image given the list of its quadrant filenames
from_single_filename
build and load the instance given the filename of a single quadrant.
- Attributes:
- SHAPE
ccds
dictionary of the ccds {ccdid:CCD, …}
collection_of
name of the collection elements.
data
data of the image ; numpy.array or dask.array
exptime
Exposure time of the image (from header)
filename
If this method was loaded from a file, this is it’s filename.
filenames
list of the filename of the different quadrants constituing the data.
filepath
If this method was loaded from a file, this is it’s filename.
filepaths
list of the filename of the different quadrants constituing the data.
filtername
Name of the image’s filter (from header)
header
header of the data.
meta
pandas.dataframe concatenating meta data from the quadrants.
obsjd
Observation Julian date of the image (from header)
use_dask
are the data dasked (did you set use_dask=True)
Methods
call_ccds
(what, *args, **kwargs)run the given input on ccds
call_quadrants
(what, *args, **kwargs)run the given input on quadrants
compute
(**kwargs)compute all dasked images = careful this may load a lot of data in memory =
from_data
(data[, header])Instanciate this class given data.
from_filename
(filename[, as_path, use_dask, ...])classmethod load an instance given an input file.
from_filenames
(filenames[, as_path, rcids, ...])loads the instance from a list of the quadrant files.
from_single_filename
(filename[, as_path, ...])given a single quadrant file, this fetchs the missing ones and loads the instance.
get_aperture
(x, y, radius[, data, bkgann, ...])get the apeture photometry, base on sep.sum_circle()
get_ccd
(ccdid)get the ccd (self.ccds[ccdid])
get_data
([rebin, incl_gap, persist, ccd_coef])get data.
get_files
([client, suffix, as_dask])fetch the files of the focal plane (using ztfquery.io.bulk_get_file)
get_header
([compute])get the current header
get_quadrant
(rcid)get the quadrant (get the ccd and then get its quadrant
get_quadrantheader
([rcids])returns a DataFrame of the header quadrants (rcid)
get_value
(key[, default, attr_ok])quick access to an image value.
has_ccds
([logic])test if (any/all see option) ccds are loaded.
has_data
()are data set ? (True means yes)
persist
(**kwargs)persist all dasked images = this loads data in your cluster's memory =
set_ccd
(ccd[, ccdid])attach ccd images to the instance.
set_data
(data)Set the data to the instance
set_header
(header)set self.header with the given header.
show
([ax, colorbar, cax, apply, data, vmin, ...])Show the image data (imshow)
show_footprint
([values, ax, level, cmap, ...])illustrate the image footprint
to_fits
(fileout[, overwrite])writes the image (data and header) into a fits file.
- get_files(client=None, suffix=['sciimg.fits', 'mskimg.fits'], as_dask='futures')#
fetch the files of the focal plane (using ztfquery.io.bulk_get_file)
- property meta#
pandas.dataframe concatenating meta data from the quadrants.
Collections#
- class ztfimg.collection.ImageCollection(images, **kwargs)#
Bases:
_Collection_
Image collection handles multi-images
- Parameters:
images (list) – list of images. Images could be numpy or dask arrays as well as dask.delayed object. self.use_dask will be set automatically accordingly.
self.set_images() (**kwargs goes to) –
- Return type:
instance
- Attributes:
Methods
call_down
(what, *args, **kwargs)call an attribute or a method to each image.
compute
(**kwargs)compute all dasked images = careful this may load a lot of data in memory =
from_filenames
(filenames[, as_path, ...])loads the instance from a list of the quadrant files.
get_data
(**kwargs)get a stacked version of the data.
map_down
(method, margs, *args, **kwargs)map margs to each image's method
persist
(**kwargs)persist all dasked images = this loads data in your cluster's memory =
set_images
(images)set the images based on which the instance works
- classmethod from_filenames(filenames, as_path=True, use_dask=False, persist=False, **kwargs)#
loads the instance from a list of the quadrant files.
- Parameters:
filanames (list of four str) – filenames for the four quadrants
as_path (bool) – Set this to true if the input file is not the fullpath but you need ztfquery.get_file() to look for it for you.
use_dask (bool) – Should dask be used ? The data will not be loaded but delayed (dask.array)
persist (bool) – = only applied if use_dask=True = should we use dask’s persist() on data ?
_COLLECTION_OF.from_filename (**kwargs goes to) –
- Return type:
class instance
- set_images(images)#
set the images based on which the instance works
= It is unlikely you need to call that directly =
- Parameters:
images (list) – list of image (or inheritance of) or list of delayed version.
See also
from_images
load the instance given a list of images.
from_filenames
loads the instance given a list of files.
- get_data(**kwargs)#
get a stacked version of the data.
- Parameters:
image.get_data() (**kwargs goes to individual's) –
- Returns:
[nimages, *shape], np.array or dask.array
- Return type:
3d-array
- call_down(what, *args, **kwargs)#
call an attribute or a method to each image.
- Parameters:
what (str) – attribute or method of individual images.
args – = ignored if what is an attribute = method options
kwargs – = ignored if what is an attribute = method options
- Returns:
list of image’s results
- Return type:
See also
map_down
map a list to the list of image
- map_down(method, margs, *args, **kwargs)#
map margs to each image’s method
- Parameters:
- Returns:
list of image’s results
- Return type:
See also
call_down
call a method or attribute on each images.
- property images#
list of images
- property use_dask#
are images dasked ?
- property nimages#
number of images
Catalog#
Tools to match catalogs
- ztfimg.catalog.get_field_catalog(name, fieldid, rcid=None, ccdid=None, use_dask=False, columns=None, **kwargs)#
get a catalog stored a field catalog
- Parameters:
- Returns:
catalog (pandas or dask, see use_dask)
- Return type:
DataFrame
- ztfimg.catalog.download_vizier_catalog(name, radec, radius=1, r_unit='deg', columns=None, column_filters={}, use_tap=False, rakey='RAJ2000', deckey='DEJ2000', use_dask=False, **kwargs)#
download data from the vizier system
- Parameters:
name (string) – name of a vizier calalog. known short-names: - ‘gaia’ or ‘gaiadr3’ -> I/350/gaiaedr3 - ‘ps1’ -> II/349/ps1
radec ([float, float]) – center cone search coordinates (RA, Dec ; in degree).
radius (float) – radius of the cone search
r_unit (string) – unit of the cone search radius. (deg, arcsec etc).
columns (list) – If provided, this will query this specific columns. (see detailed doc in astroquery.vizier.Vizier)
column_filters (dict) – provide filtering of the query; (see detailed doc in astroquery.vizier.Vizier)
use_tap (bool) – = Not yet available =
rakey (str) – column name of the catalog corresponding to the R.A.
deckey (str) – column name of the catalog corresponding to the Declination
astroquery.vizier.Vizier (**kwargs goes to) –
- Returns:
the catalog
- Return type:
DataFrame
- ztfimg.catalog.get_isolated(catdf, catdf_ref=None, xkey='ra', ykey='dec', keyunit='deg', seplimit=10)#
get a boolean single-column dataframe (‘isolated’) (not a serie for self-consistency with dask-mode)
- Parameters:
catdf (pandas.DataFrame, dask.DataFrame) – dataframe to be tested with isolation. It must contain the xkey, ykey. catdf could be dasked.
catdf_ref (None, pandas.DataFrame, dask.DataFrame) – reference for surrounding catalog. If None given, catdf used. (self-isolation)
xkey (str) – coordinate key that must be in catdf (and catdf_ref if any)
ykey (str) – coordinate key that must be in catdf (and catdf_ref if any)
keyunit (str) – unit of the coordinate keys
seplimit (float) – separation in arcsec.
- Returns:
single-column (isolated) DataFrame (pandas or dask, depending on input catdf format)
- Return type:
DataFrame
- ztfimg.catalog.match_and_merge(left, right, radec_key1=['ra', 'dec'], radec_key2=['ra', 'dec'], seplimit=0.5, mergehow='inner', suffixes=('_l', '_r'), reset_index=False, **kwargs)#
- Parameters:
cat1 (DataFrame) – pandas.DataFrame containing, at least, the radec_key1/2. ra and dec entries (see radec_key1) must by in deg.
cat2 (DataFrame) – pandas.DataFrame containing, at least, the radec_key1/2. ra and dec entries (see radec_key1) must by in deg.
radec_key1 (str) – name of the ra and dec coordinates for catalog 1 and 2, respectively.
radec_key2 (str) – name of the ra and dec coordinates for catalog 1 and 2, respectively.
seplimit (float) – maximal distance (in arcsec) for the matching.
- Return type:
DataFrame
I/O#
I/O for ztfimg data.
Aperture
- ztfimg.io.get_test_image()#
returns the path to the test image and its mask.
- ztfimg.io.get_nonlinearity_table()#
get the nonlinearity table
- Return type:
DataFrame