\(\renewcommand\AA{\unicode{x212B}}\)

SaveFITS v1

Summary

Saves image data from a workspace in FITS (Flexible Image Transport System) format

See Also

LoadFITS, SaveNXTomo

Properties

Name

Direction

Type

Default

Description

InputWorkspace

Input

MatrixWorkspace

Mandatory

Workspace holding an image (with one spectrum per pixel row).

Filename

Input

string

Mandatory

Name of the output file where the image is saved. Allowed extensions: [‘.fits’]

BitDepth

Input

number

16

The bit depth or number of bits per pixel to use for the output image(s). Only 16 bits is supported at the moment. Allowed values: [‘8’, ‘16’, ‘32’]

Description

This algorithm saves an image from a workspace into a file in FITS format. FITS stands for Flexible Image Transport System.

The input matrix workspace must have one spectrum per row (and one bin per column). This corresponds to the workspaces loaded by LoadFITS v1 when its option LoadAsRectImg is true (note its default is false). The first spectrum corresponds to the first (topmost) row and the last spectrum corresponds to the last (bottom) column. Images stored in this type of workspace can be displayed with a “color fill plot” or plot2D.

The current implementation of this algorithm only supports: - 2D files (FITS images with two axes). - 8, 16 or 32 bits as pixel bit depth (only for integer types)

The files produced by this algorithm follow the FITS standard and can be loaded by widespread software and libraries such as ImageJ/Fiji, fv or pyfits. The files include the following basic standard headers: SIMPLE, BITPIX, NAXIS, (NAXIS1 and NAXIS2), EXTEND, and a COMMENT header with the format description.

See also

LoadFITS v1.

Usage

Example - LoadSaveLoadFITS

# Load an image
wsg_name = 'images'
wsg = LoadFITS(Filename='FITS_small_01.fits', LoadAsRectImg=1, OutputWorkspace=wsg_name)
ws = wsg.getItem(0)

save_name = 'out_fits_example.fits'
SaveFITS(Filename=save_name, InputWorkspace=ws)

wsg_reload_name = 'images_reloaded'
wsg_reload = LoadFITS(Filename=save_name, LoadAsRectImg=1, OutputWorkspace=wsg_reload_name)
ws_reload = wsg_reload.getItem(0)

# Compare
bpp_log = 'BITPIX'
try:
    log = ws.getRun().getLogData(bpp_log).value
    print("Bits per pixel in first image: {0}".format(int(log)))
    log_reload = ws.getRun().getLogData(bpp_log).value
    print("Bits per pixel in second image: {0}".format(int(log_reload)))
except RuntimeError:
    print("Could not find the keyword '{0}' in the FITS file".format(bpp_log))

axis1_log = 'NAXIS1'
axis2_log = 'NAXIS2'
try:
    log1 = ws.getRun().getLogData(axis1_log).value
    log2 = ws.getRun().getLogData(axis2_log).value
    print("Image size in first image: {0} x {1} pixels".format(int(log1), int(log2)))
    log1_reload = ws_reload.getRun().getLogData(axis1_log).value
    log2_reload = ws_reload.getRun().getLogData(axis2_log).value
    print("Image size in second image: {0} x {1} pixels".format(int(log1_reload), int(log2_reload)))
except RuntimeError:
    print("Could not find the keywords '{}' and '{}' in this FITS file".format(axis1_log, axis2_log))

pos_x, pos_y = 22, 33
print("Pixel value at coordinates ({0},{1}), first image: {2:.1f}, second image: {3:.1f}".
       format(pos_x, pos_y, ws.readY(pos_y)[pos_x], ws_reload.readY(pos_y)[pos_x]))

Output:

Bits per pixel in first image: 16
Bits per pixel in second image: 16
Image size in first image: 512 x 512 pixels
Image size in second image: 512 x 512 pixels
Pixel value at coordinates (22,33), first image: 63.0, second image: 63.0

Categories: AlgorithmIndex | DataHandling\Imaging

Source

C++ header: SaveFITS.h

C++ source: SaveFITS.cpp