75 Creates an image group with the images of a (possibly multi-HDU) single FITS file.
77 If image is multi-hdu, psf and weight can either be multi hdu or lists of individual files.
79 In any case, they are matched in order and HDUs not containing images (two dimensional arrays) are ignored.
81 :param image: The filename of the FITS file containing the image(s)
82 :param psf: psf file or list of psf files
83 :param weight: FITS file for the weight image or a list of such files
85 :return: A ImageGroup representing the images
89 if "image_hdu" in kwargs.keys():
90 image_hdu_list = [kwargs.pop(
"image_hdu")]
92 image_hdu_list = image_file.hdu_list
95 if isinstance(psf, list):
96 if len(psf) != len(image_hdu_list):
97 raise ValueError(
"The number of psf files must match the number of images!")
99 psf_hdu_list = [0] * len(psf_file_list)
101 if "psf_hdu" in kwargs.keys():
102 psf_hdu_list = [kwargs.pop(
"psf_hdu")] * len(image_hdu_list)
104 psf_hdu_list = range(len(image_hdu_list))
105 psf_file_list = [psf] * len(image_hdu_list)
108 if isinstance(weight, list):
109 if len(weight) != len(image_hdu_list):
110 raise ValueError(
"The number of weight files must match the number of images!")
111 weight_file_list = weight
112 weight_hdu_list = [0] * len(weight_file_list)
114 weight_file_list = [
None] * len(image_hdu_list)
115 weight_hdu_list = [0] * len(weight_file_list)
118 if "weight_hdu" in kwargs.keys():
119 weight_hdu_list = [kwargs.pop(
"weight_hdu")] * len(image_hdu_list)
121 weight_hdu_list = weight_file.hdu_list
122 weight_file_list = [weight_file] * len(image_hdu_list)
125 for hdu, psf_file, psf_hdu, weight_file, weight_hdu
in zip(
126 image_hdu_list, psf_file_list, psf_hdu_list, weight_file_list, weight_hdu_list):
128 image_hdu=hdu, psf_hdu=psf_hdu,
129 weight_hdu=weight_hdu,
131 for img
in image_list:
136 """Creates an image group for the given images.
141 A list of relative paths to the images FITS files. Can also be single string in which case,
142 this function acts like load_fits_image
144 A list of relative paths to the PSF FITS files (optional). It must match the length of image_list or be None.
145 weights : list of str
146 A list of relative paths to the weight files (optional). It must match the length of image_list or be None.
151 A ImageGroup representing the images
156 In case of mismatched list of files
159 if isinstance(images, list):
161 raise ValueError(
"An empty list passed to load_fits_images")
163 psfs = psfs
or [
None] * len(images)
164 weights = weights
or [
None] * len(images)
166 if not isinstance(psfs, list)
or len(psfs) != len(images):
167 raise ValueError(
"The number of image files and psf files must match!")
169 if not isinstance(weights, list)
or len(weights) != len(images):
170 raise ValueError(
"The number of image files and weight files must match!")
173 for f, p, w
in zip(images, psfs, weights):
179 for img
in image_list:
186 weight_cube_hdu=-1, **kwargs):
188 Creates an image group with the images of a data cube.
190 weight can be a matching datacube, multi-hdu or list of individual images
191 psf can be a multi-hdu or list of individual images to be matched
193 In any case, they are matched in order and HDUs not containing images are ignored.
195 :param image: The filename of the FITS file containing the image datacube
196 :param psf: psf file or list of psf files
197 :param weight: FITS file contianing a weight datacube, a MEF contianing the weights
198 or a list of such files
199 :param image_cube_hdu: hdu containing the image datacube, default = first HDU containing image data
200 :param weight_cube_hdu: hdu containing the weight datacube, default = first HDU containing image data
202 :return: A ImageGroup representing the images
207 if image_cube_hdu < 0:
208 cube_hdu = image_cube_file.hdu_list[0]
210 cube_hdu = image_cube_hdu
212 dims = image_cube_file.get_dimensions(cube_hdu)
214 raise ValueError(
"Not a data cube!")
216 image_layer_list = range(cube_size)
219 if isinstance(psf, list):
220 if len(psf) != cube_size:
221 raise ValueError(
"The number of psf files must match the number of images!")
223 psf_hdu_list = [0] * cube_size
225 psf_file_list = [psf] * cube_size
226 psf_hdu_list = range(cube_size)
229 if isinstance(weight, list):
230 if len(weight) != cube_size:
231 raise ValueError(
"The number of weight files must match the number of images!")
232 weight_file_list = weight
233 weight_hdu_list = [0] * cube_size
234 weight_layer_list = [0] * cube_size
236 weight_file_list = [
None] * cube_size
237 weight_hdu_list = [0] * cube_size
238 weight_layer_list = [0] * cube_size
241 if weight_cube_hdu < 0:
242 weight_hdu = weight_fits_file.hdu_list[0]
244 weight_hdu = weight_cube_hdu
246 weight_dims = weight_fits_file.get_dimensions(weight_hdu)
247 if len(weight_dims) == 3:
249 if dims[2] != cube_size:
250 raise ValueError(
"The weight map cube doesn't match the image cube")
252 weight_file_list = [weight_fits_file] * cube_size
253 weight_hdu_list = [weight_hdu] * cube_size
254 weight_layer_list = range(cube_size)
257 weight_file_list = [weight_fits_file] * cube_size
258 weight_hdu_list = weight_fits_file.hdu_list
259 weight_layer_list = [0] * cube_size
262 for psf_file, psf_hdu, weight_file, weight_hdu, image_layer, weight_layer
in zip(
263 psf_file_list, psf_hdu_list, weight_file_list, weight_hdu_list, image_layer_list,
265 image_list.append(
DataCubeSlice(image_cube_file, psf_file, weight_file,
266 image_hdu=cube_hdu, psf_hdu=psf_hdu,
267 weight_hdu=weight_hdu,
268 image_layer=image_layer, weight_layer=weight_layer,
271 for img
in image_list:
294 Flux measurement from the image above the background inside a circular aperture.
298 target : MeasurementImage object, or leaf MeasurementGroup object with a single image, or a list of either
299 Target images on which to measure the aperture photometry. Leaf MeasurementGroup with a single image
300 are accepted as a convenience.
302 apertures : float, or list of float
303 Diameter of the aperture. As different MeasurementImage may not be aligned, nor have equivalent pixel size,
304 the aperture is interpreted as diameter in pixels of a circle on the detection image.
305 A transformation will be applied for each frame, so the covered area is equivalent.
309 list of Aperture objects
310 An Aperture object is an internal representation of a property on the measurement frame that contains the
311 apertures. To actually get the measurements on the output catalog, you need to add explicitly them to the
320 This property will generate five columns with the prefix specified by `add_output_column`:
321 - ``_flux`` and ``_flux_err``, for the flux and its associated error
322 - ``_mag`` and ``_mag_err``, for the magnitude and its associated error
323 - ``_flags``, to mark, for instance, saturation, boundary conditions, etc.
325 For M apertures and N images, the cells on the output column will be an array of MxN fluxes.
329 >>> context = MeasurementConfig()
330 >>> measurement_group = MeasurementGroup(load_fits_images(frames, psfs))
331 >>> all_apertures = []
332 >>> for img in measurement_group:
333 >>> all_apertures.extend(context.add_aperture_photometry(img, [5, 10, 20]))
334 >>> context.add_output_column('aperture', all_apertures)
336 if not isinstance(target, list):
338 if not isinstance(apertures, list):
339 apertures = [apertures]
341 apertures = [float(a)
for a
in apertures]
345 if isinstance(t, MeasurementGroup):
347 raise Exception(
'The MeasurementGroup is not a leaf')
349 raise Exception(
'The MeasurementGroup contains {} images'.format(len(t)))
350 t = [i
for i
in t][0]
352 if not isinstance(t, MeasurementImage):
354 'Only MeasurementImage supported as targets, got {}'.format(type(t)))
357 raise Exception(
'Apertures already set for the image {}'.format(t.id))
383 Add a new set of columns to the output catalog.
388 Name/prefix of the new set of columns
389 params : list of columns
390 List of properties to add to the output with the given name/prefix. They must be subtype
391 of one of the known ones: ParameterBase for model fitting, or Aperture for aperture photometry.
396 If the name has already been used
398 If any of the parameters are not of a known type (see params)
402 aperture.add_aperture_photometry
403 model_fitting.ParameterBase
406 raise ValueError(
'Column {} is already set'.format(name))
409 if not isinstance(params, list):
411 param_type = type(params[0])
413 known_subclass =
False
415 if issubclass(param_type, base):
417 known_subclass =
True
418 if issubclass(param_type, ParameterBase):
421 if not known_subclass:
422 raise TypeError(
'{} is not a known column type'.format(str(param_type)))