Beispiel #1
0
def main(argv):
    try:
        dem_file = argv[1]
        dem_error = argv[2]
    except:
        usage()
        sys.exit(1)

    dem, demrsc = _readfile.read_real_int16(dem_file)
    g = h5py.File(dem_error, 'r')
    dset = g['dem'].get('dem')
    dem_error = dset[0:dset.shape[0]]

    print 'Correcting the DEM'
    sum = dem + dem_error
    print 'Creating the new DEM'
    _writefile.write_real_int16(sum, 'DEM_w_error.dem')

    rsc_file = open('DEM_w_error.dem.rsc', 'w')
    for k in demrsc.keys():
        rsc_file.write(k + '	' + demrsc[k] + '\n')
        rsc_file.close

    date12_file = open('111111-222222_baseline.rsc', 'w')
    date12_file.write('P_BASELINE_TOP_ODR' + '     ' + '000')
    date12_file.close
Beispiel #2
0
def main(argv):
    try:
        dem_file = argv[1]
        dem_error = argv[2]
    except:
        print '''
        *******************************************
           
           Usage: correct_dem.py demFile geo_demErrorFile
           Example:
                  correct_dem.py $DEMDIR/Socorro-30/Socorro_30.dem geo_DEM_error.h5
                  correct_dem.py $DEMDIR/Socorro-30/Socorro_30.dem geo_DEM_error.h5
    
        *******************************************         
        '''
        sys.exit(1)
  
    
  
    dem, demrsc = _readfile.read_real_int16(dem_file)
    g = h5py.File(dem_error,'r')
    dset  = g['dem'].get('dem')
    dem_error = dset[0:dset.shape[0]]

    print 'Correcting the DEM'
    sum = dem + dem_error
    print 'Creating the new DEM'
    _writefile.write_real_int16(sum,'DEM_w_error.dem')
          
    rsc_file = open('DEM_w_error.dem.rsc','w')
    for k in demrsc.keys():
        rsc_file.write(k+'	'+demrsc[k]+'\n')
        rsc_file.close
          
    date12_file=open('111111-222222_baseline.rsc','w')
    date12_file.write('P_BASELINE_TOP_ODR'+'     '+ '000')
    date12_file.close
