Esempio n. 1
0
def get_delay(grib_file, inps):
    """Get delay matrix using PyAPS for one acquisition
    Inputs:
        grib_file - strng, grib file path
        atr       - dict, including the following attributes:
                    dem_file    - string, DEM file path
                    trop_model - string, Weather re-analysis data source
                    delay_type  - string, comb/dry/wet
                    ref_y/x     - string, reference pixel row/col number
                    inc_angle   - np.array, 0/1/2 D
    Output:
        phs - 2D np.array, absolute tropospheric phase delay relative to ref_y/x
    """
    if inps.geocoded:
        aps = pa.PyAPS_geo(grib_file,
                           inps.dem_file,
                           grib=inps.trop_model,
                           verb=True,
                           Del=inps.delay_type)
    else:
        aps = pa.PyAPS_rdr(grib_file,
                           inps.dem_file,
                           grib=inps.trop_model,
                           verb=True,
                           Del=inps.delay_type)
    phs = np.zeros((aps.ny, aps.nx), dtype=np.float32)
    aps.getdelay(phs, inc=0.0)

    # Get relative phase delay in space
    phs -= phs[inps.ref_yx[0], inps.ref_yx[1]]
    phs /= np.cos(inps.inc_angle)  # Project into LOS direction
    phs *= -1  # reverse the sign for consistency between different phase correction steps/methods
    return phs
Esempio n. 2
0
def get_delay(grib_file, atr, inps_dict):
    '''Get delay matrix using PyAPS for one acquisition
    Inputs:
        grib_file - strng, grib file path
        atr       - dict, including the following attributes:
                    dem_file    - string, DEM file path
                    grib_source - string, Weather re-analysis data source
                    delay_type  - string, comb/dry/wet
                    ref_y/x     - string, reference pixel row/col number
                    inc_angle   - np.array, 0/1/2 D
    Output:
        phs - 2D np.array, absolute tropospheric phase delay relative to ref_y/x
    '''
    if 'X_FIRST' in atr.keys():
        aps = pa.PyAPS_geo(grib_file, inps_dict['dem_file'], grib=inps_dict['grib_source'],\
                           verb=True, Del=inps_dict['delay_type'])
    else:
        aps = pa.PyAPS_rdr(grib_file, inps_dict['dem_file'], grib=inps_dict['grib_source'],\
                           verb=True, Del=inps_dict['delay_type'])
    phs = np.zeros((aps.ny, aps.nx), dtype=np.float32)
    aps.getdelay(phs, inc=0.0)

    # Get relative phase delay in space
    yref = int(atr['ref_y'])
    xref = int(atr['ref_x'])
    phs -= phs[yref, xref]

    # project into LOS direction
    phs /= np.cos(inps_dict['inc_angle'])
    
    # reverse the sign for consistency between different phase correction steps/methods
    phs *= -1
    
    return phs
Esempio n. 3
0
def get_delay(grib_file, inps):
    """Get delay matrix using PyAPS for one acquisition
    Inputs:
        grib_file - strng, grib file path
        atr       - dict, including the following attributes:
                    dem_file    - string, DEM file path
                    trop_model - string, Weather re-analysis data source
                    delay_type  - string, comb/dry/wet
                    ref_y/x     - string, reference pixel row/col number
                    inc_angle   - np.array, 0/1/2 D
    Output:
        phs - 2D np.array, absolute tropospheric phase delay relative to ref_y/x
    """
    # initiate pyaps object
    if inps.geocoded:
        aps = pa.PyAPS_geo(grib_file,
                           inps.dem_file,
                           grib=inps.trop_model,
                           demtype=np.float32,
                           demfmt='RMG',
                           verb=False,
                           Del=inps.delay_type)
    else:
        aps = pa.PyAPS_rdr(grib_file,
                           inps.dem_file,
                           grib=inps.trop_model,
                           demtype=np.float32,
                           demfmt='RMG',
                           verb=False,
                           Del=inps.delay_type)

    # estimate delay
    phs = np.zeros((aps.ny, aps.nx), dtype=np.float32)
    if not inps.geocoded and inps.lat_file is not None:
        aps.getgeodelay(phs,
                        lat=inps.lat_file,
                        lon=inps.lon_file,
                        inc=inps.inc_angle_file)
    else:
        aps.getdelay(phs, inc=0.)
        phs /= np.cos(inps.inc_angle * np.pi / 180.)

    # Get relative phase delay in space
    phs -= phs[inps.ref_yx[0], inps.ref_yx[1]]
    phs *= -1  # reverse the sign for consistency between different phase correction steps/methods
    return phs
