test_class.file: vortex-api/src/test/java/mil/army/usace/hec/vortex/geo/TransposerTest.java
test_class.identifier: TransposerTest
test_case.body: @Test
      void testTranspose(){
          String inFile = new File(getClass().getResource(
                  "/normalizer/qpe.dss").getFile()).toString();
          String variableName = "///PRECIPITATION/02JAN2017:1200/02JAN2017:1300//";
  
          DataReader reader = DataReader.builder()
                  .path(inFile)
                  .variable(variableName)
                  .build();
  
          List<VortexGrid> grids = reader.getDtos().stream().map(grid -> (VortexGrid)grid).collect(Collectors.toList());
          VortexGrid grid = grids.get(0);
  
          Transposer transposer = Transposer.builder()
                  .grid(grid)
                  .angle(30)
                  .build();
  
          transposer.transpose();
      }
test_case.class_method_signature: TransposerTest.testTranspose()
test_case.full_signature: @Test void testTranspose()
test_case.identifier: testTranspose
test_case.invocations: toString getFile getResource getClass build variable path builder collect map stream getDtos toList get build angle grid builder transpose
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void testTranspose()
focal_class.declarator: grid
focal_class.modifier: private
focal_class.original_string: private VortexGrid grid;
focal_class.type: VortexGrid
focal_class.var_name: grid
focal_class.declarator: angle
focal_class.modifier: private
focal_class.original_string: private double angle;
focal_class.type: double
focal_class.var_name: angle
focal_class.declarator: stormCenterX
focal_class.modifier: private
focal_class.original_string: private Double stormCenterX;
focal_class.type: Double
focal_class.var_name: stormCenterX
focal_class.declarator: stormCenterY
focal_class.modifier: private
focal_class.original_string: private Double stormCenterY;
focal_class.type: Double
focal_class.var_name: stormCenterY
focal_class.declarator: debug
focal_class.modifier: private
focal_class.original_string: private boolean debug;
focal_class.type: boolean
focal_class.var_name: debug
focal_class.declarator: tempDir
focal_class.modifier: private
focal_class.original_string: private Path tempDir;
focal_class.type: Path
focal_class.var_name: tempDir
focal_class.file: vortex-api/src/main/java/mil/army/usace/hec/vortex/geo/Transposer.java
focal_class.identifier: Transposer
focal_class.class_method_signature: Transposer.Transposer(TransposerBuilder builder)
focal_class.full_signature: private  Transposer(TransposerBuilder builder)
focal_class.identifier: Transposer
focal_class.modifiers: private
focal_class.parameters: (TransposerBuilder builder)
focal_class.signature:  Transposer(TransposerBuilder builder)
focal_class.class_method_signature: Transposer.builder()
focal_class.full_signature: public static TransposerBuilder builder()
focal_class.identifier: builder
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: TransposerBuilder
focal_class.signature: TransposerBuilder builder()
focal_class.class_method_signature: Transposer.transpose()
focal_class.full_signature: public VortexGrid transpose()
focal_class.identifier: transpose
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: VortexGrid
focal_class.signature: VortexGrid transpose()
focal_method.body: public VortexGrid transpose(){
          if (angle == 0 && (stormCenterX == null || stormCenterX.isNaN())
                  && (stormCenterY == null || stormCenterY.isNaN())){
              return grid;
          }
  
          VortexGrid sanatized;
          String desc = grid.description().toLowerCase();
          if (desc.contains("precipitation")
                  || desc.contains("precip")
                  || desc.contains("precip") && desc.contains("rate")
                  || desc.contains("qpe01h")
                  || ((desc.contains("short") && desc.contains("wave") || desc.contains("solar"))
                  && desc.contains("radiation"))
                  || ((desc.contains("snow")) && (desc.contains("water")) && (desc.contains("equivalent")))
                  || desc.contains("albedo")) {
  
              sanatized = Sanitizer.builder()
                      .inputGrid(grid)
                      .minimumThreshold(0)
                      .minimumReplacementValue(Float.NaN)
                      .build()
                      .sanitize();
          } else {
              sanatized = grid;
          }
  
          Dataset datasetIn = RasterUtils.getDatasetFromVortexGrid(sanatized);
  
          if (debug) {
              ArrayList<String> options = new ArrayList<>();
              options.add("-of");
              options.add("Gtiff");
              TranslateOptions translateOptions1 = new TranslateOptions(new Vector<>(options));
              Path pathToPreTransposed = Paths.get(tempDir.toString(), "pre-transpose.tif");
              Dataset out = gdal.Translate(pathToPreTransposed.toString(), datasetIn, translateOptions1);
              out.FlushCache();
              out.delete();
          }
  
          double[] geoTransform = datasetIn.GetGeoTransform();
          double dx = geoTransform[1];
          double dy = geoTransform[5];
          double originX = geoTransform[0];
          double originY = geoTransform[3];
          int nx = datasetIn.GetRasterXSize();
          int ny = datasetIn.GetRasterYSize();
          double terminusX = originX + dx * nx;
          double terminusY = originY + dy * ny;
          double width = Math.abs(terminusX - originX);
          double height = Math.abs(terminusY - originY);
          double centerX = originX + Math.signum(dx) * 0.5 * width;
          double centerY = originY + Math.signum(dy) * 0.5 * height;
          double x1 = originX - centerX;
          double y1 = originY - centerY;
  
          Band band = datasetIn.GetRasterBand(1);
          float[] data = new float[nx * ny];
          band.ReadRaster(0, 0, nx, ny, GDT_Float32, data);
          band.delete();
  
          double angleRad = Math.toRadians(angle);
  
          double adjustedCenterX;
          if (stormCenterX != null && !Double.isNaN(stormCenterX)){
              adjustedCenterX = stormCenterX;
          } else {
              adjustedCenterX = centerX;
          }
  
          double adjustedCenterY;
          if (stormCenterY != null && !Double.isNaN(stormCenterY)){
              adjustedCenterY = stormCenterY;
          } else {
              adjustedCenterY = centerY;
          }
  
          double[] transposedGeoTransform = new double[]{
                  adjustedCenterX + Math.signum(dx) * (x1 * Math.cos(angleRad) + y1 * Math.sin(angleRad)),
                  Math.cos(angleRad) * dx,
                  -Math.sin(angleRad) * dx,
                  adjustedCenterY + Math.signum(dy) * (x1 * Math.sin(angleRad) - y1 * Math.cos(angleRad)),
                  Math.sin(angleRad) * dy,
                  Math.cos(angleRad) * dy
          };
  
          Dataset transposed = gdal.GetDriverByName("MEM").Create("", nx, ny, 1, GDT_Float32);
          transposed.SetGeoTransform(transposedGeoTransform);
          transposed.SetProjection(datasetIn.GetProjection());
          Band transposedBand = transposed.GetRasterBand(1);
          transposedBand.WriteRaster(0, 0, nx, ny, data);
          transposedBand.FlushCache();
          transposed.FlushCache();
  
          datasetIn.delete();
  
          if (debug) {
              ArrayList<String> options = new ArrayList<>();
              options.add("-of");
              options.add("Gtiff");
              TranslateOptions translateOptions = new TranslateOptions(new Vector<>(options));
              Path pathToTransposed = Paths.get(tempDir.toString(), "transposed.tif");
              Dataset out = gdal.Translate(pathToTransposed.toString(), transposed, translateOptions);
              out.FlushCache();
              translateOptions.delete();
              out.delete();
          }
  
          ArrayList<String> options = new ArrayList<>();
          options.add("-of");
          options.add("MEM");
          options.add("-r");
          options.add("bilinear");
          WarpOptions warpOptions = new WarpOptions(new Vector<>(options));
          Dataset[] datasets = new Dataset[]{transposed};
          Dataset transposedWarped = gdal.Warp(
                  "",
                  datasets,
                  warpOptions
          );
          transposedWarped.FlushCache();
          warpOptions.delete();
          transposed.delete();
  
          double[] transposedWarpedGeoTransform = transposedWarped.GetGeoTransform();
          double transposedDx = transposedWarpedGeoTransform[1];
          double transposedDy = transposedWarpedGeoTransform[5];
          double transposedOriginX = transposedWarpedGeoTransform[0];
          double transposedOriginY = transposedWarpedGeoTransform[3];
          int transposedNx = transposedWarped.GetRasterXSize();
          int transposedNy = transposedWarped.GetRasterYSize();
          double transposedTerminusX = transposedOriginX + transposedDx * transposedNx;
          double transposedTerminusY = transposedOriginY + transposedDy * transposedNy;
  
          //Specify resampling parameters
          double cellSize = grid.dx();
          double maxX = Math.ceil(Math.max(transposedOriginX, transposedTerminusX) / cellSize) * cellSize;
          double minX = Math.floor(Math.min(transposedOriginX, transposedTerminusX) / cellSize) * cellSize;
          double maxY = Math.ceil(Math.max(transposedOriginY, transposedTerminusY) / cellSize) * cellSize;
          double minY = Math.floor(Math.min(transposedOriginY, transposedTerminusY) / cellSize) * cellSize;
  
          options.clear();
          options.add("-of");
          options.add("MEM");
          options.add("-te");
          options.add(Double.toString(minX));
          options.add(Double.toString(minY));
          options.add(Double.toString(maxX));
          options.add(Double.toString(maxY));
          options.add("-tr");
          options.add(Double.toString(cellSize));
          options.add(Double.toString(cellSize));
          options.add("-r");
          options.add("bilinear");
          Dataset transposedResampled = gdal.Warp(
                  "",
                  new Dataset[]{transposedWarped},
                  new WarpOptions(new Vector<>(options))
          );
          transposedResampled.FlushCache();
          transposedWarped.delete();
  
          double[] resampledGeoTransform = transposedResampled.GetGeoTransform();
          double resampledDx = resampledGeoTransform[1];
          double resampledDy = resampledGeoTransform[5];
          double resampledOriginX = resampledGeoTransform[0];
          double resampledOriginY = resampledGeoTransform[3];
          int resampledNx = transposedResampled.GetRasterXSize();
          int resampledNy = transposedResampled.GetRasterYSize();
  
          Band resampledBand = transposedResampled.GetRasterBand(1);
          float[] resampledData = new float[resampledNx * resampledNy];
          resampledBand.ReadRaster(0, 0, resampledNx, resampledNy, resampledData);
          transposedResampled.delete();
          resampledBand.delete();
  
          VortexGrid resampledGrid = VortexGrid.builder()
                  .dx(resampledDx).dy(resampledDy)
                  .nx(resampledNx).ny(resampledNy)
                  .originX(resampledOriginX).originY(resampledOriginY)
                  .wkt(grid.wkt()).data(resampledData).units(grid.units())
                  .fileName(grid.fileName()).shortName(grid.shortName())
                  .fullName(grid.shortName()).description(grid.description())
                  .startTime(grid.startTime()).endTime(grid.endTime()).interval(grid.interval())
                  .build();
  
          if (debug) {
              Dataset transposedResampledGrid = RasterUtils.getDatasetFromVortexGrid(resampledGrid);
              options.clear();
              options.add("-of");
              options.add("Gtiff");
              TranslateOptions translateOptions = new TranslateOptions(new Vector<>(options));
              Path pathToTransposedResampled = Paths.get(tempDir.toString(), "transposed-resampled.tif");
              Dataset out = gdal.Translate(pathToTransposedResampled.toString(), transposedResampledGrid, translateOptions);
              out.FlushCache();
              out.delete();
          }
  
          return resampledGrid;
      }
