Viewing contents of file '../idllib/sdss/allpro/astronomyimage__define.pro'
;+
; CLASS_NAME:
; astronomyImage
;
; PURPORSE:
; astronomyImage is intended to be a superclass of classes used
; store image used for astronomical applications.
;
; SUPERCLASSES:
; This inherets from no classes
;
; SUBCLASSES:
; Subclasses include dataImage, maskImage, and ircamImage
;
; CREATION:
; astronomyImage are generally created through the init
; of the desired subclass
;
; METHODS:
; Intrinsic Methods
; This class has the following methods:
;
; astronomyImage::Clone
; astronomyImage::GetData
; astronomyImage::InMemory
; astronomyImage::Load
; astronomyImage::Magnify
; astronomyImage::OnDisk
; astronomyImage::Save
; astronomyImage::SetData
; astronomyImage::Size
;
; PROCEDURES USED:
; From the GSFC IDL Astronomy User's Library
; http://idlastro.gsfc.nasa.gov/homepage.html
; READFITS, SXHREAD, SXOPEN, MKHDR, WRITEFITS, SXMAKE, SXWRITE
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen, Jr. 1997
;-
;+
; ======================================================================
;
; METHODNAME:
; astronomyImage::Cleanup
;
; PURPOSE:
; Clean up the memory used by the image object. In particular,
; free the data and header memory
;
; CALLING SEQUENCE:
; OBJ_DESTROY, oAstronomyImage
;
; or
;
; oAstronomyImage->[astronomyImage::]Cleanup
;
; INPUTS:
; There are no inputs for this method
;
; KEYWORD PARAMETERS:
; There are no keyword parameters for this method
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen, Jr. 1997
PRO astronomyImage::Cleanup
self->inMemory
PTR_FREE, self.dataHeader
PTR_FREE, self.data
END
;----------------------------------------------------------------------------
; astronomyImage::clone
;+
; METHODNAME:
; astronomyImage::Clone
;
; PURPOSE:
; This method creates a duplicate image object. If no temporary
; file name is provided, the data for the new image is stored in
; memory.
;
; CALLING SEQUENCE:
; Result = oAstronomyImage->Clone(Tempfilename)
;
; OPTIONAL INPUTS:
; tempFileName: This string contains the file name for the file
; in which to store the image data, if any.
;
; OUTPUTS:
; A copy of the image is returned.
;
; SIDE EFFECTS:
; The clone is a new object; each must be destroyed separately.
;
; EXAMPLE:
; imagecopy = exampleimage->clone(tempfilename)
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen, Jr. 1997
;-
;
;
FUNCTION astronomyImage::clone, tempFileName
imageClone=OBJ_NEW(OBJ_CLASS(self))
IF PTR_VALID(self.data) THEN BEGIN
imageClone->setData,self->getData()
ENDIF
header=*(self.dataHeader)
imageClone->setProperty, DATAHEADER=header
IF (N_PARAMS() GE 1) THEN BEGIN
PRINT,'NP=',N_PARAMS()
self.tempName=tempFileName
self->onDisk
ENDIF
RETURN, imageClone
END
;----------------------------------------------------------------------------
; astronomyImage::getData
;+
; METHODNAME:
; astronomyImage::GetData
;
; PURPOSE:
; The method is used to return an array with the image data.
;
; CALLING SEQUENCE:
; Result = oAstronomyImage->getData()
;
; OUTPUTS:
; This function returns the data array associated with the image object.
;
; EXAMPLE:
; imagedataarray = astroimageobject->getData()
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen, Jr. 1997
;-
;
FUNCTION astronomyImage::getData
IF PTR_VALID(self.data) THEN BEGIN
IF self.tempUsed THEN BEGIN
dataArray=*self.data
returnArray=dataArray(0)
RETURN, returnArray
ENDIF ELSE BEGIN
RETURN, *self.data
ENDELSE
ENDIF
END
;----------------------------------------------------------------------------
; astronomyImage::inMemory
;
;+
; METHODNAME:
; astronomyImage::InMemory
;
; PURPOSE:
; If the image data is currently stored in a file, this method
; loads the data into memory and destroys the file. Otherwise,
; it has no effect.
;
; CALLING SEQUENCE:
; oAstronomyImage->InMemory
;
; EXAMPLE:
; oAstronomyImage->InMemory
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen Jr., 1997.
;-
;
PRO astronomyImage::inMemory
IF self.tempUsed THEN BEGIN
data=*self.data(0)
lun=self.tempLUN
CLOSE, lun
FREE_LUN, lun
SPAWN,'rm '+self.tempName
PTR_FREE,self.data
self.data=PTR_NEW(data)
self.tempUsed=0
ENDIF
END
;----------------------------------------------------------------------------
; astronomyImage::load
;+
; METHODNAME:
; astronomyImage::Load
;
; PURPOSE:
; This method load an image from disk into the image object.
;
; CALLING SEQUENCE:
; oAstronomyImage->Load, FileName
;
; OPTIONAL INPUTS:
; fileName: A string containing the name of the file from which
; to load the image. If no name is given, the current
; file name associated with the object is used.
;
; SIDE EFFECTS:
; The previous data and header information is lost.
;
; EXAMPLE:
; exampleImage->load, 'exampleImageFile.fits'
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen, Jr. 1997
;-
;
PRO astronomyImage::load, fileName
IF (N_PARAMS() GE 1) THEN BEGIN
self.fileName=fileName
ENDIF
fileNameArray=[FINDFILE(self.filename),$
FINDFILE(self.filename+'.fit'),$
FINDFILE(self.filename+'.fit.gz'),$
FINDFILE(self.filename+'.fit.Z'),$
FINDFILE(self.filename+'.fits'),$
FINDFILE(self.filename+'.fits.gz'),$
FINDFILE(self.filename+'.fits.Z'),$
FINDFILE(self.filename+'.hhh')]
goodIndex = -1
FOR index = (N_ELEMENTS(fileNameArray) - 1), 0, -1 DO $
IF (STRLEN(fileNameArray[index]) GT 0) THEN goodIndex = index
fileExists = goodIndex GT -1
IF fileExists THEN BEGIN
self.filename=fileNameArray[0]
fdecomp,self.filename,disk,dir,name,ext,ver
isFits=ext NE "hhh"
IF isFits THEN BEGIN
newHeader=1
newData=READFITS(self.fileName,newHeader)
self.headerFormat = 'fits'
ENDIF ELSE BEGIN
SXHREAD,self.fileName,newHeader
SXOPEN,1,self.fileName
newData=SXREAD(1)
MKHDR,newHeader,newData
self.headerFormat = 'hhh'
CLOSE,1
ENDELSE
PTR_FREE,self.dataHeader
self.dataHeader=PTR_NEW(newHeader)
self->setData, newData
ENDIF
END
;----------------------------------------------------------------------------
; astronomyImage::magnify
;+
; METHODNAME:
; astronomyImage::Magnify
;
; PURPOSE:
; This method resizes the image.
;
; CALLING SEQUENCE:
; oAstronomyImage->magnify, Newsize
;
; INPUTS:
; Newsize: The desired size of the image. The new size must be
; an integer miltiple of the current size.
;
; PROCEDURE:
; This method uses the REBIN function, as described in the IDL
; users manuals.
;
; EXAMPLE:
; To double the size of an image:
; oAstronomyImage->magnify, 2*oAstronomyImage->size()
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen Jr., 1997.
;-
;
PRO astronomyImage::magnify, newSize
inputSize=SIZE(newSize)
IF inputSize[0] EQ 0 THEN BEGIN
newSizeX=newSize
newSizeY=newSize
ENDIF ELSE BEGIN
newSizeX=newSize[0]
newSizeY=newSize[1]
ENDELSE
newData=REBIN(self->getData(),newSizeX,newSizeY)
self->setData, newData
END
;----------------------------------------------------------------------------
; astronomyImage::onDisk
;+
; METHODNAME:
; astronomyImage::OnDisk
;
; PURPOSE:
; This method saves the data array to a temporary disk file, and
; uses an array associated with this file to store this
; data. See the IDL documentation on associated variables (the
; ASSOC function) for more information about how this works.
;
; CALLING SEQUENCE:
; oAstronomyImage->OnDisk
;
; KEYWORD PARAMETERS:
; TEMPNAME: Use this keyword to specify the name of the
; temporary file in which to store the data.
;
; EXAMPLE:
; oAstronomyImage->OnDisk, TEMPNAME='/tmp/tmpImage.dat'
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen Jr., 1997.
;-
;
PRO astronomyImage::onDisk, TEMPNAME=tempName
IF NOT self.tempUsed THEN BEGIN
IF KEYWORD_SET(tempName) THEN self.tempName=tempName
OPENW, lun, self.tempName, /GET_LUN
WRITEU, lun, *self.data
CLOSE, lun
FREE_LUN, lun
OPENR, lun, self.tempName, /GET_LUN
newData=ASSOC(lun,*self.data)
PTR_FREE,self.data
self.data=PTR_NEW(newData)
self.tempLUN=lun
self.tempUsed=1
ENDIF
END
;----------------------------------------------------------------------------
; astronomyImage::save
;+
; METHODNAME:
; astronomyImage::Save
;
; PURPOSE:
; This method saves the image object.
;
; CALLING SEQUENCE:
; oAstronomyImage->Save, FileName
;
; OPTIONAL INPUTS:
; fileName: A string containing the name of the file tp save the
; file to. If no name is given, the current
; file name associated with the object is used.
;
; RESTRICTIONS:
; Currently, images can only be saved in the STSDAS file format.
;
; EXAMPLE:
; exampleImage->save, 'exampleImageName.hhh'
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen, Jr. 1997
;-
;
PRO astronomyImage::save, fileName
IF (N_PARAMS() GE 1) THEN BEGIN
self.fileName=fileName
ENDIF
fdecomp,self.filename,disk,dir,name,ext,ver
isFits=ext NE "hhh"
IF PTR_VALID(self.data) THEN BEGIN
saveArray=self->getData()
IF isFits THEN BEGIN
IF self.headerFormat EQ 'fits' THEN BEGIN
WRITEFITS,self.fileName,saveArray,*self.dataHeader
ENDIF ELSE BEGIN
WRITEFITS,self.fileName,saveArray
ENDELSE
ENDIF ELSE BEGIN
SXMAKE,1,self.fileName,saveArray,0,1
SXWRITE,1,saveArray
SXHWRITE,self.fileName,*self.dataHeader
ENDELSE
ENDIF
END
;----------------------------------------------------------------------------
; astronomyImage::setData
;+
; METHODNAME:
; astronomyImage::SetData
;
; PURPOSE:
; This method sets the data of the image object.
;
; CALLING SEQUENCE:
; oAstronomyImage->SetData, NewDataArray
;
; INPUTS:
; newData: This parameter contains the new value of the data
; array of the image. This will generally be a two
; dimensional array.
;
; SIDE EFFECTS:
; The old data associated with the image is lost.
;
; RESTRICTIONS:
;
; EXAMPLE:
; exampleImage->setData, newDataArray
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen, Jr. 1997
;-
;
PRO astronomyImage::setData, newData
IF self.tempUsed THEN BEGIN
self->inMemory
tempUsed=1
ENDIF ELSE BEGIN
tempUsed=0
ENDELSE
PTR_FREE, self.data
self.data=PTR_NEW(newData)
IF tempUsed THEN BEGIN
self->onDisk
ENDIF
IF(PTR_VALID(self.data) AND PTR_VALID(self.dataHeader)) THEN BEGIN
sizeInfo=SIZE(*self.data)
naxis1=sizeInfo(1)
naxis2=sizeInfo(2)
SXADDPAR,*self.dataHeader,'NAXIS1',naxis1
SXADDPAR,*self.dataHeader,'NAXIS2',naxis2
ENDIF
END
;----------------------------------------------------------------------------
; astronomyImage::size
;+
; METHODNAME:
; astronomyImage::Size
;
; PURPOSE:
; This method returns a vector storing the size of the image.
;
; CALLING SEQUENCE:
; Result = oAstronomyImage->Size()
;
; OUTPUTS:
; This method returns a two element vector containing the size
; of the current image array. The first element (Result[0])
; contains the 'x' size, and the second element (Result[1]) the
; y size.
;
; EXAMPLE:
; Result = oAstronomyImage->Size()
;
; MODIFICATION HISTORY:
; Written by Eric H. Neilsen, Jr. 1997
;-
;
FUNCTION astronomyImage::size
IF PTR_VALID(self.data) THEN BEGIN
sizeArray=self->getData()
imageSize=SIZE(sizeArray)
RETURN, imageSize(1:2)
ENDIF ELSE BEGIN
empty=[0,0]
RETURN, empty
ENDELSE
END
;----------------------------------------------------------------------------
; astronomyImage::headerKerwordValue
;+
; METHODNAME:
; astronomyImage::headerKeywordValue
;
; PURPOSE:
; This method returns a the value of a keyword in the header
;
; INPUTS:
; keyword: The name of the keyword whose value to return
;
; CALLING SEQUENCE:
; Result = oAstronomyImage->headerKeywordValue('keyword')
;
; OUTPUTS:
; This method returns the value of the keyword
;
; EXAMPLE:
; time = oAstronomyImage->headerKeywordValue('EXPTIME')
;
; MODIFICATION HISTORY:
; Written by Eric H. Neilsen, Jr. October 16, 2000
;-
;
FUNCTION astronomyImage::headerKeywordValue, keyword
keywordValue = SXPAR(self.dataHeader,keyword)
IF !ERR LT 0 THEN BEGIN
keywordValue = ''
PRINT, "Keyword not found"
ENDIF
RETURN, keywordValue
END
;----------------------------------------------------------------------------
; astronomyImage::DeleteHeaderKerword
;+
; METHODNAME:
; astronomyImage::deleteHeaderKeyword
;
; PURPOSE:
; This method deletes a line from the header
;
; INPUTS:
; keyword: the name of the keyword to delete
;
; CALLING SEQUENCE:
; oAstronomyImage->deleteHeaderKeyword, 'keyword'
;
; OUTPUTS:
; There is no output
;
; EXAMPLE:
;
; MODIFICATION HISTORY:
; Written by Eric H. Neilsen, Jr. October 16, 2000
;-
;
PRO astronomyImage::deleteHeaderKeyword, keyword
SXDELPAR, self.dataHeader, keyword
END
;----------------------------------------------------------------------------
; astronomyImage::AddHeaderKerword
;+
; METHODNAME:
; astronomyImage::addHeaderKeyword
;
; PURPOSE:
; This method adds a line from the header
;
; INPUTS:
; keyword: The name of the keyword to add
; value: The value to give the keyword
;
; CALLING SEQUENCE:
; oAstronomyImage->addHeaderKeyword, 'keyword', value
;
; OUTPUTS:
; There is no output
;
; EXAMPLE:
;
; MODIFICATION HISTORY:
; Written by Eric H. Neilsen, Jr. October 16, 2000
;-
;
PRO astronomyImage::addHeaderKeyword, keyword, value
SXADDPAR, self.dataHeader, keyword, value
END
;----------------------------------------------------------------------------
; astronomyImage::ReplaceHeaderKerword
;+
; METHODNAME:
; astronomyImage::replaceHeaderKeyword
;
; PURPOSE:
; This method replaces a line from the header
;
; INPUTS:
; keyword: The name of the keyword to replace
; value: The value to give the keyword
;
; CALLING SEQUENCE:
; oAstronomyImage->replaceHeaderKeyword, 'keyword', value
;
; OUTPUTS:
; There is no output
;
; EXAMPLE:
;
; MODIFICATION HISTORY:
; Written by Eric H. Neilsen, Jr. October 16, 2000
;-
;
PRO astronomyImage::replaceHeaderKeyword, keyword, value
SXDELPAR, self.dataHeader, keyword
SXADDPAR, self.dataHeader, keyword, value
END
;----------------------------------------------------------------------------
; astronomyImage__DEFINE
;+
; NAME:
; astronomyImage__DEFINE
;
; PURPOSE:
; This routine provides the deffinition of the astronomyImage
; object. This object is not intended to be used in practice;
; under most circumstances, one of it children (dataImage or
; maskImage) probably provides more functionality.
;
; MODIFICATION HISTORY:
; Written by: Eric H. Neilsen, Jr. 1997
;-
PRO astronomyImage__DEFINE
struct = {astronomyImage, $
data:PTR_NEW(), $
fileName:' ', $
tempName:'temp', $
tempLUN: 100, $
tempUsed: 0, $
dataHeader:PTR_NEW(),$
headerFormat: 'fits'$
}
END