Esempio n. 4
0
def get_delay(grib_file, atr, inps_dict):
    # Get delay matrix using PyAPS
    if 'X_FIRST' in atr.keys():
        aps = pa.PyAPS_geo(grib_file, inps_dict['dem_file'], grib=inps_dict['grib_source'],\
                           verb=True, Del=inps_dict['delay_type'])
    else:
        aps = pa.PyAPS_rdr(grib_file, inps_dict['dem_file'], grib=inps_dict['grib_source'],\
                           verb=True, Del=inps_dict['delay_type'])
    phs = np.zeros((aps.ny, aps.nx))
    aps.getdelay(phs)

    # Get relative phase delay in space
    yref = int(atr['ref_y'])
    xref = int(atr['ref_x'])
    phs -= phs[yref, xref]

    # project into LOS direction
    phs /= np.cos(inps_dict['incidence_angle'])

    return phs
Esempio n. 5
0
def get_delay(grib_file, atr, inps_dict):
    # Get delay matrix using PyAPS
    if 'X_FIRST' in atr.keys():
        aps = pa.PyAPS_geo(grib_file, inps_dict['dem_file'], grib=inps_dict['grib_source'],\
                           verb=True, Del=inps_dict['delay_type'])
    else:
        aps = pa.PyAPS_rdr(grib_file, inps_dict['dem_file'], grib=inps_dict['grib_source'],\
                           verb=True, Del=inps_dict['delay_type'])
    phs = np.zeros((aps.ny, aps.nx), dtype=np.float32)
    aps.getdelay(phs, inc=0.0)

    # Get relative phase delay in space
    yref = int(atr['ref_y'])
    xref = int(atr['ref_x'])
    phs -= phs[yref, xref]

    # project into LOS direction
    phs /= np.cos(inps_dict['incidence_angle'])

    # reverse the sign for consistency between different phase correction steps/methods
    phs *= -1

    return phs
Esempio n. 6
0
plt.title('With latlon file')
plt.colorbar()

print 'Without Lat Lon files'
aps1.getdelay(phs1,inc=23.0,wvl=0.056)
aps2.getdelay(phs2,inc=23.0,wvl=0.056)

phs = phs2-phs1
plt.subplot(122)
plt.imshow(phs[10:600,10:350])
plt.title('Without latlon file')
plt.colorbar()
plt.show()

print 'Testing ECMWF in Geographic coordinates, with a FLT dem'
aps1 = pa.PyAPS_geo('ECMWF/ERA-Int_20030426_12.grb','Dem_crop.dem',grib='ECMWF')
aps2 = pa.PyAPS_geo('ECMWF/ERA-Int_20040526_12.grb','Dem_crop.dem',grib='ECMWF')

print 'With Lat Lon files'
phs1 = np.zeros((aps1.ny,aps1.nx))
phs2 = np.zeros((aps2.ny,aps2.nx))

aps1.getdelay(phs1,inc=23.0,wvl=0.056)
aps2.getdelay(phs2,inc=23.0,wvl=0.056)

del phs1
del phs2

