Mosaicking

measure_xy_offset_2dimages

This script determines (X,Y) offsets between two 2D images using cross-correlation.

(venv_numina) $ numina-measure_xy_offset_2dimages --help
Usage: numina-measure_xy_offset_2dimages [-h] [--image1 IMAGE1]
                                         [--image2 IMAGE2] [--extnum1 EXTNUM1]
                                         [--extnum2 EXTNUM2]
                                         [--subtract-background]
                                         [--rescale-to-01] [--method {1,2}]
                                         [--plots] [--test]
                                         [--test-fwhm TEST_FWHM]
                                         [--test-amplitude TEST_AMPLITUDE]
                                         [--test-background TEST_BACKGROUND]
                                         [--test-noise TEST_NOISE]
                                         [--test-xoffset TEST_XOFFSET]
                                         [--test-yoffset TEST_YOFFSET]
                                         [--test-num-nans TEST_NUM_NANS]
                                         [--test-seed TEST_SEED]
                                         [--save-test-images]
                                         [--output-dir OUTPUT_DIR] [--record]
                                         [--echo] [--version]
                                         [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]

Determine (X,Y) offsets between 2 2D images using cross-correlation.

Options:
  -h, --help            show this help message and exit
  --image1 IMAGE1       Path to the first 2D image
  --image2 IMAGE2       Path to the second 2D image
  --extnum1 EXTNUM1     Extension number for the first image (default: 0)
  --extnum2 EXTNUM2     Extension number for the second image (default: 0)
  --subtract-background
                        Subtract median background from images
  --rescale-to-01       Rescale images to the range [0, 1] before computing
                        cross-correlation
  --method {1,2}        Method (1: scipy (default), 2: skimage)
  --plots               Generate plots of the images and cross-correlation
  --test                Run test mode with synthetic images
  --test-fwhm TEST_FWHM
                        FWHM of the synthetic Gaussian star (default: 10.0)
  --test-amplitude TEST_AMPLITUDE
                        Amplitude of the synthetic Gaussian star (default:
                        1000.0)
  --test-background TEST_BACKGROUND
                        Background level of the synthetic images (default:
                        100.0)
  --test-noise TEST_NOISE
                        Noise level of the synthetic images (default: 5.0)
  --test-xoffset TEST_XOFFSET
                        X offset of the synthetic images (default: 5.0)
  --test-yoffset TEST_YOFFSET
                        Y offset of the synthetic images (default: 3.0)
  --test-num-nans TEST_NUM_NANS
                        Number of NaN pixels to insert in each synthetic image
                        (default: 20)
  --test-seed TEST_SEED
                        Random seed for synthetic images (default: 1234)
  --save-test-images    Save synthetic images to FITS files
  --output-dir OUTPUT_DIR
                        Output directory (default: .)
  --record              Record terminal output
  --echo                Display full command line
  --version             Display version
  --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                        Set the logging level

The inputs are two 2D images (numpy arrays) with the same dimensions.

The computed (X,Y) offsets indicate how much the second image is shifted with respect to the first image. The offsets are returned in pixels.

The input images can be pre-processed by subtracting the median background and/or rescaling to the range [0, 1].

NaN values in the input images are replaced with zeros before computing the cross-correlation.

It is possible to use --test mode to create synthetic images with a known offset, which can be used to validate the offset measurement. The synthetic images can also be saved to FITS files for further analysis.

Usage examples:

(venv_numina) $ numina-measure_xy_offset_2dimages \
  --test \
  --subtract-background --rescale-to-01 --plots
(venv_numina) $ numina-measure_xy_offset_2dimages \
  --image1 image1.fits \
  --image2 image2.fits \
  --subtract-background --rescale-to-01 --plots

extract_2d_slice_from_3d_cube

This script extracts a 2D section from a 3D FITS image. It allows specifying the axis to collapse and the interval (pixel range) along that axis.

(venv_numina) $ numina-extract_2d_slice_from_3d_cube --help
Usage: numina-extract_2d_slice_from_3d_cube [-h] [--axis AXIS] [--i1 I1]
                                            [--i2 I2]
                                            [--method {sum,mean,median}]
                                            [--wavecal {none,fridasimulator,1,2,3}]
                                            [--transpose] [--noplot]
                                            [--vmin VMIN] [--vmax VMAX]
                                            [--output OUTPUT] [--png PNG]
                                            [--echo] [--debug]
                                            input

Extract 2D slice from 3D cube

Positional Arguments:
  input                 Input FITS file

