Skip to content

Commit

Permalink
Support height metadata for FDSN (usgs#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
Diana Norgaard committed Jul 27, 2018
1 parent 88cb4d3 commit cb16cc7
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 57 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* Addition of map option to hide station icons (#124)
* Add RSAM value of selected wave panel period to status bar (#103)
* Fix issue with streaming failing on loss of data (#142)
* Fix issue using WWS instrument time zone (#201)
* Fix multiple event dialog showing up under Window menu (#216)
* Fix problem parsing server response from CWB (#221)
* Updated WWS Client to 1.3.5

## Version 2.8.5 - July 13, 2018
* Support real-time wave viewer in layouts (#40)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public abstract class AbstractChannelInfo {
*/
public abstract double getLongitude();

/**
* Get the elevation.
*
* @return the elevation.
*/
public abstract double getHeight();

/**
* Get the network name.
*
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/gov/usgs/volcanoes/swarm/ChannelGroupInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ public ChannelGroupInfo(String s, GroupsType groupsType) {
* @param location the location name.
* @param latitude the latitude.
* @param longitude the longitude.
* @param elevation the elevation
* @param siteName the site name.
* @param groupsType groups type.
*/
public ChannelGroupInfo(String station, String channel, String network, String location,
double latitude, double longitude, String siteName, GroupsType groupsType) {
super(station, channel, network, location, latitude, longitude, siteName);
double latitude, double longitude, double elevation, String siteName, GroupsType groupsType) {
super(station, channel, network, location, latitude, longitude, elevation, siteName);
this.groupsType = groupsType;
}

Expand Down
39 changes: 27 additions & 12 deletions src/main/java/gov/usgs/volcanoes/swarm/ChannelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,28 @@ public ChannelInfo(String s) {
String location = "";
double latitude = Double.NaN;
double longitude = Double.NaN;
double elevation = Double.NaN;

String delimiter = s.indexOf('$') == -1 ? " " : "\\$";
String[] ss = s.split(delimiter);
station = ss[0];
if (ss.length > 2) {
channel = ss[1];
network = ss[2];
if (ss.length > 3) {
location = ss[3];
if (ss.length > 4) {
latitude = StationInfo.parseDouble(ss[4]);
if (ss.length > 5) {
longitude = StationInfo.parseDouble(ss[5]);
}
}
}
}
stationInfo = new StationInfo(station, network, latitude, longitude);
if (ss.length > 3) {
location = ss[3];
}
if (ss.length > 4) {
latitude = StationInfo.parseDouble(ss[4]);
}
if (ss.length > 5) {
longitude = StationInfo.parseDouble(ss[5]);
}
if (ss.length > 6) {
elevation = StationInfo.parseDouble(ss[6]);
}
stationInfo = new StationInfo(station, network, latitude, longitude, elevation);
this.channel = channel;
this.location = location;
formattedSCNL = ChannelUtil.getFormattedSCNL(station, channel, network, location);
Expand All @@ -80,12 +84,14 @@ public ChannelInfo(String s) {
* @param network the network name.
* @param location the location name.
* @param latitude the latitude.
* @param elevation the elevation
* @param longitude the longitude.
* @param siteName the site name.
*/
public ChannelInfo(String station, String channel, String network, String location,
double latitude, double longitude, String siteName) {
this(new StationInfo(station, network, latitude, longitude, siteName), channel, location);
double latitude, double longitude, double elevation, String siteName) {
this(new StationInfo(station, network, latitude, longitude, elevation, siteName), channel,
location);
}

/**
Expand Down Expand Up @@ -177,4 +183,13 @@ public String getStation() {
public StationInfo getStationInfo() {
return stationInfo;
}


/**
* Get elevation.
* @see gov.usgs.volcanoes.swarm.AbstractChannelInfo#getHeight()
*/
public double getHeight() {
return stationInfo.getElevation();
}
}
1 change: 1 addition & 0 deletions src/main/java/gov/usgs/volcanoes/swarm/ChannelUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static String addChannel(List<String> channels, AbstractChannelInfo ch,
Metadata md = SwarmConfig.getInstance().getMetadata(formattedScnl, true);
md.updateLongitude(ch.getLongitude());
md.updateLatitude(ch.getLatitude());
md.updateHeight(ch.getHeight());
for (String g : ch.getGroups()) {
md.addGroup(g);
}
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/gov/usgs/volcanoes/swarm/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,32 +415,6 @@ public int compare(Pair<Double, String> o1, Pair<Double, String> o2) {
};
}

/**
* Find nearest stations to point.
* @param metadata map of metadata
* @param pt point
* @param requireDs true if data source required
* @return list of dance and channels
*/
@Deprecated
public static List<Pair<Double, String>> findNearest(Map<String, Metadata> metadata,
Point2D.Double pt, boolean requireDs) {
ArrayList<Pair<Double, String>> result = new ArrayList<Pair<Double, String>>();
synchronized (metadata) {
for (String key : metadata.keySet()) {
Metadata md = metadata.get(key);
if (md.hasLonLat() && (!requireDs || md.source != null)) {
double d = md.distanceTo(pt);
if (!Double.isNaN(d) && d > 0) {
result.add(new Pair<Double, String>(new Double(d), md.channel));
}
}
}
}
Collections.sort(result, getDistanceComparator());
return result.size() == 0 ? null : result;
}

/**
* Find nearest stations to channel.
* @param metadata map of metadata
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/gov/usgs/volcanoes/swarm/StationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ public static double parseDouble(String s) {

/** The longitude. */
private final double longitude;

/** The height */
private final double elevation;

/** The site name. */
private final String siteName;

public StationInfo(String station, String network, double latitude, double longitude) {
this(station, network, latitude, longitude, (String) null);
public StationInfo(String station, String network, double latitude, double longitude, double elevation) {
this(station, network, latitude, longitude, elevation, (String) null);
}

/**
Expand All @@ -48,14 +51,15 @@ public StationInfo(String station, String network, double latitude, double longi
* @param network network
* @param latitude latitude
* @param longitude longitude
* @param elevation elevation
* @param siteName name
*/
public StationInfo(String station, String network, double latitude, double longitude,
String siteName) {
public StationInfo(String station, String network, double latitude, double longitude, double elevation, String siteName) {
this.station = station;
this.network = network;
this.latitude = latitude;
this.longitude = longitude;
this.elevation = elevation;
this.siteName = siteName != null ? siteName : station;
}

Expand Down Expand Up @@ -110,6 +114,13 @@ public String getStation() {
* @return the string representation of the station information.
*/
public String toString() {
return station + " " + network + " " + latitude + " " + longitude + " " + siteName;
return station + " " + network + " " + latitude + " " + longitude + " " + elevation + " "+ siteName;
}

/**
* @return the elevation
*/
public double getElevation() {
return elevation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,22 @@ public void close() {
* @param location the location.
* @param latitude the latitude.
* @param longitude the longitude.
* @param elevation the elevation
* @param siteName the site name.
* @param groupsType groups type.
* @return the channel information.
*/
protected ChannelInfo createChannelInfo(String station, String channel, String network,
String location, double latitude, double longitude, String siteName, GroupsType groupsType) {
String location, double latitude, double longitude, double elevation, String siteName,
GroupsType groupsType) {
if (currentStation == null) {
if (clearLatLon()) {
latitude = Double.NaN;
longitude = Double.NaN;
elevation = Double.NaN;
}
return new ChannelGroupInfo(station, channel, network, location, latitude, longitude,
elevation,
siteName, groupsType);
} else {
return new ChannelGroupInfo(currentStation, channel, location, groupsType);
Expand All @@ -272,16 +276,18 @@ protected ChannelInfo createChannelInfo(String station, String channel, String n
* @param network the network.
* @param latitude the latitude.
* @param longitude the longitude.
* @param elevation the elevation
* @param siteName the site name.
* @return the station information.
*/
protected StationInfo createStationInfo(String station, String network, double latitude,
double longitude, String siteName) {
double longitude, double elevation, String siteName) {
if (clearLatLon()) {
latitude = Double.NaN;
longitude = Double.NaN;
elevation = Double.NaN;
}
return new StationInfo(station, network, latitude, longitude, siteName);
return new StationInfo(station, network, latitude, longitude, elevation, siteName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ protected void processLine(String line) {
String station = getColumnText(columns, 1);
double latitude = StationInfo.parseDouble(getColumnText(columns, 2));
double longitude = StationInfo.parseDouble(getColumnText(columns, 3));
double elevation = StationInfo.parseDouble(getColumnText(columns, 4));
String siteName = getColumnText(columns, 5);
processStation(createStationInfo(station, network, latitude, longitude, siteName));
processStation(
createStationInfo(station, network, latitude, longitude, elevation, siteName));
}
break;
case CHANNEL:
Expand All @@ -169,8 +171,13 @@ protected void processLine(String line) {
String siteName = null; // site name is not available
double latitude = StationInfo.parseDouble(getColumnText(columns, 4));
double longitude = StationInfo.parseDouble(getColumnText(columns, 5));
processChannel(createChannelInfo(station, channel, network, location, latitude, longitude,
siteName, groupsType));
double elevation = Double.NaN;
if (columns.length > 6) {
elevation = StationInfo.parseDouble(getColumnText(columns, 6));
}
processChannel(
createChannelInfo(station, channel, network, location, latitude, longitude, elevation,
siteName, groupsType));
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ protected boolean checkSchemaVersion(FDSNStationXML staMessage) {
return true;
}
} catch (Exception ex) {
//
}
LOGGER.warn(
"XM schema of this document ({}) does not match this code ({}) , results may be incorrect.",
Expand Down Expand Up @@ -164,15 +165,16 @@ protected void fetch(URL url) throws Exception {
String station = s.getCode();
double latitude = s.getLatitude().getValue();
double longitude = s.getLongitude().getValue();
double elevation = s.getElevation().getValue();

String siteName = null;
if (s.getSite() != null) {
siteName = s.getSite().getName();
}
switch (getLevel()) {
case STATION:
processStation(createStationInfo(station,

network, latitude, longitude, siteName));
network, latitude, longitude, elevation, siteName));
// break;
// case CHANNEL:
// List<Channel> chanList = s.getChannelList();
Expand All @@ -187,8 +189,7 @@ protected void fetch(URL url) throws Exception {
String location = chan.getLocCode();
String channel = chan.getCode();
processChannel(createChannelInfo(station,

channel, network, location, latitude, longitude, siteName, groupsType));
channel, network, location, latitude, longitude, elevation, siteName, groupsType));
}
// break;
// default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void text(String str) throws Exception {}

private double latitude = Double.NaN;
private double longitude = Double.NaN;
private double elevation = Double.NaN;

private String location;
private String network;
Expand Down Expand Up @@ -234,4 +235,9 @@ public String getStation() {
public String getType() {
return type;
}

@Override
public double getHeight() {
return elevation;
}
}
15 changes: 13 additions & 2 deletions src/main/java/gov/usgs/volcanoes/swarm/map/MapMiniPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ public String getLabel() {
}

/**
* Paint.
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
Expand Down Expand Up @@ -553,6 +554,7 @@ protected void determineSelection(MouseEvent e) {
}

/**
* Mouse clicked event.
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
public void mouseClicked(MouseEvent e) {
Expand Down Expand Up @@ -587,11 +589,17 @@ public void setSelected(boolean b) {
}

/**
* Mouse entered event.
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
*/
public void mouseEntered(MouseEvent e) {
MapFrame.getInstance().setStatusText(
activeMetadata.getSCNL().station + ": " + GeoUtils.lonLatToString(activeMetadata.getLonLat()));
String text =
activeMetadata.getSCNL().station + ": "
+ GeoUtils.lonLatToString(activeMetadata.getLonLat());
if (!Double.isNaN(activeMetadata.getHeight()) && activeMetadata.getHeight() != -999.0) {
text += ", " + activeMetadata.getHeight() + " m";
}
MapFrame.getInstance().setStatusText(text);
// setTitleBackground(MOUSEOVER_BACKGROUND);
// parent.setSelectedPanel(this);
}
Expand All @@ -607,6 +615,7 @@ public void mouseExited(MouseEvent e) {
private int deltaY;

/**
* Mouse pressed event.
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
*/
public void mousePressed(MouseEvent e) {
Expand All @@ -622,6 +631,7 @@ public void mousePressed(MouseEvent e) {
}

/**
* Mouse released event.
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
*/
public void mouseReleased(MouseEvent e) {
Expand Down Expand Up @@ -659,6 +669,7 @@ public void adjustLine() {
}

/**
* Mouse dragged event.
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
*/
public void mouseDragged(MouseEvent e) {
Expand Down

0 comments on commit cb16cc7

Please sign in to comment.