本文整理汇总了Python中stsci.tools.fileutil.openImage函数的典型用法代码示例。如果您正苦于以下问题:Python openImage函数的具体用法?Python openImage怎么用?Python openImage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openImage函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:30,代码来源:stisData.py
示例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
开发者ID:bsugerman,项目名称:drizzlepac,代码行数:28,代码来源:wfc3Data.py
示例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
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:31,代码来源:imageObject.py
示例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
开发者ID:spacetelescope,项目名称:pydrizzle,代码行数:33,代码来源:pattern.py
示例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
开发者ID:jhunkeler,项目名称:nictools,代码行数:18,代码来源:readTDD.py
示例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()
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:9,代码来源:imageObject.py
示例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
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:10,代码来源:imageObject.py
示例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
开发者ID:spacetelescope,项目名称:pydrizzle,代码行数:10,代码来源:process_input.py
示例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
开发者ID:ih64,项目名称:XRB-phot,代码行数:10,代码来源:check_files.py
示例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
开发者ID:spacetelescope,项目名称:stwcs,代码行数:55,代码来源:wfpc2_dgeo.py
示例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
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:55,代码来源:nicmosData.py
示例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
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:11,代码来源:adrizzle.py
示例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()
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:20,代码来源:adrizzle.py
示例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
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:41,代码来源:stisData.py
示例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
开发者ID:spacetelescope,项目名称:pydrizzle,代码行数:13,代码来源:makewcs.py
示例16: _updateKW
def _updateKW(image, filename, exten, skyKW, Value):
"""update the header with the kw,value"""
# Update the value in memory
image.header[skyKW] = Value
# Now update the value on disk
if isinstance(exten,tuple):
strexten = '[%s,%s]'%(exten[0],str(exten[1]))
else:
strexten = '[%s]'%(exten)
log.info('Updating keyword %s in %s' % (skyKW, filename + strexten))
fobj = fileutil.openImage(filename, mode='update')
fobj[exten].header[skyKW] = (Value, 'Sky value computed by AstroDrizzle')
fobj.close()
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:14,代码来源:sky.py
示例17: getflat
def getflat(self, chip):
"""
Method for retrieving a detector's flat field.
Returns
-------
flat: array
This method will return an array the same shape as the image in
**units of electrons**.
"""
sci_chip = self._image[self.scienceExt, chip]
# The keyword for ACS flat fields in the primary header of the flt
# file is pfltfile. This flat file is already in the required
# units of electrons.
# The use of fileutil.osfn interprets any environment variable, such as
# jref$, used in the specification of the reference filename
filename = fileutil.osfn(self._image["PRIMARY"].header[self.flatkey])
hdulist = None
try:
hdulist = fileutil.openImage(filename, mode='readonly',
memmap=False)
data = hdulist[(self.scienceExt, chip)].data
if data.shape[0] != sci_chip.image_shape[0]:
ltv2 = int(np.round(sci_chip.ltv2))
else:
ltv2 = 0
size2 = sci_chip.image_shape[0] + ltv2
if data.shape[1] != sci_chip.image_shape[1]:
ltv1 = int(np.round(sci_chip.ltv1))
else:
ltv1 = 0
size1 = sci_chip.image_shape[1] + ltv1
flat = data[ltv2:size2, ltv1:size1]
except FileNotFoundError:
flat = np.ones(sci_chip.image_shape, dtype=sci_chip.image_dtype)
log.warning("Cannot find flat field file '{}'".format(filename))
log.warning("Treating flatfield as a constant value of '1'.")
finally:
if hdulist is not None:
hdulist.close()
return flat
开发者ID:jhunkeler,项目名称:drizzlepac,代码行数:49,代码来源:imageObject.py
示例18: doUnitConversions
def doUnitConversions(self):
""" Apply unit conversions to all the chips, ignoring the group parameter.
This insures that all the chips get the same conversions when this
gets done, even if only 1 chip was specified to be processed.
"""
# Image information
#_handle = fileutil.openImage(self._filename,mode='update',memmap=0)
_handle = fileutil.openImage(self._filename,mode='readonly')
# Now convert the SCI array(s) units
for det in range(1,self._numchips+1):
chip=self._image[self.scienceExt,det]
conversionFactor = 1.0
# add D2IMFILE to outputNames for removal by 'clean()' method later
if 'D2IMFILE' in _handle[0].header and _handle[0].header['D2IMFILE'] not in ["","N/A"]:
chip.outputNames['d2imfile'] = _handle[0].header['D2IMFILE']
if chip._gain != None:
"""
# Multiply the values of the sci extension pixels by the gain.
print "Converting %s[%d] from COUNTS to ELECTRONS"%(self._filename,det)
# If the exptime is 0 the science image will be zeroed out.
np.multiply(_handle[self.scienceExt,det].data,chip._gain,_handle[self.scienceExt,det].data)
chip.data=_handle[self.scienceExt,det].data
# Set the BUNIT keyword to 'electrons'
chip._bunit = 'ELECTRONS'
chip.header.update('BUNIT','ELECTRONS')
_handle[self.scienceExt,det].header.update('BUNIT','ELECTRONS')
# Update the PHOTFLAM value
photflam = _handle[self.scienceExt,det].header['PHOTFLAM']
_handle[self.scienceExt,det].header.update('PHOTFLAM',(photflam/chip._gain))
"""
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.
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:49,代码来源:wfpc2Data.py
示例19: buildIVMmask
def buildIVMmask(self,chip,dqarr,scale):
""" Builds a weight mask from an input DQ array and either an IVM array
provided by the user or a self-generated IVM array derived from the
flat-field reference file associated with the input image.
"""
sci_chip = self._image[self.scienceExt,chip]
ivmname = self.outputNames['ivmFile']
if ivmname != None:
log.info("Applying user supplied IVM files for chip %s" % chip)
#Parse the input file name to get the extension we are working on
extn = "IVM,{}".format(chip)
#Open the mask image for updating and the IVM image
ivm = fileutil.openImage(ivmname, mode='readonly')
ivmfile = fileutil.getExtn(ivm, extn)
# Multiply the IVM file by the input mask in place.
ivmarr = ivmfile.data * dqarr
ivm.close()
else:
log.info("Automatically creating IVM files for chip %s" % chip)
# If no IVM files were provided by the user we will
# need to automatically generate them based upon
# instrument specific information.
flat = self.getflat(chip)
RN = self.getReadNoiseImage(chip)
darkimg = self.getdarkimg(chip)
skyimg = self.getskyimg(chip)
#exptime = self.getexptimeimg(chip)
#exptime = sci_chip._exptime
#ivm = (flat*exptime)**2/(darkimg+(skyimg*flat)+RN**2)
ivm = (flat)**2/(darkimg+(skyimg*flat)+RN**2)
# Multiply the IVM file by the input mask in place.
ivmarr = ivm * dqarr
# Update 'wt_scl' parameter to match use of IVM file
sci_chip._wtscl = pow(sci_chip._exptime,2)/pow(scale,4)
#sci_chip._wtscl = 1.0/pow(scale,4)
return ivmarr.astype(np.float32)
开发者ID:brechmos-stsci,项目名称:drizzlepac,代码行数:47,代码来源:imageObject.py
示例20: convert_dgeo_to_d2im
def convert_dgeo_to_d2im(dgeofile, output, clobber=True):
""" Routine that converts the WFPC2 DGEOFILE into a D2IMFILE.
"""
dgeo = fileutil.openImage(dgeofile)
outname = output + '_d2im.fits'
removeFileSafely(outname)
data = np.array([dgeo['dy', 1].data[:, 0]])
scihdu = fits.ImageHDU(data=data)
dgeo.close()
# add required keywords for D2IM header
scihdu.header['EXTNAME'] = ('DY', 'Extension name')
scihdu.header['EXTVER'] = (1, 'Extension version')
fits_str = 'PYFITS Version ' + str(astropy.__version__)
scihdu.header['ORIGIN'] = (fits_str, 'FITS file originator')
scihdu.header['INHERIT'] = (False, 'Inherits global header')
dnow = datetime.datetime.now()
scihdu.header['DATE'] = (str(dnow).replace(' ', 'T'),
'Date FITS file was generated')
scihdu.header['CRPIX1'] = (0, 'Distortion array reference pixel')
scihdu.header['CDELT1'] = (1, 'Grid step size in first coordinate')
scihdu.header['CRVAL1'] = (0, 'Image array pixel coordinate')
scihdu.header['CRPIX2'] = (0, 'Distortion array reference pixel')
scihdu.header['CDELT2'] = (1, 'Grid step size in second coordinate')
scihdu.header['CRVAL2'] = (0, 'Image array pixel coordinate')
phdu = fits.PrimaryHDU()
phdu.header['INSTRUME'] = 'WFPC2'
d2imhdu = fits.HDUList()
d2imhdu.append(phdu)
scihdu.header['DETECTOR'] = (1, 'CCD number of the detector: PC 1, WFC 2-4 ')
d2imhdu.append(scihdu.copy())
scihdu.header['EXTVER'] = (2, 'Extension version')
scihdu.header['DETECTOR'] = (2, 'CCD number of the detector: PC 1, WFC 2-4 ')
d2imhdu.append(scihdu.copy())
scihdu.header['EXTVER'] = (3, 'Extension version')
scihdu.header['DETECTOR'] = (3, 'CCD number of the detector: PC 1, WFC 2-4 ')
d2imhdu.append(scihdu.copy())
scihdu.header['EXTVER'] = (4, 'Extension version')
scihdu.header['DETECTOR'] = (4, 'CCD number of the detector: PC 1, WFC 2-4 ')
d2imhdu.append(scihdu.copy())
d2imhdu.writeto(outname)
d2imhdu.close()
return outname
开发者ID:jhunkeler,项目名称:stwcs,代码行数:47,代码来源:wfpc2_dgeo.py
注:本文中的stsci.tools.fileutil.openImage函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论