focal_method.class_method_signature: Transposer.transpose()
focal_method.full_signature: public VortexGrid transpose()
focal_method.identifier: transpose
focal_method.invocations: isNaN isNaN toLowerCase description contains contains contains contains contains contains contains contains contains contains contains contains contains sanitize build minimumReplacementValue minimumThreshold inputGrid builder getDatasetFromVortexGrid add add get toString Translate toString FlushCache delete GetGeoTransform GetRasterXSize GetRasterYSize abs abs signum signum GetRasterBand ReadRaster delete toRadians isNaN isNaN signum cos sin cos sin signum sin cos sin cos Create GetDriverByName SetGeoTransform SetProjection GetProjection GetRasterBand WriteRaster FlushCache FlushCache delete add add get toString Translate toString FlushCache delete delete add add add add Warp FlushCache delete delete GetGeoTransform GetRasterXSize GetRasterYSize dx ceil max floor min ceil max floor min clear add add add add toString add toString add toString add toString add add toString add toString add add Warp FlushCache delete GetGeoTransform GetRasterXSize GetRasterYSize GetRasterBand ReadRaster delete delete build interval endTime startTime description fullName shortName fileName units data wkt originY originX ny nx dy dx builder wkt units fileName shortName shortName description startTime endTime interval getDatasetFromVortexGrid clear add add get toString Translate toString FlushCache delete
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.return: VortexGrid
focal_method.signature: VortexGrid transpose()