print 'ECMWF OK'
print '------------------------------------------------'
print '------------------------------------------------'
Esempio n. 7
0
def main(argv):

    DelayType = 'comb'

    try:
        opts, args = getopt.getopt(argv, "f:d:s:h:D:i:")
    except getopt.GetoptError:
        Usage()
        sys.exit(1)

    for opt, arg in opts:
        if opt == '-f': timeSeriesFile = arg
        elif opt == '-d': demFile = arg
        elif opt == '-s': atmSource = arg
        elif opt == '-h': hr = arg
        elif opt == '-D': DelayType = arg
        elif opt == '-i': inc_angle = arg

    try:
        timeSeriesFile
        demFile
    except:
        Usage()
        sys.exit(1)

    demFile = ut.check_variable_name(demFile)
    demCoord = ut.radar_or_geo(demFile)

    h5timeseries = h5py.File(timeSeriesFile)
    yref = h5timeseries['timeseries'].attrs['ref_y']
    xref = h5timeseries['timeseries'].attrs['ref_x']

    ###############################################################
    #incidence angle to map the zenith delay to the slant delay

    try:
        inc_angle
    except:
        print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
        print 'WARNING:'
        print 'incedence angle is not specified >>>> Average look angle is used ... '
        print 'For more precise results use input option -i to introduce the incidence angle file or average incodence angle'
        print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
        input_inc_angle = 'None'

        wavelength = float(h5timeseries['timeseries'].attrs['WAVELENGTH'])
        inc_angle1 = float(h5timeseries['timeseries'].attrs['LOOK_REF1'])
        inc_angle2 = float(h5timeseries['timeseries'].attrs['LOOK_REF2'])
        inc_angle = (inc_angle1 + inc_angle2) / 2.0
        print '*******************************************************************************'
        print 'Near Look Angle: ' + str(inc_angle1)
        print 'Far  Look Angle:' + str(inc_angle2)
        print 'Average Look Angle (used in pyaps to calculate delay): ' + str(
            inc_angle)
        print 'Acquisition time is : ' + hr
        print '*******************************************************************************'
        inc_angle = str(inc_angle)

    if os.path.isfile(inc_angle):
        incidenceFile = inc_angle
        h5incidence = h5py.File(incidenceFile, 'r')
        iset = h5incidence['mask'].get('mask')
        inc_angle = iset[0:iset.shape[0], 0:iset.shape[1]]
        h5incidence.close()
    else:
        inc_angle = float(inc_angle)
        print 'incidence angle = ' + str(inc_angle)

    inc_angle = inc_angle * pi / 180.0
    ################################################################

    dateList = h5timeseries['timeseries'].keys()

    if atmSource in ['ecmwf', 'ECMWF']:
        gribSource = 'ECMWF'
        if not os.path.isdir('ECMWF'):
            print 'making directory: ECMWF'
            os.mkdir('ECMWF')

        ecmwf_file = []
        for d in dateList:
            ecm = './ECMWF/ERA-Int_' + d + '_' + hr + '.grb'
            ecmwf_file.append(ecm)
            print[d]
            if not os.path.isfile(ecm):
                pa.ECMWFdload([d], hr, './ECMWF/')
            else:
                print ecm + ' already exists.'

    elif atmSource in ['narr', 'NARR']:
        gribSource = 'NARR'
        if not os.path.isdir('NARR'):
            print 'making directory: NARR'
            os.mkdir('NARR')

        ecmwf_file = []
        for d in dateList:
            ecm = './NARR/narr-a_221_' + d + '_' + hr + '00_000.grb'
            ecmwf_file.append(ecm)
            print[d]
            if not os.path.isfile(ecm):
                pa.NARRdload([d], hr, './NARR/')
            else:
                print ecm + ' already exists.'

    elif atmSource in ['era', 'ERA']:
        gribSource = 'ERA'
        if not os.path.isdir('ERA'):
            print 'making directory: ERA'
            os.mkdir('ERA')

        ecmwf_file = []
        for d in dateList:
            ecm = './ERA/ERA_' + d + '_' + hr + '.grb'
            ecmwf_file.append(ecm)
            print[d]
            if not os.path.isfile(ecm):
                pa.ERAdload([d], hr, './ERA/')
            else:
                print ecm + ' already exists.'

    elif atmSource in ['merra', 'MERRA']:
        gribSource = 'MERRA'
        if not os.path.isdir('MERRA'):
            print 'making directory: MERRA'
            os.mkdir('MERRA')

        ecmwf_file = []
        for d in dateList:
            ecm = './MERRA/merra-' + d + '-' + hr + '.hdf'
            ecmwf_file.append(ecm)
            print[d]
            if not os.path.isfile(ecm):
                pa.MERRAdload([d], hr, './MERRA/')
            else:
                print ecm + ' already exists.'

    else:
        Usage()
        sys.exit(1)

    print '*******************************************************************************'
    print 'Calcualting delay for each epoch.'
    h5phsName = atmSource + '.h5'
    h5phs = h5py.File(h5phsName, 'w')
    outName = timeSeriesFile.replace(
        '.h5', '_') + atmSource + '.h5'  #Yunjun, Feb 15, 2015
    #outName=timeSeriesFile.replace('.h5','')+'_tropCorPyAPS.h5'
    h5apsCor = h5py.File(outName, 'w')
    group = h5apsCor.create_group('timeseries')
    group_phs = h5phs.create_group('timeseries')

    #if 'X_FIRST' in  h5timeseries['timeseries'].attrs.keys():
    #   demCoord='geo'
    #   print 'The coordinate system is : Geo'
    #else:
    #   demCoord='radar'
    #   print 'The coordinate system is : radar'

    print ecmwf_file[0]
    if demCoord == 'radar':
        aps1 = pa.PyAPS_rdr(str(ecmwf_file[0]),
                            demFile,
                            grib=gribSource,
                            verb=True,
                            Del=DelayType)
    else:
        aps1 = pa.PyAPS_geo(str(ecmwf_file[0]),
                            demFile,
                            grib=gribSource,
                            verb=True,
                            Del=DelayType)

    phs1 = zeros((aps1.ny, aps1.nx))
    aps1.getdelay(phs1)
    phs1 = (phs1 - phs1[yref, xref]) / cos(inc_angle)
    dset = group.create_dataset(dateList[0],
                                data=phs1 - phs1,
                                compression='gzip')

    for i in range(1, len(ecmwf_file)):
        ecm = ecmwf_file[i]
        print ecm
        if demCoord == 'radar':
            aps = pa.PyAPS_rdr(str(ecm),
                               demFile,
                               grib=gribSource,
                               verb=True,
                               Del=DelayType)
        else:
            aps = pa.PyAPS_geo(str(ecm),
                               demFile,
                               grib=gribSource,
                               verb=True,
                               Del=DelayType)
        phs = zeros((aps.ny, aps.nx))
        aps.getdelay(phs)
        phs = (phs - phs[yref, xref]) / cos(inc_angle)
        phs = phs - phs1
        dset = group_phs.create_dataset(dateList[i],
                                        data=phs,
                                        compression='gzip')
        dset1 = h5timeseries['timeseries'].get(dateList[i])
        data1 = dset1[0:dset1.shape[0], 0:dset1.shape[1]]
        dset = group.create_dataset(dateList[i],
                                    data=data1 + phs,
                                    compression='gzip')

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

    dset1 = h5timeseries['mask'].get('mask')
    Mask = dset1[0:dset1.shape[0], 0:dset1.shape[1]]
    group = h5apsCor.create_group('mask')
    dset = group.create_dataset('mask', data=Mask, compression='gzip')
