use of org.esa.s1tbx.commons.OrbitStateVectors in project s1tbx by senbox-org.
the class DEMAssistedCoregistrationOp method getProductMetadata.
private static void getProductMetadata(final Product sourceProduct, final Metadata metadata) throws Exception {
metadata.product = sourceProduct;
metadata.sourceImageWidth = sourceProduct.getSceneRasterWidth();
metadata.sourceImageHeight = sourceProduct.getSceneRasterHeight();
metadata.absRoot = AbstractMetadata.getAbstractedMetadata(sourceProduct);
metadata.srgrFlag = AbstractMetadata.getAttributeBoolean(metadata.absRoot, AbstractMetadata.srgr_flag);
metadata.wavelength = SARUtils.getRadarWavelength(metadata.absRoot);
metadata.rangeSpacing = AbstractMetadata.getAttributeDouble(metadata.absRoot, AbstractMetadata.range_spacing);
metadata.azimuthSpacing = AbstractMetadata.getAttributeDouble(metadata.absRoot, AbstractMetadata.azimuth_spacing);
metadata.firstLineTime = AbstractMetadata.parseUTC(metadata.absRoot.getAttributeString(AbstractMetadata.first_line_time)).getMJD();
metadata.lastLineTime = AbstractMetadata.parseUTC(metadata.absRoot.getAttributeString(AbstractMetadata.last_line_time)).getMJD();
metadata.lineTimeInterval = metadata.absRoot.getAttributeDouble(AbstractMetadata.line_time_interval) / // s to day
Constants.secondsInDay;
OrbitStateVector[] orbitStateVectors = AbstractMetadata.getOrbitStateVectors(metadata.absRoot);
metadata.orbit = new OrbitStateVectors(orbitStateVectors, metadata.firstLineTime, metadata.lineTimeInterval, metadata.sourceImageHeight);
if (metadata.srgrFlag) {
metadata.srgrConvParams = AbstractMetadata.getSRGRCoefficients(metadata.absRoot);
} else {
metadata.nearEdgeSlantRange = AbstractMetadata.getAttributeDouble(metadata.absRoot, AbstractMetadata.slant_range_to_first_pixel);
}
final TiePointGrid incidenceAngle = OperatorUtils.getIncidenceAngle(sourceProduct);
metadata.nearRangeOnLeft = SARGeocoding.isNearRangeOnLeft(incidenceAngle, metadata.sourceImageWidth);
}
use of org.esa.s1tbx.commons.OrbitStateVectors in project s1tbx by senbox-org.
the class TerrainFlatteningOp method initialize.
/**
* Initializes this operator and sets the one and only target product.
* <p>The target product can be either defined by a field of type {@link Product}
* annotated with the {@link TargetProduct TargetProduct} annotation or
* by calling {@link #setTargetProduct} method.</p>
* <p>The framework calls this method after it has created this operator.
* Any client code that must be performed before computation of tile data
* should be placed here.</p>
*
* @throws OperatorException If an error occurs during operator initialisation.
* @see #getTargetProduct()
*/
@Override
public void initialize() throws OperatorException {
try {
final InputProductValidator validator = new InputProductValidator(sourceProduct);
validator.checkIfSARProduct();
validator.checkIfMapProjected(false);
PolBandUtils.MATRIX sourceProductType = PolBandUtils.getSourceProductType(sourceProduct);
if (sourceProductType.equals(PolBandUtils.MATRIX.T3) || sourceProductType.equals(PolBandUtils.MATRIX.C3) || sourceProductType.equals(PolBandUtils.MATRIX.C2)) {
isPolSar = true;
} else if (!validator.isCalibrated()) {
final OperatorSpi spi = new CalibrationOp.Spi();
final CalibrationOp op = (CalibrationOp) spi.createOperator();
op.setSourceProduct(sourceProduct);
op.setParameter("outputBetaBand", true);
newSourceProduct = op.getTargetProduct();
} else {
newSourceProduct = sourceProduct;
}
if (demName.equals("External DEM") && externalDEMFile == null) {
throw new OperatorException("External DEM file is not found");
}
if (externalDEMApplyEGM == null) {
externalDEMApplyEGM = false;
}
selectedResampling = ResamplingFactory.createResampling(demResamplingMethod);
if (selectedResampling == null) {
throw new OperatorException("Resampling method " + demResamplingMethod + " is invalid");
}
if (additionalOverlap == null) {
additionalOverlap = 0.1;
}
if (oversamplingMultiple == null) {
oversamplingMultiple = 1.0;
}
getMetadata();
getTiePointGrid();
getSourceImageDimension();
orbit = new OrbitStateVectors(orbitStateVectors, firstLineUTC, lineTimeInterval, sourceImageHeight);
createTargetProduct();
if (externalDEMFile == null) {
DEMFactory.checkIfDEMInstalled(demName);
}
DEMFactory.validateDEM(demName, newSourceProduct);
noDataValue = newSourceProduct.getBands()[0].getNoDataValue();
aBeta = azimuthSpacing * rangeSpacing;
} catch (Throwable e) {
OperatorUtils.catchOperatorException(getId(), e);
}
}
use of org.esa.s1tbx.commons.OrbitStateVectors in project s1tbx by senbox-org.
the class Gaofen3ProductDirectory method geo2pixelRangeDoppler.
private double[] geo2pixelRangeDoppler(final Product product, final double lat, final double lon, final double alt) {
final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
assert absRoot != null;
final String firstLineTimeString = absRoot.getAttributeString(AbstractMetadata.first_line_time);
final ProductData.UTC firstLineTimeUtc = AbstractMetadata.parseUTC(firstLineTimeString);
final double firstLineTimeMjd = firstLineTimeUtc.getMJD();
final double firstLineTimeSec = DateUtils.dateTimeToSecOfDay(firstLineTimeUtc.toString());
final double lineTimeIntervalInSecs = absRoot.getAttributeDouble(AbstractMetadata.line_time_interval);
final double lineTimeIntervalInDays = lineTimeIntervalInSecs / Constants.secondsInDay;
final double rangeSpacing = absRoot.getAttributeDouble(AbstractMetadata.range_spacing);
final double nearEdgeSlantRange = absRoot.getAttributeDouble(AbstractMetadata.slant_range_to_first_pixel);
final double wavelength = Constants.lightSpeed / absRoot.getAttributeDouble(AbstractMetadata.radar_frequency) / Constants.oneMillion;
List<PosVector> sensorPosition = new ArrayList<>();
List<PosVector> sensorVelocity = new ArrayList<>();
final Orbit orbit = getPolyOrbit(product);
final OrbitStateVector[] stateVectors = new OrbitStateVector[height];
for (int i = 0; i < height; i++) {
double azTimeSec = firstLineTimeSec + i * lineTimeIntervalInSecs;
double azTimeMjd = firstLineTimeMjd + i * lineTimeIntervalInDays;
final ProductData.UTC utcTime = new ProductData.UTC(azTimeMjd);
final Point pos = orbit.getXYZ(azTimeSec);
final Point vel = orbit.getXYZDot(azTimeSec);
sensorPosition.add(new PosVector(pos.getX(), pos.getY(), pos.getZ()));
sensorVelocity.add(new PosVector(vel.getX(), vel.getY(), vel.getZ()));
stateVectors[i] = new OrbitStateVector(utcTime, pos.getX(), pos.getY(), pos.getZ(), vel.getX(), vel.getY(), vel.getZ());
}
final OrbitStateVectors orbitStateVectors = new OrbitStateVectors(stateVectors, firstLineTimeMjd, lineTimeIntervalInDays, height);
final PosVector xyz = new PosVector();
GeoUtils.geo2xyzWGS84(lat, lon, alt, xyz);
final PosVector[] sensorPositionArray = new PosVector[height];
final PosVector[] sensorVelocityArray = new PosVector[height];
sensorPosition.toArray(sensorPositionArray);
sensorVelocity.toArray(sensorVelocityArray);
double zeroDopplerTime = SARGeocoding.getEarthPointZeroDopplerTime(firstLineTimeMjd, lineTimeIntervalInDays, wavelength, xyz, sensorPositionArray, sensorVelocityArray);
final PosVector xysSensor = new PosVector();
double slantRange = SARGeocoding.computeSlantRange(zeroDopplerTime, orbitStateVectors, xyz, xysSensor);
final double rangeIndex = (slantRange - nearEdgeSlantRange) / rangeSpacing;
final double azimuthIndex = (zeroDopplerTime - firstLineTimeMjd) / lineTimeIntervalInDays;
return new double[] { rangeIndex, azimuthIndex };
}
Aggregations