Beispiel #3
0
def main(argv):

    try:    opts, args = getopt.getopt(argv,"h:f:t:p:")
    except getopt.GetoptError:
        Usage() ; sys.exit(1)
  
    if opts==[]:
        Usage() ; sys.exit(1)
    for opt,arg in opts:
        if opt in ("-h","--help"):  Usage(); sys.exit()
        elif opt == '-f':           file     = arg
        elif opt == '-t':           filtType = arg
        elif opt == '-p':           par      = arg
  
    ext = os.path.splitext(file)[1]
    outName=file.split('.')[0]+'_'+filtType+ext
    try:    par
    except: par=[]
  
    #print '+++++++++++++++++++++++++++'
    print 'Filter type : '+filtType
    print 'parameters : ' + str(par)
    #print '+++++++++++++++++++++++++++'
    ###############################################
    if ext == '.int' or ext == '.slc':
        a,p,r = readfile.read_complex_float32(file)
        plks=multilook(p,alks,rlks)
        alks=multilook(a,alks,rlks)
    
        r['FILE_LENGTH']=str(dlks.shape[0])
        r['WIDTH']=str(dlks.shape[1])
        r['XMAX']=str(int(r['WIDTH']) - 1)
        r['YMAX']=str(int(r['FILE_LENGTH']) - 1)
        try:
            r['Y_STEP']=str(float(r['Y_STEP'])*alks)
            r['X_STEP']=str(float(r['X_STEP'])*rlks)
        except:
            Geo=0
    
        f = open(outName+'.rsc','w')
        for k in r.keys():
            f.write(k+'    '+r[k]+'\n')
        f.close()   

    elif ext == '.unw' or ext == '.cor' or ext == '.hgt':
        a,p,r = readfile.read_float32(file)
        plks=multilook(p,alks,rlks)
        alks=multilook(a,alks,rlks)
        
        writefile.write_float32(plks,outName)
    
        r['FILE_LENGTH']=str(dlks.shape[0])
        r['WIDTH']=str(dlks.shape[1])
        r['XMAX']=str(int(r['WIDTH']) - 1)
        r['YMAX']=str(int(r['FILE_LENGTH']) - 1)
        
        try:
            r['Y_STEP']=str(float(r['Y_STEP'])*alks)
            r['X_STEP']=str(float(r['X_STEP'])*rlks)
        except:
            Geo=0
    
        f = open(outName+'.rsc','w')
        for k in r.keys():
            f.write(k+'    '+r[k]+'\n')
        f.close()
  
    elif ext == ('.dem'):
        d,r = readfile.read_real_int16(file)
        dlks=multilook(d,alks,rlks)
    
        print 'writing '+outName
        writefile.write_real_int16(dlks,outName)
        
        r['FILE_LENGTH']=str(dlks.shape[0])
        r['WIDTH']=str(dlks.shape[1])
        r['XMAX']=str(int(r['WIDTH']) - 1)
        r['YMAX']=str(int(r['FILE_LENGTH']) - 1)
    
        try:
            r['Y_STEP']=str(float(r['Y_STEP'])*alks)
            r['X_STEP']=str(float(r['X_STEP'])*rlks)
        except:
            Geo=0
    
        f = open(outName+'.rsc','w')
        for k in r.keys():
            f.write(k+'    '+r[k]+'\n')
        f.close()

    elif ext in ['.jpeg','jpg','png']:
  
        import Image
        im = Image.open(file)
    
        width = im.size[0] / int(rlks)
        height = im.size[1] / int(alks)
    
        imlks = im.resize((width, height), Image.NEAREST)
        print 'writing ' + outName
        imlks.save(outName)
    
        try:
            r=readfile.read_roipac_rsc(file+'.rsc')
        except:
            sys.exit(1)
    
        r['FILE_LENGTH']=str(height)
        r['WIDTH']=str(width)
        r['XMAX']=str(int(r['WIDTH']) - 1)
        r['YMAX']=str(int(r['FILE_LENGTH']) - 1)
        try:
            r['Y_STEP']=str(float(r['Y_STEP'])*alks)
            r['X_STEP']=str(float(r['X_STEP'])*rlks)
        except:
            Geo=0
        
        f = open(outName+'.rsc','w')
        for k in r.keys():
            f.write(k+'    '+r[k]+'\n')
        f.close()


    elif ext == ('.h5'):
  
        h5file=h5py.File(file,'r')
        # outName=file.split('.')[0]+'_a'+str(int(alks))+'lks_r'+str(int(rlks))+'lks.h5'
        h5file_lks=h5py.File(outName,'w')
      
        if 'interferograms' in h5file.keys():
            print 'Filtering the interferograms in space'
            gg = h5file_lks.create_group('interferograms')
            igramList=h5file['interferograms'].keys()
            for igram in igramList:
                print igram
                unwSet = h5file['interferograms'][igram].get(igram)
                unw=unwSet[0:unwSet.shape[0],0:unwSet.shape[1]]
                unw=filter(unw,filtType,par)
                group = gg.create_group(igram)
                dset = group.create_dataset(igram, data=unw, compression='gzip')
                for key, value in h5file['interferograms'][igram].attrs.iteritems():
                    group.attrs[key] = value
    
            dset1=h5file['mask'].get('mask')
            mask=dset1[0:dset1.shape[0],0:dset1.shape[1]]
            group=h5file_lks.create_group('mask')
            dset = group.create_dataset('mask', data=mask, compression='gzip')
    
        elif 'timeseries' in h5file.keys():
            print 'Filtering the time-series'
            group = h5file_lks.create_group('timeseries')
            dateList=h5file['timeseries'].keys()
            for d in dateList:
                print d
                dset1 = h5file['timeseries'].get(d)
                data=dset1[0:dset1.shape[0],0:dset1.shape[1]]
                data=filter(data,filtType,par)
                
                dset = group.create_dataset(d, data=data, compression='gzip')      
      
            for key,value in h5file['timeseries'].attrs.iteritems():
                group.attrs[key] = value
      
      
            try:
                dset1 = h5file['mask'].get('mask')
                Mask = dset1[0:dset1.shape[0],0:dset1.shape[1]]
                # Masklks=multilook(Mask,alks,rlks)
                group=h5file_lks.create_group('mask')
                dset = group.create_dataset('mask', data=Mask, compression='gzip')
            except:
                print 'Filterd file does not include the maske'
    
    
        elif 'temporal_coherence' in h5file.keys() or 'velocity' in h5file.keys() or 'mask' in h5file.keys():
            k=h5file.keys()
            print 'filtering the '+ k[0]
         
            group=h5file_lks.create_group(k[0])    
            dset1 = h5file[k[0]].get(k[0])
            data = dset1[0:dset1.shape[0],0:dset1.shape[1]]
            data = filter(data,filtType,par)
            dset = group.create_dataset(k[0], data=data, compression='gzip')
            for key , value in h5file[k[0]].attrs.iteritems():
                group.attrs[key]=value
    
        h5file.close()
        h5file_lks.close()
        print 'writing >>> '+outName
