def check_mask_dim(img, ota): mask_name = odi.bppath + 'reproj_mask_' + ota + '.' + img.stem() reproj_img = odi.reprojpath + 'reproj_' + ota + '.' + img.stem() bgsub_img = odi.bgsubpath + 'bgsub_' + ota + '.' + img.stem() mask_header = iraf.imhead(mask_name, Stdout=1)[0] mask_dim1, mask_dim2 = get_dims(mask_header) reproj_header = iraf.imhead(reproj_img, Stdout=1)[0] reproj_dim1, reproj_dim2 = get_dims(reproj_header) bgsub_header = iraf.imhead(bgsub_img, Stdout=1)[0] bgsub_dim1, bgsub_dim2 = get_dims(bgsub_header) dim_status = ((mask_dim1 == reproj_dim1 == bgsub_dim1) & (mask_dim2 == reproj_dim2 == bgsub_dim2)) if dim_status == False: tqdm.write('mask and image dimensions to not match for: ', img, ota) tqdm.write('mask: {:5d} {:5d}'.format(mask_dim1, mask_dim2)) tqdm.write('reproj: {:5d} {:5d}'.format(reproj_dim1, reproj_dim2)) tqdm.write('bgsub: {:5d} {:5d}'.format(bgsub_dim1, bgsub_dim2)) else: tqdm.write('dimension test passed') tqdm.write('mask: {:5d} {:5d}'.format(mask_dim1, mask_dim2)) tqdm.write('reproj: {:5d} {:5d}'.format(reproj_dim1, reproj_dim2)) tqdm.write('bgsub: {:5d} {:5d}'.format(bgsub_dim1, bgsub_dim2)) return dim_status
def check_mask_dim(img,ota): mask_name = odi.bppath+'reproj_mask_'+ota+'.'+img.stem() reproj_img = odi.reprojpath+'reproj_'+ota+'.'+img.stem() bgsub_img = odi.bgsubpath+'bgsub_'+ota+'.'+img.stem() mask_header = iraf.imhead(mask_name,Stdout=1)[0] mask_dim1, mask_dim2 = get_dims(mask_header) reproj_header = iraf.imhead(reproj_img,Stdout=1)[0] reproj_dim1, reproj_dim2 = get_dims(reproj_header) bgsub_header = iraf.imhead(bgsub_img,Stdout=1)[0] bgsub_dim1, bgsub_dim2 = get_dims(bgsub_header) dim_status = ((mask_dim1 == reproj_dim1 == bgsub_dim1) & (mask_dim2 == reproj_dim2 == bgsub_dim2)) if dim_status == False: tqdm.write('mask and image dimensions to not match for: ', img, ota) tqdm.write('mask: {:5d} {:5d}'.format(mask_dim1,mask_dim2)) tqdm.write('reproj: {:5d} {:5d}'.format(reproj_dim1,reproj_dim2)) tqdm.write('bgsub: {:5d} {:5d}'.format(bgsub_dim1,bgsub_dim2)) else: tqdm.write('dimension test passed') tqdm.write('mask: {:5d} {:5d}'.format(mask_dim1,mask_dim2)) tqdm.write('reproj: {:5d} {:5d}'.format(reproj_dim1,reproj_dim2)) tqdm.write('bgsub: {:5d} {:5d}'.format(bgsub_dim1,bgsub_dim2)) return dim_status
def get_HeaderValue(self, Item, Fit_Address, Digitalize = False): Header = iraf.imhead(Fit_Address, long='yes', Stdout=1) for i in range(len(Header)): key = Header[i].replace(' ','').split('=')[0] if key == Item: value = Header[i].replace(' ','').split('=')[1] value = value.split('/')[0] if Digitalize == True: return float(value) else: return value
def run_imhead(imageFilename): ''' invokes the iraf method imhead on the given image filename parses the result to be returned as a list of string values parameter imageFilename - the full path filename of the image on which to invoke imexam returns - a string list of image info in the form [galaxy_id, filt, cam_number, image_number, frame_height, frame_width] ''' imhead_return = iraf.imhead(imageFilename, Stdout=1)[0].strip() imhead_info = imhead_return.split("/")[-1] directory_location = imhead_return.replace(imhead_info, "") # "VELA01_a0.110_0006317__skipir_CAMERA0-BROADBAND_F125W_simulation.fits[600,600][real]:" frame_dimensions = imhead_info.split("[")[1].replace("]", "").split(",") # ["600","600"] frame_width = frame_dimensions[0] # "600" frame_height = frame_dimensions[1] # "600" galaxy_id = imhead_info.split("_")[0] #"VELA01" filt = imhead_info.split("_")[6] #"F125W" image_number = imhead_info.split("_")[1].split(".")[1] # "110" cam_str = imhead_info.split("_")[5].split("-")[0] # "CAMERA0" #these statements accomodate for camera numbers greater than 9 digits = ["1","2","3","4","5","6","7","8","9"] #determines if camera number is greater than 10, does not allow greater than 99 # ex: "CAMERA0" -> cam_str[-2] = "M" # ex: "CAMERA12" -> cam_str[-2] = "1" if cam_str[-2] in digits: cam_number = cam_str[-2:] else: cam_number = cam_str[-1] #print cam_number return [directory_location, galaxy_id, filt, cam_number, image_number, frame_height, frame_width]
def get_HeaderValue(Item, Fit_Address, Digitalize=False): Header = iraf.imhead(Fit_Address, long="yes", Stdout=1) for i in range(len(Header)): key = Header[i].replace(" ", "").split("=")[0] if key == Item: value = Header[i].replace(" ", "").split("=")[1] value = value.split("/")[0] if Digitalize == True: return float(value) else: return value
def get_files(fileparm): '''In iraf cl, sometimes a pattern or a file list is given instead of a proper name. Python doesn't handle that very well, so here's a cludge to get it to work using imhead.''' result = iraf.imhead(images=fileparm, longheader=0, Stdout=1) if len(result) == 0: return None if result[0] == '' or result[0] == 'no images found': return None out = [] for res in result: out.append(file_pat.search(res).group(1)) return out
rotoff['MMIRS'] = -90 fitsfiles = sys.argv[1] mode = sys.argv[2] fitsfile = average(fitsfiles) if fitsfile.find('/') is -1: fitsfile = "%s/%s" % (os.getcwd(), fitsfile) os.system("rm -f back.fits") iraf.images() iraf.images.imfit() iraf.images.imutil() #iraf.crutil() if mode == 'MMIRS': flipme = True headers = iraf.imhead(fitsfile, long='yes', Stdout=1) for line in headers: if re.match('WAT', line): flipme = False if flipme: print "not flipped" iraf.imsurfit(fitsfile, 'back.fits', xorder=2, yorder=2, upper=2, lower=2, ngrow=15) iraf.imarith(fitsfile, '-', 'back.fits', fitsfile) iraf.imcopy(fitsfile + '[*,*]', fitsfile) # iraf.cosmicrays(fitsfile, fitsfile, interactive='no') else: print "flipped" else:
def get_head(image): s = iraf.imhead(image, long='yes', Stdout=1) for i in s: print i
def test_imhead(self): out = six.StringIO() iraf.imhead('dev$pix', Stdout=out) assert out.getvalue() == 'dev$pix[512,512][short]: m51 B 600s\n'
import os import sys from astropy.utils.data import get_pkg_data_contents from distutils.spawn import find_executable IS_PY2 = sys.version_info < (3, 0) DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') HAS_PYRAF_EXEC = bool(find_executable('pyraf')) try: from pyraf import iraf iraf.imhead("dev$pix", Stdout=os.devnull, Stderr=os.devnull) except: # Only this can catch the error! HAS_IRAF = False else: HAS_IRAF = True def diff_outputs(fin, reffile): """Compare output lines with reference file.""" if isinstance(fin, list): lines = fin else: with open(fin) as f: lines = f.readlines() ans = get_pkg_data_contents(reffile).split(os.linesep) all_bad_lines = [] for x, y in zip(lines, ans):
import os import sys from astropy.utils.data import get_pkg_data_contents from distutils.spawn import find_executable IS_PY2 = sys.version_info < (3, 0) DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') HAS_PYRAF_EXEC = bool(find_executable('pyraf')) try: from pyraf import iraf iraf.imhead("dev$pix", Stdout=os.devnull, Stderr=os.devnull) except: # Only this can catch the error! HAS_IRAF = False else: HAS_IRAF = True def diff_outputs(fin, reffile): """Compare output lines with reference file.""" if isinstance(fin, list): lines = fin else: with open(fin) as f: lines = f.readlines() ans = get_pkg_data_contents(reffile).split(os.linesep) all_bad_lines = []
files.append(filelist) else: files.extend(open(filelist).read().split()) if len(files) == 0: raise FileError("Error: No images in filelists. Exiting") print files #Display images for i, afile in enumerate(files): if not isfile(afile): raise FileError("Error: Image %s does not exist" % afile) iraf.display.frame = i + 1 iraf.display(afile) iraf.imhead(afile) ############################### Aligning ########################################################## if do_align and len(files) > 1: #Determine reference image if not reference: print 'Image number , Header info' for k, afile in enumerate(files): head = iraf.imhead(afile, Stdout=1) print str(k) + ' ', head[0] print green( "Choose which image to use as reference, by typing in it's number." ) print green( "Note that due to a bug in iraf.imalign you should use the smallest" )
def get_head(image): s=iraf.imhead(image,long='yes', Stdout=1) for i in s: print i