GeoTessJavaExamples  2.0
GridPointData.java
Go to the documentation of this file.
1 package gov.sandia.geotess.examples.customdata;
2 
3 import java.io.DataInputStream;
4 import java.io.DataOutputStream;
5 import java.io.IOException;
6 import java.util.Collection;
7 import java.util.HashMap;
8 import java.util.List;
9 import java.util.Map;
10 import java.util.Scanner;
11 import java.util.Set;
12 
13 import gov.sandia.geotess.Data;
14 import gov.sandia.geotess.DataCustom;
15 import gov.sandia.geotess.GeoTessUtils;
16 import gov.sandia.gmp.util.globals.DataType;
17 
18 /**
19  * GridPointData manages the information associated with a single point in
20  * a GeoTessModel. GridPointData has information about GeoAttributes at a
21  * bunch of stations and phases. It is stored in a map
22  * station -> phase -> GeoAttributes -> value.
23  * @author sandy
24  */
25 public class GridPointData extends DataCustom implements Map<String, StationData>
26 {
27  /**
28  * Horizontal radius of the cell centered on the grid point, in degrees or maybe km(?)
29  */
30  double cellRadius;
31 
32  /**
33  * Upper limit of the depth range that encompasses the grid point, in km.
34  */
35  double minDepth;
36 
37  /**
38  * Lower limit of the depth range that encompasses the grid point, in km.
39  */
40  double maxDepth;
41 
42  /**
43  * Map from Station Name -> Phase Name -> GeoAttribute -> dataValue
44  */
45  private Map<String, StationData> dataValues;
46 
47  /**
48  * A list of all the attributes supported by this model.
49  * All of these attributes will have values in each PhaseData map and will
50  * be read from, and written to the output files.
51  */
53 
54  /**
55  * Map from attribute index -> [Station Name, Phase Name, Attribute Name]
56  */
57  private List<Triple> indexList;
58 
59  /**
60  *
61  */
62  public GridPointData()
63  {
64  }
65 
66  /**
67  *
68  */
70  {
71  this.dataValues = new HashMap<String, StationData>(model.stationNames.length);
72  this.attributes = model.getAttributes();
73  this.indexList = model.getIndexList();
74  }
75 
77  double cellRadius,
78  double minDepth,
79  double maxDepth)
80  {
81  this(model);
82  this.cellRadius = cellRadius;
83  this.minDepth = minDepth;
84  this.maxDepth = maxDepth;
85  }
86 
87  /**
88  *
89  * @param input
90  * @param model
91  */
92  protected GridPointData(Scanner input, GeoTessModelGA model)
93  {
94  this(model);
95  cellRadius = input.nextDouble();
96  minDepth = input.nextDouble();
97  maxDepth = input.nextDouble();
98  int nStations = input.nextInt();
99  for (int i=0; i<nStations; ++i)
100  {
101  String station = input.next();
102  StationData stationData = new StationData(input, attributes);
103  dataValues.put(station, stationData);
104  }
105  }
106 
107  /**
108  *
109  * @param input
110  * @param model
111  * @throws IOException
112  */
113  protected GridPointData(DataInputStream input, GeoTessModelGA model) throws IOException
114  {
115  this(model);
116 
117  cellRadius = input.readDouble();
118  minDepth = input.readDouble();
119  maxDepth = input.readDouble();
120  int nStations = input.readInt();
121  for (int i=0; i<nStations; ++i)
122  {
123  String station = GeoTessUtils.readString(input);
124  StationData stationData = new StationData(input, attributes);
125  dataValues.put(station, stationData);
126  }
127  }
128 
129  @Override
130  public void write(DataOutputStream output) throws IOException {
131  output.writeDouble(cellRadius);
132  output.writeDouble(minDepth);
133  output.writeDouble(maxDepth);
134  output.writeInt(dataValues.size()); // number of stations
135  for (Entry<String, StationData> entry : dataValues.entrySet())
136  {
137  GeoTessUtils.writeString(output, entry.getKey()); // station name
138  entry.getValue().write(output, attributes); // StationData
139  }
140  }
141 
142  /**
143  * toString() is the format of the output to ascii files when
144  * a model is written to ascii file. This text will be used to
145  * construct a new GridPointData object from a Scanner.
146  */
147  @Override
148  public String toString() {
149  StringBuffer output = new StringBuffer();
150  output.append(String.format("%1.6f %1.6f %1.6f%n", cellRadius, minDepth, maxDepth));
151  output.append(String.format("%d%n", dataValues.size())); // number of stations
152  for (Entry<String, StationData> e1 : dataValues.entrySet())
153  {
154  output.append(e1.getKey()+'\n'); // station name
155  e1.getValue().write(output, attributes); // Station Data
156  }
157  return output.toString();
158  }
159 
160  public double getCellRadius() {
161  return cellRadius;
162  }
163 
164  public void setCellRadius(double cellRadius) {
165  this.cellRadius = cellRadius;
166  }
167 
168  public double getMinDepth() {
169  return minDepth;
170  }
171 
172  public void setMinDepth(double minDepth) {
173  this.minDepth = minDepth;
174  }
175 
176  public double getMaxDepth() {
177  return maxDepth;
178  }
179 
180  public void setMaxDepth(double maxDepth) {
181  this.maxDepth = maxDepth;
182  }
183 
184  public Map<String, StationData> getDataValues() {
185  return dataValues;
186  }
187 
188  public void setDataValues(Map<String, StationData> dataValues) {
189  this.dataValues = dataValues;
190  }
191 
192  public List<Triple> getindexList() {
193  return indexList;
194  }
195 
196  public void setindexList(List<Triple> indexList) {
197  this.indexList = indexList;
198  }
199 
200  /**
201  * Returns true if this and other are of the same DataType, both have a
202  * single element and those elements are == (or both values are NaN).
203  *
204  * @param other
205  * @return true if this and other are of the same DataType, both have a
206  * single element and those elements are == (or both values are NaN).
207  */
208  @Override
209  public boolean equals(Object other)
210  {
211  if (other == null || !(other instanceof GridPointData))
212  return false;
213 
214  // TODO have to write code here to check that every value and every
215  // index in every map is equal.
216  return true;
217  }
218 
219  @Override
220  public Data getNew() {
221  return new GridPointData();
222  }
223 
224  @Override
225  public Data[] getNew(int n) {
226  throw new UnsupportedOperationException();
227  }
228 
229  @Override
230  public String getDataTypeString() {
231  return this.getClass().getSimpleName();
232  }
233 
234  @Override
235  public DataType getDataType() {
236  return DataType.DOUBLE;
237  }
238 
239  @Override
240  public int size() {
241  return indexList.size();
242  }
243 
244  /**
245  * Get the value of specified attributeIndex,
246  * or NaN if does not exist.
247  */
248  @Override
249  public double getDouble(int attributeIndex) {
250  Triple map = indexList.get(attributeIndex);
251  StationData s = dataValues.get(map.station);
252  if (s == null) return Double.NaN;
253  PhaseData p = s.get(map.phase);
254  if (p == null) return Double.NaN;
255  Double a = p.get(map.attribute);
256  if (a == null) return Double.NaN;
257  return a.doubleValue();
258  }
259 
260  @Override
261  public Data setValue(int attributeIndex, double value) {
262  // as written, this only allows modification of
263  // existing values, not addition of new values.
264  Triple map = indexList.get(attributeIndex);
265  StationData phaseMap = dataValues.get(map.station);
266  if (phaseMap != null)
267  {
268  PhaseData attributeMap = phaseMap.get(map.phase);
269  if (attributeMap != null)
270  attributeMap.put(map.attribute, value);
271  }
272  return this;
273  }
274 
275  /**
276  * Return a deep copy of this.
277  */
278  @Override
279  public Data copy() {
280  // TODO: add code to return a deep copy of this
281  return new GridPointData();
282  }
283 
284  @Override
285  public float getFloat(int attributeIndex) {
286  throw new UnsupportedOperationException();
287  }
288 
289  @Override
290  public long getLong(int attributeIndex) {
291  throw new UnsupportedOperationException();
292  }
293 
294  @Override
295  public int getInt(int attributeIndex) {
296  throw new UnsupportedOperationException();
297  }
298 
299  @Override
300  public short getShort(int attributeIndex) {
301  throw new UnsupportedOperationException();
302  }
303 
304  @Override
305  public byte getByte(int attributeIndex) {
306  throw new UnsupportedOperationException();
307  }
308 
309  @Override
310  public Data setValue(int attributeIndex, float value) {
311  throw new UnsupportedOperationException();
312  }
313 
314  @Override
315  public Data setValue(int attributeIndex, long value) {
316  throw new UnsupportedOperationException();
317  }
318 
319  @Override
320  public Data setValue(int attributeIndex, int value) {
321  throw new UnsupportedOperationException();
322  }
323 
324  @Override
325  public Data setValue(int attributeIndex, short value) {
326  throw new UnsupportedOperationException();
327  }
328 
329  @Override
330  public Data setValue(int attributeIndex, byte value) {
331  throw new UnsupportedOperationException();
332  }
333 
334  @Override
335  public Data fill(Number fillValue) {
336  throw new UnsupportedOperationException();
337  }
338 
339  // Methods that override methods in Map interface
340 
341  @Override
342  public boolean isEmpty() {
343  return dataValues.isEmpty();
344  }
345 
346  @Override
347  public boolean containsKey(Object key) {
348  return dataValues.containsKey(key);
349  }
350 
351  @Override
352  public boolean containsValue(Object value) {
353  return dataValues.containsValue(value);
354  }
355 
356  @Override
357  public StationData get(Object key) {
358  return dataValues.get(key);
359  }
360 
361  @Override
362  public StationData put(String key, StationData value) {
363  return dataValues.put((String)key, (StationData)value);
364  }
365 
366  @Override
367  public StationData remove(Object key) {
368  return dataValues.remove(key);
369  }
370 
371  @Override
372  public void clear() {
373  dataValues.clear();
374  }
375 
376  @Override
377  public Set<String> keySet() {
378  return dataValues.keySet();
379  }
380 
381  @Override
382  public Collection<StationData> values() {
383  return dataValues.values();
384  }
385 
386  @Override
387  public Set<Entry<String, StationData>> entrySet() {
388  return dataValues.entrySet();
389  }
390 
391  @Override
392  public void putAll(Map<? extends String, ? extends StationData> m) {
393  dataValues.putAll(m);
394  }
395 
396 }
gov.sandia.geotess.examples.customdata.GridPointData.toString
String toString()
toString() is the format of the output to ascii files when a model is written to ascii file.
Definition: GridPointData.java:148
gov.sandia.geotess.examples.customdata.GridPointData.getFloat
float getFloat(int attributeIndex)
Definition: GridPointData.java:285
gov.sandia.geotess.examples.customdata.Triple
Definition: Triple.java:4
gov.sandia.geotess.examples.customdata.GridPointData.getNew
Data[] getNew(int n)
Definition: GridPointData.java:225
gov.sandia.geotess.examples.customdata.GridPointData.GridPointData
GridPointData(GeoTessModelGA model, double cellRadius, double minDepth, double maxDepth)
Definition: GridPointData.java:76
gov.sandia.geotess.examples.customdata.GeoTessModelGA.getAttributes
GeoAttributes[] getAttributes()
Definition: GeoTessModelGA.java:242
gov.sandia.geotess.examples.customdata.GridPointData.setValue
Data setValue(int attributeIndex, byte value)
Definition: GridPointData.java:330
gov.sandia.geotess.examples.customdata.GridPointData.copy
Data copy()
Return a deep copy of this.
Definition: GridPointData.java:279
gov.sandia.geotess.examples.customdata.GridPointData.getMinDepth
double getMinDepth()
Definition: GridPointData.java:168
gov.sandia.geotess.examples.customdata.GridPointData.entrySet
Set< Entry< String, StationData > > entrySet()
Definition: GridPointData.java:387
gov.sandia.geotess.examples.customdata.GridPointData.setindexList
void setindexList(List< Triple > indexList)
Definition: GridPointData.java:196
gov.sandia.geotess.examples.customdata.GridPointData.getDouble
double getDouble(int attributeIndex)
Get the value of specified attributeIndex, or NaN if does not exist.
Definition: GridPointData.java:249
gov.sandia.geotess.examples.customdata.GridPointData.equals
boolean equals(Object other)
Returns true if this and other are of the same DataType, both have a single element and those element...
Definition: GridPointData.java:209
gov.sandia.geotess.examples.customdata.GridPointData.getMaxDepth
double getMaxDepth()
Definition: GridPointData.java:176
gov.sandia.geotess.examples.customdata.GridPointData.getNew
Data getNew()
Definition: GridPointData.java:220
gov.sandia.geotess.examples.customdata.GridPointData.GridPointData
GridPointData(Scanner input, GeoTessModelGA model)
Definition: GridPointData.java:92
gov.sandia.geotess.examples.customdata.GridPointData.getDataType
DataType getDataType()
Definition: GridPointData.java:235
gov.sandia.geotess.examples.customdata.GridPointData.put
StationData put(String key, StationData value)
Definition: GridPointData.java:362
gov.sandia.geotess.examples.customdata.GridPointData.containsKey
boolean containsKey(Object key)
Definition: GridPointData.java:347
gov.sandia.geotess.examples.customdata.GridPointData.values
Collection< StationData > values()
Definition: GridPointData.java:382
gov.sandia.geotess.examples.customdata.GridPointData.getCellRadius
double getCellRadius()
Definition: GridPointData.java:160
gov.sandia.geotess.examples.customdata.GridPointData.clear
void clear()
Definition: GridPointData.java:372
gov
gov.sandia.geotess.examples.customdata.GridPointData.getByte
byte getByte(int attributeIndex)
Definition: GridPointData.java:305
gov.sandia.geotess.examples.customdata.GridPointData.setValue
Data setValue(int attributeIndex, long value)
Definition: GridPointData.java:315
gov.sandia.geotess.examples.customdata.GridPointData.getLong
long getLong(int attributeIndex)
Definition: GridPointData.java:290
gov.sandia.geotess.examples.customdata.GridPointData.containsValue
boolean containsValue(Object value)
Definition: GridPointData.java:352
gov.sandia.geotess.examples.customdata.GridPointData.getDataTypeString
String getDataTypeString()
Definition: GridPointData.java:230
gov.sandia.geotess.examples.customdata.GeoTessModelGA
Definition: GeoTessModelGA.java:20
gov.sandia.geotess.examples.customdata.GridPointData.getindexList
List< Triple > getindexList()
Definition: GridPointData.java:192
gov.sandia.geotess.examples.customdata.GridPointData.keySet
Set< String > keySet()
Definition: GridPointData.java:377
gov.sandia.geotess.examples.customdata.GeoTessModelGA.stationNames
String[] stationNames
A list of all the station names supported by this model.
Definition: GeoTessModelGA.java:25
gov.sandia.geotess.examples.customdata.GridPointData.getShort
short getShort(int attributeIndex)
Definition: GridPointData.java:300
gov.sandia.geotess.examples.customdata.GridPointData.setMaxDepth
void setMaxDepth(double maxDepth)
Definition: GridPointData.java:180
gov.sandia.geotess.examples.customdata.GridPointData.GridPointData
GridPointData(DataInputStream input, GeoTessModelGA model)
Definition: GridPointData.java:113
gov.sandia.geotess.examples.customdata.GridPointData.getDataValues
Map< String, StationData > getDataValues()
Definition: GridPointData.java:184
gov.sandia.geotess
gov.sandia.geotess.examples.customdata.GridPointData.fill
Data fill(Number fillValue)
Definition: GridPointData.java:335
gov.sandia.geotess.examples.customdata.PhaseData
Defines travel time information for an event hypothesis at a single grid point and single station - p...
Definition: PhaseData.java:16
gov.sandia.geotess.examples.customdata.GridPointData.GridPointData
GridPointData(GeoTessModelGA model)
Definition: GridPointData.java:69
gov.sandia.geotess.examples.customdata.GridPointData.getInt
int getInt(int attributeIndex)
Definition: GridPointData.java:295
gov.sandia.geotess.examples.customdata.GridPointData.setValue
Data setValue(int attributeIndex, double value)
Definition: GridPointData.java:261
gov.sandia.geotess.examples.customdata.GridPointData
GridPointData manages the information associated with a single point in a GeoTessModel.
Definition: GridPointData.java:26
gov.sandia.geotess.examples.customdata.GridPointData.setValue
Data setValue(int attributeIndex, float value)
Definition: GridPointData.java:310
gov.sandia.geotess.examples.customdata.GridPointData.indexList
List< Triple > indexList
Map from attribute index -> [Station Name, Phase Name, Attribute Name].
Definition: GridPointData.java:57
gov.sandia.geotess.examples.customdata.GridPointData.dataValues
Map< String, StationData > dataValues
Map from Station Name -> Phase Name -> GeoAttribute -> dataValue.
Definition: GridPointData.java:45
gov.sandia.geotess.examples.customdata.GridPointData.setDataValues
void setDataValues(Map< String, StationData > dataValues)
Definition: GridPointData.java:188
gov.sandia.geotess.examples.customdata.GridPointData.isEmpty
boolean isEmpty()
Definition: GridPointData.java:342
gov.sandia.geotess.examples.customdata.GridPointData.setMinDepth
void setMinDepth(double minDepth)
Definition: GridPointData.java:172
gov.sandia.geotess.examples.customdata.GridPointData.size
int size()
Definition: GridPointData.java:240
gov.sandia.geotess.examples.customdata.GeoAttributes
Definition: GeoAttributes.java:3
gov.sandia.geotess.examples.customdata.StationData
Defines information for an event hypothesis at a single grid point and a single station.
Definition: StationData.java:18
gov.sandia.geotess.examples.customdata.GridPointData.setCellRadius
void setCellRadius(double cellRadius)
Definition: GridPointData.java:164
gov.sandia.geotess.examples.customdata.GeoTessModelGA.getIndexList
List< Triple > getIndexList()
Definition: GeoTessModelGA.java:246
gov.sandia.geotess.examples.customdata.GridPointData.GridPointData
GridPointData()
Definition: GridPointData.java:62
gov.sandia.geotess.examples.customdata.GridPointData.setValue
Data setValue(int attributeIndex, int value)
Definition: GridPointData.java:320
gov.sandia.geotess.examples.customdata.GridPointData.write
void write(DataOutputStream output)
Definition: GridPointData.java:130
gov.sandia.geotess.examples.customdata.GridPointData.attributes
GeoAttributes[] attributes
A list of all the attributes supported by this model.
Definition: GridPointData.java:52
gov.sandia.geotess.examples.customdata.GridPointData.putAll
void putAll(Map<? extends String, ? extends StationData > m)
Definition: GridPointData.java:392
gov.sandia
gov.sandia.geotess.examples.customdata.GridPointData.setValue
Data setValue(int attributeIndex, short value)
Definition: GridPointData.java:325