@Test public void sixthTest_Resampling() throws Exception { logger.trace("Start Resampling [development code]"); processingPath = "/d2/test.processing/unit_tests/etna.volcano/process/crop/01486_21159.cpm/"; dataPath = "rsmp/"; SLCImage master = new SLCImage(); master.parseResFile(new File(processingPath + dataPath + "01486.res")); master.setOriginalWindow(new Window(1, 26292, 1, 4900)); SLCImage slave = new SLCImage(); slave.parseResFile(new File(processingPath + dataPath + "21159.res")); slave.setSlaveMasterOffset(1.38941008e+02, -2.19844746e+00, 1.38856333e+02, -2.39968790e+00, 1.38911145e+02, -2.19893253e+00, 1.38936348e+02, -2.36860850e+00); boolean shiftAziSpectra = true; boolean demAssisted = false; String method = "cc6p"; int polyOrder = 2; int polyCoeffs = PolyUtils.numberOfCoefficients(polyOrder); double[] cpmL = new double[polyCoeffs + 1]; cpmL[0] = -138.60102699999999; cpmL[1] = -0.61342283399999997; cpmL[2] = 0.31677070099999999; cpmL[3] = 0.086886668400000006; cpmL[4] = -0.58635061099999997; cpmL[5] = -0.016647044699999999; double[] cpmP = new double[polyCoeffs + 1]; cpmP[0] = 2.2027052999999999; cpmP[1] = 0.32394611499999998; cpmP[2] = -0.60784787200000001; cpmP[3] = -0.52443622899999998; cpmP[4] = -0.16831470000000001; cpmP[5] = -0.684955745; if (shiftAziSpectra == true) { logger.info("Shifting kernel_L to data fDC"); } final int Npoints = extractNumber(method); logger.debug("Number of kernel points: {}", Npoints); if (MathUtils.isOdd(Npoints)) { logger.error("Resample only even point interpolators, defined number of points: {}", Npoints); throw new IllegalArgumentException(); } final int Npointsd2 = Npoints / 2; final int Npointsd2m1 = Npointsd2 - 1; final double minL = master.getOriginalWindow().linelo; final double maxL = master.getOriginalWindow().linehi; final double minP = master.getOriginalWindow().pixlo; final double maxP = master.getOriginalWindow().pixhi; logger.info("resample: polynomial normalized by factors [AZIMUTH]: {} {} to [-2,2]", minL, maxL); logger.info("resample: polynomial normalized by factors [RANGE]: {} {} to [-2,2]", minP, maxP); final float CHI_az = (float) (slave.getPRF() / slave.getAzimuthBandwidth()); final float CHI_rg = (float) ((slave.getRsr2x() / 2.0) / slave.getRangeBandwidth()); final float CHI = min(CHI_az, CHI_rg); logger.info("Oversampling ratio azimuth (PRF/ABW): {}", CHI_az); logger.info("Oversampling ratio range (RSR/RBW): {}", CHI_rg); logger.info("KNAB/RC kernel uses: oversampling ratio: {}", CHI); if (CHI < 1.1) { logger.warn("Oversampling ratio: {} not optimal for KNAB/RC", CHI); } LUT lut = new LUT(LUT.CC6P, Npoints); lut.constructLUT(); final ComplexDoubleMatrix pntKernelAz = new ComplexDoubleMatrix(lut.getKernel()); final ComplexDoubleMatrix pntKernelRg = new ComplexDoubleMatrix(lut.getKernel()); final DoubleMatrix pntAxis = lut.getAxis(); Window fullOverlap = Coregistration.getOverlap(master, slave, (double) Npointsd2, 0d, 0d); logger.info("Overlap window: " + fullOverlap.linelo + ":" + fullOverlap.linehi + ", " + fullOverlap.pixlo + ":" + fullOverlap.pixhi); Window tileOverlap = fullOverlap; int firstTileLine; int lastTileLine; int firstTilePixel; int lastTilePixel; int line; int pixel; final double normPixLo = normalize2(fullOverlap.pixlo, minP, maxP); final double normPixHi = normalize2(fullOverlap.pixhi, minP, maxP); final double normLinLo = normalize2(fullOverlap.linelo, minL, maxL); final double normLinHi = normalize2(fullOverlap.linehi, minL, maxL); line = (int) tileOverlap.linelo; firstTileLine = (int) ((ceil(min(line + polyval(normalize2(line, minL, maxL), normPixLo, cpmL), line + polyval(normalize2(line, minL, maxL), normPixHi, cpmL)))) - Npoints); final int line2 = (int) (line + tileOverlap.lines() - 1); lastTileLine = (int) ((ceil(min(line2 + polyval(normalize2(line2, minL, maxL), normPixLo, cpmL), line2 + polyval(normalize2(line2, minL, maxL), normPixHi, cpmL)))) + Npoints); pixel = (int) tileOverlap.pixlo; firstTilePixel = (int) ((ceil(min(pixel + polyval(normLinLo, normalize2(pixel, minP, maxP), cpmP), line + polyval(normLinHi, normalize2(pixel, minP, maxP), cpmP)))) - Npoints); int pixel2 = (int) (pixel + tileOverlap.pixels() - 1); lastTilePixel = (int) ((ceil(min(pixel2 + polyval(normLinLo, normalize2(pixel2, minP, maxP), cpmP), pixel2 + polyval(normLinHi, normalize2(pixel2, minP, maxP), cpmP)))) - Npoints); final int FORSURE = 25; firstTileLine -= FORSURE; lastTileLine += FORSURE; firstTilePixel -= FORSURE; lastTilePixel += FORSURE; if (firstTileLine < (int) (slave.getCurrentWindow().linelo)) firstTileLine = (int) slave.getCurrentWindow().linelo; if (lastTileLine > (int) (slave.getCurrentWindow().linehi)) lastTileLine = (int) slave.getCurrentWindow().linehi; if (firstTilePixel < (int) (slave.getCurrentWindow().pixlo)) firstTilePixel = (int) slave.getCurrentWindow().pixlo; if (lastTilePixel > (int) (slave.getCurrentWindow().pixhi)) lastTilePixel = (int) slave.getCurrentWindow().pixhi; Window winSlaveFile = new Window(firstTileLine, lastTileLine, firstTilePixel, lastTilePixel); logger.debug("Reading slave: [" + winSlaveFile.linelo + ":" + winSlaveFile.linehi + ", " + winSlaveFile.pixlo + ":" + winSlaveFile.pixhi + "]"); String fileName = "resample_buffer.cr4"; int nRows = (int) winSlaveFile.lines(); int nCols = (int) winSlaveFile.pixels(); ComplexDoubleMatrix BUFFER = DataReader.readCplxFloatData(processingPath + dataPath + fileName, nRows, nCols, littleEndian); logger.info("Loaded BUFFER size: {} rows, {} cols", nRows, nCols); ComplexDoubleMatrix RESULT = ComplexDoubleMatrix.zeros((int) tileOverlap.lines(), (int) tileOverlap.pixels()); ComplexDoubleMatrix PART = new ComplexDoubleMatrix(Npoints, Npoints); double interpL = 0; double interpP = 0; int pixelCnt = 0; int lineCnt = 0; int percent = 0; int tenpercent = (int)(Math.ceil(tileOverlap.lines() / 10.0)); if (tenpercent == 0) tenpercent = 1000; clock.start(); for (line = (int) tileOverlap.linelo; line <= tileOverlap.linehi; line++) { if (((line - tileOverlap.linelo) % tenpercent) == 0) { logger.info("RESAMPLE: {} %", percent); percent += 10; } for (pixel = (int) tileOverlap.pixlo; pixel <= (int) (tileOverlap.pixhi); pixel++) { if (!demAssisted) { interpL = line + polyval(normalize2(line, minL, maxL), normalize2(pixel, minP, maxP), cpmL); interpP = pixel + polyval(normalize2(line, minL, maxL), normalize2(pixel, minP, maxP), cpmP); } int fl_interpL = (int) (interpL); int fl_interpP = (int) (interpP); int firstL = fl_interpL - Npointsd2m1; int firstP = fl_interpP - Npointsd2m1; double interpLdec = interpL - fl_interpL; double interpPdec = interpP - fl_interpP; int kernelnoL = (int) (interpLdec * LUT.getInterval() + 0.5); int kernelnoP = (int) (interpPdec * LUT.getInterval() + 0.5); ComplexDoubleMatrix kernelL = pntKernelAz.getRow(kernelnoL); final DoubleMatrix pntAxisRow = pntAxis.getRow(kernelnoL); final ComplexDoubleMatrix kernelP = pntKernelRg.getRow(kernelnoP); if (shiftAziSpectra == true) { double tmp = 2.0 * Constants.PI * slave.doppler.pix2fdc(interpP) / slave.getPRF(); for (int i = 0; i < Npoints; ++i) { double t = pntAxisRow.get(i) * tmp; kernelL.put(i, kernelL.get(i).mul(new ComplexDouble(Math.cos(t), (-1) * Math.sin(t)))); } } Window inWin = new Window(firstL - firstTileLine, firstL - firstTileLine + (Npoints - 1), firstP - firstTilePixel, firstP - firstTilePixel + (Npoints - 1)); LinearAlgebraUtils.setdata(PART, BUFFER, inWin); RESULT.put(lineCnt, pixelCnt, LinearAlgebraUtils.matTxmat(PART.mmul(kernelP.transpose()), kernelL.transpose()).get(0, 0)); pixelCnt++; } lineCnt++; pixelCnt = 0; } clock.stop(); logger.info("Resampling time: {} [ms]", clock.getElapsedTime()); }
@Deprecated public static Window getOverlap(final Window master, final Window slave) { Window overlap = new Window(slave); if (master.linelo > overlap.linelo) overlap.linelo = master.linelo; if (master.linehi < overlap.linehi) overlap.linehi = master.linehi; if (master.pixlo > overlap.pixlo) overlap.pixlo = master.pixlo; if (master.pixhi < overlap.pixhi) overlap.pixhi = master.pixhi; return overlap; }
Coregistration implements ICoregistration { @Deprecated public static Window getOverlap(final Window master, final Window slave) { Window overlap = new Window(slave); if (master.linelo > overlap.linelo) overlap.linelo = master.linelo; if (master.linehi < overlap.linehi) overlap.linehi = master.linehi; if (master.pixlo > overlap.pixlo) overlap.pixlo = master.pixlo; if (master.pixhi < overlap.pixhi) overlap.pixhi = master.pixhi; return overlap; } }
Coregistration implements ICoregistration { @Deprecated public static Window getOverlap(final Window master, final Window slave) { Window overlap = new Window(slave); if (master.linelo > overlap.linelo) overlap.linelo = master.linelo; if (master.linehi < overlap.linehi) overlap.linehi = master.linehi; if (master.pixlo > overlap.pixlo) overlap.pixlo = master.pixlo; if (master.pixhi < overlap.pixhi) overlap.pixhi = master.pixhi; return overlap; }  }
Coregistration implements ICoregistration { @Deprecated public static Window getOverlap(final Window master, final Window slave) { Window overlap = new Window(slave); if (master.linelo > overlap.linelo) overlap.linelo = master.linelo; if (master.linehi < overlap.linehi) overlap.linehi = master.linehi; if (master.pixlo > overlap.pixlo) overlap.pixlo = master.pixlo; if (master.pixhi < overlap.pixhi) overlap.pixhi = master.pixhi; return overlap; }  @Override void coarseporbit(Ellipsoid ell, SLCImage master, SLCImage slave, Orbit masterorbit, Orbit slaveorbit, Baseline baseline); @Override void coarsecorrel(Input.CoarseCorr input, SLCImage minfo, SLCImage sinfo); @Override void coarsecorrelfft(Input.CoarseCorr coarsecorrinput, SLCImage minfo, SLCImage sinfo); @Override void mtiming_correl(Input.MasterTiming input, SLCImage minfo, todo_classes.productinfo sinfo); @Override void mtiming_correlfft(Input.MasterTiming input, SLCImage minfo, todo_classes.productinfo sinfo); @Override int[][] distributepoints(float numberofpoints, Window win); @Override void getoffset(DoubleMatrix Result, long offsetLines, long offsetPixels); @Override void getmodeoffset(float[][] Result, long offsetLines, long offsetPixels); @Override void finecoreg(Input.FineCorr fineinput, SLCImage minfo, SLCImage sinfo); @Override double coherencefft(ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, int ovsfactor, int AccL,
                               int AccP, double offsetL, double offsetP); @Override double crosscorrelate(ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask,
                                 int ovsfactor,
                                 int AccL, int AccP,
                                 double offsetL, double offsetP); @Override double coherencespace(final int AccL, final int AccP, final int osfactor,
                                 ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask,
                                 double offsetL, double offsetP); @Override void coregpm(SLCImage master, SLCImage slave, String i_resfile, Input.CoregPM coregpminput,
                        int demassist); @Override DoubleMatrix getofffile(String file, float threshold); @Override void resample(Input.Resample resampleinput,
                         SLCImage master, SLCImage slave,
                         double[] cpmL, double[] cpmP,
                         int demassist); @Override void ms_timing_error(SLCImage master, String i_resfile, Input.RelTiming timinginput,
                                int coarse_orbit_offsetL, int coarse_orbit_offsetP); DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask); void shiftazispectrum(final ComplexDoubleMatrix data, // slcData in space domain
                                 final double prf,
                                 final double rsr2x,
                                 final double[] doppler,   // polynomial fDC
                                 final double shift); @Deprecated static Window getOverlap(final Window master, final Window slave); static Window getOverlap(final SLCImage master, final SLCImage slave, final double[] cpmL, final double[] cpmP); static Window getOverlap(final SLCImage master, final SLCImage slave,
                                    final double Npointsd2, final double timing_L, final double timing_P); }
