Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
add FDSN-WS data source
Browse files Browse the repository at this point in the history
  • Loading branch information
tparker-usgs committed Oct 23, 2019
1 parent 2695744 commit 1ccc6bf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
50 changes: 41 additions & 9 deletions src/main/java/gov/usgs/volcanoes/pensive/FdsnwsSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.iris.dmc.seedcodec.CodecException;
import edu.iris.dmc.seedcodec.DecompressedData;
import edu.iris.dmc.seedcodec.UnsupportedCompressionType;
import edu.sc.seis.seisFile.ChannelTimeWindow;
import edu.sc.seis.seisFile.SeisFileException;
import edu.sc.seis.seisFile.fdsnws.FDSNDataSelectQuerier;
import edu.sc.seis.seisFile.fdsnws.FDSNDataSelectQueryParams;
Expand All @@ -16,13 +17,13 @@
import edu.sc.seis.seisFile.mseed.DataRecordIterator;
import edu.sc.seis.seisFile.mseed.SeedFormatException;

import gov.usgs.volcanoes.core.configfile.ConfigFile;
import gov.usgs.volcanoes.core.data.HelicorderData;
import gov.usgs.volcanoes.core.data.Wave;
import gov.usgs.volcanoes.core.time.J2kSec;
import gov.usgs.volcanoes.swarm.data.GulperListener;
import gov.usgs.volcanoes.swarm.data.SeismicDataSource;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -38,10 +39,10 @@ public class FdsnwsSource extends SeismicDataSource {
private final String user;
private final String password;

public FdsnwsSource(String dataselectUri, String user, String password) {
this.dataselectUri = dataselectUri;
this.user = user;
this.password = password;
public FdsnwsSource(final ConfigFile config) {
this.dataselectUri = config.getString("dataselectUrl");
this.user = config.getString("user", null);
this.password = config.getString("password", null);
}


Expand All @@ -55,7 +56,7 @@ public void parse(String params) {
throw new UnsupportedOperationException();
}

private FDSNDataSelectQueryParams configureParams(String station, double t1, double t2) {
private FDSNDataSelectQueryParams configureParamsOld(String station, double t1, double t2) {
System.out.println("Station: " + station);
String[] parts = station.split("\\s+");
FDSNDataSelectQueryParams queryParams = new FDSNDataSelectQueryParams();
Expand Down Expand Up @@ -84,6 +85,25 @@ private FDSNDataSelectQueryParams configureParams(String station, double t1, dou
return queryParams;
}

private FDSNDataSelectQueryParams configureParams() {
FDSNDataSelectQueryParams queryParams = new FDSNDataSelectQueryParams();

URI uri;
try {
uri = new URI(dataselectUri);
queryParams.setScheme(uri.getScheme());
queryParams.setPort(uri.getPort());
queryParams.setFdsnwsPath(uri.getPath());
queryParams.setHost(uri.getHost());
System.out.println(queryParams.formURI());
} catch (URISyntaxException e) {
throw new RuntimeException(
"Cannot parse URI " + dataselectUri + ": " + e.getLocalizedMessage());
}

return queryParams;
}

private static double btimeToJ2k(Btime btime) {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.set(Calendar.YEAR, btime.getYear());
Expand Down Expand Up @@ -133,11 +153,23 @@ private Wave readResponse(DataRecordIterator it)

@Override
public Wave getWave(String station, double t1, double t2) {
FDSNDataSelectQueryParams queryParams = configureParams(station, t1, t2);
FDSNDataSelectQuerier querier = new FDSNDataSelectQuerier(queryParams);
FDSNDataSelectQueryParams queryParams = configureParams();
String[] parts = station.split("\\s+");
String sta = parts[0];
String cha = parts[1];
String net = parts[2];
String loc = "";
if (parts.length > 3) {
loc = parts[3];
}

ChannelTimeWindow channelTime = new ChannelTimeWindow(net, sta, loc, cha, J2kSec.asDate(t1), J2kSec.asDate(t2));
List<ChannelTimeWindow> request = new ArrayList<ChannelTimeWindow>();
request.add(channelTime);
FDSNDataSelectQuerier querier = new FDSNDataSelectQuerier(queryParams, request);
if (user != null) {
querier.enableRestrictedData(user, password);
}
}

DataRecordIterator it = null;
Wave wave = null;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/gov/usgs/volcanoes/pensive/WaveSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public WaveSource(final String name, final BlockingQueue<PlotJob> plotJobs,
dsString = String.format("%s;ws:%s:%d:%d:1800:1000:UTC", name, host, port, timeout * 1000);
dataSource = DataSourceType.parseConfig(dsString);
} else if (type.equals("fdsnws")) {
String user = config.getString("user", null);
String password = config.getString("password", null);
dataSource = new FdsnwsSource(config.getString("dataselectUrl"), user, password);
dataSource = new FdsnwsSource(config);
} else {
throw new RuntimeException("Unknown wave server type");
}
Expand Down

0 comments on commit 1ccc6bf

Please sign in to comment.