Пример #1
0
def geo_correction_original(date_pair, params, incidence_angle_or_map):

    dem_file = params[cf.DEM_FILE]
    geotif_dem = os.path.join(
        params[cf.OUT_DIR],
        os.path.basename(dem_file).split('.')[0] + '.tif')

    mlooked_dem = prepifg.mlooked_path(geotif_dem,
                                       looks=params[cf.IFG_LKSX],
                                       crop_out=params[cf.IFG_CROP_OPT])
    # make sure mlooked dem exist
    if not os.path.exists(mlooked_dem):
        raise prepifg.PreprocessError('mlooked dem was not found.'
                                      'Please run prepifg.')

    dem_header = gamma.parse_dem_header(params[cf.DEM_HEADER_FILE])
    lat, lon, nx, ny = return_pyaps_lat_lon(dem_header)
    """ using geo coordinates to remove APS """

    aps1 = pa.PyAPS_geo(os.path.join(ECMWF_DIR,
                                     ECMWF_PRE + date_pair[0] + ECMWF_EXT),
                        mlooked_dem,
                        grib=ECMWF,
                        verb=True,
                        demfmt=GEOTIFF,
                        demtype=np.float32,
                        dem_header=(lon, lat, nx, ny))
    aps2 = pa.PyAPS_geo(os.path.join(ECMWF_DIR,
                                     ECMWF_PRE + date_pair[1] + ECMWF_EXT),
                        mlooked_dem,
                        grib=ECMWF,
                        verb=True,
                        demfmt=GEOTIFF,
                        demtype=np.float32,
                        dem_header=(lon, lat, nx, ny))
    phs1 = np.zeros((aps1.ny, aps1.nx))
    phs2 = np.zeros((aps2.ny, aps2.nx))
    print('Without Lat Lon files')
    aps1.getdelay(phs1, inc=incidence_angle_or_map)
    aps2.getdelay(phs2, inc=incidence_angle_or_map)
    aps_delay = phs2 - phs1  # delay in meters as we don't provide wavelength
    return aps_delay
Пример #2
0
def parallel_aps(data_path, dem, dem_header, incidence_angle, incidence_map,
                 list_of_dates_for_grb_download, mlooked_dem, params):
    if params[cf.PROCESSOR] == 1:  # gamma
        date_pair = [i for i in GAMMA_PTN.findall(os.path.basename(data_path))]
    elif params[cf.PROCESSOR] == 0:  # roipac
        # adding 20 to dates here, so dates before 2000 won't work
        # TODO: fix pre 2000 dates
        date_pair = [
            '20' + i for i in ROIPAC_PTN.findall(os.path.basename(data_path))
        ]
    else:
        raise AttributeError('processor needs to be gamma(1) or roipac(0)')
    list_of_dates_for_grb_download += date_pair
    first_grb = os.path.join(ECMWF_DIR, ECMWF_PRE + date_pair[0] + ECMWF_EXT)
    second_grb = os.path.join(ECMWF_DIR, ECMWF_PRE + date_pair[1] + ECMWF_EXT)
    # download .grb file if does not exist
    if not (os.path.exists(first_grb) and os.path.exists(second_grb)):
        # download weather files at 12:00 UTC (other options 00:00, 06:00, 18:00)
        pa.ecmwf_download(date_pair, '12', 'ECMWF')

    # rdr_correction(date_pair)
    # TODO: lat lon correction when lat and lon files are available
    # aps1.getgeodelay(phs1, inc=23.0, wvl=0.056,
    #   lat=os.path.join(PYAPS_EXAMPLES, 'lat.flt'),
    #   lon=os.path.join(PYAPS_EXAMPLES, 'lon.flt'))
    # aps2.getgeodelay(phs2, inc=23.0, wvl=0.056,
    #   lat=os.path.join(PYAPS_EXAMPLES, 'lat.flt'),
    #   lon=os.path.join(PYAPS_EXAMPLES, 'lon.flt'))
    # LLphs = phs2-phs1
    # print dem_header, mlooked_dem
    if params[cf.APS_METHOD] == 1:
        # no need to calculate incidence angle for all ifgs, they are the same
        if incidence_angle is None:
            incidence_angle = get_incidence_angle(date_pair, params)
        aps_delay = geo_correction(date_pair, dem_header, dem, incidence_angle)
    elif params[cf.APS_METHOD] == 2:
        # no need to calculate incidence map for all ifgs, they are the same
        aps_delay = geo_correction(date_pair, dem_header, dem, incidence_map)
    else:
        raise APSException('APS method must be 1 or 2')
    return aps_delay
