::pawt::fitsTop, Main, Index
CommandsTop, Main, Index
ReadImageFile [::pawt::fits]Top, Main, Index
Read a FITS image file into a dictionary.
Parameters
fitsImgFile | File name of the FITS image. |
args | Optional format specific arguments. Currently none. |
Description
Get the image data as a dictionary containing 2 keys: Header
and Data
.
- See ::pawt::ReadImageHeader for the entries of the
Header
key. - See ::pawt::ReadImageFile for the entries of the
Data
key.
Return value
Returns the image information as a dictionary. If the file does not exist, no supported image format can be detected, or if the fitstcl extension is not available, an error is thrown.
See also
ReadImageHeader, WriteImageFile
proc ::pawt::fits::ReadImageFile {fitsImgFile args} { # Read a FITS image file into a dictionary. # # fitsImgFile - File name of the FITS image. # args - Optional format specific arguments. Currently none. # # Get the image data as a dictionary containing 2 keys: `Header` and `Data`. # * See [::pawt::ReadImageHeader] for the entries of the `Header` key. # * See [::pawt::ReadImageFile] for the entries of the `Data` key. # # Returns the image information as a dictionary. # If the file does not exist, no supported image format can be detected, # or if the fitstcl extension is not available, an error is thrown. # # See also: ReadImageHeader WriteImageFile if { ! [pawt::HavePkg "fitstcl"] } { error "Read FITS file: Missing fitstcl extension" } set retVal [catch { fits open $fitsImgFile } fitsObj] if { $retVal != 0 } { error "Read FITS file: Cannot open file $fitsImgFile" } set imgDict [dict create] set headerDict [_GetImageHeader $fitsObj [file tail $fitsImgFile]] _GetImageData $fitsObj $headerDict imgDict dict append imgDict Header $headerDict $fitsObj close return $imgDict }
ReadImageHeader [::pawt::fits]Top, Main, Index
Read the header of a FITS image file.
Parameters
fitsImgFile | File name of the FITS image. |
args | Optional format specific arguments. Currently none. |
Description
See ::pawt::ReadImageHeader for the default entries of a header dictionary.
Return value
Returns the header information as a dictionary. If the file does not exist, the header contains invalid information, or if the fitstcl extension is not available, an error is thrown.
See also
proc ::pawt::fits::ReadImageHeader {fitsImgFile args} { # Read the header of a FITS image file. # # fitsImgFile - File name of the FITS image. # args - Optional format specific arguments. Currently none. # # See [::pawt::ReadImageHeader] for the default entries of a # header dictionary. # # Returns the header information as a dictionary. # If the file does not exist, the header contains invalid information, # or if the fitstcl extension is not available, an error is thrown. # # See also: ReadImageFile WriteImageFile if { ! [pawt::HavePkg "fitstcl"] } { error "Read FITS header: Missing fitstcl extension" } set retVal [catch { fits open $fitsImgFile } fitsObj] if { $retVal != 0 } { error "Read FITS file: Cannot open file $fitsImgFile" } set headerDict [_GetImageHeader $fitsObj [file tail $fitsImgFile]] $fitsObj close return $headerDict }
WriteImageFile [::pawt::fits]Top, Main, Index
Write the values of an image dict into a FITS image file.
Parameters
imgDict | Image dictionary. |
fitsImgFile | File name of the image. |
args | Optional format specific arguments. Currently none. |
Description
See ::pawt::WriteImageFile for general informations regarding writing images.
Return value
Returns no value. If invalid options are specified or the file could not be written, an error is thrown.
See also
ReadImageFile, ReadImageHeader
proc ::pawt::fits::WriteImageFile {imgDict fitsImgFile args} { # Write the values of an image dict into a FITS image file. # # imgDict - Image dictionary. # fitsImgFile - File name of the image. # args - Optional format specific arguments. Currently none. # # See [::pawt::WriteImageFile] for general informations regarding writing images. # # Returns no value. If invalid options are specified or the file could not # be written, an error is thrown. # # See also: ReadImageFile ReadImageHeader if { ! [pawt::HavePkg "fitstcl"] } { error "Write FITS file: Missing fitstcl extension" } set headerDict [dict get $imgDict Header] set width [dict get $headerDict Width] set height [dict get $headerDict Height] set numChan [dict get $headerDict NumChan] set pixelType [dict get $headerDict PixelType] set pixelSize [_GetPixelSize $pixelType] # Create new FITS file (mode=2). set fitsObj [fits open $fitsImgFile 2] if { $pixelType eq "double" } { # 64-bit floating point image. set bitDepth -64 } elseif { $pixelType eq "float" } { # 32-bit floating point image. set bitDepth -32 } else { set bitDepth [expr { $pixelSize * 8 }] } if { $numChan == 1 } { set chansAxes 2 set chanAxesSizes [list $width $height] } elseif { $numChan == 3 } { set chansAxes 3 set chanAxesSizes [list $width $height 3] } else { error "Write FITS file: Invalid number of channels: $numChan (must be 1 or 3)" } $fitsObj insert image $bitDepth $chansAxes $chanAxesSizes set imgAsList [pawt GetImageAsList imgDict -scanorder "BottomUp"] if { $pixelType eq "short" } { # Map unsigned short values to signed short. set imgAsList [lmap a $imgAsList { expr { $a - 32768 }}] } if { $pixelType eq "int" } { # Map unsigned int values to signed int. set imgAsList [lmap a $imgAsList { expr { $a - 2147483648 }}] } if { $numChan == 3 || $numChan == 4 } { # FITS returns RGB images channel by channel, while RAW images need RGB. set len [llength $imgAsList] for { set r 0 } { $r < $len } { incr r 3 } { lappend chanList [lindex $imgAsList $r] } for { set g 1 } { $g < $len } { incr g 3 } { lappend chanList [lindex $imgAsList $g] } for { set b 2 } { $b < $len } { incr b 3 } { lappend chanList [lindex $imgAsList $b] } set imgAsList $chanList } $fitsObj put image 1 $imgAsList $fitsObj flush $fitsObj close }