1 package gov.sandia.geotess.examples;
11 import gov.
sandia.gmp.util.globals.DataType;
12 import gov.
sandia.gmp.util.globals.InterpolatorType;
13 import gov.
sandia.gmp.util.numerical.polygon.GreatCircle;
14 import gov.
sandia.gmp.util.numerical.polygon.Polygon;
15 import gov.
sandia.gmp.util.numerical.vector.EarthShape;
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Date;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.Map.Entry;
26 import static java.lang.Math.toRadians;
67 private static double[]
ANMO = EarthShape.WGS84_RCONST.getVectorDegrees(34.9462, -106.4567);
74 public static void main(String[] args)
101 Polygon polygon =
new Polygon(
ANMO, toRadians(38.), 100);
102 model.setActiveRegion(polygon);
119 float[] attributeChanges =
new float[model.getNPoints()];
120 Arrays.fill(attributeChanges, 0.01F);
141 GeoTessModel hitCountModel = tomo.
hitCount(model, rayPaths);
144 hitCountModel.writeModel(
"hitcount_model_original.geotess");
165 GeoTessModel hitCountModelRefined =
new GeoTessModel(
166 "hitcount_model_refined.geotess");
174 GeoTessModel refinedModel = tomo.
refineModel(model,
175 hitCountModelRefined);
177 refinedModel.writeModel(
"attenuation_model_refined_java.geotess");
179 System.out.println(
"Done.");
202 .println(
"************************************************************");
203 System.out.println(
"*");
204 System.out.println(
"* startingModel()");
205 System.out.println(
"*");
207 .println(
"************************************************************");
208 System.out.println();
214 File gridFile =
new File(
"geotess_grid_04000.geotess");
216 if (!gridFile.exists())
217 throw new Exception(
"\nGrid file geotess_grid_04000.geotess does not exist.\n"
218 +
"This program should be run from directory GeoTessBuilderExamples/tomo2dTest\n");
222 GeoTessMetaData metaData =
new GeoTessMetaData();
227 metaData.setDescription(
"GeoTessModel for example program Tomography2D");
230 metaData.setLayerNames(
"surface");
233 metaData.setAttributes(
"attenuation",
"1/km");
237 metaData.setDataType(DataType.FLOAT);
241 metaData.setModelSoftwareVersion(getClass().getCanonicalName());
245 metaData.setModelGenerationDate(
new Date().toString());
250 GeoTessModel model =
new GeoTessModel(gridFile, metaData);
253 for (
int vtx = 0; vtx < model.getGrid().getNVertices(); ++vtx)
256 model.setProfile(vtx, Data.getDataFloat(0.1F));
258 System.out.println(model);
285 .println(
"************************************************************");
286 System.out.println(
"*");
287 System.out.println(
"* generateRayPaths()");
288 System.out.println(
"*");
290 .println(
"************************************************************");
291 System.out.println();
293 ArrayList<double[][]> rayPaths =
new ArrayList<double[][]>(10);
295 for (
int i = 0; i <= 10; ++i)
297 double[]
event =
new double[3];
300 GeoTessUtils.move(
ANMO, toRadians(i * 5), toRadians(i * 36), event);
303 double[][] rayPath =
new double[][] { event,
ANMO };
305 rayPaths.add(rayPath);
312 .println(
" id event station distance azimuth");
313 for (
int i = 0; i < rayPaths.size(); ++i)
315 double[][] rayPath = rayPaths.get(i);
316 double[]
event = rayPath[0];
317 double[] station = rayPath[1];
319 System.out.printf(
"%3d %s %s %10.4f %10.4f%n", i,
320 EarthShape.WGS84.getLatLonString(event, 4),
321 EarthShape.WGS84.getLatLonString(station, 4),
322 GeoTessUtils.angleDegrees(station, event),
323 GeoTessUtils.azimuthDegrees(station, event, Double.NaN));
325 System.out.println();
327 ArrayList<double[]> points =
new ArrayList<double[]>();
328 for (
double[][] ray : rayPaths)
330 GreatCircle gc =
new GreatCircle(ray[0], ray[1]);
331 for (
double[] point : gc.getPoints(
332 (
int) Math.ceil(gc.getDistance() / Math.toRadians(1) + 1),
334 if (!Double.isNaN(point[0]))
338 GeoTessModelUtils.vtkPoints(points,
"ray_path_points.vtk");
370 .println(
"************************************************************");
371 System.out.println(
"*");
372 System.out.println(
"* rayTrace()");
373 System.out.println(
"*");
375 .println(
"************************************************************");
376 System.out.println();
384 double pointSpacing = toRadians(0.1);
390 double earthRadius = -1;
393 InterpolatorType interpType = InterpolatorType.NATURAL_NEIGHBOR;
399 HashMap<Integer, Double> weights =
new HashMap<Integer, Double>();
402 for (
int i = 0; i < rayPaths.size(); ++i)
406 double[][] rayPath = rayPaths.get(i);
407 double[]
event = rayPath[0];
408 double[] station = rayPath[1];
410 GreatCircle greatCircle =
new GreatCircle(event, station);
421 double attenuation = model.getPathIntegral2D(attribute,
422 greatCircle, pointSpacing, earthRadius, interpType, weights);
432 .println(
"----------------------------------------------------------------------------");
434 .println(
"ray station event distance azimuth attenuation");
435 System.out.printf(
"%3d %s %s %10.4f %10.4f %12.5f%n%n", i,
436 EarthShape.WGS84.getLatLonString(station, 4),
437 EarthShape.WGS84.getLatLonString(event, 4),
438 GeoTessUtils.angleDegrees(station, event),
439 GeoTessUtils.azimuthDegrees(station, event, Double.NaN),
444 .println(
"pointId weight | point lat, lon, distance and azimuth from station");
446 double sumWeights = 0;
448 if (weights.size() == 0)
450 .println(
"No weights because event-station distance = 0");
452 for (Entry<Integer, Double> entry : weights.entrySet())
454 int pointIndex = entry.getKey();
455 double weight = entry.getValue();
457 sumWeights += weight;
461 System.out.printf(
"%7d %9.2f | outside polygon%n",
466 double[] gridNode = model.getPointMap().getPointUnitVector(
469 System.out.printf(
"%7d %9.2f | %s %10.4f %10.4f%n",
470 pointIndex, weight, EarthShape.WGS84
471 .getLatLonString(gridNode), GeoTessUtils
472 .angleDegrees(station, gridNode),
473 GeoTessUtils.azimuthDegrees(station, gridNode,
477 System.out.println();
479 System.out.printf(
"Sum of weights = %10.4f km %n%n", sumWeights);
494 .println(
"************************************************************");
495 System.out.println(
"*");
496 System.out.println(
"* regularization()");
497 System.out.println(
"*");
499 .println(
"************************************************************");
500 System.out.println();
507 int level = model.getGrid().getTopLevel(tessId);
514 for (
int pointIndex = 0; pointIndex < model.getNPoints(); ++pointIndex)
520 int vertexId = model.getPointMap().getVertexIndex(pointIndex);
523 double[] vertex = model.getGrid().getVertex(vertexId);
527 HashSet<Integer> neighbors = model.getGrid().getVertexNeighbors(
528 tessId, level, vertexId, order);
531 if (pointIndex % 100 == 0)
534 .println(
"-------------------------------------------------------- ");
535 System.out.printf(
"point %d, vertex %d, lat,lon %s:%n%n",
536 pointIndex, vertexId,
537 EarthShape.WGS84.getLatLonString(vertex, 3));
539 System.out.println(
"neighbor neighbor distance azimuth");
540 System.out.println(
"vertexid pointid (deg) (deg)");
541 for (Integer neighbor : neighbors)
545 double[] neighborVertex = model.getGrid().getVertex(
548 int neighborPoint = model.getPointMap().getPointIndex(
551 System.out.printf(
"%8d %8d %8.2f %8.2f%n", neighbor,
552 neighborPoint, GeoTessUtils.angleDegrees(vertex,
553 neighborVertex), GeoTessUtils
554 .azimuthDegrees(vertex, neighborVertex,
557 System.out.println();
573 int attributeIndex,
float[] attributeChanges)
575 for (
int pointIndex = 0; pointIndex < model.getNPoints(); ++pointIndex)
576 model.setValue(pointIndex, attributeIndex,
577 model.getValueFloat(pointIndex, attributeIndex)
578 + attributeChanges[pointIndex]);
592 protected GeoTessModel
hitCount(GeoTessModel inputModel,
593 ArrayList<
double[][]> rayPaths)
throws Exception
596 .println(
"************************************************************");
597 System.out.println(
"*");
598 System.out.println(
"* hitCount()");
599 System.out.println(
"*");
601 .println(
"************************************************************");
602 System.out.println();
606 GeoTessMetaData metaData =
new GeoTessMetaData();
609 metaData.setDescription(
"GeoTessModel of hit count for example program Tomography2D");
612 metaData.setLayerNames(
"surface");
615 metaData.setAttributes(
"HIT_COUNT",
"count");
618 metaData.setDataType(DataType.INT);
622 metaData.setModelSoftwareVersion(getClass().getCanonicalName()
627 metaData.setModelGenerationDate(
new Date().toString());
631 GeoTessModel hitCountModel =
new GeoTessModel(inputModel.getGrid(),
635 for (
int vertexId = 0; vertexId < hitCountModel.getNVertices(); ++vertexId)
636 hitCountModel.setProfile(vertexId, Data.getDataInt(0));
640 hitCountModel.setActiveRegion(inputModel.getPointMap().getPolygon());
643 double pointSpacing = toRadians(0.1);
646 InterpolatorType interpType = InterpolatorType.LINEAR;
649 int attributeIndex = 0;
654 HashMap<Integer, Double> weights =
new HashMap<Integer, Double>();
657 for (
int i = 0; i < rayPaths.size(); ++i)
661 double[][] rayPath = rayPaths.get(i);
662 double[]
event = rayPath[0];
663 double[] station = rayPath[1];
664 GreatCircle greatCircle =
new GreatCircle(event, station);
672 inputModel.getPathIntegral2D(-1, greatCircle,
673 pointSpacing, -1., interpType, weights);
675 for (Integer pointIndex : weights.keySet())
678 int hitcount = hitCountModel.getValueInt(pointIndex, attributeIndex);
680 hitCountModel.setValue(pointIndex, attributeIndex, hitcount);
689 GeoTessModelUtils.vtk(hitCountModel,
"hitcount_model_original.vtk", 0,
690 false,
new int[] { 0 });
691 GeoTessModelUtils.vtkTriangleSize(hitCountModel.getGrid(),
new File(
692 "triangle_size_original.vtk"), 0);
695 System.out.println(
" point vertex lat lon distance hitcount");
696 for (
int pointIndex = 0; pointIndex < hitCountModel.getNPoints(); ++pointIndex)
697 if (hitCountModel.getValueInt(pointIndex, 0) > 0)
699 double[] u = hitCountModel.getPointMap().getPointUnitVector(
703 "%8d %8d %s %9.2f %6d%n",
705 hitCountModel.getPointMap().getVertexIndex(pointIndex),
706 hitCountModel.getPointMap().getPointLatLonString(
708 GeoTessUtils.angleDegrees(
ANMO, u),
709 hitCountModel.getValueInt(pointIndex, 0));
711 System.out.println();
713 return hitCountModel;
733 GeoTessModel hitCountModelRefined)
throws Exception
736 .println(
"************************************************************");
737 System.out.println(
"*");
738 System.out.println(
"* refineModel()");
739 System.out.println(
"*");
741 .println(
"************************************************************");
742 System.out.println();
745 GeoTessGrid refinedGrid = hitCountModelRefined.getGrid();
748 GeoTessModelUtils.vtk(hitCountModelRefined,
749 "hitcount_model_refined.vtk", 0,
false,
new int[] { 0 });
750 GeoTessModelUtils.vtkTriangleSize(refinedGrid,
new File(
751 "triangle_size_refined.vtk"), 0);
755 GeoTessModel newModel =
new GeoTessModel(
756 hitCountModelRefined.getGrid(), oldModel.getMetaData());
761 GeoTessPosition pos = oldModel.getGeoTessPosition(InterpolatorType.LINEAR);
767 for (
int vtx = 0; vtx < newModel.getNVertices(); ++vtx)
772 double[] u = refinedGrid.getVertex(vtx);
777 int oldVtx = oldModel.getGrid().getVertexIndex(u);
782 data = pos.set(layerIndex, u, 6371.).getData();
788 data = oldModel.getProfile(oldVtx, layerIndex).getDataTop();
791 newModel.setProfile(vtx, data);
795 System.out.println(GeoTessModelUtils.statistics(oldModel));
796 System.out.println(GeoTessModelUtils.statistics(newModel));