Search in sources :

Example 1 with TiePointGeoCoding

use of org.esa.snap.core.datamodel.TiePointGeoCoding in project s1tbx by senbox-org.

the class Radarsat2ProductDirectory method addGeoCoding.

@Override
protected void addGeoCoding(final Product product) {
    final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
    final boolean isAscending = absRoot.getAttributeString(AbstractMetadata.PASS).equals("ASCENDING");
    final boolean isAntennaPointingRight = absRoot.getAttributeString(AbstractMetadata.antenna_pointing).equals("right");
    final MetadataElement origProdRoot = AbstractMetadata.getOriginalProductMetadata(product);
    final MetadataElement productElem = origProdRoot.getElement("product");
    final MetadataElement imageAttributes = productElem.getElement("imageAttributes");
    final MetadataElement geographicInformation = imageAttributes.getElement("geographicInformation");
    final MetadataElement geolocationGrid = geographicInformation.getElement("geolocationGrid");
    final MetadataElement[] geoGrid = geolocationGrid.getElements();
    float[] latList = new float[geoGrid.length];
    float[] lngList = new float[geoGrid.length];
    int gridWidth = 0, gridHeight = 0;
    int i = 0;
    for (MetadataElement imageTiePoint : geoGrid) {
        final MetadataElement geodeticCoordinate = imageTiePoint.getElement("geodeticCoordinate");
        final MetadataElement latitude = geodeticCoordinate.getElement("latitude");
        final MetadataElement longitude = geodeticCoordinate.getElement("longitude");
        latList[i] = (float) latitude.getAttributeDouble("latitude", 0);
        lngList[i] = (float) longitude.getAttributeDouble("longitude", 0);
        final MetadataElement imageCoordinate = imageTiePoint.getElement("imageCoordinate");
        final double pix = imageCoordinate.getAttributeDouble("pixel", 0);
        if (pix == 0) {
            if (gridWidth == 0)
                gridWidth = i;
            ++gridHeight;
        }
        ++i;
    }
    if (flipToSARGeometry) {
        float[] flippedLatList = new float[geoGrid.length];
        float[] flippedLonList = new float[geoGrid.length];
        int is, id;
        if (isAscending) {
            if (isAntennaPointingRight) {
                // flip upside down
                for (int r = 0; r < gridHeight; r++) {
                    is = r * gridWidth;
                    id = (gridHeight - r - 1) * gridWidth;
                    for (int c = 0; c < gridWidth; c++) {
                        flippedLatList[id + c] = latList[is + c];
                        flippedLonList[id + c] = lngList[is + c];
                    }
                }
            } else {
                // flip upside down then left to right
                for (int r = 0; r < gridHeight; r++) {
                    is = r * gridWidth;
                    id = (gridHeight - r) * gridWidth;
                    for (int c = 0; c < gridWidth; c++) {
                        flippedLatList[id - c - 1] = latList[is + c];
                        flippedLonList[id - c - 1] = lngList[is + c];
                    }
                }
            }
        } else {
            if (isAntennaPointingRight) {
                // flip left to right
                for (int r = 0; r < gridHeight; r++) {
                    is = r * gridWidth;
                    id = r * gridWidth + gridWidth;
                    for (int c = 0; c < gridWidth; c++) {
                        flippedLatList[id - c - 1] = latList[is + c];
                        flippedLonList[id - c - 1] = lngList[is + c];
                    }
                }
            } else {
                // no flipping is needed
                flippedLatList = latList;
                flippedLonList = lngList;
            }
        }
        latList = flippedLatList;
        lngList = flippedLonList;
    }
    double subSamplingX = (double) (product.getSceneRasterWidth() - 1) / (gridWidth - 1);
    double subSamplingY = (double) (product.getSceneRasterHeight() - 1) / (gridHeight - 1);
    final TiePointGrid latGrid = new TiePointGrid(OperatorUtils.TPG_LATITUDE, gridWidth, gridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, latList);
    latGrid.setUnit(Unit.DEGREES);
    final TiePointGrid lonGrid = new TiePointGrid(OperatorUtils.TPG_LONGITUDE, gridWidth, gridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, lngList, TiePointGrid.DISCONT_AT_180);
    lonGrid.setUnit(Unit.DEGREES);
    final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid);
    if (product.getTiePointGrid(OperatorUtils.TPG_LATITUDE) == null) {
        product.addTiePointGrid(latGrid);
        product.addTiePointGrid(lonGrid);
    }
    setLatLongMetadata(product, latGrid, lonGrid);
    if (product.getSceneGeoCoding() == null) {
        product.setSceneGeoCoding(tpGeoCoding);
    }
}
Also used : TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding) TiePointGrid(org.esa.snap.core.datamodel.TiePointGrid) MetadataElement(org.esa.snap.core.datamodel.MetadataElement)