Beispiel #4
0
def main(argv):

    ########### Check Inputs #############
    try:
        file = sys.argv[1]
        operator = sys.argv[2]
        operand = float(sys.argv[3])
    except:
        usage()
        sys.exit(1)

    if operator in ['+', 'plus', 'add', 'addition']: operator = 'plus'
    elif operator in ['-', 'minus', 'substract', 'substraction']:
        operator = 'minus'
    elif operator in ['*', 'times', 'multiply', 'multiplication']:
        operator = 'multiply'
    elif operator in ['/', 'obelus', 'divide', 'division']:
        operator = 'divide'
    elif operator in ['^', 'exp', 'exponential']:
        operator = 'exp'
    else:
        print 'ERROR: Unrecognized operator: ' + operator
        sys.exit(1)
    print '\n*************** Image Math ******************'
    print 'operation: ' + operator + ' ' + str(operand)

    ext = os.path.splitext(file)[1]
    try:
        outName = sys.argv[4]
    except:
        outName = file.split('.')[0] + '_' + operator + str(operand) + ext

    ########### Read - Calculate - Write  ###########
    ##### PySAR HDF5 files ######
    if ext in ['.h5', '.he5']:
        try:
            h5file = h5py.File(file, 'r')
        except:
            print 'ERROR: can not open file: ' + file
            sys.exit(1)
        k = h5file.keys()
        if 'interferograms' in k: k[0] = 'interferograms'
        elif 'coherence' in k: k[0] = 'coherence'
        elif 'timeseries' in k: k[0] = 'timeseries'
        print 'Input file is ' + k[0]

        h5fileOut = h5py.File(outName, 'w')
        print 'writing >>> ' + outName
        group = h5fileOut.create_group(k[0])

        if k[0] in ('velocity', 'temporal_coherence', 'rmse', 'mask', 'dem'):
            dset = h5file[k[0]].get(k[0])
            data = dset[0:dset.shape[0], 0:dset.shape[1]]

            dataOut = operation(data, operator, operand)

            dset = group.create_dataset(k[0], data=dataOut, compression='gzip')
            for key, value in h5file[k[0]].attrs.iteritems():
                group.attrs[key] = value

        elif k[0] == 'timeseries':
            dateList = h5file[k[0]].keys()
            print 'number of dates: ' + str(len(dateList))
            for date in dateList:
                print date
                dset = h5file[k[0]].get(date)
                data = dset[0:dset.shape[0], 0:dset.shape[1]]

                dataOut = operation(data, operator, operand)

                dset = group.create_dataset(date,
                                            data=dataOut,
                                            compression='gzip')
            for key, value in h5file[k[0]].attrs.iteritems():
                group.attrs[key] = value

        elif k[0] in ['interferograms', 'coherence', 'wrapped']:
            ifgramList = h5file[k[0]].keys()
            print 'number of epochs: ' + str(len(ifgramList))
            for igram in ifgramList:
                print igram
                dset = h5file[k[0]][igram].get(igram)
                data = dset[0:dset.shape[0], 0:dset.shape[1]]

                dataOut = operation(data, operator, operand)

                group2 = group.create_group(igram)
                dset = group2.create_dataset(igram,
                                             data=dataOut,
                                             compression='gzip')
                for key, value in h5file[k[0]][igram].attrs.iteritems():
                    group2.attrs[key] = value

            try:
                mask = h5file['mask'].get('mask')
                gm = h5fileOut.create_group('mask')
                dset = gm.create_dataset('mask', data=mask, compression='gzip')
            except:
                print 'No group for mask found in the file.'

            try:
                Cset = h5file['meanCoherence'].get('meanCoherence')
                gm = h5fileOut.create_group('meanCoherence')
                dset = gm.create_dataset('meanCoherence',
                                         data=Cset,
                                         compression='gzip')
            except:
                print 'No group for meanCoherence found in the file'

        else:
            print 'ERROR: Unrecognized HDF5 file type: ' + k[0]
            sys.exit(1)

        h5file.close()
        h5fileOut.close()

    ##### ROI_PAC files #######
    elif ext in ['.unw', '.cor', '.hgt', '.dem', '.trans']:
        print 'Input file is ' + ext + '\nwriting >>> ' + outName
        if ext in ['.unw', '.cor', '.hgt']:
            a, p, r = readfile.read_float32(file)
            p2 = operation(p, operator, operand)
            writefile.write_float32(p2, outName)
        elif ext == '.dem':
            p, r = readfile.read_real_int16(file)
            p2 = operation(p, operator, operand)
            writefile.write_real_int16(p2, outName)
        elif ext == '.trans':
            a, p, r = readfile.read_float32(file)
            a2 = operation(a, operator, operand)
            p2 = operation(p, operator, operand)
            writefile.write_float32(a2, p2, outName)

        ## Write atrributes file
        f = open(outName + '.rsc', 'w')
        for k in r.keys():
            f.write(k + '    ' + r[k] + '\n')
        f.close()

    else:
        print 'ERROR: Unrecognized file extension: ' + ext
        sys.exit(1)

    print 'Done.'
