# Computing Coverage and Figures of Merit

This topic contains details pertaining to coverage calculation and computing figures of merit.

Note

The functionality described in this topic requires a license for the Spatial Analysis Library.

Computing Coverage and Figures of Merit

Once the grid and assets are configured, DME Component Libraries can compute and return a CoverageResults object which holds the set of CoverageGridPointWithResults, each of which stores coverage data represented by CoverageQueryResults in addition to the geometric grid point represented by CoverageGridPoint. Once we compute the CoverageResults, there are two ways to compute a "figure of merit". We can choose from a number of static figures of merit, or we can instantiate a dynamic figure of merit which implements the IFigureOfMeritDefinition interface. Each figure of merit can operate on a single grid point, and the GridDescriptiveStatistics class can be used to compute statistics on the figures of merit for all grid points. The following is an example of computing coverage and applying several static figures of merit to acquire meaningful interpretation of the results:

Java
```CoverageResults resultsOverTheGrid = coverage.computeCoverageOverTheGrid(start, stop);

// Retrieve results for a single grid point
CoverageQueryResult resultForFirstGridPoint = resultsOverTheGrid.getGridPoints().get(0).getAssetCoverage();

// The percentage of the grid which was covered over the given span of time
// (Weighted by surface area, since the grid was generated by SurfaceRegionsCoverageGrid)
double percentCovered = GridDescriptiveStatistics.percentCovered(resultsOverTheGrid.getGridPoints());

// Find the maximum response time to the first grid point
double maximumResponseOfFirstPoint = ResponseTime.maximumResponseTime(resultForFirstGridPoint);

// Find the value of the absolute maximum response time for any point in the grid
double maximumResponseTimeOverGrid = GridDescriptiveStatistics.maximumFigureOfMerit(resultsOverTheGrid.getGridPoints(),
FigureOfMerit.of(ResponseTime::maximumResponseTime));

```

To create dynamic figures of merit, instantiate a type that implements IFigureOfMeritDefinition and call the appropriate static method in GridDescriptiveStatistics or compute GridTimeSampledValues directly by calling the computeData method. Several of the libraries included with DME Component Libraries, such as the Navigation Accuracy Library, contain additional dynamic figures of merit for use with Spatial Analysis Library. Presented here is an example of how to set up a coverage definition for use with the navigation figures of merit:

Java
```// Create a coverage definition
ParameterizedSpatiallyPartitionedCoverageDefinition coverageDefinition = getCoverageDefinition();

Platform template = new Platform();
template.setLocationPoint(coverageDefinition.getGridPoint());
template.setOrientationAxes(new AxesNorthEastDown(earth, template.getLocationPoint()));

coverageDefinition.setGridPointPlaceholder(template);

PlatformCollection gps = getConstellation();
for (Platform gpsSV : gps) {
ElevationAngleConstraint constraint = new ElevationAngleConstraint(minimumElevation);
// Create a link from the SV to the grid
// Add the asset to the coverage definition with the "asset object" being
// the instance of the GPS SV platform.
// The navigation figures of merit will use the GPS SV to identify
// coverage data by PRN.
}
```

Note that there must be a GpsReceiverExtension added to the grid points and that the asset objects added to the AssetDefinition must be the Platforms for the GPS SVs with a GpsSatelliteExtension on them. Once the coverage data is available, instantiate a figure of merit and compute over the grid:

Java
```// Compute coverage results over the grid
CoverageResults coverageResult = coverageDefinition.computeCoverageOverTheGrid(analysisInterval.getStart(), analysisInterval.getStop());

// If it isn't already constrained, make sure that we only consider times
// when there are at least 4 navigation satellites
coverageResult = coverageResult.applyFilter(new CoverageFilter(CoverageFilterType.AT_LEAST_N, 4));

// Create a dilution of precision figure of merit
DilutionOfPrecisionFigureOfMerit dopFom = new DilutionOfPrecisionFigureOfMerit(DilutionOfPrecisionType.POSITION);

// Compute the figure of merit data over the grid
GridTimeSampledValues dopFomResults = GridTimeSampledValues.computeData(coverageResult, dopFom, analysisInterval, timeStep);
```

The navigation figures of merit will make use of the coverage results to improve performance when determining which GPS SVs are available for a navigation solution. GridTimeSampledValues computes a set of TimeSampledValues for each grid point using multiple threads (depending on the settings in the ThreadingPolicy). We can then obtain statistics over the grid:

Java
```// Compute the overall statistics for the
// entire grid over the entire time
double gridMean = dopFomResults.computeOverallMean();
double gridMin = dopFomResults.computeOverallMinimum();
double gridMax = dopFomResults.computeOverallMaximum();
double gridStd = dopFomResults.computeOverallStandardDeviation();
double gridRms = dopFomResults.computeOverallRootMeanSquare();
double gridPrct = dopFomResults.computeOverallPercentile(90.0);

// Compute statistics for a particular grid point sampled over time
TimeSampledValues particularResult = dopFomResults.getGridPointData().get(0);
double min = particularResult.computeMinimum();
double max = particularResult.computeMaximum();
double mean = DescriptiveStatistics.mean(particularResult.getData());
double std = DescriptiveStatistics.standardDeviation(particularResult.getData());
double rms = DescriptiveStatistics.rootMeanSquare(particularResult.getData());
```

Note that the list of GridPointData (get) on the GridTimeSampledValues corresponds to the list of CoverageGridPointWithResults on the CoverageResults used to generate the figure of merit data.