Example 2 with TiePointGeoCoding

use of org.esa.snap.core.datamodel.TiePointGeoCoding in project s1tbx by senbox-org.

the class Sentinel1Level1Directory method addGeoCoding.

@Override
protected void addGeoCoding(final Product product) {
    TiePointGrid latGrid = product.getTiePointGrid(OperatorUtils.TPG_LATITUDE);
    TiePointGrid lonGrid = product.getTiePointGrid(OperatorUtils.TPG_LONGITUDE);
    if (latGrid != null && lonGrid != null) {
        setLatLongMetadata(product, latGrid, lonGrid);
        final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid);
        product.setSceneGeoCoding(tpGeoCoding);
        return;
    }
    final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
    final String acquisitionMode = absRoot.getAttributeString(AbstractMetadata.ACQUISITION_MODE);
    int numOfSubSwath;
    switch(acquisitionMode) {
        case "IW":
            numOfSubSwath = 3;
            break;
        case "EW":
            numOfSubSwath = 5;
            break;
        default:
            numOfSubSwath = 1;
    }
    String[] bandNames = product.getBandNames();
    Band firstSWBand = null, lastSWBand = null;
    boolean firstSWBandFound = false, lastSWBandFound = false;
    for (String bandName : bandNames) {
        if (!firstSWBandFound && bandName.contains(acquisitionMode + 1)) {
            firstSWBand = product.getBand(bandName);
            firstSWBandFound = true;
        }
        if (!lastSWBandFound && bandName.contains(acquisitionMode + numOfSubSwath)) {
            lastSWBand = product.getBand(bandName);
            lastSWBandFound = true;
        }
    }
    if (firstSWBand != null && lastSWBand != null) {
        final GeoCoding firstSWBandGeoCoding = bandGeocodingMap.get(firstSWBand);
        final int firstSWBandHeight = firstSWBand.getRasterHeight();
        final GeoCoding lastSWBandGeoCoding = bandGeocodingMap.get(lastSWBand);
        final int lastSWBandWidth = lastSWBand.getRasterWidth();
        final int lastSWBandHeight = lastSWBand.getRasterHeight();
        final PixelPos ulPix = new PixelPos(0, 0);
        final PixelPos llPix = new PixelPos(0, firstSWBandHeight - 1);
        final GeoPos ulGeo = new GeoPos();
        final GeoPos llGeo = new GeoPos();
        firstSWBandGeoCoding.getGeoPos(ulPix, ulGeo);
        firstSWBandGeoCoding.getGeoPos(llPix, llGeo);
        final PixelPos urPix = new PixelPos(lastSWBandWidth - 1, 0);
        final PixelPos lrPix = new PixelPos(lastSWBandWidth - 1, lastSWBandHeight - 1);
        final GeoPos urGeo = new GeoPos();
        final GeoPos lrGeo = new GeoPos();
        lastSWBandGeoCoding.getGeoPos(urPix, urGeo);
        lastSWBandGeoCoding.getGeoPos(lrPix, lrGeo);
        final float[] latCorners = { (float) ulGeo.getLat(), (float) urGeo.getLat(), (float) llGeo.getLat(), (float) lrGeo.getLat() };
        final float[] lonCorners = { (float) ulGeo.getLon(), (float) urGeo.getLon(), (float) llGeo.getLon(), (float) lrGeo.getLon() };
        ReaderUtils.addGeoCoding(product, latCorners, lonCorners);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_near_lat, ulGeo.getLat());
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_near_long, ulGeo.getLon());
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_far_lat, urGeo.getLat());
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_far_long, urGeo.getLon());
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_near_lat, llGeo.getLat());
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_near_long, llGeo.getLon());
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_far_lat, lrGeo.getLat());
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_far_long, lrGeo.getLon());
        // add band geocoding
        final Band[] bands = product.getBands();
        for (Band band : bands) {
            band.setGeoCoding(bandGeocodingMap.get(band));
        }
    } else {
        try {
            final String annotFolder = getRootFolder() + "annotation";
            final String[] filenames = listFiles(annotFolder);
            addTiePointGrids(product, null, filenames[0], "");
            latGrid = product.getTiePointGrid(OperatorUtils.TPG_LATITUDE);
            lonGrid = product.getTiePointGrid(OperatorUtils.TPG_LONGITUDE);
            if (latGrid != null && lonGrid != null) {
                setLatLongMetadata(product, latGrid, lonGrid);
                final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid);
                product.setSceneGeoCoding(tpGeoCoding);
            }
        } catch (IOException e) {
            SystemUtils.LOG.severe("Unable to add tpg geocoding " + e.getMessage());
        }
    }
}
Also used : GeoPos(org.esa.snap.core.datamodel.GeoPos) MetadataElement(org.esa.snap.core.datamodel.MetadataElement) Band(org.esa.snap.core.datamodel.Band) TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding) TiePointGrid(org.esa.snap.core.datamodel.TiePointGrid) PixelPos(org.esa.snap.core.datamodel.PixelPos) GeoCoding(org.esa.snap.core.datamodel.GeoCoding) TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding)