Пример #3
0
def geo_correction(date_pair, dem_header, dem, incidence_angle_or_map):
    """ using geo coordinates to remove APS """

    aps1 = pa.PyAPSPyRateGeo(os.path.join(ECMWF_DIR, ECMWF_PRE + date_pair[0] +
                                          ECMWF_EXT),
                             dem_header=dem_header,
                             dem=dem,
                             grib=ECMWF,
                             verb=True)
    aps2 = pa.PyAPSPyRateGeo(os.path.join(ECMWF_DIR, ECMWF_PRE + date_pair[1] +
                                          ECMWF_EXT),
                             dem_header=dem_header,
                             dem=dem,
                             grib=ECMWF,
                             verb=True)
    phs1 = np.zeros((aps1.ny, aps1.nx))
    phs2 = np.zeros((aps2.ny, aps2.nx))
    print('Without Lat Lon files')
    aps1.getdelay_pyrate(phs1, dem, inc=incidence_angle_or_map)
    aps2.getdelay_pyrate(phs2, dem, inc=incidence_angle_or_map)
    aps_delay = phs2 - phs1  # delay in meters as we don't provide wavelength
    return aps_delay
Пример #4
0
def remove_aps_delay_original(ifgs, params):
    list_of_dates_for_grb_download = []

    incidence_angle = None
    incidence_map = None
    for ifg in ifgs:  # demo for only one ifg
        if params[cf.PROCESSOR] == 1:  # gamma
            PTN = re.compile(r'\d{8}')
            date_pair = [
                i for i in PTN.findall(os.path.basename(ifg.data_path))
            ]
        elif params[cf.PROCESSOR] == 0:  # roipac
            # adding 20 to dates here, so dates before 2000 won't work
            # TODO: fix pre 2000 dates
            PTN = re.compile(r'\d{6}')
            date_pair = [
                '20' + i for i in PTN.findall(os.path.basename(ifg.data_path))
            ]
        else:
            raise AttributeError('processor needs to be gamma(1) or roipac(0)')

        list_of_dates_for_grb_download += date_pair

        first_grb = os.path.join(ECMWF_DIR,
                                 ECMWF_PRE + date_pair[0] + ECMWF_EXT)
        second_grb = os.path.join(ECMWF_DIR,
                                  ECMWF_PRE + date_pair[1] + ECMWF_EXT)

        # download .grb file if does not exist
        if not (os.path.exists(first_grb) and os.path.exists(second_grb)):
            # download weather files at 12:00 UTC (other options 00:00, 06:00, 18:00)
            pa.ecmwf_download(date_pair, '12', 'ECMWF')

        def get_incidence_map():
            """
            :param incidence_map:
            :param params:
            :param inc_or_ele: 1 when incidence map, 0 when elevation map
            :return:
            """
            if params[cf.APS_ELEVATION_MAP] is not None:
                f, e = os.path.basename(
                    params[cf.APS_ELEVATION_MAP]).split('.')
            else:
                f, e = os.path.basename(
                    params[cf.APS_INCIDENCE_MAP]).split('.')
            multilooked = os.path.join(
                params[cf.OUT_DIR],
                f + '_' + e + '_{looks}rlks_{crop}cr.tif'.format(
                    looks=params[cf.IFG_LKSX], crop=params[cf.IFG_CROP_OPT]))
            assert os.path.exists(multilooked), \
                'cropped and multilooked incidence map file not found. ' \
                'Use apsmethod=1, Or run prepifg with gamma processor'
            ds = gdal.Open(multilooked, gdalconst.GA_ReadOnly)
            if params[cf.APS_INCIDENCE_MAP] is not None:
                incidence_map = ds.ReadAsArray()
            else:
                incidence_map = 90 - ds.ReadAsArray()
            ds = None  # close file
            return incidence_map

        if params[cf.APS_METHOD] == 1:
            # no need to calculate incidence angle for all ifgs, they are the same
            if incidence_angle is None:
                incidence_angle = get_incidence_angle(date_pair, params)
            aps_delay = geo_correction(date_pair, params, incidence_angle)
        elif params[cf.APS_METHOD] == 2:
            # no need to calculate incidence map for all ifgs, they are the same
            if incidence_map is None:
                if params[cf.APS_INCIDENCE_MAP] is not None:
                    incidence_map = get_incidence_map()
                else:  # elevation map was provided
                    assert params[cf.APS_ELEVATION_MAP] is not None
                    incidence_map = get_incidence_map()
            aps_delay = geo_correction_original(date_pair, params,
                                                incidence_map)
        else:
            raise APSException('APS method must be 1 or 2')

        ifg.phase_data -= aps_delay  # remove delay
        # add it to the meta_data dict
        ifg.meta_data[ifc.PYRATE_APS_ERROR] = APS_STATUS
        # write meta_data to file
        ifg.dataset.SetMetadataItem(ifc.PYRATE_APS_ERROR, APS_STATUS)

        ifg.write_modified_phase()
