private List<Orbits.OrbitVector> readOrbitFile(final File file) throws Exception { final List<Orbits.OrbitVector> osvList = new ArrayList<>(); try (final BufferedReader lineReader = new BufferedReader(new FileReader(file))) { for (String line = lineReader.readLine(); line != null; line = lineReader.readLine()) { if (line.startsWith("*")) { ProductData.UTC time = parseTime(line); Orbits.OrbitVector orbitVector = new Orbits.OrbitVector(time.getMJD()); line = lineReader.readLine(); parsePosition(line, orbitVector); line = lineReader.readLine(); parseVelocity(line, orbitVector); osvList.add(orbitVector); } } } return osvList; }
private void writeOrbitStateVectors(final PrintStream p) { final OrbitStateVector[] osvList = AbstractMetadata.getOrbitStateVectors(absRoot); if (osvList != null && osvList.length > 0) { double seconds = (osvList[0].time_mjd - dateDay.getMJD()) * daysToSeconds; double seconds2 = (osvList[1].time_mjd - dateDay.getMJD()) * daysToSeconds; double interval = seconds2 - seconds; p.println(GammaConstants.HEADER_KEY_NUM_STATE_VECTORS + sep + osvList.length); p.println(GammaConstants.HEADER_KEY_TIME_FIRST_STATE_VECTORS + sep + seconds + tab + 's'); p.println(GammaConstants.HEADER_KEY_STATE_VECTOR_INTERVAL + sep + interval + tab + 's'); int num = 1; for (OrbitStateVector osv : osvList) { p.println(GammaConstants.HEADER_KEY_STATE_VECTOR_POSITION + '_' + num + sep + osv.x_pos + tab + osv.y_pos + tab + osv.z_pos + tab + "m m m"); p.println(GammaConstants.HEADER_KEY_STATE_VECTOR_VELOCITY + '_' + num + sep + osv.x_vel + tab + osv.y_vel + tab + osv.z_vel + tab + "m/s m/s m/s"); ++num; } } }
public File retrieveOrbitFile(final String orbitType) throws Exception { final double stateVectorTime = absRoot.getAttributeUTC(AbstractMetadata.STATE_VECTOR_TIME).getMJD(); final Calendar calendar = absRoot.getAttributeUTC(AbstractMetadata.STATE_VECTOR_TIME).getAsCalendar(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; // zero based final int day = calendar.get(Calendar.DAY_OF_MONTH); orbitFile = findOrbitFile(orbitType, stateVectorTime, year, month); if (orbitFile == null) { String timeStr = absRoot.getAttributeUTC(AbstractMetadata.STATE_VECTOR_TIME).format(); final File destFolder = getDestFolder(orbitType, year, month); throw new IOException("No valid orbit file found for " + timeStr + "\nOrbit files may be downloaded from " + remoteURL + "\nand placed in " + destFolder.getAbsolutePath()); } // read content of the orbit file osvList = readOrbitFile(orbitFile); return orbitFile; }
@Override protected void prepareInputs() throws OperatorException { super.prepareInputs(); final Product sourceProduct = getSourceProduct(); ensureSingleRasterSize(sourceProduct); sceneGeoCoding = sourceProduct.getSceneGeoCoding(); final double mjd = sourceProduct.getStartTime().getMJD(); int dayOfYear = ((int)(mjd % 365.25)) + 1; try { Product climatologiesProduct = null; try { if (StringUtils.isNotNullAndNotEmpty(climatologiesFile)) { climatologiesProduct = ProductIO.readProduct(climatologiesFile); } } catch(IOException e) { climatologiesProduct = null; } aerosolTypeProvider = new AerosolTypeProvider(dayOfYear, climatologiesProduct); } catch (IOException e) { throw new OperatorException("Could not determine aerosol type: " + e.getMessage()); } }
public boolean readOrbitFile(Path path) throws Exception { if (OpenOrbitFile(path)) { parseHeader1(); parseHeader2(); if (numRecords > 0) { dataRecords = new OrbitDataRecord[numRecords]; orbitPositions = new OrbitPositionRecord[numRecords]; recordTimes = new double[numRecords]; days1985To2000 = ProductData.UTC.parse("01-JAN-1985 00:00:00").getMJD(); for (int i = 0; i < numRecords; ++i) { dataRecords[i] = parseDataRecord(); orbitPositions[i] = computeOrbitPosition(dataRecords[i]); recordTimes[i] = orbitPositions[i].utcTime; } } return true; } return false; }
private void getT0andDeltaTS(final String imageName) { // imageName is something like s1a-iw-grd-hh-... final MetadataElement annotationElem = origMetadataRoot.getElement("annotation"); final MetadataElement[] annotationDataSetListElem = annotationElem.getElements(); for (MetadataElement dataSetListElem : annotationDataSetListElem) { if (dataSetListElem.getName().equals(imageName)){ //System.out.println("getT0andDeltaTS: found " + imageName); MetadataElement productElem = dataSetListElem.getElement("product"); MetadataElement imageAnnotationElem = productElem.getElement("imageAnnotation"); MetadataElement imageInformationElem = imageAnnotationElem.getElement("imageInformation"); double t01 = absRoot.getAttributeUTC(AbstractMetadata.first_line_time).getMJD(); // just for comparison double t0 = Sentinel1Utils.getTime(imageInformationElem ,"productFirstLineUtcTime").getMJD(); t0Map.put(imageName, t0); double deltaTS1 = absRoot.getAttributeDouble(AbstractMetadata.line_time_interval) / Constants.secondsInDay; // just for comparison double deltaTS = imageInformationElem.getAttributeDouble("azimuthTimeInterval") / Constants.secondsInDay; // s to day deltaTsMap.put(imageName, deltaTS); //System.out.println("getT0andDeltaTS: " + imageName + ": t01 = " + t01 + " t0 = " + t0 + " deltaTS1 = " + deltaTS1 + " deltaTS = " + deltaTS); break; } } }
/** * Update metadata in the target product. */ private void updateTargetProductMetadata() { final MetadataElement absTgt = AbstractMetadata.getAbstractedMetadata(targetProduct); if (excludeMaster) { final String[] slaveNames = StackUtils.getSlaveProductNames(sourceProduct); absTgt.setAttributeString(AbstractMetadata.PRODUCT, slaveNames[0]); final ProductData.UTC[] times = StackUtils.getProductTimes(sourceProduct); targetProduct.setStartTime(times[1]); double lineTimeInterval = absTgt.getAttributeDouble(AbstractMetadata.line_time_interval); int height = sourceProduct.getSceneRasterHeight(); ProductData.UTC endTime = new ProductData.UTC(times[1].getMJD() + (lineTimeInterval * height) / Constants.secondsInDay); targetProduct.setEndTime(endTime); } else { // only if its a full coregistered stack including master band AbstractMetadata.setAttribute(absTgt, AbstractMetadata.coregistered_stack, 1); } }
/** * Check if product acquisition time is within the validity period of the orbit file. * * @throws Exception */ private void checkOrbitFileValidity() throws Exception { final double stateVectorTime = absRoot.getAttributeUTC(AbstractMetadata.STATE_VECTOR_TIME).getMJD(); final String validityStartTimeStr = getValidityStartFromHeader(); final String validityStopTimeStr = getValidityStopFromHeader(); final double validityStartTimeMJD = SentinelPODOrbitFile.toUTC(validityStartTimeStr).getMJD(); final double validityStopTimeMJD = SentinelPODOrbitFile.toUTC(validityStopTimeStr).getMJD(); if (stateVectorTime < validityStartTimeMJD || stateVectorTime > validityStopTimeMJD) { throw new IOException("Product acquisition time is not within the validity period of the orbit"); } }
private static boolean isWithinRange(final String filename, final double stateVectorTime) { try { final ProductData.UTC utcStart = SentinelPODOrbitFile.getValidityStartFromFilenameUTC(filename); final ProductData.UTC utcEnd = SentinelPODOrbitFile.getValidityStopFromFilenameUTC(filename); if (utcStart != null && utcEnd != null) { if (stateVectorTime >= utcStart.getMJD() && stateVectorTime < utcEnd.getMJD()) { return true; } } return false; } catch (Exception e) { return false; } }
private ProductData.UTC getSourceMeanTime() { ProductData.UTC startTime = sourceProduct.getStartTime(); ProductData.UTC endTime = sourceProduct.getEndTime(); ProductData.UTC meanTime; if (startTime != null && endTime != null) { meanTime = new ProductData.UTC(0.5 * (startTime.getMJD() + endTime.getMJD())); } else if (startTime != null) { meanTime = startTime; } else if (endTime != null) { meanTime = endTime; } else { meanTime = null; } return meanTime; }
public CalibrationVector(final ProductData.UTC time, final int line, final int[] pixels, final float[] sigmaNought, final float[] betaNought, final float[] gamma, final float[] dn) { this.timeMJD = time.getMJD(); this.line = line; this.pixels = pixels; this.sigmaNought = sigmaNought; this.betaNought = betaNought; this.gamma = gamma; this.dn = dn; }
/** * Retrieve required data from Abstracted Metadata * * @throws Exception if metadata not found */ private void getMetadata() throws Exception { final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(sourceProduct); final double wavelength = SARUtils.getRadarFrequency(absRoot); waveNumber = Constants.TWO_PI / wavelength; orbitStateVectors = AbstractMetadata.getOrbitStateVectors(absRoot); firstLineUTC = absRoot.getAttributeUTC(AbstractMetadata.first_line_time).getMJD(); // in days sourceImageWidth = sourceProduct.getSceneRasterWidth(); sourceImageHeight = sourceProduct.getSceneRasterHeight(); }
private String writeCenterTime() { if (srcProduct.getStartTime() != null) { double center = (srcProduct.getStartTime().getMJD() + (srcProduct.getEndTime().getMJD() - srcProduct.getStartTime().getMJD()) / 2.0); double seconds = (center - dateDay.getMJD()) * daysToSeconds; return seconds + tab + 's'; } return ""; }
private void getMetadata() throws Exception { final MetadataElement slvAbsRoot = AbstractMetadata.getSlaveMetadata(sourceProduct.getMetadataRoot()).getElementAt(0); final double mstFirstLineTime = AbstractMetadata.parseUTC( mstAbsRoot.getAttributeString(AbstractMetadata.first_line_time)).getMJD(); // in days rangeSpacing = AbstractMetadata.getAttributeDouble(mstAbsRoot, AbstractMetadata.range_spacing); azimuthSpacing = AbstractMetadata.getAttributeDouble(mstAbsRoot, AbstractMetadata.azimuth_spacing); final double slvFirstLineTime = AbstractMetadata.parseUTC( slvAbsRoot.getAttributeString(AbstractMetadata.first_line_time)).getMJD(); // in days acquisitionTimeInterval = Math.abs(slvFirstLineTime - mstFirstLineTime); // in days maxOffset = maxVelocity * acquisitionTimeInterval; // in m }
private void getMetadata() { firstLineUTC = absRoot.getAttributeUTC(AbstractMetadata.first_line_time).getMJD(); // in days lineTimeInterval = absRoot.getAttributeDouble(AbstractMetadata.line_time_interval) / Constants.secondsInDay; // s to day if (lineTimeInterval == 0.0) { throw new OperatorException("Invalid input for Line Time Interval: " + lineTimeInterval); } }
public NoiseVector(final ProductData.UTC time, final int line, final int[] pixels, final float[] noiseLUT) { this.timeMJD = time.getMJD(); this.line = line; this.pixels = pixels; this.noiseLUT = noiseLUT; } }
/** * Get first line time from the abstracted metadata (in days). */ private void getFirstLineTime() { firstLineUTC = absRoot.getAttributeUTC(AbstractMetadata.first_line_time).getMJD(); // in days }