Example 3 with TiePointGeoCoding

use of org.esa.snap.core.datamodel.TiePointGeoCoding in project s1tbx by senbox-org.

the class TerraSarXProductDirectory method readGeoRef.

private static void readGeoRef(final Product product, final File georefFile) throws IOException {
    final Document xmlDoc = XMLSupport.LoadXML(georefFile.getAbsolutePath());
    final Element root = xmlDoc.getRootElement();
    final Element geoGrid = root.getChild("geolocationGrid");
    final Element numGridPnt = geoGrid.getChild("numberOfGridPoints");
    final Element numAzimuth = numGridPnt.getChild("azimuth");
    final int numAz = Integer.parseInt(numAzimuth.getValue());
    final Element numRange = numGridPnt.getChild("range");
    final int numRg = Integer.parseInt(numRange.getValue());
    final Element gridReferenceTime = geoGrid.getChild("gridReferenceTime");
    final Element tReferenceTimeUTC = gridReferenceTime.getChild("tReferenceTimeUTC");
    final int size = numAz * numRg;
    final double[] latList = new double[size];
    final double[] lonList = new double[size];
    final double[] incList = new double[size];
    final double[] timeList = new double[size];
    final int[] row = new int[size];
    final int[] col = new int[size];
    // final boolean flip = !isSLC();
    int i = 0;
    int r = numRg - 1;
    int c = 0;
    boolean regridNeeded = false;
    final List<Element> grdPntList = geoGrid.getChildren("gridPoint");
    for (Element pnt : grdPntList) {
        int index = i;
        /*
            if(flip) {
                index = (numRg * c) + r;
                --r;
                if(r < 0) {
                    r = numRg-1;
                    ++c;
                }
            }
            */
        final Element tElem = pnt.getChild("tau");
        timeList[index] = Double.parseDouble(tElem.getValue());
        final Element latElem = pnt.getChild("lat");
        latList[index] = Double.parseDouble(latElem.getValue());
        final Element lonElem = pnt.getChild("lon");
        lonList[index] = Double.parseDouble(lonElem.getValue());
        final Element rowElem = pnt.getChild("row");
        if (rowElem != null) {
            row[index] = Integer.parseInt(rowElem.getValue()) - 1;
            regridNeeded = true;
        }
        final Element colElem = pnt.getChild("col");
        if (colElem != null) {
            col[index] = Integer.parseInt(colElem.getValue()) - 1;
        }
        final Element incElem = pnt.getChild("inc");
        incList[index] = Double.parseDouble(incElem.getValue());
        ++i;
    }
    final int gridWidth = numRg;
    final int gridHeight = numAz;
    final int newGridWidth = gridWidth;
    final int newGridHeight = gridHeight;
    float[] newLatList = new float[newGridWidth * newGridHeight];
    float[] newLonList = new float[newGridWidth * newGridHeight];
    float[] newIncList = new float[newGridWidth * newGridHeight];
    final int sceneRasterWidth = product.getSceneRasterWidth();
    final int sceneRasterHeight = product.getSceneRasterHeight();
    final double subSamplingX = sceneRasterWidth / (double) (newGridWidth - 1);
    final double subSamplingY = sceneRasterHeight / (double) (newGridHeight - 1);
    if (regridNeeded) {
        getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, latList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newLatList);
        getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, lonList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newLonList);
        getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, incList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newIncList);
    } else {
        for (int m = 0; m < newLatList.length; ++m) {
            newLatList[m] = (float) latList[m];
            newLonList[m] = (float) lonList[m];
            newIncList[m] = (float) incList[m];
        }
    }
    final TiePointGrid latGrid = new TiePointGrid(OperatorUtils.TPG_LATITUDE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newLatList);
    latGrid.setUnit(Unit.DEGREES);
    product.addTiePointGrid(latGrid);
    final TiePointGrid lonGrid = new TiePointGrid(OperatorUtils.TPG_LONGITUDE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newLonList, TiePointGrid.DISCONT_AT_180);
    lonGrid.setUnit(Unit.DEGREES);
    product.addTiePointGrid(lonGrid);
    final TiePointGrid incidentAngleGrid = new TiePointGrid(OperatorUtils.TPG_INCIDENT_ANGLE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newIncList);
    incidentAngleGrid.setUnit(Unit.DEGREES);
    product.addTiePointGrid(incidentAngleGrid);
    final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid);
    product.setSceneGeoCoding(tpGeoCoding);
