Skip to content
Snippets Groups Projects
Commit ae04470b authored by LabatAllee Lucie's avatar LabatAllee Lucie
Browse files

refactoring main classes

parent 594f7fc5
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,7 @@ public class GroundMeasureGenerator implements Measurable {
public void createMeasure(final int lineSampling,final int pixelSampling) throws RuggedException
{
for (double line = 0; line < viewingModel.dimension; line += lineSampling) {
for (double line = 0; line < viewingModel.dimension; line += lineSampling) {
AbsoluteDate date = sensor.getDate(line);
for (int pixel = 0; pixel < sensor.getNbPixels(); pixel += pixelSampling) {
......@@ -111,22 +111,18 @@ public class GroundMeasureGenerator implements Measurable {
double latErrorStd = std[0]*latLongError.getX(); // in line: -0.000002 deg
double lonErrorStd = std[1]*latLongError.getY(); // in line: 0.000012 deg
System.out.format("Corresponding error estimation on ground: {lat mean: %1.10f rad , lat stddev: %1.10f rad} %n",latErrorMean,latErrorStd);
System.out.format("Corresponding error estimation on ground: {lon mean: %1.10f rad, lat stddev: %1.10f rad } %n",lonErrorMean,lonErrorStd);
System.out.format("Corresponding error estimation on ground: {alt mean: %1.3f m, alt stddev: %1.3f m } %n",mean[2], std[2]);
// Gaussian random generator
// Build a null mean random uncorrelated vector generator with standard deviation corresponding to the estimated error on ground
double meanGenerator[] = {latErrorMean, lonErrorMean, mean[0]};
double stdGenerator[] = {latErrorStd, lonErrorStd, mean[1]};
System.out.format(" mean : %1.10f %1.10f %1.10f %n",meanGenerator[0],meanGenerator[1],meanGenerator[2]);
System.out.format(" std : %1.10f %1.10f %1.10f %n",stdGenerator[0],stdGenerator[1],stdGenerator[2]);
double meanGenerator[] = {latErrorMean, lonErrorMean, mean[2]};
double stdGenerator[] = {latErrorStd, lonErrorStd, std[2]};
System.out.format("Corresponding error estimation on ground {Latitude, Longitude, Altitude}:%n");
System.out.format("\tMean: {%1.10f rad, %1.10f rad, %1.10f m} %n",meanGenerator[0],meanGenerator[1],meanGenerator[2]);
System.out.format("\tStd : {%1.10f rad, %1.10f rad, %1.10f m} %n",stdGenerator[0],stdGenerator[1],stdGenerator[2]);
GaussianRandomGenerator rng = new GaussianRandomGenerator(new Well19937a(0xefac03d9be4d24b9l));
UncorrelatedRandomVectorGenerator rvg = new UncorrelatedRandomVectorGenerator(meanGenerator, stdGenerator, rng);
System.out.format("Add a gaussian noise to measures without biais (null mean) and standard deviation corresponding to the estimated error on ground.%n");
System.out.format("Add a gaussian noise to measures without biais (null mean) and standard deviation%n corresponding to the estimated error on ground.%n");
for (double line = 0; line < viewingModel.dimension; line += lineSampling) {
AbsoluteDate date = sensor.getDate(line);
......@@ -159,7 +155,7 @@ public class GroundMeasureGenerator implements Measurable {
System.out.format("Uncertainty in pixel (in line) for a real geometric refining: 1 pixel (assumption)%n");
final int pix =sensor.getNbPixels()/2;
final int line= (int) FastMath.floor(pix); // assumption : same number of line and pixels;
System.out.format(" pixel size estimated at position pix : %d line : %d %n", pix, line);
System.out.format("Pixel size estimated at position pix: %d line: %d %n", pix, line);
final AbsoluteDate date = sensor.getDate(line);
GeodeticPoint gp_pix0 = rugged.directLocation(date, sensor.getPosition(), sensor.getLOS(date, pix));
final AbsoluteDate date1 = sensor.getDate(line+1);
......@@ -170,7 +166,7 @@ public class GroundMeasureGenerator implements Measurable {
final double distanceX = DistanceTools.computeDistanceInMeter(gp_pix0.getLongitude(), gp_pix0.getLatitude(),gp_pix1.getLongitude(), gp_pix0.getLatitude());
final double distanceY = DistanceTools.computeDistanceInMeter(gp_pix0.getLongitude(), gp_pix0.getLatitude(),gp_pix0.getLongitude(), gp_pix1.getLatitude());
System.out.format(" estimated distance %3.3f %3.3f %n",distanceX, distanceY);
System.out.format("Estimated distance: X %3.3f Y %3.3f %n",distanceX, distanceY);
//System.out.format(" lat : %1.10f %1.10f %n", latErr, lonErr);
return new Vector3D(latErr,lonErr,0.0);
......
......@@ -34,7 +34,7 @@ import org.hipparchus.geometry.euclidean.threed.Vector3D;
/**
* class for testing geometric performances in absolute location.
* Metrics are computed for two scenarii: fulcrum points and liaison points *
* Metrics are computed for two scenarios: fulcrum points and liaison points
* @author Jonathan Guinet
* @author Lucie Labat-Allee
* @see SensorToSensorMapping
......
/* Copyright 2013-2016 CS Systèmes d'Information
* Licensed to CS Systèmes d'Information (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package AffinagePleiades;
import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresOptimizer.Optimum;
import org.hipparchus.util.FastMath;
import java.io.File;
import java.util.Locale;
import java.util.Collections;
import org.orekit.bodies.BodyShape;
import org.orekit.bodies.GeodeticPoint;
import org.orekit.data.DataProvidersManager;
import org.orekit.data.DirectoryCrawler;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitExceptionWrapper;
import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider;
import org.orekit.orbits.Orbit;
import org.orekit.rugged.api.AlgorithmId;
import org.orekit.rugged.api.BodyRotatingFrameId;
import org.orekit.rugged.api.EllipsoidId;
import org.orekit.rugged.api.InertialFrameId;
import org.orekit.rugged.api.Rugged;
import org.orekit.rugged.api.RuggedBuilder;
import org.orekit.rugged.errors.RuggedException;
import org.orekit.rugged.linesensor.LineSensor;
import org.orekit.rugged.refining.generators.GroundMeasureGenerator;
import org.orekit.rugged.refining.measures.Noise;
import org.orekit.rugged.refining.metrics.DistanceTools;
import org.orekit.rugged.refining.metrics.LocalisationMetrics;
import org.orekit.rugged.refining.models.OrbitModel;
import org.orekit.rugged.refining.models.PleiadesViewingModel;
import org.orekit.time.AbsoluteDate;
import org.orekit.utils.AngularDerivativesFilter;
import org.orekit.utils.CartesianDerivativesFilter;
import org.orekit.utils.PVCoordinates;
/**
* Parameter refining context
* @author Jonathan Guinet
* @author Lucie LabatAllee
*/
public class AffinageRugged {
public static void main(String[] args) {
try {
// Initialize Orekit, assuming an orekit-data folder is in user home directory
File home = new File(System.getProperty("user.home"));
//File orekitData = new File(home, "workspace/data/orekit-data");
File orekitData = new File(home, "COTS/orekit-data");
DataProvidersManager.getInstance().addProvider(new DirectoryCrawler(orekitData));
//CreateOrbit
OrbitModel orbitmodel = new OrbitModel();
BodyShape earth = orbitmodel.createEarth();
NormalizedSphericalHarmonicsProvider gravityField = orbitmodel.createGravityField();
//create Pleiades Viewing Model
PleiadesViewingModel pleiadesViewingModel = new PleiadesViewingModel();
AbsoluteDate minDate = pleiadesViewingModel.getMinDate();
AbsoluteDate maxDate = pleiadesViewingModel.getMaxDate();
AbsoluteDate refDate = pleiadesViewingModel.getDatationReference();
Orbit orbit = orbitmodel.createOrbit(gravityField.getMu(), refDate);
final double [] rollPoly = {0.0,0.0,0.0};
double[] pitchPoly = {0.0,0.0};
double[] yawPoly = {0.0,0.0,0.0};
orbitmodel.setLOFTransform(rollPoly, pitchPoly, yawPoly, minDate);
PVCoordinates PV = orbit.getPVCoordinates(earth.getBodyFrame());
GeodeticPoint gp = earth.transform(PV.getPosition(), earth.getBodyFrame(), orbit.getDate());
System.out.format(" **** Orbit Definition **** %n");
System.out.format(Locale.US, "Geodetic Point at date %s : φ = %8.10f °, λ = %8.10f %n",orbit.getDate().toString(),
FastMath.toDegrees(gp.getLatitude()),
FastMath.toDegrees(gp.getLongitude()));
System.out.format(" **** Build Viewing Model **** %n");
// Build Rugged ...
RuggedBuilder ruggedBuilder = new RuggedBuilder();
LineSensor lineSensor = pleiadesViewingModel.getLineSensor();
ruggedBuilder.addLineSensor(lineSensor);
ruggedBuilder.setAlgorithm(AlgorithmId.IGNORE_DEM_USE_ELLIPSOID);
ruggedBuilder.setEllipsoid(EllipsoidId.WGS84, BodyRotatingFrameId.ITRF);
ruggedBuilder.setTimeSpan(minDate,maxDate, 0.001, 5.0).
setTrajectory(InertialFrameId.EME2000,
orbitmodel.orbitToPV(orbit, earth, minDate.shiftedBy(-0.0), maxDate.shiftedBy(+0.0), 0.25),
8, CartesianDerivativesFilter.USE_PV,
orbitmodel.orbitToQ(orbit, earth, minDate.shiftedBy(-0.0), maxDate.shiftedBy(+0.0), 0.25),
2, AngularDerivativesFilter.USE_R);
Rugged rugged = ruggedBuilder.build();
Vector3D position = lineSensor.getPosition(); // This returns a zero vector since we set the relative position of the sensor w.r.T the satellite to 0.
AbsoluteDate firstLineDate = lineSensor.getDate(0);
Vector3D los = lineSensor.getLOS(firstLineDate,0);
GeodeticPoint upLeftPoint = rugged.directLocation(firstLineDate, position, los);
los = lineSensor.getLOS(firstLineDate,pleiadesViewingModel.dimension-1);
//GeodeticPoint upRightPoint = rugged.directLocation(firstLineDate, position, los);
AbsoluteDate lineDate = lineSensor.getDate(pleiadesViewingModel.dimension/2);
los = lineSensor.getLOS(lineDate,pleiadesViewingModel.dimension/2);
GeodeticPoint centerPoint = rugged.directLocation(lineDate, position, los);
System.out.format(Locale.US, "center geodetic position : φ = %8.10f °, λ = %8.10f °, h = %8.3f m%n",
FastMath.toDegrees(centerPoint.getLatitude()),
FastMath.toDegrees(centerPoint.getLongitude()),centerPoint.getAltitude());
/*try {
FileWriter out = new FileWriter("geodetic_position.txt");
out.write("LATITUDE, LONGITUDE, LINE, PIX \n");
for (double line = 0; line < pleiadesViewingModel.dimension; line += 1000) {
AbsoluteDate date = lineSensor.getDate(line);
for (int pixel = 0; pixel < lineSensor.getNbPixels(); pixel += 1000) {
GeodeticPoint gp2 = rugged.directLocation(date, lineSensor.getPosition(),
lineSensor.getLOS(date, pixel));
String result = String.format("%8.10f, %8.10f, %2.1f, %2.1f \n ",FastMath.toDegrees(gp2.getLatitude()),
FastMath.toDegrees(gp2.getLongitude()), line,(double) pixel);
//System.out.println(result);
out.write(result);
}
}
out.close();
}
catch (IOException e) {
System.err.println(e.getLocalizedMessage());
System.exit(1);
}*/
int pixelPosition = pleiadesViewingModel.dimension-1;
los = lineSensor.getLOS(firstLineDate,pixelPosition);
GeodeticPoint upperRight = rugged.directLocation(firstLineDate, position, los);
AbsoluteDate lineDate_y = lineSensor.getDate(pleiadesViewingModel.dimension-1);
los = lineSensor.getLOS(lineDate_y,0);
GeodeticPoint lowerLeft = rugged.directLocation(lineDate_y, position, los);
double GSD_X = DistanceTools.computeDistanceInMeter(upLeftPoint.getLongitude(), upLeftPoint.getLatitude(),upperRight.getLongitude() , upperRight.getLatitude())/pleiadesViewingModel.dimension;
double GSD_Y = DistanceTools.computeDistanceInMeter(upLeftPoint.getLongitude(), upLeftPoint.getLatitude(),lowerLeft.getLongitude() , lowerLeft.getLatitude())/pleiadesViewingModel.dimension;
System.out.format(" GSD X %2.2f Y %2.2f **** %n", GSD_X, GSD_Y);
System.out.format(" **** Add roll and pitch values **** %n");
double rollValue = FastMath.toRadians(-0.01);
double pitchValue = FastMath.toRadians(0.02);
double factorValue = 1.05;
System.out.format("roll : %3.5f pitch : %3.5f factor : %3.5f \n",rollValue,pitchValue,factorValue);
rugged.
getLineSensor("line").
getParametersDrivers().
filter(driver -> driver.getName().equals("line_roll")).
findFirst().get().setValue(rollValue);
rugged.
getLineSensor("line").
getParametersDrivers().
filter(driver -> driver.getName().equals("line_pitch")).
findFirst().get().setValue(pitchValue);
rugged.
getLineSensor("line").
getParametersDrivers().
filter(driver -> driver.getName().equals("factor")).
findFirst().get().setValue(factorValue);
System.out.format(" **** Generate Measures **** %n");
GroundMeasureGenerator measure = new GroundMeasureGenerator(pleiadesViewingModel,rugged);
int lineSampling = 1000;
int pixelSampling = 1000;
//measure.CreateMeasure(lineSampling, pixelSampling);
final Noise noise = new Noise(0,3); /* distribution: gaussian(0), vector dimension:3 */
final double[] mean = {0.0,0.0,0.0}; // {lat mean, long mean, alt mean}
final double[] standardDeviation = {0.0,0.0,0.0}; // {lat std, long std, alt std}
noise.setMean(mean);
noise.setStandardDeviation(standardDeviation);
measure.createNoisyMeasure(lineSampling, pixelSampling, noise); // Test with noisy measures
System.out.format("nb TiePoints %d %n", measure.getMeasureCount());
System.out.format(" **** Initial Residuals **** %n");
LocalisationMetrics gtResiduals = new LocalisationMetrics(measure.getGroundMapping(),rugged, false);
System.out.format("gt residuals max : %3.4f mean %3.4f meters %n",gtResiduals.getMaxResidual(),gtResiduals.getMeanResidual());
System.out.format(" **** Reset Roll/Pitch/Factor **** %n");
rugged.
getLineSensor(pleiadesViewingModel.getSensorName()).
getParametersDrivers().
filter(driver -> driver.getName().equals("line_roll") || driver.getName().equals("line_pitch")).
forEach(driver -> {
try {
driver.setSelected(true);
driver.setValue(0.0);
} catch (OrekitException e) {
throw new OrekitExceptionWrapper(e);
}
});
rugged.
getLineSensor(pleiadesViewingModel.getSensorName()).
getParametersDrivers().
filter(driver -> driver.getName().equals("line_factor")).
forEach(driver -> {
try {
driver.setSelected(true);
driver.setValue(1.0); // default value: no Z scale factor applied
} catch (OrekitException e) {
throw new OrekitExceptionWrapper(e);
}
});
System.out.format(" **** Initial Residuals **** %n");
LocalisationMetrics initlialResiduals = new LocalisationMetrics(measure.getGroundMapping(),rugged, false);
System.out.format("residuals max : %3.4f mean %3.4f meters %n",initlialResiduals.getMaxResidual(),initlialResiduals.getMeanResidual());
System.out.format(" **** Start optimization **** %n");
// perform parameters estimation
int maxIterations = 100;
double convergenceThreshold = 1e-14;
System.out.format("iterations max %d convergence threshold %3.6e \n",maxIterations, convergenceThreshold);
Optimum optimum = rugged.estimateFreeParameters(Collections.singletonList(measure.getGroundMapping()), maxIterations,convergenceThreshold);
System.out.format("max value %3.6e %n",optimum.getResiduals().getMaxValue());
System.out.format(" Optimization performed in %d iterations \n",optimum.getEvaluations());
System.out.format(" RMSE: %f \n",optimum.getRMS());
// check estimated values
double estimatedRoll = rugged.getLineSensor(pleiadesViewingModel.getSensorName()).
getParametersDrivers().
filter(driver -> driver.getName().equals("line_roll")).
findFirst().get().getValue();
double rollError = (estimatedRoll - rollValue);
System.out.format("Estimated roll %3.5f roll error %3.6e %n", estimatedRoll, rollError);
double estimatedPitch = rugged.getLineSensor(pleiadesViewingModel.getSensorName()).
getParametersDrivers().
filter(driver -> driver.getName().equals("line_pitch")).
findFirst().get().getValue();
double pitchError = (estimatedPitch - pitchValue);
System.out.format("Estimated pitch %3.5f pitch error %3.6e %n ", estimatedPitch, pitchError);
double estimatedFactor = rugged.getLineSensor(pleiadesViewingModel.getSensorName()).
getParametersDrivers().
filter(driver -> driver.getName().equals("factor")).
findFirst().get().getValue();
double factorError = (estimatedFactor - factorValue);
System.out.format("Estimated factor %3.5f factor error %3.6e %n ", estimatedFactor, factorError);
System.out.format(" **** Compute Statistics **** %n");
LocalisationMetrics localisationResiduals = new LocalisationMetrics(measure.getGroundMapping(),rugged, false);
System.out.format("residuals max : %3.4e mean %3.4e meters %n",localisationResiduals.getMaxResidual(),localisationResiduals.getMeanResidual());
LocalisationMetrics localisationResidualsDeg = new LocalisationMetrics(measure.getGroundMapping(),rugged, true);
System.out.format("residuals max : %3.4e deg mean %3.4e deg %n",localisationResidualsDeg.getMaxResidual(),localisationResidualsDeg.getMeanResidual());
} catch (OrekitException oe) {
System.err.println(oe.getLocalizedMessage());
System.exit(1);
} catch (RuggedException re) {
System.err.println(re.getLocalizedMessage());
System.exit(1);
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment