def test_time_series_unit(self): """ Checks that the code works the same as the calculated example """ imaster = asarray([1, 1, 2, 2, 3, 3, 4, 5]) islave = asarray([2, 4, 3, 4, 5, 6, 6, 6]) timeseries = asarray([0.0, 0.1, 0.6, 0.8, 1.1, 1.3]) phase = asarray([0.5, 4, 2.5, 3.5, 2.5, 3.5, 2.5, 1]) nan_fraction = asarray([0.5, 0.4, 0.2, 0.3, 0.1, 0.3, 0.2, 0.1]) now = date.today() dates = [now + timedelta(days=(t * 365.25)) for t in timeseries] dates.sort() master = [dates[m_num - 1] for m_num in imaster] slave = [dates[s_num - 1] for s_num in islave] self.ifgs = [ SinglePixelIfg(m, s, p, n) for m, s, p, n in zip(master, slave, phase, nan_fraction) ] tsincr, tscum, tsvel = time_series(self.ifgs, params=self.params, vcmt=self.vcmt, mst=None) expected = asarray([[[0.50, 3.0, 4.0, 5.5, 6.5]]]) assert_array_almost_equal(tscum, expected, decimal=2)
def timeseries_calc(ifg_paths, params, vcmt, tiles, preread_ifgs): """ Time series calculation. :param ifg_paths: List of interferogram paths :param params: Parameters dictionary corresponding to config file :param vcmt: vcmt array :param tiles: List of all tiles used during MPI processes :param preread_ifgs: Dictionary containing interferogram characteristics for efficient computing :return xxxx """ process_tiles = mpiops.array_split(tiles) log.info('Calculating time series') output_dir = params[cf.TMPDIR] for t in process_tiles: log.info('Calculating time series for tile {}'.format(t.index)) ifg_parts = [shared.IfgPart(p, t, preread_ifgs) for p in ifg_paths] mst_tile = np.load( os.path.join(output_dir, 'mst_mat_{}.npy'.format(t.index))) res = timeseries.time_series(ifg_parts, params, vcmt, mst_tile) tsincr, tscum, _ = res np.save(file=os.path.join(output_dir, 'tsincr_{}.npy'.format(t.index)), arr=tsincr) np.save(file=os.path.join(output_dir, 'tscuml_{}.npy'.format(t.index)), arr=tscum) mpiops.comm.barrier()
def _timeseries_calc(ifg_paths, params, vcmt, tiles, preread_ifgs): """ MPI wrapper for time series calculation. """ if params[cf.TIME_SERIES_CAL] == 0: log.info('Time Series Calculation not required') return if params[cf.TIME_SERIES_METHOD] == 1: log.info('Calculating time series using Laplacian Smoothing method') elif params[cf.TIME_SERIES_METHOD] == 2: log.info('Calculating time series using SVD method') output_dir = params[cf.TMPDIR] process_tiles = mpiops.array_split(tiles) for t in process_tiles: log.info('Calculating time series for tile {}'.format(t.index)) ifg_parts = [shared.IfgPart(p, t, preread_ifgs) for p in ifg_paths] mst_tile = np.load(os.path.join(output_dir, 'mst_mat_{}.npy'.format(t.index))) res = timeseries.time_series(ifg_parts, params, vcmt, mst_tile) tsincr, tscum, _ = res np.save(file=os.path.join(output_dir, 'tsincr_{}.npy'.format(t.index)), arr=tsincr) np.save(file=os.path.join(output_dir, 'tscuml_{}.npy'.format(t.index)), arr=tscum) mpiops.comm.barrier()
def _calc_svd_time_series(ifg_paths, params, preread_ifgs, tiles): """ Helper function to obtain time series for spatio-temporal filter using SVD method """ # Is there other existing functions that can perform this same job? log.info('Calculating time series via SVD method for ' 'spatio-temporal filter') # copy params temporarily new_params = deepcopy(params) new_params[cf.TIME_SERIES_METHOD] = 2 # use SVD method process_tiles = mpiops.array_split(tiles) output_dir = params[cf.TMPDIR] nvels = None for t in process_tiles: log.info('Calculating time series for tile {} during aps ' 'correction'.format(t.index)) ifg_parts = [shared.IfgPart(p, t, preread_ifgs) for p in ifg_paths] mst_tile = np.load( os.path.join(output_dir, 'mst_mat_{}.npy'.format(t.index))) tsincr = time_series(ifg_parts, new_params, vcmt=None, mst=mst_tile)[0] np.save(file=os.path.join(output_dir, 'tsincr_aps_{}.npy'.format(t.index)), arr=tsincr) nvels = tsincr.shape[2] nvels = mpiops.comm.bcast(nvels, root=0) # need to assemble tsincr from all processes tsincr_g = mpiops.run_once(_assemble_tsincr, ifg_paths, params, preread_ifgs, tiles, nvels) log.info('Finished calculating time series for spatio-temporal filter') return tsincr_g
def calculate_time_series(ifgs, params, vcmt, mst): res = timeseries.time_series(ifgs, params, vcmt, mst) for r in res: if len(r.shape) != 3: raise timeseries.TimeSeriesError tsincr, tscum, tsvel = res return tsincr, tscum, tsvel