// final TiePointGrid timeGrid = new TiePointGrid("Time", gridWidth, gridHeight, 0, 0,
// subSamplingX, subSamplingY, timeList);
// timeGrid.setUnit(Unit.NANOSECONDS);
// product.addTiePointGrid(timeGrid);
}
Also used : TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding) MetadataElement(org.esa.snap.core.datamodel.MetadataElement) Element(org.jdom2.Element) TiePointGrid(org.esa.snap.core.datamodel.TiePointGrid) Document(org.jdom2.Document)

Example 4 with TiePointGeoCoding

use of org.esa.snap.core.datamodel.TiePointGeoCoding in project s1tbx by senbox-org.

the class NetCDFWriter method writeProductNodesImpl.

/**
 * Writes the in-memory representation of a data product. This method was called by <code>writeProductNodes(product,
 * output)</code> of the AbstractProductWriter.
 *
 * @throws IllegalArgumentException if <code>output</code> type is not one of the supported output sources.
 * @throws java.io.IOException      if an I/O error occurs
 */
@Override
protected void writeProductNodesImpl() throws IOException {
    outputFile = null;
    final File file;
    if (getOutput() instanceof String) {
        file = new File((String) getOutput());
    } else {
        file = (File) getOutput();
    }
    outputFile = FileUtils.ensureExtension(file, NetcdfConstants.NETCDF_FORMAT_FILE_EXTENSIONS[0]);
    deleteOutput();
    final Product product = getSourceProduct();
    netCDFWriteable = NetcdfFileWriter.createNew(outputFile.getAbsolutePath(), true);
    netCDFWriteable.addDimension(NetcdfConstants.LON_VAR_NAMES[0], product.getSceneRasterWidth());
    netCDFWriteable.addDimension(NetcdfConstants.LAT_VAR_NAMES[0], product.getSceneRasterHeight());
    final Group rootGroup = netCDFWriteable.getNetcdfFile().getRootGroup();
    final List<Dimension> latLonList = new ArrayList<>();
    latLonList.add(rootGroup.findDimension(NetcdfConstants.LAT_VAR_NAMES[0]));
    latLonList.add(rootGroup.findDimension(NetcdfConstants.LON_VAR_NAMES[0]));
    netCDFWriteable.addVariable(NetcdfConstants.LAT_VAR_NAMES[0], DataType.FLOAT, latLonList.subList(0, 0));
    netCDFWriteable.addVariableAttribute(NetcdfConstants.LAT_VAR_NAMES[0], "units", "degrees_north (+N/-S)");
    netCDFWriteable.addVariable(NetcdfConstants.LON_VAR_NAMES[0], DataType.FLOAT, latLonList.subList(1, 1));
    netCDFWriteable.addVariableAttribute(NetcdfConstants.LON_VAR_NAMES[0], "units", "degrees_east (+E/-W)");
    for (Band band : product.getBands()) {
        final String name = StringUtils.createValidName(band.getName(), new char[] { '_' }, '_');
        netCDFWriteable.addVariable(name, DataType.DOUBLE, latLonList);
        if (band.getDescription() != null)
            netCDFWriteable.addVariableAttribute(name, "description", band.getDescription());
        if (band.getUnit() != null)
            netCDFWriteable.addVariableAttribute(name, "unit", band.getUnit());
    }
    for (TiePointGrid tpg : product.getTiePointGrids()) {
        final String name = tpg.getName();
        netCDFWriteable.addDimension(name + 'x', tpg.getGridWidth());
        netCDFWriteable.addDimension(name + 'y', tpg.getGridHeight());
        final List<Dimension> nameXYList = new ArrayList<>();
        nameXYList.add(rootGroup.findDimension(name + 'y'));
        nameXYList.add(rootGroup.findDimension(name + 'x'));
        netCDFWriteable.addVariable(name, DataType.FLOAT, nameXYList);
        if (tpg.getDescription() != null)
            netCDFWriteable.addVariableAttribute(name, "description", tpg.getDescription());
        if (tpg.getUnit() != null)
            netCDFWriteable.addVariableAttribute(name, "unit", tpg.getUnit());
    }
    addMetadata(product);
    netCDFWriteable.create();
    final GeoCoding sourceGeoCoding = product.getSceneGeoCoding();
    String latGridName = "latitude";
    String lonGridName = "longitude";
    if (sourceGeoCoding instanceof TiePointGeoCoding) {
        final TiePointGeoCoding geoCoding = (TiePointGeoCoding) sourceGeoCoding;
        latGridName = geoCoding.getLatGrid().getName();
        lonGridName = geoCoding.getLonGrid().getName();
    }
    final float[] latData = getLatData(product, latGridName);
    final float[] lonData = getLonData(product, lonGridName);
    if (latData != null && lonData != null) {
        final Array latNcArray = Array.factory(DataType.FLOAT, new int[] { latData.length }, latData);
        final Array lonNcArray = Array.factory(DataType.FLOAT, new int[] { lonData.length }, lonData);
        try {
            netCDFWriteable.write(NetcdfConstants.LAT_VAR_NAMES[0], latNcArray);
            netCDFWriteable.write(NetcdfConstants.LON_VAR_NAMES[0], lonNcArray);
            for (TiePointGrid tpg : product.getTiePointGrids()) {
                final float[][] tiePointGridData = getTiePointGridData(tpg);
                final int[] tiePointShape = new int[tiePointGridData.length];
                for (int i = 0; i < tiePointGridData.length; ++i) {
                    tiePointShape[i] = tiePointGridData[i].length;
                }
                final Array tpgArray = Array.factory(DataType.FLOAT, tiePointShape, tiePointGridData);
                netCDFWriteable.write(tpg.getName(), tpgArray);
            }
        } catch (InvalidRangeException rangeE) {
            rangeE.printStackTrace();
            throw new RuntimeException(rangeE);
        }
    }
}
Also used : Group(ucar.nc2.Group) InvalidRangeException(ucar.ma2.InvalidRangeException) Product(org.esa.snap.core.datamodel.Product) VirtualBand(org.esa.snap.core.datamodel.VirtualBand) Band(org.esa.snap.core.datamodel.Band) Dimension(ucar.nc2.Dimension) Array(ucar.ma2.Array) TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding) TiePointGrid(org.esa.snap.core.datamodel.TiePointGrid) File(java.io.File) GeoCoding(org.esa.snap.core.datamodel.GeoCoding) TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding)