Options:
  -h, --help            show this help message and exit
  --axis AXIS           Axis to be collapsed in output
  --i1 I1               First pixel of the projected axis
  --i2 I2               Last pixel of the projected axis (0=NAXIS value)
  --method {sum,mean,median}
                        Collapse method (default=sum)
  --wavecal {none,fridasimulator,1,2,3}
                        Wavelength calibration type
  --transpose           Transpose data array in output
  --noplot              Do not plot result
  --vmin VMIN           vmin value for imshow
  --vmax VMAX           vmax value for imshow
  --output OUTPUT       Output FITS file
  --png PNG             Output PNG file (plot of the result)
  --echo                Display full command line
  --debug               Debug

generate_mosaic_of_2d_images

This script generates a mosaic of 2D images from a list of 2D FITS files.

(venv_numina) $ numina-generate_mosaic_of_2d_images --help
Usage: numina-generate_mosaic_of_2d_images [-h]
                                           [--reproject_method {interp,adaptive,exact}]
                                           [--extname_image EXTNAME_IMAGE]
                                           [--extname_mask EXTNAME_MASK]
                                           [--combination_function {mean,median,sum,std,sigmaclip_mean,sigmaclip_median,sigmaclip_stddev}]
                                           [--output_3D_stack OUTPUT_3D_STACK]
                                           [--verbose] [--echo]
                                           input_list output_filename

Generate mosaic of 2D images

Positional Arguments:
  input_list            TXT file with list of 2D images to be combined
  output_filename       filename of output FITS image

Options:
  -h, --help            show this help message and exit
  --reproject_method {interp,adaptive,exact}
                        Reprojection method (interp, adaptive, exact)
  --extname_image EXTNAME_IMAGE
                        Extension name for image in input files. Default
                        value: PRIMARY
  --extname_mask EXTNAME_MASK
                        Extension name for mask in input files. Default
                        'None': use np.nan in image
  --combination_function {mean,median,sum,std,sigmaclip_mean,sigmaclip_median,sigmaclip_stddev}
                        Combination function. Default: mean
  --output_3D_stack OUTPUT_3D_STACK
                        filename for stacked 3D array. Default None
  --verbose             Display intermediate information
  --echo                Display full command line

generate_mosaic_of_3d_cubes

This script generates a mosaic of 3D data cubes from a list of 3D FITS files.

  • It is possible to use arguments to fix the desired outupt celestial 2D WCS, as well as the output CRVAL3 and CDELT3 parameters that define the output linear wavelength sampling.

  • If the input is a single 3D FITS cube, the code can be used to resample the initial cube with different values of CRVAL3 and CDELT3. In that case, it is recommended to use interp as the reprojection method to avoid the default Gaussian kernel used when the reprojection method is adaptive).

(venv_numina) $ numina-generate_mosaic_of_3d_cubes --help
Usage: numina-generate_mosaic_of_3d_cubes [-h] [--crval3out CRVAL3OUT]
                                          [--cdelt3out CDELT3OUT]
                                          [--naxis3out NAXIS3OUT]
                                          [--desired_celestial_2d_wcs DESIRED_CELESTIAL_2D_WCS]
                                          [--reproject_method {interp,adaptive,exact}]
                                          [--parallel]
                                          [--extname_image EXTNAME_IMAGE]
                                          [--output_celestial_2d_wcs OUTPUT_CELESTIAL_2D_WCS]
                                          [--footprint] [--verbose] [--echo]
                                          input_list output_filename

Generate a 3D mosaic from individual 3D cubes

Positional Arguments:
  input_list            TXT file with list of 3D images to be combined or
                        single FITS file
  output_filename       filename of output FITS image

Options:
  -h, --help            show this help message and exit
  --crval3out CRVAL3OUT
                        Minimum wavelength (in m) for the output image
  --cdelt3out CDELT3OUT
                        Wavelength step (in m/pixel) for the output image
  --naxis3out NAXIS3OUT
                        Number of slices in the output image
  --desired_celestial_2d_wcs DESIRED_CELESTIAL_2D_WCS
                        Desired 2D celestial WCS projection. Default None
                        (compute for current 3D cube combination)
  --reproject_method {interp,adaptive,exact}
                        Reprojection method (interp, adaptive, exact)
  --parallel            Use parallel processing for reprojection
  --extname_image EXTNAME_IMAGE
                        Extension name for image in input files. Default
                        value: PRIMARY
  --output_celestial_2d_wcs OUTPUT_CELESTIAL_2D_WCS
                        filename for output 2D celestial WCS
  --footprint           Generate a FOOTPRINT extension with the final
                        footprint
  --verbose             Display intermediate information
  --echo                Display full command line