Пример #5
0
    sys.exit(1)

#outfile
oname = sys.argv[3]

#Wavelength, conversion cm to m
wvl = float(sys.argv[4])/100.0

#Incidence angle, conversion deg to rad
inc = float(sys.argv[5])*math.pi/180.0

#--------------------------------------------------------
# Initialize Constants 
#--------------------------------------------------------
# Reading atmo constants dictionary
cdic = PyAPS.initconst()
cdic['wvl'] = wvl
cdic['inc'] = inc

#Values for interpolation
minAlt = cdic['minAlt']
maxAlt = cdic['maxAlt']
nhgt = cdic['nhgt']
minAltp = cdic['minAltP']
hgt = np.linspace(minAlt, maxAlt, nhgt)

# Scaling for interpolation
# For rdr geom grid is about 200*200 pixels
# nght gives the spacing
#hgtscale = 0.5 for nhgt=151
hgtscale = ((maxAlt-minAlt)/nhgt)/200
Пример #6
0
############################################################
# Program is part of PyAPS                                 #
# Copyright 2012, by the California Institute of Technology#
# Contact: [email protected]                        #
# Modified by A. Benoit and R. Jolivet 2019                #
# Ecole Normale Superieure, Paris                          #
# Contact: [email protected]                           #
############################################################
'''Script to automatically download weather model data corresponding to our interferograms.'''

import PyAPS
import tsinsar as ts
import datetime as dt

dates,sat,bperp = ts.load_list('ifg.list')
days,usat,Jmat = ts.ConnectMatrix(dates,sat)


daylist = []
for k in days:
	dobj = dt.date.fromordinal(int(k))
	strobj = '%4d%02d%02d'%(dobj.year,dobj.month,dobj.day)
	daylist.append(strobj)

PyAPS.ECMWFdload(daylist,'18','./Atmos/ECMWF/')

#PyAPS.NARRdload(daylist,'18','./Atmos/NARR/')
#PyAPS.ERAdload(daylist,'18','./Atmos/ERA')
Пример #7
0
'''Script to automatically download weather model data corresponding to our interferograms.'''

import PyAPS
import tsinsar as ts
import datetime as dt

dates, sat, bperp = ts.load_list('ifg.list')
days, usat, Jmat = ts.ConnectMatrix(dates, sat)

daylist = []
for k in days:
    dobj = dt.date.fromordinal(int(k))
    strobj = '%4d%02d%02d' % (dobj.year, dobj.month, dobj.day)
    daylist.append(strobj)

#PyAPS.ECMWFdload(daylist,'18','./Atmos/ECMWF/')

#PyAPS.NARRdload(daylist,'18','./Atmos/NARR/')
PyAPS.ERAdload(daylist, '18', './Atmos/ERA')

############################################################
# Program is part of PyAPS                                 #
# Copyright 2012, by the California Institute of Technology#
# Contact: [email protected]                        #
############################################################
Пример #8
0
if not os.path.isfile(dname):
    print 'DEM File not found: ', dname
    sys.exit(1)

if not os.path.isfile(dname+'.rsc'):
    print 'DEM RSC File not found: ', dname
    sys.exit(1)

oname = sys.argv[3]
wvl = float(sys.argv[4])/100.0          #Conversion from cm to meters
inc = float(sys.argv[5])*math.pi/180.0	#Conversion to radians
####################Completed parsing inputs


#####Reading DEM.rsc file ############################
[lon, lat, nx, ny, bufspc] = PyAPS.geo_rsc(dname)

##############Completed reading DEM.rsc file##############
cdict=PyAPS.initconst()
cdict['wvl'] = wvl
cdict['inc'] = inc

plotflag = 'n'
hgt = np.linspace(cdict['minAlt'], cdict['maxAlt'], cdict['nhgt']) #Heights for interpolation

# Scaling for interpolation
# For geo geom grid is about 0.703*0.703 
# nght gives the spacing
#hgtscale = 142.25 for nhgt=151
hgtscale=((cdict['maxAlt']-cdict['minAlt'])/cdict['nhgt'])/0.703