Skip to content

Commit

Permalink
swapped orbital fit correction to script 2 as it is causing memory er…
Browse files Browse the repository at this point in the history
…rors with script 1
  • Loading branch information
basaks committed Jul 18, 2016
1 parent 9577087 commit 031c5fc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
38 changes: 1 addition & 37 deletions pyrate/nci/run_pyrate_pypar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import os
from os.path import join
import sys
from collections import namedtuple, Counter
from collections import namedtuple
from operator import itemgetter
import numpy as np
from osgeo import gdal

from pyrate import config as cf
from pyrate import mst
from pyrate import orbital
from pyrate import refpixel
from pyrate import remove_aps_delay as aps
from pyrate import shared
Expand Down Expand Up @@ -118,26 +117,6 @@ def main(params, config_file=sys.argv[1]):
for i in ifgs:
i.close()

parallel.barrier()

orb_fit_calc_mpi(dest_tifs, parallel, params)

parallel.barrier()
output_dir = params[cf.OUT_DIR]
# save phase data and phase_sum used in the reference phase estimation
if rank == MASTER_PROCESS:
phase_sum = 0
for d in dest_tifs:
ifg = shared.Ifg(d)
ifg.open()
ifg.nodata_value = params[cf.NO_DATA_VALUE]
phase_sum += ifg.phase_data
ifg.save_numpy_phase(numpy_file=os.path.join(
output_dir, os.path.basename(d).split('.')[0] + '.npy'))
ifg.close()
comp = np.isnan(phase_sum) # this is the same as in Matlab
comp = np.ravel(comp, order='F') # this is the same as in Matlab
np.save(file=os.path.join(output_dir, 'comp.npy'), arr=comp)
parallel.finalize()


Expand Down Expand Up @@ -187,21 +166,6 @@ def convert_phase_to_numpy(dest_tifs, output_dir, tiles, parallel):
return preread_ifgs


def orb_fit_calc_mpi(ifg_paths, parallel, params):
print 'calculating orbfit correction'
if params[cf.ORBITAL_FIT_METHOD] != 1:
raise cf.ConfigException('For now orbfit method must be 1')

# ifgs = shared.prepare_ifgs_without_phase(ifg_paths, params)
no_ifgs = len(ifg_paths)
process_indices = parallel.calc_indices(no_ifgs)
process_ifgs = [itemgetter(p)(ifg_paths) for p in process_indices]

mlooked = None
# TODO: MPI orbfit method 2
orbital.orbital_correction(process_ifgs, params, mlooked=mlooked)


def ref_pixel_calc_mpi(MPI_myID, ifg_paths, num_processors, parallel, params):
half_patch_size, thresh, grid = refpixel.ref_pixel_setup(ifg_paths, params)

Expand Down
37 changes: 37 additions & 0 deletions pyrate/nci/run_pyrate_pypar_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pyrate.nci.parallel import Parallel
from pyrate.scripts import run_pyrate
from pyrate.scripts.run_pyrate import write_msg
from pyrate import orbital
gdal.SetCacheMax(64)

__author__ = 'sudipta'
Expand All @@ -39,6 +40,26 @@ def main(params, config_file=sys.argv[1]):
refpx, refpy = np.load(ref_pixel_file)
print 'Found reference pixel', refpx, refpy

orb_fit_calc_mpi(dest_tifs, parallel, params)

parallel.barrier()
output_dir = params[cf.OUT_DIR]

# save phase data and phase_sum used in the reference phase estimation
if rank == MASTER_PROCESS:
phase_sum = 0
for d in dest_tifs:
ifg = shared.Ifg(d)
ifg.open()
ifg.nodata_value = params[cf.NO_DATA_VALUE]
phase_sum += ifg.phase_data
ifg.save_numpy_phase(numpy_file=os.path.join(
output_dir, os.path.basename(d).split('.')[0] + '.npy'))
ifg.close()
comp = np.isnan(phase_sum) # this is the same as in Matlab
comp = np.ravel(comp, order='F') # this is the same as in Matlab
np.save(file=os.path.join(output_dir, 'comp.npy'), arr=comp)

parallel.barrier()
# estimate and remove reference phase
ref_phase_estimation_mpi(rank, dest_tifs, parallel, params, refpx, refpy)
Expand Down Expand Up @@ -174,6 +195,22 @@ def maxvar_vcm_mpi(rank, ifg_paths, parallel, params):
return maxvar, vcmt


def orb_fit_calc_mpi(ifg_paths, parallel, params):
print 'calculating orbfit correction'
if params[cf.ORBITAL_FIT_METHOD] != 1:
raise cf.ConfigException('For now orbfit method must be 1')

# ifgs = shared.prepare_ifgs_without_phase(ifg_paths, params)
no_ifgs = len(ifg_paths)
process_indices = parallel.calc_indices(no_ifgs)
process_ifgs = [itemgetter(p)(ifg_paths) for p in process_indices]

mlooked = None
# TODO: MPI orbfit method 2
orbital.orbital_correction(process_ifgs, params, mlooked=mlooked)
print 'finished orbfit calculation for process {}'.format(parallel.rank)


if __name__ == '__main__':
# read in the config file, and params for the simulation
params = run_pyrate.get_ifg_paths()[2]
Expand Down

0 comments on commit 031c5fc

Please sign in to comment.