Beispiel #5
0
def main(argv):

    try:
        opts, args = getopt.getopt(argv, "h:f:t:p:")
    except getopt.GetoptError:
        usage()
        sys.exit(1)

    if opts == []:
        usage()
        sys.exit(1)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt == '-f':
            file = arg
        elif opt == '-t':
            filtType = arg
        elif opt == '-p':
            par = arg

    ext = os.path.splitext(file)[1]
    outName = file.split('.')[0] + '_' + filtType + ext
    try:
        par
    except:
        par = []

    #print '+++++++++++++++++++++++++++'
    print 'Filter type : ' + filtType
    print 'parameters : ' + str(par)
    #print '+++++++++++++++++++++++++++'
    ###############################################
    if ext == '.int' or ext == '.slc':
        a, p, r = readfile.read_complex_float32(file)
        plks = multilook(p, alks, rlks)
        alks = multilook(a, alks, rlks)

        r['FILE_LENGTH'] = str(dlks.shape[0])
        r['WIDTH'] = str(dlks.shape[1])
        r['XMAX'] = str(int(r['WIDTH']) - 1)
        r['YMAX'] = str(int(r['FILE_LENGTH']) - 1)
        try:
            r['Y_STEP'] = str(float(r['Y_STEP']) * alks)
            r['X_STEP'] = str(float(r['X_STEP']) * rlks)
        except:
            Geo = 0

        f = open(outName + '.rsc', 'w')
        for k in r.keys():
            f.write(k + '    ' + r[k] + '\n')
        f.close()

    elif ext == '.unw' or ext == '.cor' or ext == '.hgt':
        a, p, r = readfile.read_float32(file)
        plks = multilook(p, alks, rlks)
        alks = multilook(a, alks, rlks)

        writefile.write_float32(plks, outName)

        r['FILE_LENGTH'] = str(dlks.shape[0])
        r['WIDTH'] = str(dlks.shape[1])
        r['XMAX'] = str(int(r['WIDTH']) - 1)
        r['YMAX'] = str(int(r['FILE_LENGTH']) - 1)

        try:
            r['Y_STEP'] = str(float(r['Y_STEP']) * alks)
            r['X_STEP'] = str(float(r['X_STEP']) * rlks)
        except:
            Geo = 0

        f = open(outName + '.rsc', 'w')
        for k in r.keys():
            f.write(k + '    ' + r[k] + '\n')
        f.close()

    elif ext == ('.dem'):
        d, r = readfile.read_real_int16(file)
        dlks = multilook(d, alks, rlks)

        print 'writing ' + outName
        writefile.write_real_int16(dlks, outName)

        r['FILE_LENGTH'] = str(dlks.shape[0])
        r['WIDTH'] = str(dlks.shape[1])
        r['XMAX'] = str(int(r['WIDTH']) - 1)
        r['YMAX'] = str(int(r['FILE_LENGTH']) - 1)

        try:
            r['Y_STEP'] = str(float(r['Y_STEP']) * alks)
            r['X_STEP'] = str(float(r['X_STEP']) * rlks)
        except:
            Geo = 0

        f = open(outName + '.rsc', 'w')
        for k in r.keys():
            f.write(k + '    ' + r[k] + '\n')
        f.close()

    elif ext in ['.jpeg', 'jpg', 'png']:
        im = Image.open(file)

        width = im.size[0] / int(rlks)
        height = im.size[1] / int(alks)

        imlks = im.resize((width, height), Image.NEAREST)
        print 'writing ' + outName
        imlks.save(outName)

        try:
            r = readfile.read_roipac_rsc(file + '.rsc')
        except:
            sys.exit(1)

        r['FILE_LENGTH'] = str(height)
        r['WIDTH'] = str(width)
        r['XMAX'] = str(int(r['WIDTH']) - 1)
        r['YMAX'] = str(int(r['FILE_LENGTH']) - 1)
        try:
            r['Y_STEP'] = str(float(r['Y_STEP']) * alks)
            r['X_STEP'] = str(float(r['X_STEP']) * rlks)
        except:
            Geo = 0

        f = open(outName + '.rsc', 'w')
        for k in r.keys():
            f.write(k + '    ' + r[k] + '\n')
        f.close()

    elif ext == ('.h5'):

        h5file = h5py.File(file, 'r')
        # outName=file.split('.')[0]+'_a'+str(int(alks))+'lks_r'+str(int(rlks))+'lks.h5'
        h5file_lks = h5py.File(outName, 'w')

        if 'interferograms' in h5file.keys():
            print 'Filtering the interferograms in space'
            gg = h5file_lks.create_group('interferograms')
            igramList = h5file['interferograms'].keys()
            for igram in igramList:
                print igram
                unwSet = h5file['interferograms'][igram].get(igram)
                unw = unwSet[0:unwSet.shape[0], 0:unwSet.shape[1]]
                unw = filter(unw, filtType, par)
                group = gg.create_group(igram)
                dset = group.create_dataset(igram,
                                            data=unw,
                                            compression='gzip')
                for key, value in h5file['interferograms'][
                        igram].attrs.iteritems():
                    group.attrs[key] = value

            dset1 = h5file['mask'].get('mask')
            mask = dset1[0:dset1.shape[0], 0:dset1.shape[1]]
            group = h5file_lks.create_group('mask')
            dset = group.create_dataset('mask', data=mask, compression='gzip')

        elif 'timeseries' in h5file.keys():
            print 'Filtering the time-series'
            group = h5file_lks.create_group('timeseries')
            dateList = h5file['timeseries'].keys()
            for d in dateList:
                print d
                dset1 = h5file['timeseries'].get(d)
                data = dset1[0:dset1.shape[0], 0:dset1.shape[1]]
                data = filter(data, filtType, par)

                dset = group.create_dataset(d, data=data, compression='gzip')

            for key, value in h5file['timeseries'].attrs.iteritems():
                group.attrs[key] = value

            try:
                dset1 = h5file['mask'].get('mask')
                Mask = dset1[0:dset1.shape[0], 0:dset1.shape[1]]
                # Masklks=multilook(Mask,alks,rlks)
                group = h5file_lks.create_group('mask')
                dset = group.create_dataset('mask',
                                            data=Mask,
                                            compression='gzip')
            except:
                print 'Filterd file does not include the maske'

        elif 'temporal_coherence' in h5file.keys(
        ) or 'velocity' in h5file.keys() or 'mask' in h5file.keys():
            k = h5file.keys()
            print 'filtering the ' + k[0]

            group = h5file_lks.create_group(k[0])
            dset1 = h5file[k[0]].get(k[0])
            data = dset1[0:dset1.shape[0], 0:dset1.shape[1]]
            data = filter(data, filtType, par)
            dset = group.create_dataset(k[0], data=data, compression='gzip')
            for key, value in h5file[k[0]].attrs.iteritems():
                group.attrs[key] = value

        h5file.close()
        h5file_lks.close()
        print 'writing >>> ' + outName