Example 5 with TiePointGeoCoding

use of org.esa.snap.core.datamodel.TiePointGeoCoding in project s1tbx by senbox-org.

the class AlosPalsarProductDirectory method addTPGGeoCoding.

/**
 * Update target product GEOCoding. A new tie point grid is generated.
 *
 * @param product The product.
 * @param refLat  reference latitude
 * @param refLon  reference longitude
 * @throws IOException The exceptions.
 */
private static void addTPGGeoCoding(final Product product, final double refLat, final double refLon) throws IOException {
    final int gridWidth = 11;
    final int gridHeight = 11;
    final float[] targetLatTiePoints = new float[gridWidth * gridHeight];
    final float[] targetLonTiePoints = new float[gridWidth * gridHeight];
    final int sourceImageWidth = product.getSceneRasterWidth();
    final int sourceImageHeight = product.getSceneRasterHeight();
    final int isubSamplingX = sourceImageWidth / (gridWidth - 1);
    final int isubSamplingY = sourceImageHeight / (gridHeight - 1);
    final double subSamplingX = (double) isubSamplingX;
    final double subSamplingY = (double) isubSamplingY;
    final TiePointGrid slantRangeTime = product.getTiePointGrid(OperatorUtils.TPG_SLANT_RANGE_TIME);
    final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
    final double firstLineUTC = absRoot.getAttributeUTC(AbstractMetadata.first_line_time).getMJD();
    final double lastLineUTC = absRoot.getAttributeUTC(AbstractMetadata.last_line_time).getMJD();
    final double lineTimeInterval = (lastLineUTC - firstLineUTC) / (double) (sourceImageHeight - 1);
    OrbitStateVector[] orbitStateVectors;
    try {
        orbitStateVectors = AbstractMetadata.getOrbitStateVectors(absRoot);
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
    if (!checkStateVectorValidity(orbitStateVectors))
        return;
    final int numVectors = orbitStateVectors.length;
    int startIdx = 0;
    int endIdx = 0;
    final double t1 = Math.min(firstLineUTC, lastLineUTC);
    final double t2 = Math.max(firstLineUTC, lastLineUTC);
    for (int i = 0; i < numVectors; i++) {
        double time = orbitStateVectors[i].time_mjd;
        if (time < t1) {
            startIdx = i;
        }
        if (time < t2) {
            endIdx = i;
        }
    }
    while (endIdx - startIdx + 1 < Math.min(5, numVectors)) {
        startIdx = Math.max(startIdx - 1, 0);
        endIdx = Math.min(endIdx + 1, numVectors - 1);
    }
    final int numVectorsUsed = endIdx - startIdx + 1;
    final double[] timeArray = new double[numVectorsUsed];
    final double[] xPosArray = new double[numVectorsUsed];
    final double[] yPosArray = new double[numVectorsUsed];
    final double[] zPosArray = new double[numVectorsUsed];
    final double[] xVelArray = new double[numVectorsUsed];
    final double[] yVelArray = new double[numVectorsUsed];
    final double[] zVelArray = new double[numVectorsUsed];
    for (int i = startIdx; i <= endIdx; i++) {
        timeArray[i - startIdx] = orbitStateVectors[i].time_mjd;
        // m
        xPosArray[i - startIdx] = orbitStateVectors[i].x_pos;
        // m
        yPosArray[i - startIdx] = orbitStateVectors[i].y_pos;
        // m
        zPosArray[i - startIdx] = orbitStateVectors[i].z_pos;
        // m/s
        xVelArray[i - startIdx] = orbitStateVectors[i].x_vel;
        // m/s
        yVelArray[i - startIdx] = orbitStateVectors[i].y_vel;
        // m/s
        zVelArray[i - startIdx] = orbitStateVectors[i].z_vel;
    }
    // Create new tie point grid
    int k = 0;
    for (int r = 0; r < gridHeight; r++) {
        // get the zero Doppler time for the rth line
        int y;
        y = (r * isubSamplingY);
        // pixel-is-point
        final double curLineUTC = firstLineUTC + y * lineTimeInterval - lineTimeInterval / 2.0;
        // compute the satellite position and velocity for the zero Doppler time using cubic interpolation
        final Orbits.OrbitVector data = getOrbitData(curLineUTC, timeArray, xPosArray, yPosArray, zPosArray, xVelArray, yVelArray, zVelArray);
        for (int c = 0; c < gridWidth; c++) {
            int x;
            x = (c * isubSamplingX);
            // Tie-point grid needs lat/long at top left corner of pixel - public getPixelDouble returns the tie point value
            // corresponding to x+0.5, y+0.5
            // 
            // ns to s;
            final double slrgTime = 0.5 * (slantRangeTime.getPixelFloat(x - 1, y - 1) + slantRangeTime.getPixelFloat(x, y)) / Constants.oneBillion;
            final GeoPos geoPos = computeLatLon(refLat, refLon, slrgTime, data);
            targetLatTiePoints[k] = (float) geoPos.lat;
            targetLonTiePoints[k] = (float) geoPos.lon;
            ++k;
        }
    }
    final TiePointGrid latGrid = new TiePointGrid(OperatorUtils.TPG_LATITUDE, gridWidth, gridHeight, 0.0f, 0.0f, subSamplingX, subSamplingY, targetLatTiePoints);
    final TiePointGrid lonGrid = new TiePointGrid(OperatorUtils.TPG_LONGITUDE, gridWidth, gridHeight, 0.0f, 0.0f, subSamplingX, subSamplingY, targetLonTiePoints, TiePointGrid.DISCONT_AT_180);
    final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid);
    product.addTiePointGrid(latGrid);
    product.addTiePointGrid(lonGrid);
    product.setSceneGeoCoding(tpGeoCoding);
}
Also used : GeoPos(org.esa.snap.core.datamodel.GeoPos) MetadataElement(org.esa.snap.core.datamodel.MetadataElement) Orbits(org.esa.snap.engine_utilities.datamodel.Orbits) IOException(java.io.IOException) IOException(java.io.IOException) IllegalBinaryFormatException(org.esa.s1tbx.io.binary.IllegalBinaryFormatException) TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding) TiePointGrid(org.esa.snap.core.datamodel.TiePointGrid) OrbitStateVector(org.esa.snap.engine_utilities.datamodel.OrbitStateVector)

Aggregations

TiePointGeoCoding (org.esa.snap.core.datamodel.TiePointGeoCoding)11 TiePointGrid (org.esa.snap.core.datamodel.TiePointGrid)11 MetadataElement (org.esa.snap.core.datamodel.MetadataElement)9 GeoPos (org.esa.snap.core.datamodel.GeoPos)4 IOException (java.io.IOException)3 OrbitStateVector (org.esa.snap.engine_utilities.datamodel.OrbitStateVector)3 Orbits (org.esa.snap.engine_utilities.datamodel.Orbits)3 IllegalBinaryFormatException (org.esa.s1tbx.io.binary.IllegalBinaryFormatException)2 Band (org.esa.snap.core.datamodel.Band)2 GeoCoding (org.esa.snap.core.datamodel.GeoCoding)2 Product (org.esa.snap.core.datamodel.Product)2 File (java.io.File)1 PixelPos (org.esa.snap.core.datamodel.PixelPos)1 VirtualBand (org.esa.snap.core.datamodel.VirtualBand)1 Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 Array (ucar.ma2.Array)1 InvalidRangeException (ucar.ma2.InvalidRangeException)1 Dimension (ucar.nc2.Dimension)1 Group (ucar.nc2.Group)1