Esempio n. 8
0
def download_atmosphereModel(inps):  #EMRE
    S, N, W, E = [val for val in inps.bbox.split()]  #EMRE
    start_year, start_month, start_day = [
        int(val) for val in inps.start_date.split('-')
    ]  #EMRE
    end_year, end_month, end_day = [
        int(val) for val in inps.end_date.split('-')
    ]  #EMRE
    start_date = date(start_year, start_month, start_day)  #EMRE
    end_date = date(end_year, end_month, end_day)  #EMRE
    d1 = start_date
    d2 = end_date

    dateList = []
    #    d1 = datetime.date(2002,1,1)
    #    d2 = datetime.date(2002,2,1)
    diff = d2 - d1
    day_step = 1  #EMRE
    hr = '18'
    for i in range(0, diff.days + 1, day_step):
        dd = (d1 + datetime.timedelta(i)).isoformat()
        dateList.append(dd.replace('-', ''))

#    if atmSource in ['ecmwf','ECMWF']:
    if inps.data_source in ['ecmwf', 'ECMWF']:  #EMRE
        gribSource = 'ECMWF'
        if not os.path.isdir('ECMWF'):
            print 'making directory: ECMWF'
            os.mkdir('ECMWF')

        ecmwf_file = []
        for d in dateList:
            ecm = './ECMWF/ERA-Int_' + d + '_' + hr + '.grb'
            ecmwf_file.append(ecm)
            print[d]
            if not os.path.isfile(ecm):
                pa.ECMWFdload([d], hr, './ECMWF/')
            else:
                print ecm + ' already exists.'

#    elif atmSource in ['narr','NARR']:
    elif inps in ['narr', 'NARR']:  #EMRE
        gribSource = 'NARR'
        if not os.path.isdir('NARR'):
            print 'making directory: NARR'
            os.mkdir('NARR')

        ecmwf_file = []
        for d in dateList:
            ecm = './NARR/narr-a_221_' + d + '_' + hr + '00_000.grb'
            ecmwf_file.append(ecm)
            print[d]
            if not os.path.isfile(ecm):
                pa.NARRdload([d], hr, './NARR/')
            else:
                print ecm + ' already exists.'

#    elif atmSource in ['era','ERA']:
    elif inps in ['era', 'ERA']:
        gribSource = 'ERA'
        if not os.path.isdir('ERA'):
            print 'making directory: ERA'
            os.mkdir('ERA')

        ecmwf_file = []
        for d in dateList:
            ecm = './ERA/ERA_' + d + '_' + hr + '.grb'
            ecmwf_file.append(ecm)
            print[d]
            if not os.path.isfile(ecm):
                pa.ERAdload([d], hr, './ERA/')
            else:
                print ecm + ' already exists.'


