本文整理汇总了Python中stsci.tools.fileutil.openImage函数的典型用法代码示例。如果您正苦于以下问题:Python openImage函数的具体用法?Python openImage怎么用?Python openImage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openImage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doUnitConversions
def doUnitConversions(self):
"""Convert the data to electrons.
This converts all science data extensions and saves
the results back to disk. We need to make sure
the data inside the chips already in memory is altered as well.
"""
# Image information
#_handle = fileutil.openImage(self._filename,mode='update',memmap=0)
_handle = fileutil.openImage(self._filename,mode='readonly')
for det in range(1,self._numchips+1,1):
chip=self._image[self.scienceExt,det]
if chip._gain != None:
conversionFactor = chip._gain
chip._effGain = chip._gain #1.
chip._conversionFactor = conversionFactor #1.
else:
msg = "Invalid gain value for data, no conversion done"
print(msg)
raise ValueError(msg)
# Close the files and clean-up
_handle.close()
self._effGain = conversionFactor # 1.0
示例2: getdarkimg
def getdarkimg(self,chip):
"""
Return an array representing the dark image for the detector.
Returns
-------
dark: array
Dark image array in the same shape as the input image with **units of cps**
"""
sci_chip = self._image[self.scienceExt,chip]
# First attempt to get the dark image specified by the "DARKFILE"
# keyword in the primary keyword of the science data.
try:
filename = self.header["DARKFILE"]
handle = fileutil.openImage(filename, mode='readonly', memmap=False)
hdu = fileutil.getExtn(handle,extn="sci,1")
darkobj = hdu.data[sci_chip.ltv2:sci_chip.size2,sci_chip.ltv1:sci_chip.size1]
# If the darkfile cannot be located, create the dark image from
# what we know about the detector dark current and assume a
# constant dark current for the whole image.
except:
darkobj = np.ones(sci_chip.image_shape,dtype=sci_chip.image_dtype)*self.getdarkcurrent()
return darkobj
示例3: getData
def getData(self,exten=None):
""" Return just the data array from the specified extension
fileutil is used instead of fits to account for non-
FITS input images. openImage returns a fits object.
"""
if exten.lower().find('sci') > -1:
# For SCI extensions, the current file will have the data
fname = self._filename
else:
# otherwise, the data being requested may need to come from a
# separate file, as is the case with WFPC2 DQ data.
#
# convert exten to 'sci',extver to get the DQ info for that chip
extn = exten.split(',')
sci_chip = self._image[self.scienceExt,int(extn[1])]
fname = sci_chip.dqfile
extnum = self._interpretExten(exten)
if self._image[extnum].data is None:
if os.path.exists(fname):
_image=fileutil.openImage(fname,clobber=False,memmap=0)
_data=fileutil.getExtn(_image,extn=exten).data
_image.close()
del _image
self._image[extnum].data = _data
else:
_data = None
else:
_data = self._image[extnum].data
return _data
示例4: getHeaderHandle
def getHeaderHandle(self):
""" Sets up the PyFITS image handle and Primary header
as self.image_handle and self.header.
When Pattern being used for output product, filename will be
set to None and this returns None for header and image_handle.
"""
_numsci = 0
if self.name:
_handle = fileutil.openImage(self.name,mode='readonly',memmap=self.pars['memmap'])
_fname,_extn = fileutil.parseFilename(self.name)
_hdr = _handle['PRIMARY'].header.copy()
# Count number of SCI extensions
for _fext in _handle:
if 'extname' in _fext.header and _fext.header['extname'] == 'SCI':
_numsci += 1
if _extn and _extn > 0:
# Append correct extension/chip/group header to PRIMARY...
for _card in fileutil.getExtn(_handle,_extn).header.ascard:
_hdr.ascard.append(_card)
else:
# Default to None
_handle = None
_hdr = None
# Set attribute to point to these products
self.image_handle = None
self.header = _hdr
self.nmembers = _numsci
return _handle
示例5: fromcalfile
def fromcalfile(filename):
"""
fromcalfile: function that returns a darkobject instance given the
name of a cal.fits file as input. If there is no TEMPFILE keyword
in the primary header of the cal.fits file or if the file specified
by TEMPFILE cannot be found, a None object is returned.
"""
hdulist = openImage(filename)
if 'TEMPFILE' in hdulist[0].header:
if tddfile == 'N/A':
return None
else:
tddfile = hdulist[0].header['TEMPFILE']
tddhdulist = openImage(tddfile)
return darkobject(tddhdulist)
else:
return None
示例6: updateData
def updateData(self,exten,data):
""" Write out updated data and header to
the original input file for this object.
"""
_extnum=self._interpretExten(exten)
fimg = fileutil.openImage(self._filename,mode='update')
fimg[_extnum].data = data
fimg[_extnum].header = self._image[_extnum].header
fimg.close()
示例7: getHeader
def getHeader(self,exten=None):
""" Return just the specified header extension fileutil
is used instead of fits to account for non-FITS
input images. openImage returns a fits object.
"""
_image=fileutil.openImage(self._filename,clobber=False,memmap=0)
_header=fileutil.getExtn(_image,extn=exten).header
_image.close()
del _image
return _header
示例8: convert
def convert(file):
newfilename = fileutil.buildFITSName(file)
try:
newimage = fileutil.openImage(file,writefits=True,
fitsname=newfilename, clobber=True)
del newimage
return newfilename
except IOError:
print('Warning: File %s could not be found' % file)
return None
示例9: convert
def convert(file):
newfilename = fileutil.buildNewRootname(file, extn='_c0h.fits')
try:
newimage = fileutil.openImage(file,writefits=True,
fitsname=newfilename,clobber=True)
del newimage
return newfilename
except IOError:
print 'Warning: File %s could not be found' % file
return None
示例10: update_wfpc2_d2geofile
def update_wfpc2_d2geofile(filename, fhdu=None):
"""
Creates a D2IMFILE from the DGEOFILE for a WFPC2 image (input), and
modifies the header to reflect the new usage.
Parameters
----------
filename: string
Name of WFPC2 file to be processed. This file will be updated
to delete any reference to a DGEOFILE and add a D2IMFILE to replace
that correction when running updatewcs.
fhdu: object
FITS object for WFPC2 image. If user has already opened the WFPC2
file, they can simply pass that FITS object in for direct processing.
Returns
-------
d2imfile: string
Name of D2IMFILE created from DGEOFILE. The D2IMFILE keyword in the
image header will be updated/added to point to this newly created file.
"""
if isinstance(filename, fits.HDUList):
fhdu = filename
filename = fhdu.filename()
close_fhdu = False
else:
fhdu = fileutil.openImage(filename, mode='update')
close_fhdu = True
dgeofile = fhdu['PRIMARY'].header.get('DGEOFILE', None)
already_converted = dgeofile not in [None, "N/A", "", " "]
if already_converted or 'ODGEOFIL' in fhdu['PRIMARY'].header:
if not already_converted:
dgeofile = fhdu['PRIMARY'].header.get('ODGEOFIL', None)
logger.info('Converting DGEOFILE %s into D2IMFILE...' % dgeofile)
rootname = filename[:filename.find('.fits')]
d2imfile = convert_dgeo_to_d2im(dgeofile, rootname)
fhdu['PRIMARY'].header['ODGEOFIL'] = dgeofile
fhdu['PRIMARY'].header['DGEOFILE'] = 'N/A'
fhdu['PRIMARY'].header['D2IMFILE'] = d2imfile
else:
d2imfile = None
fhdu['PRIMARY'].header['DGEOFILE'] = 'N/A'
if 'D2IMFILE' not in fhdu['PRIMARY'].header:
fhdu['PRIMARY'].header['D2IMFILE'] = 'N/A'
# Only close the file handle if opened in this function
if close_fhdu:
fhdu.close()
# return the d2imfile name so that calling routine can keep
# track of the new file created and delete it later if necessary
# (multidrizzle clean=True mode of operation)
return d2imfile
示例11: doUnitConversions
def doUnitConversions(self):
"""Convert the data to electrons
This converts all science data extensions and saves
the results back to disk. We need to make sure
the data inside the chips already in memory is altered as well.
"""
# Image information
#_handle = fileutil.openImage(self._filename,mode='update',memmap=0)
_handle = fileutil.openImage(self._filename,mode='readonly')
for det in range(1,self._numchips+1,1):
chip=self._image[self.scienceExt,det]
if chip._gain != None:
#conversionFactor = (self.getExpTime() * self.getGain())
conversionFactor = chip._gain
if self.isCountRate():
conversionFactor *= chip._exptime
counts_str = 'COUNTS/S'
else:
counts_str = 'COUNTS'
# Multiply the values of the sci extension pixels by the gain.
print("Converting %s[%s,%d] from %s to ELECTRONS"%(self._filename,self.scienceExt,det,counts_str))
"""
# If the exptime is 0 the science image will be zeroed out.
np.multiply(_handle[self.scienceExt,det].data,conversionFactor,_handle[self.scienceExt,det].data)
#chip.data=_handle[self.scienceExt,det].data.copy()
# Set the BUNIT keyword to 'electrons'
chip.header.update('BUNIT','ELECTRONS')
_handle[0].header.update('BUNIT','ELECTRONS')
# Update the PHOTFLAM value
photflam = _handle[0].header['PHOTFLAM']
_handle[0].header.update('PHOTFLAM',(photflam/chip._gain))
chip._effGain = 1.0
"""
chip._effGain = chip._gain
chip._conversionFactor = conversionFactor
else:
msg = "Invalid gain value for data, no conversion done"
print(msg)
raise ValueError(msg)
# Close the files and clean-up
_handle.close()
self._effGain = conversionFactor #1.0
示例12: get_data
def get_data(filename):
fileroot,extn = fileutil.parseFilename(filename)
extname = fileutil.parseExtn(extn)
if extname[0] == '': extname = "PRIMARY"
if os.path.exists(fileroot):
handle = fileutil.openImage(filename)
data = handle[extname].data
handle.close()
else:
data = None
return data
示例13: updateInputDQArray
def updateInputDQArray(dqfile,dq_extn,chip, crmaskname,cr_bits_value):
if not isinstance(crmaskname, fits.HDUList) and not os.path.exists(crmaskname):
log.warning('No CR mask file found! Input DQ array not updated.')
return
if cr_bits_value == None:
log.warning('Input DQ array not updated!')
return
if isinstance(crmaskname, fits.HDUList):
# in_memory case
crmask = crmaskname
else:
crmask = fileutil.openImage(crmaskname)
if os.path.exists(dqfile):
fullext=dqfile+"["+dq_extn+str(chip)+"]"
infile = fileutil.openImage(fullext,mode='update')
__bitarray = np.logical_not(crmask[0].data).astype(np.int16) * cr_bits_value
np.bitwise_or(infile[dq_extn,chip].data,__bitarray,infile[dq_extn,chip].data)
infile.close()
crmask.close()
示例14: getflat
def getflat(self,chip):
"""
Method for retrieving a detector's flat field. For STIS there are three.
This method will return an array the same shape as the image.
"""
sci_chip = self._image[self.scienceExt,chip]
exten = self.errExt+','+str(chip)
# The keyword for STIS flat fields in the primary header of the flt
lflatfile = fileutil.osfn(self._image["PRIMARY"].header['LFLTFILE'])
pflatfile = fileutil.osfn(self._image["PRIMARY"].header['PFLTFILE'])
# Try to open the file in the location specified by LFLTFILE.
try:
handle = fileutil.openImage(lflatfile,mode='readonly',memmap=0)
hdu = fileutil.getExtn(handle,extn=exten)
lfltdata = hdu.data
if lfltdata.shape != self.full_shape:
lfltdata = interp2d.expand2d(lfltdata,self.full_shape)
except:
lfltdata = np.ones(self.full_shape,dtype=sci_chip.image_dtype)
str = "Cannot find file "+filename+". Treating flatfield constant value of '1'.\n"
print(str)
# Try to open the file in the location specified by PFLTFILE.
try:
handle = fileutil.openImage(pflatfile,mode='readonly',memmap=0)
hdu = fileutil.getExtn(handle,extn=exten)
pfltdata = hdu.data
except:
pfltdata = np.ones(self.image_shape,dtype=sci_chip.image_dtype)
str = "Cannot find file "+filename+". Treating flatfield constant value of '1'.\n"
print(str)
print("lfltdata shape: ",lfltdata.shape)
print("pfltdata shape: ",pfltdata.shape)
flat = lfltdata * pfltdata
return flat
示例15: get_numsci
def get_numsci(image):
""" Find the number of SCI extensions in the image.
Input:
image - name of single input image
"""
handle = fileutil.openImage(image)
num_sci = 0
for extn in handle:
if 'extname' in extn.header:
if extn.header['extname'].lower() == 'sci':
num_sci += 1
handle.close()
return num_sci