Coregistration implements ICoregistration { @Deprecated public static Window getOverlap(final Window master, final Window slave) { Window overlap = new Window(slave); if (master.linelo > overlap.linelo) overlap.linelo = master.linelo; if (master.linehi < overlap.linehi) overlap.linehi = master.linehi; if (master.pixlo > overlap.pixlo) overlap.pixlo = master.pixlo; if (master.pixhi < overlap.pixhi) overlap.pixhi = master.pixhi; return overlap; }  @Override void coarseporbit(Ellipsoid ell, SLCImage master, SLCImage slave, Orbit masterorbit, Orbit slaveorbit, Baseline baseline); @Override void coarsecorrel(Input.CoarseCorr input, SLCImage minfo, SLCImage sinfo); @Override void coarsecorrelfft(Input.CoarseCorr coarsecorrinput, SLCImage minfo, SLCImage sinfo); @Override void mtiming_correl(Input.MasterTiming input, SLCImage minfo, todo_classes.productinfo sinfo); @Override void mtiming_correlfft(Input.MasterTiming input, SLCImage minfo, todo_classes.productinfo sinfo); @Override int[][] distributepoints(float numberofpoints, Window win); @Override void getoffset(DoubleMatrix Result, long offsetLines, long offsetPixels); @Override void getmodeoffset(float[][] Result, long offsetLines, long offsetPixels); @Override void finecoreg(Input.FineCorr fineinput, SLCImage minfo, SLCImage sinfo); @Override double coherencefft(ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, int ovsfactor, int AccL,
                               int AccP, double offsetL, double offsetP); @Override double crosscorrelate(ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask,
                                 int ovsfactor,
                                 int AccL, int AccP,
                                 double offsetL, double offsetP); @Override double coherencespace(final int AccL, final int AccP, final int osfactor,
                                 ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask,
                                 double offsetL, double offsetP); @Override void coregpm(SLCImage master, SLCImage slave, String i_resfile, Input.CoregPM coregpminput,
                        int demassist); @Override DoubleMatrix getofffile(String file, float threshold); @Override void resample(Input.Resample resampleinput,
                         SLCImage master, SLCImage slave,
                         double[] cpmL, double[] cpmP,
                         int demassist); @Override void ms_timing_error(SLCImage master, String i_resfile, Input.RelTiming timinginput,
                                int coarse_orbit_offsetL, int coarse_orbit_offsetP); DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask); void shiftazispectrum(final ComplexDoubleMatrix data, // slcData in space domain
                                 final double prf,
                                 final double rsr2x,
                                 final double[] doppler,   // polynomial fDC
                                 final double shift); @Deprecated static Window getOverlap(final Window master, final Window slave); static Window getOverlap(final SLCImage master, final SLCImage slave, final double[] cpmL, final double[] cpmP); static Window getOverlap(final SLCImage master, final SLCImage slave,
                                    final double Npointsd2, final double timing_L, final double timing_P);  }