#    elif atmSource in ['merra','MERRA']:
    elif inps in ['merra', 'MERRA']:
        gribSource = 'MERRA'
        if not os.path.isdir('MERRA'):
            print 'making directory: MERRA'
            os.mkdir('MERRA')

        ecmwf_file = []
        for d in dateList:
            ecm = './MERRA/merra-' + d + '-' + hr + '.hdf'
            ecmwf_file.append(ecm)
            print[d]
            if not os.path.isfile(ecm):
                pa.MERRAdload([d], hr, './MERRA/')
            else:
                print ecm + ' already exists.'

    else:
        #       Usage();
        print 'FAILED'  #EMRE
        sys.exit(1)

    print '*******************************************************************************'
    print 'Calculating delay for each epoch.'
    h5phs = h5py.File('aps.h5', 'w')
    outName = 'ECMWF.h5'
    #h5apsCor=h5py.File(outName,'w')
    # group=h5apsCor.create_group('timeseries')
    group_phs = h5phs.create_group('timeseries')

    demCoord = 'geo'
    print ecmwf_file[0]
    #demCoord='radar'
    if demCoord == 'radar':
        aps1 = pa.PyAPS_rdr(str(ecmwf_file[0]),
                            demFile,
                            grib=gribSource,
                            verb=True,
                            Del=DelayType)
    else:
        aps1 = pa.PyAPS_geo(str(ecmwf_file[0]),
                            demFile,
                            grib=gribSource,
                            verb=True,
                            Del=DelayType)

    phs1 = np.zeros((aps1.ny, aps1.nx))
    print aps1.ny
    print aps1.nx
    # aps1.getdelay(phs1,inc=inc_angle,wvl=wavelength)
    aps1.getdelay(phs1)
    dset = group_phs.create_dataset(dateList[0], data=phs1, compression='gzip')
    #    phs1=(phs1 - phs1[yref,xref])*wavelength/(4*np.pi)

    # dset = group.create_dataset(dateList[0], data= phs1- phs1, compression='gzip')

    for i in range(1, len(ecmwf_file)):
        ecm = ecmwf_file[i]
        print ecm
        if demCoord == 'radar':
            aps = pa.PyAPS_rdr(str(ecm),
                               demFile,
                               grib=gribSource,
                               verb=True,
                               Del=DelayType)
        else:
            aps = pa.PyAPS_geo(str(ecm),
                               demFile,
                               grib=gribSource,
                               verb=True,
                               Del=DelayType)
        phs = np.zeros((aps.ny, aps.nx))
        #  aps.getdelay(phs,inc=inc_angle,wvl=wavelength)
        aps.getdelay(phs)
        #  phs=(phs - phs[yref,xref])*wavelength/(4*np.pi)
        #  phs=phs-phs1
        dset = group_phs.create_dataset(dateList[i],
                                        data=phs,
                                        compression='gzip')
    #   dset1 = h5timeseries['timeseries'].get(dateList[i])
    #   data1 = dset1[0:dset1.shape[0],0:dset1.shape[1]]
    #   dset = group.create_dataset(dateList[i], data= data1+phs, compression='gzip')

    for key, value in h5timeseries['timeseries'].attrs.iteritems():
        # group.attrs[key] = value
        group_phs.attrs[key] = value
Esempio n. 9
0
aps2.getgeodelay(phs2, inc=23.0, wvl=0.056, lat='lat.flt', lon='lon.flt')

phs = phs2 - phs1
plt.subplot(122)
plt.imshow(phs[10:600, 10:350])
plt.title('MERRA')
plt.colorbar()
plt.show()

print 'Radar Coordinates OK'
print '------------------------------------------------'
print '------------------------------------------------'

print 'Testing ECMWF in GEO geometry, with a FLT dem'
aps1 = pa.PyAPS_geo('ECMWF/ERA-Int_20030426_12.grb',
                    'Dem_crop.dem',
                    grib='ECMWF',
                    verb=True)
aps2 = pa.PyAPS_geo('ECMWF/ERA-Int_20040526_12.grb',
                    'Dem_crop.dem',
                    grib='ECMWF',
                    verb=True)

print 'With Lat Lon files'
phs1 = np.zeros((aps1.ny, aps1.nx))
phs2 = np.zeros((aps2.ny, aps2.nx))