Beispiel #6
0
def main(argv):

    ########### Check Inputs #############
    try:
        file     = sys.argv[1]
        operator = sys.argv[2]
        operand  = float(sys.argv[3])
    except:
        Usage();sys.exit(1)
  
    if   operator in ['+','plus',  'add',      'addition']:        operator = 'plus'
    elif operator in ['-','minus', 'substract','substraction']:    operator = 'minus'
    elif operator in ['*','times', 'multiply', 'multiplication']:  operator = 'multiply'
    elif operator in ['/','obelus','divide',   'division']:        operator = 'divide'
    elif operator in ['^','exp',   'exponential']:                 operator = 'exp'
    else:  print 'ERROR: Unrecognized operator: '+operator;  sys.exit(1)
    print '\n*************** Image Math ******************'
    print 'operation: '+operator+' '+str(operand)
  
    ext = os.path.splitext(file)[1]
    try:    outName = sys.argv[4]
    except: outName = file.split('.')[0]+'_'+operator+str(operand)+ext

    ########### Read - Calculate - Write  ###########
    ##### PySAR HDF5 files ######
    if ext == '.h5':
        import h5py
        try: h5file=h5py.File(file,'r')
        except: print 'ERROR: can not open file: '+file; sys.exit(1)
        k=h5file.keys()
        if 'interferograms' in k: k[0] = 'interferograms'
        elif 'coherence'    in k: k[0] = 'coherence'
        elif 'timeseries'   in k: k[0] = 'timeseries'
        print 'Input file is '+k[0]
      
        h5fileOut = h5py.File(outName,'w'); print 'writing >>> '+outName
        group = h5fileOut.create_group(k[0])
   
        if k[0] in ('velocity','temporal_coherence','rmse','mask','dem'):
            dset = h5file[k[0]].get(k[0])
            data = dset[0:dset.shape[0],0:dset.shape[1]]
       
            dataOut = operation(data,operator,operand)
       
            dset = group.create_dataset(k[0], data=dataOut, compression='gzip')
            for key , value in h5file[k[0]].attrs.iteritems():
                group.attrs[key]=value
   
        elif k[0] == 'timeseries':
            dateList = h5file[k[0]].keys();  print 'number of dates: '+str(len(dateList))
            for date in dateList:
                print date
                dset = h5file[k[0]].get(date)
                data = dset[0:dset.shape[0],0:dset.shape[1]]
       
                dataOut = operation(data,operator,operand)
       
                dset = group.create_dataset(date, data=dataOut, compression='gzip')
            for key,value in h5file[k[0]].attrs.iteritems():
                group.attrs[key] = value
   
        elif k[0] in ['interferograms','coherence','wrapped']:
            ifgramList = h5file[k[0]].keys();  print 'number of epochs: '+str(len(ifgramList))
            for igram in ifgramList:
                print igram
                dset = h5file[k[0]][igram].get(igram)
                data = dset[0:dset.shape[0],0:dset.shape[1]]
        
                dataOut = operation(data,operator,operand)
        
                group2 = group.create_group(igram)
                dset = group2.create_dataset(igram, data=dataOut, compression='gzip')
                for key, value in h5file[k[0]][igram].attrs.iteritems():
                    group2.attrs[key] = value
       
            try:
                mask = h5file['mask'].get('mask')
                gm = h5fileOut.create_group('mask')
                dset = gm.create_dataset('mask', data=mask, compression='gzip')
            except:  print 'No group for mask found in the file.'
       
            try:
                Cset = h5file['meanCoherence'].get('meanCoherence')
                gm = h5fileOut.create_group('meanCoherence')
                dset = gm.create_dataset('meanCoherence', data=Cset, compression='gzip')
            except:  print 'No group for meanCoherence found in the file'

        else: print 'ERROR: Unrecognized HDF5 file type: '+k[0]; sys.exit(1)
   
        h5file.close()
        h5fileOut.close()

    ##### ROI_PAC files #######
    elif ext in ['.unw','.cor','.hgt','.dem','.trans']:
        import pysar._readfile as readfile
        import pysar._writefile as writefile
        print 'Input file is '+ext+'\nwriting >>> '+outName
        if ext in ['.unw','.cor','.hgt']:
            a,p,r = readfile.read_float32(file)
            p2 = operation(p,operator,operand)
            writefile.write_float32(p2,outName)
        elif ext == '.dem':
            p,r = readfile.read_real_int16(file)
            p2 = operation(p,operator,operand)
            writefile.write_real_int16(p2,outName)
        elif ext == '.trans':
            a,p,r = readfile.read_float32(file)
            a2 = operation(a,operator,operand)
            p2 = operation(p,operator,operand)
            writefile.write_float32(a2,p2,outName)
   
        ## Write atrributes file
        f = open(outName+'.rsc','w')
        for k in r.keys():    f.write(k+'    '+r[k]+'\n')
        f.close()
  
  
    else: print 'ERROR: Unrecognized file extension: '+ext; sys.exit(1)
  
    print 'Done.'