aps1.getdelay(phs1, inc=23.0, wvl=0.056)
aps2.getdelay(phs2, inc=23.0, wvl=0.056)

LLphs = phs2 - phs1
plt.subplot(121)
Esempio n. 10
0
    def estimateDelay(self):
        '''Estimate the delay using PyAPS.'''

        self.outfile = 'corrections_pyAPS_%s'%(self.model)
        print('Processing master delay')
        delay = np.zeros((self.length, self.width), dtype=np.float32)

        ######Processing in radar coordinates
        if not self.geo:
            try:
                atmobj = pyaps.PyAPS_rdr(self.flist[0],self.hgt,grib=self.model,demfmt='HGT')
                atmobj.getgeodelay(delay, lat=self.lat, lon=self.lon, inc=self.inc,wvl=self.wvl) 
            except Exception as e:
                toContext(process,ErrorCodes['Master Delay Estimation Failed'],str(e))
                print(e)
                sys.exit(ErrorCodes['Master Delay Estimation Failed'])
        else:
        #######Processing in geo coordinates
            try:
                atmobj = pyaps.PyAPS_geo(self.flist[0], self.hgt, grib=self.model,demfmt='HGT')
                atmobj.getdelay(delay, inc=self.inc,wvl=sel.wvl)
            except Exception as e:
                toContext(process,ErrorCodes['Master Delay Estimation Failed'],str(e))
                print(e)
                sys.exit(ErrorCodes['Master Delay Estimation Failed'])

        del atmobj
        
        if(np.isnan(np.sum(delay))):
            print("pyAPSCorrect.py estimateDelay: found NaN. Aborting") 
            toContext(process,ErrorCodes['NaN Present'],"pyAPSCorrect.py estimateDelay: found NaN. Aborting")
            sys.exit(ErrorCodes['NaN Present'])

        
        print('Processing slave delay')
        delay_slav = np.zeros((self.length, self.width), dtype=np.float32)
        if not self.geo:
            try:
                atmobj = pyaps.PyAPS_rdr(self.flist[1],self.hgt,grib=self.model,demfmt='HGT')
                atmobj.getgeodelay(delay_slav, lat=self.lat, lon=self.lon, inc=self.inc,wvl=self.wvl)
            except Exception as e:
                print(e)
                toContext(process,ErrorCodes['Slave Delay Estimation Failed'],str(e))
                sys.exit(ErrorCodes['Slave Delay Estimation Failed'])
        else:
            try:
                atmobj = pyaps.PyAPS_geo(self.flist[1], self.hgt,grib=self.model,demfmt='HGT')
                atmobj.getdelay(delay_slav, inc=self.inc,wvl=self.wvl)
            except Exception as e:
                toContext(process,ErrorCodes['Slave Delay Estimation Failed'],str(e))
                print(e)
                sys.exit(ErrorCodes['Slave Delay Estimation Failed'])

        del atmobj

        if(np.isnan(np.sum(delay_slav))):
            print("pyAPSCorrect.py estimateDelay: found NaN. Aborting") 
            toContext(process,ErrorCodes['NaN Present'],"pyAPSCorrect.py estimateDelay: found NaN. Aborting")
            sys.exit(ErrorCodes['NaN'])
        delay -= delay_slav
        del delay_slav

        try:
            #import pdb
            #pdb.set_trace()
            self.insar._insar.correctionsFilename = self.outfile+'.rdr'
            delay.astype(np.float32).tofile(self.insar._insar.correctionsFilename)
            ifImage = IF.createImage()
            accessMode = 'read'
            dataType = 'FLOAT'
            ifImage.initImage(self.insar._insar.correctionsFilename,accessMode,self.width,dataType)
            descr = 'Troposheric corrections'
            ifImage.setImageType('sbi')
            ifImage.addDescription(descr)
            ifImage.renderHdr()
        except Exception as e:
            toContext(process,ErrorCodes['Write Error'],str(e))
            print(e)
            sys.exit(ErrorCodes['Write Error'])
        
        cJ = np.complex64(1.0j)
        delay = np.exp(cJ*(delay))
        try:
            delay.tofile(self.outfile+'.mph')
        except Exception as e:
            toContext(process,ErrorCodes['Write Error'],str(e))
            print(e)
            sys.exit(ErrorCodes['Write Error'])
        #since some time this is the only stage executed dump the pickle
        #if there are other stages they'll be overwritten
        fp = open(self.pickle,'w')
        cp.dump(self.insar,fp)
        fp.close()
        toContext(process,0,'pyAPSCorrections delay created')