@@ -3,21 +3,35 @@ |
import java.util.ArrayList; |
|
/** |
-* Last Updated: 1-July-2014 |
+* Last Updated: 9-July-2014 |
* @author Tyler Wible |
* @since 25-January-2014 |
*/ |
public class Data { |
- public String[][] extractFlowData(String mainFolder, String organizationName, String stationID, String beginDate, String endDate, String userData) throws IOException, InterruptedException{ |
+ /** |
+ * Main Data extraction for daily flow data from the various databases that this tool can access |
+ * @param mainFolder the output file location (used by STORET Data extraction) |
+ * @param database the database from which to extract daily flow data (USGS, UserData, STORET, or CDWR) |
+ * @param organizationName the organization which provided the data to the database (used by STORET Data extraction) |
+ * @param stationID the station ID for which flow data is desired |
+ * @param beginDate the begin date of desired flow data (yyyy-MM-dd) |
+ * @param endDate the end date of desired flow data (yyyy-MM-dd) |
+ * @param userData a concatenated string of User Data (tab-delimited) to extract flow data from (column1 = date, column2 = value) |
+ * @return a String[][] of all the flow data available for the specified period (column1 = date yyyy-MM-dd format, column2 = value) |
+ * @throws Exception |
+ */ |
+ public String[][] extractFlowData(String mainFolder, |
+ String database, |
+ String organizationName, |
+ String stationID, |
+ String beginDate, |
+ String endDate, |
+ String userData) throws Exception{ |
//Depending on the provided inputs, search for and return flow data |
- USGS_Data usgs_Data = new USGS_Data(); |
- User_Data user_Data = new User_Data(); |
- STORET_Data storet_Data = new STORET_Data(); |
- |
String[][] flowData = new String[0][2]; |
- if(organizationName.equalsIgnoreCase("USGS")){ |
- |
+ if(database.equalsIgnoreCase("USGS")){ |
//Search for USGS flow data |
+ USGS_Data usgs_Data = new USGS_Data(); |
Object[] returnArray = usgs_Data.getUSGSflowData(stationID, beginDate, endDate); |
//ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
flowData = (String[][]) returnArray[1]; |
@@ -37,29 +51,57 @@ |
flowData = usgs_Data.getUSGSwqFlowData(flowData, allWQdata, beginDate, endDate); |
} |
|
- }else if(organizationName.equalsIgnoreCase("UserData")){ |
+ }else if(database.equalsIgnoreCase("UserData")){ |
//Find the user uploaded data file and uses this for a timeseries graph |
+ User_Data user_Data = new User_Data(); |
flowData = user_Data.readUserFile(userData, "flow", beginDate, endDate); |
|
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
//Search for STORET peak flow data |
+ STORET_Data storet_Data = new STORET_Data(); |
String zip_location = storet_Data.downloadSTORET(mainFolder, organizationName, stationID, "flow", beginDate, endDate); |
|
//Unzip results file and extract all flow data |
flowData = storet_Data.Unzip_STORETDownloadFiles(zip_location, "flow", true); |
+ |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ //Search for CDWR flow data |
+ CDWR_Data cdwr_Data = new CDWR_Data(); |
+ Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Daily"); |
+ //ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
+ flowData = (String[][]) returnArray[1]; |
+ //String start = (String) returnArray[2]; |
+ //String end = (String) returnArray[3]; |
} |
|
return flowData; |
} |
- public Object[] extractWQdata(String mainFolder, String organizationName, String stationID, String beginDate, String endDate, String userData, String wqTest) throws IOException, InterruptedException{ |
- USGS_Data usgs_Data = new USGS_Data(); |
- User_Data user_Data = new User_Data(); |
- STORET_Data storet_Data = new STORET_Data(); |
- |
+ /** |
+ * Main Data extraction for water quality data from the various databases that this tool can access |
+ * @param mainFolder the output file location (used by STORET Data extraction) |
+ * @param database the database from which to extract water quality data (USGS, UserData, STORET, or CDWR) |
+ * @param organizationName the organization which provided the data to the database (used by STORET Data extraction) |
+ * @param stationID the station ID for which water quality data is desired |
+ * @param beginDate the begin date of desired water quality data (yyyy-MM-dd) |
+ * @param endDate the end date of desired water quality data (yyyy-MM-dd) |
+ * @param userData a concatenated string of User Data (tab-delimited) to extract water quality data from (column1 = date, column2 = value) |
+ * @param wqTest the water quality test desired (if USGS it is the 5-digit water quality code for their database) |
+ * @return a String[][] of all the specified water quality data available for the specified period (column1 = date yyyy-MM-dd format, column2 = value) |
+ * @throws IOException |
+ * @throws InterruptedException |
+ */ |
+ public Object[] extractWQdata(String mainFolder, |
+ String database, |
+ String organizationName, |
+ String stationID, |
+ String beginDate, |
+ String endDate, |
+ String userData, |
+ String wqTest) throws IOException, InterruptedException{ |
String[][] WQdata = new String[0][2]; |
String WQlabel = "??"; |
String graphUnits = "??"; |
- if(organizationName.equalsIgnoreCase("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
if(wqTest.length() > 5){ |
//Pull only the code portion of the WQ test |
int endIndex = wqTest.lastIndexOf(", "); |
@@ -72,6 +114,7 @@ |
} |
|
//Retrieve all WQ data from USGS website |
+ USGS_Data usgs_Data = new USGS_Data(); |
Object[] returnArray1 = usgs_Data.getUSGSwqData(stationID); |
//ArrayList<String> webpageAll = (ArrayList<String>) returnArray1[0]; |
String[][] allWQdata = (String[][]) returnArray1[1]; |
@@ -84,7 +127,7 @@ |
//Get Units and conversion for current WQ test |
graphUnits = usgs_Data.getUSGSwqUnits(wqTest); |
|
- }else if(organizationName.equalsIgnoreCase("UserData")){ |
+ }else if(database.equalsIgnoreCase("UserData")){ |
if(wqTest.length() > 5){ |
//Pull only the code portion of the WQ test |
int endIndex = wqTest.lastIndexOf(", "); |
@@ -97,35 +140,61 @@ |
} |
|
//Find the user uploaded data file and uses this for a timeseries graph |
+ User_Data user_Data = new User_Data(); |
Object[] returnArray = user_Data.readUserFile(userData, wqTest, beginDate, endDate); |
WQdata = (String[][]) returnArray[1]; |
|
//Use the header to get the WQ test name |
+ USGS_Data usgs_Data = new USGS_Data(); |
graphUnits = usgs_Data.getUSGSwqUnits(wqTest);//Because user uploaded file headers are wqTest |
|
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
//Search for STORET flow data |
+ STORET_Data storet_Data = new STORET_Data(); |
String zipLocation = storet_Data.downloadSTORET(mainFolder, organizationName, stationID, "flow", beginDate, endDate); |
|
//Unzip results file and extract all flow and WQ results |
WQdata = storet_Data.Unzip_STORETDownloadFiles(zipLocation, wqTest, true); |
WQlabel = wqTest; |
graphUnits = "mg/L"; |
+ |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ ArrayList<String> errorMessage = new ArrayList<String>(); |
+ errorMessage.add("There is no available water quality data available for the CDWR database. This feature is only available for stations in the USGS or STORET databases."); |
+ writeError(errorMessage); |
} |
|
Object[] returnArray = {WQdata, graphUnits, WQlabel}; |
return returnArray; |
} |
- public Object[] extractFlow_and_WQdata(String mainFolder, String organizationName, String stationID, String beginDate, String endDate, String userData, String wqTest) throws IOException, InterruptedException{ |
- USGS_Data usgs_Data = new USGS_Data(); |
- User_Data user_Data = new User_Data(); |
- STORET_Data storet_Data = new STORET_Data(); |
- |
+ /** |
+ * Main Data extraction for daily flow and water quality data from the various databases that this tool can access (used for LDC and LOADEST) |
+ * @param mainFolder the output file location (used by STORET Data extraction) |
+ * @param database the database from which to extract water quality data (USGS, UserData, STORET, or CDWR) |
+ * @param organizationName the organization which provided the data to the database (used by STORET Data extraction) |
+ * @param stationID the station ID for which flow and water quality data is desired |
+ * @param beginDate the begin date of desired flow and water quality data (yyyy-MM-dd) |
+ * @param endDate the end date of desired flow and water quality data (yyyy-MM-dd) |
+ * @param userData a concatenated string of User Data (tab-delimited) to extract flow (column1 = date, column2 = value) |
+ * and water quality data (column1 = date, column2 = value) with a "$$" delimiter between the two types of data |
+ * @param wqTest the water quality test desired (if USGS it is the 5-digit water quality code for their database) |
+ * @return a String[][] of all the specified water quality data available for the specified period (column1 = date yyyy-MM-dd format, column2 = value) |
+ * @throws IOException |
+ * @throws InterruptedException |
+ */ |
+ public Object[] extractFlow_and_WQdata(String mainFolder, |
+ String database, |
+ String organizationName, |
+ String stationID, |
+ String beginDate, |
+ String endDate, |
+ String userData, |
+ String wqTest) throws IOException, InterruptedException{ |
String[][] flowData = new String[0][2]; |
String[][] WQdata = new String[0][2]; |
- if(organizationName.equalsIgnoreCase("USGS")){ |
- |
+ if(database.equalsIgnoreCase("USGS")){ |
//Search for USGS flow data |
+ USGS_Data usgs_Data = new USGS_Data(); |
Object[] returnArray = usgs_Data.getUSGSflowData(stationID, beginDate, endDate); |
//ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
flowData = (String[][]) returnArray[1]; |
@@ -155,41 +224,65 @@ |
//Extract and combine USGS discharge water quality codes with the flow dataset |
flowData = usgs_Data.getUSGSwqFlowData(flowData, allWQdata, beginDate, endDate); |
|
- }else if(organizationName.equalsIgnoreCase("UserData")){ |
+ }else if(database.equalsIgnoreCase("UserData")){ |
//Find the user uploaded data file and uses this for a timeseries graph |
+ User_Data user_Data = new User_Data(); |
Object[] returnArray = user_Data.readUserFileLDC(userData, wqTest, beginDate, endDate); |
flowData = (String[][]) returnArray[0]; |
WQdata = (String[][]) returnArray[1]; |
|
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
//Search for STORET flow data |
+ STORET_Data storet_Data = new STORET_Data(); |
String zipLocation = storet_Data.downloadSTORET(mainFolder, organizationName, stationID, "flow", beginDate, endDate); |
|
//Unzip results file and extract all flow and WQ results |
flowData = storet_Data.Unzip_STORETDownloadFiles(zipLocation, "flow", false); |
WQdata = storet_Data.Unzip_STORETDownloadFiles(zipLocation, wqTest, true); |
+ |
+ }else if(database.equalsIgnoreCase("UserData")){ |
+ ArrayList<String> errorMessage = new ArrayList<String>(); |
+ errorMessage.add("There is no available water quality data available for the CDWR database. This feature is only available for stations in the USGS or STORET databases."); |
+ writeError(errorMessage); |
} |
|
Object[] returnArray = {flowData, WQdata}; |
return returnArray; |
} |
- public double[][] extractFloodData(String mainFolder, String organizationName, String stationID, String beginDate, String endDate, String userData) throws IOException{ |
- USGS_Data usgs_Data = new USGS_Data(); |
- User_Data user_Data = new User_Data(); |
- STORET_Data storet_Data = new STORET_Data(); |
+ /** |
+ * Main Data extraction for flood flow data from the various databases that this tool can access |
+ * @param mainFolder the output file location (used by STORET Data extraction) |
+ * @param database the database from which to extract daily flow data (USGS, UserData, STORET, or CDWR) |
+ * @param organizationName the organization which provided the data to the database (used by STORET Data extraction) |
+ * @param stationID the station ID for which flow data is desired |
+ * @param beginDate the begin date of desired flow data (yyyy-MM-dd) |
+ * @param endDate the end date of desired flow data (yyyy-MM-dd) |
+ * @param userData a concatenated string of User Data (tab-delimited) to extract flow data from (column1 = date, column2 = value) |
+ * @return a String[][] of all the flow data available for the specified period (column1 = date yyyy-MM-dd format, column2 = value) |
+ * @throws Exception |
+ */ |
+ public double[][] extractFloodData(String mainFolder, |
+ String database, |
+ String organizationName, |
+ String stationID, |
+ String beginDate, |
+ String endDate, |
+ String userData) throws IOException, Exception{ |
DoubleArray doubleArray = new DoubleArray(); |
|
double[][] peakFlowData = new double[0][0]; |
- if(organizationName.equalsIgnoreCase("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
//Search for USGS peak flow data |
+ USGS_Data usgs_Data = new USGS_Data(); |
Object[] returnArray = usgs_Data.getUSGSPeakData(stationID, beginDate, endDate); |
//ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
peakFlowData = (double[][]) returnArray[1]; |
//double start = (double) returnArray[2]; |
//double end = (double) returnArray[3]; |
|
- }else if(organizationName.equalsIgnoreCase("UserData")){ |
+ }else if(database.equalsIgnoreCase("UserData")){ |
//Find the user uploaded data file and uses this for a timeseries graph |
+ User_Data user_Data = new User_Data(); |
String[][] flowData = user_Data.readUserFile(userData, "flow", beginDate, endDate); |
|
//Removed duplicate dates |
@@ -198,9 +291,10 @@ |
//Convert into an annual peak time series |
peakFlowData = doubleArray.convertSTORETpeakData(flowData); |
|
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
//Search for STORET peak flow data |
System.out.println("calling downloadSTORET"); |
+ STORET_Data storet_Data = new STORET_Data(); |
String zip_location = storet_Data.downloadSTORET(mainFolder, organizationName, stationID, "flow", beginDate, endDate); |
|
//Unzip results file and extract all flow data |
@@ -211,63 +305,105 @@ |
|
//Convert into an annual peak time series |
peakFlowData = doubleArray.convertSTORETpeakData(flowData); |
+ |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ //Search for CDWR flow data |
+ CDWR_Data cdwr_Data = new CDWR_Data(); |
+ Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Daily"); |
+ //ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
+ String[][] flowData = (String[][]) returnArray[1]; |
+ //double start = (double) returnArray[2]; |
+ //double end = (double) returnArray[3]; |
+ |
+ //Removed duplicate dates |
+ flowData = doubleArray.removeDuplicateDates(flowData); |
+ |
+ //Convert into an annual peak time series |
+ peakFlowData = doubleArray.convertSTORETpeakData(flowData); |
} |
|
return peakFlowData; |
} |
/** |
- * Extracts 15 minute data from USGS and/or User data (as long as the date is formatted properly) returns an error otherwise |
- * @param mainFolder |
- * @param organizationName |
- * @param stationID |
- * @param beginDate |
- * @param endDate |
- * @param userData |
- * @return |
+ * Extracts 15 minute data from USGS and/or User data or hourly data from CDWR (as long as the date is formatted properly) returns an error otherwise |
+ * @param mainFolder the output file location (used by STORET Data extraction) |
+ * @param database the database from which to extract water quality data (USGS, UserData, STORET, or CDWR) |
+ * @param stationID the station ID for which flow and water quality data is desired |
+ * @param beginDate the begin date of desired flow and water quality data (yyyy-MM-dd) |
+ * @param endDate the end date of desired flow and water quality data (yyyy-MM-dd) |
+ * @param userData a concatenated string of User Data (tab-delimited) to extract flow (column1 = date, column2 = value) |
+ * @return a String[][] of all the specified 15-minute flow data available for the specified period (column1 = date yyyy-MM-dd HH:mm format, column2 = value) |
* @throws IOException |
* @throws InterruptedException |
+ * @throws Exception |
*/ |
- public String[][] extract15minFlowData(String mainFolder, String organizationName, String stationID, String beginDate, String endDate, String userData) throws IOException, InterruptedException{ |
+ public String[][] extractInstantaneousFlowData(String mainFolder, |
+ String database, |
+ String stationID, |
+ String beginDate, |
+ String endDate, |
+ String userData) throws IOException, InterruptedException, Exception{ |
//Depending on the provided inputs, search for and return flow data |
- USGS_Data usgs_Data = new USGS_Data(); |
- User_Data user_Data = new User_Data(); |
- |
String[][] flowData = new String[0][2]; |
- if(organizationName.equalsIgnoreCase("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
//Search for USGS flow data |
+ USGS_Data usgs_Data = new USGS_Data(); |
Object[] returnArray = usgs_Data.getUSGS15minFlowData(stationID, beginDate, endDate); |
//ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
flowData = (String[][]) returnArray[1]; |
//String start = (String) returnArray[2]; |
//String end = (String) returnArray[3]; |
|
- }else if(organizationName.equalsIgnoreCase("UserData")){ |
+ }else if(database.equalsIgnoreCase("UserData")){ |
//Find the user uploaded data file and uses this for a timeseries graph |
+ User_Data user_Data = new User_Data(); |
flowData = user_Data.read15minUserFile(userData, "flow", beginDate + " 00:00", endDate + " 23:00"); |
|
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
ArrayList<String> errorMessage = new ArrayList<String>(); |
errorMessage.add("There is no available 15-minute flow data available for the STORET database. This feature is only available for stations in the USGS NWIS database."); |
writeError(errorMessage); |
+ |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ //Search for CDWR flow data |
+ CDWR_Data cdwr_Data = new CDWR_Data(); |
+ Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Hourly"); |
+ //ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
+ flowData = (String[][]) returnArray[1]; |
+ //String start = (String) returnArray[2]; |
+ //String end = (String) returnArray[3]; |
} |
|
return flowData; |
} |
- public double[][] extractStageDischarge(String mainFolder, String organizationName, String stationID) throws IOException{ |
+ /** |
+ * Main Data extraction for stage-discharge relationship data from the various databases that this tool can access |
+ * @param database the database from which to extract data (USGS, UserData, STORET, or CDWR) |
+ * @param stationID the station ID for which data is desired |
+ * @return |
+ * @throws IOException |
+ */ |
+ public double[][] extractStageDischarge(String database, String stationID) throws IOException, Exception{ |
//Depending on the provided inputs, search for and return flow data |
- USGS_Data usgs_Data = new USGS_Data(); |
- |
double[][] ratingCurve = new double[0][2]; |
- if(organizationName.equalsIgnoreCase("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
//Search for USGS flow data |
+ USGS_Data usgs_Data = new USGS_Data(); |
Object[] returnArray = usgs_Data.getUSGSratingCurve(stationID); |
//ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
ratingCurve = (double[][]) returnArray[1]; |
|
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
ArrayList<String> errorMessage = new ArrayList<String>(); |
- errorMessage.add("There is no rating curve data available for non-USGS NWIS stations."); |
+ errorMessage.add("There is no rating curve data available for STORET stations."); |
writeError(errorMessage); |
+ |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ //Search for USGS flow data |
+ CDWR_Data cdwr_Data = new CDWR_Data(); |
+ Object[] returnArray = cdwr_Data.getCDWRratingCurve(stationID); |
+ //ArrayList<String> webpageAll = (ArrayList<String>) returnArray[0]; |
+ ratingCurve = (double[][]) returnArray[1]; |
} |
|
return ratingCurve; |
@@ -24,15 +24,16 @@ |
import org.jfree.data.time.TimeSeries; |
|
/** |
-* Last Updated: 1-July-2014 |
+* Last Updated: 10-July-2014 |
* @author Tyler Wible |
* @since 23-June-2014 |
*/ |
public class gui15minTimeseries_Model { |
String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA/Timeseries"; |
- String organizationName = "USGS"; |
- String stationID = "06752260";//"06752000";// |
- String stationName = "CACHE LA POUDRE RIVER AT FORT COLLINS, CO"; |
+ String database = "USGS";//"CDWR";//"STORET";//"UserData";// |
+ String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";// |
+ String stationID = "06752260";//"CLAGRECO";//"000028";// |
+ String stationName = "CACHE LA POUDRE RIVER AT FORT COLLINS, CO";//"Cache La Poudre Near Greeley";//"BIG THOMPSON R NEAR MOUTH";// |
String beginDate = "";//yyyy-MM-dd |
String endDate = "";//yyyy-MM-dd |
String userData = "";//"Date\tFlow\n1999-04-29 00:00\t8.3\n1999-05-09 00:00\t60.2\n1999-05-29 00:00\t20.1";// |
@@ -98,6 +99,9 @@ |
public void setMainFolder(String mainFolder) { |
this.mainFolder = mainFolder; |
} |
+ public void setDatabase(String database) { |
+ this.database = database; |
+ } |
public void setOrganizationName(String organizationName) { |
this.organizationName = organizationName; |
} |
@@ -223,7 +227,7 @@ |
*/ |
private void createTimeseriesGraph(String[][] sortedData, |
String[][] sortedData_user) throws ParseException, IOException { |
- //Change analysis period dates into calendar objects |
+ //Change analysis period dates into Date objects |
// SimpleDateFormat desiredDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
// Date period1Begin_date = new Date(); |
// Date period1End_date = new Date(); |
@@ -422,8 +426,8 @@ |
plotTime = graphing.setTimeAxisPreferences(plotTime); |
|
//Create the chart with the plot and a legend |
- String title = "Time Series for Station: " + stationID + "; " + stationName; |
- JFreeChart chart = new JFreeChart(title, graphing.titleFont, plotTime, showLegend); |
+ String graphTitle = "Time Series for " + database + " Station " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plotTime, showLegend); |
|
//Set legend Font |
if(showLegend){ |
@@ -478,7 +482,7 @@ |
writer.close(); |
System.out.println("Text File located at:\t" + path); |
} |
- public void run() throws IOException, InterruptedException, ParseException{ |
+ public void run() throws IOException, InterruptedException, ParseException, Exception{ |
//If no date input, make it the maximum of available data |
if(beginDate == null || beginDate.equalsIgnoreCase("")){ |
beginDate = "2007-10-01"; |
@@ -500,7 +504,7 @@ |
|
//Check if any flow data exists |
Data data = new Data(); |
- String[][] sortableData = data.extract15minFlowData(mainFolder, organizationName, stationID, beginDate, endDate, userData); |
+ String[][] sortableData = data.extractInstantaneousFlowData(mainFolder, database, stationID, beginDate, endDate, userData); |
|
//If the user wants the datasets (public and user) merged then retrieve the second dataset (user) |
String[][] sortableData_user = new String[0][0]; |
@@ -519,11 +523,10 @@ |
if(sortedData_combined.length == 0){ |
ArrayList<String> errorMessage = new ArrayList<String>(); |
if(sortableData.length == 0){ |
- String database = "USGS"; |
- if(!organizationName.equals("USGS")){ |
- database = "STORET"; |
+ errorMessage.add("There is no available 15-minute (instantaneous) flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ if(database.equalsIgnoreCase("CDWR")){ |
+ errorMessage.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
} |
- errorMessage.add("There is no available 15-minute (instantaneous) flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
} |
if(sortableData_user.length == 0){ |
errorMessage.add("There is no available 15-minute (instantaneous) uploaded data for station '" + stationID + "' and the specified date range"); |
@@ -545,7 +548,11 @@ |
Date currentDate = new Date(); |
SimpleDateFormat sourceDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
String today = sourceDateFormat.format(currentDate); |
- this.dataSource = "Stream flow data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
+ if(database.equalsIgnoreCase("USGS")){ |
+ this.dataSource = "Stream flow data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ this.dataSource = "Stream flow data courtesy of the Colorado Division of Water Resources, CDWR. http://www.dwr.state.co.us accessed: " + today; |
+ } |
this.len = String.valueOf(sortedData_combined.length); |
this.units = "cfs"; |
} |
@@ -29,16 +29,17 @@ |
|
|
/** |
- * Last Updated: 1-July-2014 |
+ * Last Updated: 10-July-2014 |
* @author Tyler Wible |
* @since 15-June-2012 |
*/ |
public class guiBaseflow_Model { |
//Inputs |
String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA/Baseflow";//"/od/projects/cfa/GUI_FlowAnalysis"; |
- String organizationName = "USGS"; |
- String stationID = "06741510"; |
- String stationName = "USGS BIG THOMPSON RIVER AT LOVELAND, CO."; |
+ String database = "USGS";//"CDWR";//"STORET";//"UserData";// |
+ String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";// |
+ String stationID = "06741510";//"CLAGRECO";//"000028";// |
+ String stationName = "BIG THOMPSON RIVER AT LOVELAND, CO.";//"Cache La Poudre Near Greeley";//"BIG THOMPSON R NEAR MOUTH";// |
double drainageArea = 27.3;//Square miles |
String modelType = "BFLOW";//"HYSEP";// |
String beginDate = "";//"1900-01-01"; |
@@ -86,6 +87,9 @@ |
public void setMainFolder(String mainFolder) { |
this.mainFolder = mainFolder; |
} |
+ public void setDatabase(String database) { |
+ this.database = database; |
+ } |
public void setOrganizationName(String organizationName) { |
this.organizationName = organizationName; |
} |
@@ -151,10 +155,12 @@ |
Date currentDate = new Date(); |
SimpleDateFormat sourceDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
String today = sourceDateFormat.format(currentDate); |
- if(organizationName.equalsIgnoreCase("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
this.dataSource = "Stream flow data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
this.dataSource = "Stream flow data courtesy of the U.S. Environmental Protection Agency, STORET. http://www.epa.gov/storet/index.html accessed: " + today; |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ this.dataSource = "Stream flow data courtesy of the Colorado Division of Water Resources, CDWR. http://www.dwr.state.co.us accessed: " + today; |
} |
this.len = String.valueOf(allFlowData.length); |
this.start = allFlowData[0][0]; |
@@ -204,17 +210,9 @@ |
} |
/** |
* Graph the 3-pass base-flow separation results from "BFLOW" |
- * @param mainFolder the file location where the input file is and where graph will be saved |
- * @param organizationName the name of the supervising agency for the current station |
- * @param stationID the station ID of the current station, used for graph labels and error catches |
- * @param stationName the name of the current station, used for graph labels |
* @throws IOException |
*/ |
- private void graphBFLOWresults(String mainFolder, |
- String organizationName, |
- String stationID, |
- String stationName, |
- String[][] sortedData_user) throws IOException{ |
+ private void graphBFLOWresults(String[][] sortedData_user) throws IOException{ |
DoubleMath doubleMath = new DoubleMath(); |
Graphing graphing = new Graphing(); |
|
@@ -329,8 +327,8 @@ |
graphing.setTimeAxisPreferences(plotTime); |
|
//Graph plot onto JfreeChart |
- String title = "BFLOW Base-flow Separation For Station: " + stationID + ", " + stationName + " Agency: " + organizationName; |
- JFreeChart parentChart = new JFreeChart(title, graphing.titleFont, plotTime, true); |
+ String graphTitle = "BFLOW Base-flow Separation for " + database + " Station " + stationID + "; " + stationName; |
+ JFreeChart parentChart = new JFreeChart(graphTitle, graphing.titleFont, plotTime, true); |
|
//Set legend Font |
LegendTitle legendTitle = parentChart.getLegend(); |
@@ -561,10 +559,12 @@ |
Date currentDate = new Date(); |
SimpleDateFormat sourceDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
String today = sourceDateFormat.format(currentDate); |
- if(organizationName.equalsIgnoreCase("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
this.dataSource = "Stream flow data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
this.dataSource = "Stream flow data courtesy of the U.S. Environmental Protection Agency, STORET. http://www.epa.gov/storet/index.html accessed: " + today; |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ this.dataSource = "Stream flow data and water quality test data courtesy of the Colorado Division of Water Resources, CDWR. http://www.dwr.state.co.us accessed: " + today; |
} |
this.len = String.valueOf(allFlowData.length); |
this.start = allFlowData[0][0]; |
@@ -667,13 +667,9 @@ |
} |
/** |
* Graph the hydrograph separation results from "HYSEP |
- * @param mainFolder the file location where the input file is and where graph will be saved |
- * @param organizationName the name of the supervising agency for the current station |
- * @param stationID the station ID of the current station, used for graph labels and error catches |
- * @param stationName the name of the current station, used for graph labels |
* @throws IOException |
*/ |
- private void graphHYSEPresults(String mainFolder, String organizationName, String stationID, String stationName) throws IOException{ |
+ private void graphHYSEPresults() throws IOException{ |
Graphing graphing = new Graphing(); |
|
|
@@ -749,7 +745,7 @@ |
graphing.setTimeAxisPreferences(plotTime); |
|
//Graph plot onto JfreeChart |
- String title = "USGS-HYSEP Hydrograph Separation For Station: " + stationID + ", " + stationName + " By: " + organizationName; |
+ String title = "USGS-HYSEP Hydrograph Separation For " + database + " Station: " + stationID + ", " + stationName; |
JFreeChart parentChart = new JFreeChart(title, graphing.titleFont, plotTime, true); |
|
//Set legend Font |
@@ -916,7 +912,7 @@ |
throw new IOException("Error encountered. Please see the following message for details: \n" + errorContents); |
} |
|
- public void run() throws IOException, InterruptedException { |
+ public void run() throws IOException, InterruptedException, Exception { |
//If no date input, make it the maximum of available data |
if(beginDate == null || beginDate.equalsIgnoreCase("")){ |
beginDate = "1900-01-01"; |
@@ -930,7 +926,7 @@ |
|
//Check if any flow data exists |
Data data = new Data(); |
- String[][] sortableData = data.extractFlowData(mainFolder, organizationName, stationID, beginDate, endDate, userData); |
+ String[][] sortableData = data.extractFlowData(mainFolder, database, organizationName, stationID, beginDate, endDate, userData); |
|
//If the user wants the datasets (public and user) merged then retrieve the second dataset (user) |
String[][] sortableData_user = new String[0][0]; |
@@ -947,18 +943,16 @@ |
//Merge the two datasets (if user data is empty nothing will be merged) |
String[][] sortedData_combined = doubleArray.mergeData(sortedData, sortedData_user, mergeMethod); |
if(sortedData_combined.length == 0){ |
- ArrayList<String> errorMessage = new ArrayList<>(); |
+ ArrayList<String> errorMessage = new ArrayList<String>(); |
if(sortedData.length == 0){ |
- String database = "USGS"; |
- if(!organizationName.equals("USGS")){ |
- database = "STORET"; |
+ errorMessage.add("There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ if(database.equalsIgnoreCase("CDWR")){ |
+ errorMessage.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
} |
- errorMessage.add("There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
} |
if(sortedData_user.length == 0){ |
errorMessage.add("There is no available uploaded data for station '" + stationID + "' and the specified date range"); |
} |
- errorMessage.add("Error: Baseflow0001"); |
writeError(errorMessage); |
} |
|
@@ -997,7 +991,7 @@ |
} |
|
//Call graphing function for the outputs of the BFLOW model |
- graphBFLOWresults(mainFolder, organizationName, stationID, stationName, sortedData_user); |
+ graphBFLOWresults(sortedData_user); |
|
}else if(modelType.equalsIgnoreCase("HYSEP")){ |
//Reformat data for HYSEP |
@@ -1010,7 +1004,7 @@ |
|
|
//Call graphing function for the outputs of the BFLOW model |
- graphHYSEPresults(mainFolder, organizationName, stationID, stationName); |
+ graphHYSEPresults(); |
|
} |
|
@@ -47,17 +47,18 @@ |
} |
} |
/** |
-* Last Updated: 1-July-2014 |
+* Last Updated: 10-July-2014 |
* @author Tyler Wible |
* @since 12-June-2011 |
*/ |
public class guiDC_Model { |
//Inputs |
String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA/DurationCurve"; |
+ String database = "USGS";//"CDWR";//"STORET";//"UserData";// |
+ String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";// |
+ String stationID = "06752280";//"CLAGRECO";//"000028";// |
+ String stationName = "CACHE LA POUDRE RIV AB BOXELDER CRK NR TIMNATH, CO";//"Cache La Poudre Near Greeley";//"BIG THOMPSON R NEAR MOUTH";// |
String modelType = "FDC";//"LDC";// |
- String organizationName = "USGS";//"Colorado Dept. of Public Health & Environment";// |
- String stationID = "06752280";//"000028";// |
- String stationName = "CACHE LA POUDRE RIV AB BOXELDER CRK NR TIMNATH, CO"; |
String wqTest = "flow";//"00600 Total nitrogen, water, unfiltered, milligrams per liter -- mg/l";//"Nitrogen, Nitrate (NO3) as NO3";// |
double wqTarget = 10;//in units of current test |
String beginDate = ""; |
@@ -131,6 +132,9 @@ |
public void setModelType(String modelType) { |
this.modelType = modelType; |
} |
+ public void setDatabase(String database) { |
+ this.database = database; |
+ } |
public void setOrganizationName(String organizationName) { |
this.organizationName = organizationName; |
} |
@@ -184,7 +188,7 @@ |
* @throws IOException |
* @throws InterruptedException |
*/ |
- private String[] createFDC() throws IOException, InterruptedException, ParseException{ |
+ private String[] createFDC() throws IOException, InterruptedException, ParseException, Exception{ |
//Inputs |
// String mainFolder = the file location where the resulting load duration curve graph will be saved and the dynamic paragraph text file will be saved |
// String fileName = the name of the graph and text file to be saved (the graph created will be fileNamegraph.txt and the txt file will be fileNameparagraph.txt) |
@@ -200,7 +204,7 @@ |
|
//Check if any flow data exists |
Data data = new Data(); |
- String[][] sortableData = data.extractFlowData(mainFolder, organizationName, stationID, beginDate, endDate, userData); |
+ String[][] sortableData = data.extractFlowData(mainFolder, database, organizationName, stationID, beginDate, endDate, userData); |
|
//If the user wants the datasets (public and user) merged then retrieve the second dataset (user) |
String[][] sortableData_user = new String[0][0]; |
@@ -219,16 +223,14 @@ |
if(sortedData_combined.length == 0){ |
ArrayList<String> errorMessage = new ArrayList<String>(); |
if(sortedData.length == 0){ |
- String database = "USGS"; |
- if(!organizationName.equals("USGS")){ |
- database = "STORET"; |
+ errorMessage.add("There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ if(database.equalsIgnoreCase("CDWR")){ |
+ errorMessage.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
} |
- errorMessage.add("There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
} |
if(sortedData_user.length == 0){ |
errorMessage.add("There is no available uploaded data for station '" + stationID + "' and the specified date range"); |
} |
- errorMessage.add("Error: Baseflow0001"); |
writeError(errorMessage); |
} |
|
@@ -266,7 +268,7 @@ |
} |
|
//Create Display Paragraph |
- String[] partial_Paragraph = dynamicParagraph("Flow Duration Curve Overview: ","USGS"); |
+ String[] partial_Paragraph = dynamicParagraph("Flow Duration Curve Overview: "); |
|
return partial_Paragraph; |
} |
@@ -424,8 +426,8 @@ |
plot = graphing.addIntervalLabel(plot, "Low Flow", 90, 100); |
|
//Graph plot onto JfreeChart |
- String graph_title = "Flow Duration Curve for Station No. " + stationName; |
- JFreeChart chart = new JFreeChart(graph_title, graphing.titleFont, plot, showLegend); |
+ String graphTitle = "Flow Duration Curve for " + database + " Station " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, showLegend); |
|
//Write a results file containing the flow duration curve interval (non-exceedence values) and their corresponding discharge values |
writeResults(xyRanks, mainFolder, "Discharge (cfs)"); |
@@ -465,7 +467,7 @@ |
|
//Check if any flow and water quality data exists |
Data data = new Data(); |
- Object[] returnArray1 = data.extractFlow_and_WQdata(mainFolder, organizationName, stationID, beginDate, endDate, userData, wqTest); |
+ Object[] returnArray1 = data.extractFlow_and_WQdata(mainFolder, database, organizationName, stationID, beginDate, endDate, userData, wqTest); |
String[][] sortableData = (String[][]) returnArray1[0]; |
String[][] WQdata = (String[][]) returnArray1[1]; |
|
@@ -489,14 +491,13 @@ |
String[][] WQdata_combined = doubleArray.mergeData(WQdata, WQdata_user, mergeMethod); |
|
//Check if any data exists |
- String database = "USGS"; |
- if(!organizationName.equals("USGS")){ |
- database = "STORET"; |
- } |
ArrayList<String> errorMessage = new ArrayList<String>(); |
if(sortedData_combined.length == 0){ |
if(sortedData.length == 0){ |
errorMessage.add("There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ if(database.equalsIgnoreCase("CDWR")){ |
+ errorMessage.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
+ } |
} |
if(sortedData_user.length==0){ |
errorMessage.add("There is no uploaded flow data for station '" + stationID + "' and the specified date range."); |
@@ -555,9 +556,8 @@ |
String[][] seasonalWQ_user = doubleArray.getSeasonalData(WQdata_user, seasonBegin, seasonEnd); |
|
//Graph resulting LDC data |
- String graphTitle = "Load Duration Curve for Station No. " + stationID + " - " + stationName; |
String yaxisTitle = WQlabel + " [" + endUnits + "]"; |
- Object[] returnArray = graphLDC(graphTitle, yaxisTitle,conversion, sortedData_combined, sortedData_user, WQdata_combined, WQdata_user, seasonalWQ_combined, seasonalWQ_user, mQn, m, n); |
+ Object[] returnArray = graphLDC(yaxisTitle,conversion, sortedData_combined, sortedData_user, WQdata_combined, WQdata_user, seasonalWQ_combined, seasonalWQ_user, mQn, m, n); |
String paragraphTitle = (String) returnArray[0]; |
double totalCount = (Double) returnArray[1]; |
|
@@ -578,13 +578,12 @@ |
} |
|
//Create display paragraph based on the above summary (firstLine) and the provided paragraphTitle for the LDC |
- String[] displayParagraph = dynamicParagraph(paragraphTitle, organizationName); |
+ String[] displayParagraph = dynamicParagraph(paragraphTitle); |
|
return displayParagraph; |
} |
/** |
* Sub-graphing function to create combined-range graph |
- * @param graph_title the desired graph title. |
* @param yaxis_title the desired y-axis title. |
* @param conversion |
* @param sortedData_combined the load duration curve XY line data of combined data |
@@ -599,8 +598,7 @@ |
* @return the name/title of the dynamic paragraph to be created to accompany the graph created during this function |
* @throws IOException |
*/ |
- private Object[] graphLDC(String graph_title, |
- String yaxis_title, |
+ private Object[] graphLDC(String yaxis_title, |
double conversion, |
String[][] sortedData_combined, |
String[][] sortedData_user, |
@@ -1040,7 +1038,8 @@ |
plot = graphing.setLogYaxisPreferences(plot); |
|
//Graph plot onto JfreeChart |
- JFreeChart chart = new JFreeChart(graph_title, graphing.titleFont, plot, true); |
+ String graphTitle = "Load Duration Curve for " + database + " Station " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, true); |
|
//Set legend Font |
LegendTitle legendTitle = chart.getLegend(); |
@@ -1097,10 +1096,9 @@ |
/** |
* Create the dynamic paragraph requested |
* @param paragraphTitle title of the desired paragraph |
- * @param database Database type to give credit to where the data originated in the reference cited section |
* @return the dynamic paragraph to be displayed to the user |
*/ |
- public String[] dynamicParagraph(String paragraphTitle, String database) { |
+ public String[] dynamicParagraph(String paragraphTitle) { |
String[] dynamic_paragraph = new String[9]; |
|
//Get today's date for the source reference |
@@ -1110,10 +1108,12 @@ |
|
String sourceText = ""; |
//Determine if current source is USGS or STORET to give credit for the data |
- if(database.equals("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
sourceText = "Stream flow data and water quality test data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
sourceText = "Stream flow data and water quality test data courtesy of the U.S. Environmental Protection Agency, STORET. http://www.epa.gov/storet/index.html accessed: " + today; |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ this.dataSource = "Stream flow data and water quality test data courtesy of the Colorado Division of Water Resources, CDWR. http://www.dwr.state.co.us accessed: " + today; |
} |
this.dataSource = sourceText; |
|
@@ -1193,7 +1193,7 @@ |
* @throws IOException |
* @throws InterruptedException |
*/ |
- public void run() throws IOException, InterruptedException, ParseException { |
+ public void run() throws IOException, InterruptedException, ParseException, Exception { |
|
//If no date input, make it the maximum of available data |
if(beginDate == null || beginDate.equalsIgnoreCase("")){ |
@@ -10,14 +10,15 @@ |
import java.util.Date; |
|
/** |
-* Last Updated: 24-June-2014 |
+* Last Updated: 10-July-2014 |
* @author Tyler Wible |
* @since 21-June-2012 |
*/ |
public class guiDownload_Data { |
String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA"; |
- String organizationName = "USGS";//"Colorado Dept. of Public Health & Environment";//"California Gulch (US EPA Region 8)"; |
- String stationID = "06752260";//"000028";//"EF-01";//"L01"; |
+ String database = "USGS";//"CDWR";//"STORET";//"UserData";// |
+ String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";//"California Gulch (US EPA Region 8)"; |
+ String stationID = "06752260";//"CLAGRECO";//"000028";//"EF-01";//"L01";// |
String wqTest = "flow";//"00600";//"Nitrogen, Nitrate (NO3) as NO3";//"Fecal Coliform";//"15-min flow";//"stage-discharge";// |
String beginDate = ""; |
String endDate = ""; |
@@ -43,6 +44,9 @@ |
public void setMainFolder(String mainFolder) { |
this.mainFolder = mainFolder; |
} |
+ public void setDatabase(String database) { |
+ this.database = database; |
+ } |
public void setOrganizationName(String organizationName) { |
this.organizationName = organizationName; |
} |
@@ -59,6 +63,147 @@ |
this.endDate = endDate; |
} |
/** |
+ * Main CDWR data download subroutine |
+ * @return an ArrayList<String> containing the result file of the download request |
+ * @throws Exception |
+ */ |
+ private ArrayList<String> downloadCDWRdata() throws Exception{ |
+ CDWR_Data cdwr_Data = new CDWR_Data(); |
+ ArrayList<String> textData = new ArrayList<String>(); |
+ |
+ //Determine the type of download for CDWR: flow, hourly-flow, stage-discharge |
+ if(wqTest.equalsIgnoreCase("flow")){ |
+ //Search for CDWR flow data |
+ Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Daily"); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //flowData = (String[][]) returnArray[1]; |
+ start = (String) returnArray[2]; |
+ end = (String) returnArray[3]; |
+ |
+ }else if(wqTest.equalsIgnoreCase("Flood Flow")){ |
+ //Search for CDWR flow data |
+ Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Daily"); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //flowData = (String[][]) returnArray[1]; |
+ start = (String) returnArray[2]; |
+ end = (String) returnArray[3]; |
+ |
+ }else if(wqTest.equalsIgnoreCase("15-min flow")){ |
+ //Search for CDWR hourly flow data |
+ Object[] returnArray = cdwr_Data.getCDWRflowData(stationID, beginDate, endDate, "Hourly"); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //String[][] flowData = (String[][]) returnArray[1]; |
+ start = (String) returnArray[2]; |
+ end = (String) returnArray[3]; |
+ |
+ }else if(wqTest.equalsIgnoreCase("stage-discharge")){ |
+ Object[] returnArray = cdwr_Data.getCDWRratingCurve(stationID); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //double[][] ratingCurve = (double[][]) returnArray[1]; |
+ |
+ }else{ |
+ ArrayList<String> errorMessage = new ArrayList<String>(); |
+ errorMessage.add("There is no available data available for " + wqTest + " in the CDWR database. This feature is only available for stations in the USGS or STORET databases."); |
+ writeError(errorMessage); |
+ } |
+ |
+ //Check if there is actually data |
+ if(textData.size() == 1){ |
+ //If only the headers and no data, replace with an error |
+ textData.set(0, "There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ textData.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
+ } |
+ |
+ return textData; |
+ } |
+ /** |
+ * Main STORET data download subroutine |
+ * @return an ArrayList<String> containing the result file of the download request |
+ * @throws IOException |
+ */ |
+ private ArrayList<String> downloadSTORETdata() throws IOException{ |
+ STORET_Data storet_Data = new STORET_Data(); |
+ ArrayList<String> textData = new ArrayList<String>(); |
+ |
+ //Determine the type of download for STORET: flow, water quality (individual test) |
+ if(wqTest.equalsIgnoreCase("Flood Flow")){ |
+ //Since STORET doesn't have annual flood flow values, just return normal flow data to the user |
+ wqTest = "flow"; |
+ }else if(wqTest.equalsIgnoreCase("15-min flow")){ |
+ //Since STORET doesn't have 15-minute data, thrown an error and alert the user of this |
+ ArrayList<String> errorMessage = new ArrayList<String>(); |
+ errorMessage.add("There is no available 15-minute flow data available for the STORET database. This feature is only available for stations in the USGS NWIS database."); |
+ writeError(errorMessage); |
+ }else if(wqTest.equalsIgnoreCase("stage-discharge")){ |
+ //Since STORET doesn't have stage-discharge/rating curve data, thrown an error and alert the user of this |
+ ArrayList<String> errorMessage = new ArrayList<String>(); |
+ errorMessage.add("There is no available stage-discharge data available for the STORET database. This feature is only available for stations in the USGS NWIS database."); |
+ writeError(errorMessage); |
+ } |
+ String zip_location = storet_Data.downloadSTORET(mainFolder, organizationName, stationID, wqTest, beginDate, endDate); |
+ |
+ //Unzip results file and extract all flow data |
+ textData = storet_Data.Unzip_STORETDownloadFilesAll(zip_location); |
+ |
+ return textData; |
+ } |
+ /** |
+ * Main USGS data download subroutine |
+ * @return an ArrayList<String> containing the result file of the download request |
+ * @throws IOException |
+ * @throws InterruptedException |
+ */ |
+ private ArrayList<String> downloadUSGSdata() throws IOException, InterruptedException{ |
+ USGS_Data usgs_Data = new USGS_Data(); |
+ ArrayList<String> textData = new ArrayList<String>(); |
+ |
+ //Determine the type of download for USGS: flow, flood flow, 15-minute-flow, stage-discharge, WQ data (all), WQ data (individual test) |
+ if(wqTest.equalsIgnoreCase("flow")){ |
+ //Retrieve flow data from USGS website |
+ Object[] returnArray = usgs_Data.getUSGSflowData(stationID, beginDate, endDate); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //String[][] flowData = (String[][]) returnArray[1]; |
+ start = (String) returnArray[2]; |
+ end = (String) returnArray[3]; |
+ |
+ }else if(wqTest.equalsIgnoreCase("Flood Flow")){ |
+ //Retrieve flood flow data from USGS website |
+ Object[] returnArray = usgs_Data.getUSGSPeakData(stationID, beginDate, endDate); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //double[][] floodData = (double[][]) returnArray[1]; |
+ start = String.valueOf((double) returnArray[2]); |
+ end = String.valueOf((double) returnArray[3]); |
+ |
+ }else if(wqTest.equalsIgnoreCase("15-min flow")){ |
+ //Retrive 15-minute flow data from USGS website |
+ Object[] returnArray = usgs_Data.getUSGS15minFlowData(stationID, beginDate, endDate); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //String[][] flowData = (String[][]) returnArray[1]; |
+ start = (String) returnArray[2]; |
+ end = (String) returnArray[3]; |
+ |
+ }else if(wqTest.equalsIgnoreCase("stage-discharge")){ |
+ //Retrive rating curve data from USGS website |
+ Object[] returnArray = usgs_Data.getUSGSratingCurve(stationID); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //double[][] ratingCurve = (double[][]) returnArray[1]; |
+ |
+ }else if(wqTest.equalsIgnoreCase("all")){ |
+ //Retrive all WQ data from USGS website |
+ Object[] returnArray = usgs_Data.getUSGSwqData(stationID); |
+ textData = (ArrayList<String>) returnArray[0]; |
+ //String[][] allWQdata = (String[][]) returnArray1[1]; |
+ start = (String) returnArray[2]; |
+ end = (String) returnArray[3]; |
+ |
+ }else{ |
+ //Retrive only the selected WQ data from USGS website |
+ textData = usgs_Data.getUSGSwqData_partial(stationID, wqTest); |
+ } |
+ |
+ return textData; |
+ } |
+ /** |
* Writes out the error message, if any, for finding the file and then exits the program |
* @param error string array to be written as each line of an error message |
* @throws IOException |
@@ -89,13 +234,12 @@ |
writer.close(); |
System.out.println("File located at: " + path); |
} |
- /**Primary LDC download program |
- * It calls the subfunctions based on user selection/inputs. |
- * Calls STORET or USGS database queries and their respective subfunctions |
+ /** |
+ * Primary download function, queries CDWR, STORET, or USGS database |
* @throws IOException |
* @throws InterruptedException |
*/ |
- public void run() throws IOException, InterruptedException { |
+ public void run() throws IOException, InterruptedException, Exception { |
//Inputs |
// assert args.length > 0; |
// String mainFolder = args[0]; |
@@ -118,80 +262,22 @@ |
endDate = desiredDateFormat.format(currentDate); |
} |
|
- //Determine the requested download type and download data from the correct site (USGS or STORET) |
+ //Determine the requested download type and download data from the correct site |
ArrayList<String> textData = new ArrayList<String>(); |
- if(organizationName.equalsIgnoreCase("USGS")){ |
- USGS_Data usgs_Data = new USGS_Data(); |
- //Determine the type of download for USGS, flow, flood flow, WQ data (some), WQ data (all) |
- if(wqTest.equalsIgnoreCase("flow")){ |
- //Retrieve flow data from USGS website |
- Object[] returnArray = usgs_Data.getUSGSflowData(stationID, beginDate, endDate); |
- textData = (ArrayList<String>) returnArray[0]; |
- //String[][] flowData = (String[][]) returnArray[1]; |
- start = (String) returnArray[2]; |
- end = (String) returnArray[3]; |
- |
- }else if(wqTest.equalsIgnoreCase("Flood Flow")){ |
- //Retrieve flood flow data from USGS website |
- Object[] returnArray = usgs_Data.getUSGSPeakData(stationID, beginDate, endDate); |
- textData = (ArrayList<String>) returnArray[0]; |
- //double[][] floodData = (double[][]) returnArray[1]; |
- start = String.valueOf((double) returnArray[2]); |
- end = String.valueOf((double) returnArray[3]); |
- |
- }else if(wqTest.equalsIgnoreCase("15-min flow")){ |
- //Retrive 15-minute flow data from USGS website |
- Object[] returnArray = usgs_Data.getUSGS15minFlowData(stationID, beginDate, endDate); |
- textData = (ArrayList<String>) returnArray[0]; |
- //String[][] flowData = (String[][]) returnArray[1]; |
- start = (String) returnArray[2]; |
- end = (String) returnArray[3]; |
- |
- }else if(wqTest.equalsIgnoreCase("stage-discharge")){ |
- //Retrive rating curve data from USGS website |
- Object[] returnArray = usgs_Data.getUSGSratingCurve(stationID); |
- textData = (ArrayList<String>) returnArray[0]; |
- //double[][] ratingCurve = (double[][]) returnArray[1]; |
- |
- }else if(wqTest.equalsIgnoreCase("all")){ |
- //Retrive all WQ data from USGS website |
- Object[] returnArray = usgs_Data.getUSGSwqData(stationID); |
- textData = (ArrayList<String>) returnArray[0]; |
- //String[][] allWQdata = (String[][]) returnArray1[1]; |
- start = (String) returnArray[2]; |
- end = (String) returnArray[3]; |
- |
- }else{ |
- //Retrive only the selected WQ data from USGS website |
- textData = usgs_Data.getUSGSwqData_partial(stationID, wqTest); |
- } |
- }else{ |
- //Search for STORET data |
- STORET_Data storet_Data = new STORET_Data(); |
- if(wqTest.equalsIgnoreCase("Flood Flow")){ |
- //Since STORET doesn't have annual flood flow values, just return normal flow data to the user |
- wqTest = "flow"; |
- }else if(wqTest.equalsIgnoreCase("15-min flow")){ |
- //Since STORET doesn't have 15-minute data, thrown an error and alert the user of this |
- ArrayList<String> errorMessage = new ArrayList<String>(); |
- errorMessage.add("There is no available 15-minute flow data available for the STORET database. This feature is only available for stations in the USGS NWIS database."); |
- writeError(errorMessage); |
- }else if(wqTest.equalsIgnoreCase("stage-discharge")){ |
- //Since STORET doesn't have stage-discharge/rating curve data, thrown an error and alert the user of this |
- ArrayList<String> errorMessage = new ArrayList<String>(); |
- errorMessage.add("There is no available stage-discharge data available for the STORET database. This feature is only available for stations in the USGS NWIS database."); |
- writeError(errorMessage); |
- } |
- String zip_location = storet_Data.downloadSTORET(mainFolder, organizationName, stationID, wqTest, beginDate, endDate); |
- |
- //Unzip results file and extract all flow data |
- textData = storet_Data.Unzip_STORETDownloadFilesAll(zip_location); |
+ if(database.equalsIgnoreCase("USGS")){ |
+ textData = downloadUSGSdata(); |
+ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
+ textData = downloadSTORETdata(); |
+ |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ textData = downloadCDWRdata(); |
} |
|
//write out data to text file |
writeOutputFile(textData); |
} |
- public static void main(String[] args) throws IOException, InterruptedException{ |
+ public static void main(String[] args) throws IOException, InterruptedException, Exception{ |
guiDownload_Data downloadModel = new guiDownload_Data(); |
|
//Run Model |
@@ -44,16 +44,17 @@ |
import org.jfree.ui.TextAnchor; |
|
/** |
-* Last Updated: 1-July-2014 |
+* Last Updated: 10-July-2014 |
* @author Tyler Wible |
* @since 10-July-2012 |
*/ |
public class guiDrought_Model { |
//Inputs |
String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA/Drought"; |
- String organizationName = "USGS";//"UserData";// |
- String stationID = "06752000";//"ARTest2_7";//"06741510";//"ARExample";//"06752260";// |
- String stationName = "CACHE LA POUDRE RIV AT MO OF CN, NR FT COLLINS, CO"; |
+ String database = "USGS";//"CDWR";//"STORET";//"UserData";// |
+ String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";// |
+ String stationID = "06752000";//"CLAGRECO";//"000028";// |
+ String stationName = "CACHE LA POUDRE RIV AT MO OF CN, NR FT COLLINS, CO";//"Cache La Poudre Near Greeley";//"BIG THOMPSON R NEAR MOUTH";// |
String beginDate = "";//"1900-01-01";// |
String endDate = "";//"2002-01-01";// |
String lambdaString = "optimize";//"1";// |
@@ -153,6 +154,9 @@ |
public void setMainFolder(String mainFolder) { |
this.mainFolder = mainFolder; |
} |
+ public void setDatabase(String database) { |
+ this.database = database; |
+ } |
public void setOrganizationName(String organizationName) { |
this.organizationName = organizationName; |
} |
@@ -206,7 +210,6 @@ |
* if "useParameters" then it takes the previously generated parameters and uses these to perform the regression |
* @param phiValues |
* @param thetaValues |
- * @param graphTitle the title of the graph to be created (should contain station ID and station Name for user's benefit) |
* @return a String[] containing a tab-delimited summary of the droughts (water supply < water demand) |
* @throws IOException |
*/ |
@@ -214,8 +217,7 @@ |
String lambdaString, |
String action, |
String phiValues, |
- String thetaValues, |
- String graphTitle) throws IOException{ |
+ String thetaValues) throws IOException{ |
DoubleMath doubleMath = new DoubleMath(); |
DoubleArray doubleArray = new DoubleArray(); |
//Calculate total annual flows |
@@ -227,7 +229,7 @@ |
|
|
//Call built in function to perform the drough analysis and graph the resulting data |
- String[] droughtInfo = generalDroughtAnalysis(sortedData, droughtLimit, lambdaString, action, phiValues, thetaValues, graphTitle); |
+ String[] droughtInfo = generalDroughtAnalysis(sortedData, droughtLimit, lambdaString, action, phiValues, thetaValues); |
|
|
return droughtInfo; |
@@ -246,7 +248,6 @@ |
* if "useParameters" then it takes the previously generated parameters and uses these to perform the regression |
* @param phiValues |
* @param thetaValues |
- * @param graphTitle the title of the graph to be created (should contain station ID and station Name for user's benefit) |
* @return a String[] containing a tab-delimited summary of the droughts (water supply < water demand) |
* @throws IOException |
*/ |
@@ -256,8 +257,7 @@ |
String lambdaString, |
String action, |
String phiValues, |
- String thetaValues, |
- String graphTitle) throws IOException{ |
+ String thetaValues) throws IOException{ |
// //Test AR(p) model on sample data |
// double[][] annualData = sumAnnualFlows(sortedData); |
// Object[] returnArray = autoRegression.AR(p, annualData); |
@@ -372,11 +372,11 @@ |
|
|
//Graph the drought data |
- graphTimeseries(annualData, droughtLimit, graphTitle); //graph1 |
- graphNegativeBarChart(annualData, droughtLimit, graphTitle); //graph2 |
- graphFittedData(originalData, fittedData, methodType, graphTitle); //graph3 |
- graphPredictedData(originalData, predictedData, methodType, graphTitle); //graph4 |
- graphReturnPeriod(historicDroughts, predictedDroughts, graphTitle); //graph5 |
+ graphTimeseries(annualData, droughtLimit); //graph1 |
+ graphNegativeBarChart(annualData, droughtLimit); //graph2 |
+ graphFittedData(originalData, fittedData, methodType); //graph3 |
+ graphPredictedData(originalData, predictedData, methodType);//graph4 |
+ graphReturnPeriod(historicDroughts, predictedDroughts); //graph5 |
|
|
|
@@ -547,11 +547,9 @@ |
* Graph the timeseries data and save the resulting graph to the specified location |
* @param sortedData the String[][] containing sorted data for the timeseries (column 1 = dates (yyyy-mm-dd) column 2 = values) |
* @param droughtLimit the calculated drought limit (if supply < drought limit then that year is a drought) |
- * @param graphTitle the graph title |
*/ |
private void graphTimeseries(double[][] sortedData, |
- double droughtLimit, |
- String graphTitle) throws IOException{ |
+ double droughtLimit) throws IOException{ |
Graphing graphing = new Graphing(); |
|
//Round the long term average to fit the data better |
@@ -594,6 +592,7 @@ |
graphing.setTimeAxisPreferences(plotTime); |
|
//Create the chart with the plot and a legend |
+ String graphTitle = "Annual Time Series for " + database + " Station: " + stationID + "; " + stationName; |
JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plotTime, true); |
|
//Set legend Font |
@@ -613,11 +612,9 @@ |
* Graph the bar chart of the timeseries data where the values graphed ar those in sortedData and save the resulting graph to the specified location |
* @param sortedData the String[][] containing sorted data for the timeseries (column 1 = dates (yyyy-mm-dd) column 2 = values) |
* @param droughtLimit the calculated drought limit (if supply < drought limit then that year is a drought) |
- * @param graphTitle the graph title |
*/ |
private void graphNegativeBarChart(double[][] sortedData, |
- double droughtLimit, |
- String graphTitle) throws IOException{ |
+ double droughtLimit) throws IOException{ |
Graphing graphing = new Graphing(); |
|
//Round the long term average to fit the data better |
@@ -675,6 +672,7 @@ |
graphing.setTimeAxisPreferences(plot); |
|
//Create the chart with the plot |
+ String graphTitle = "Annual Drought/Surplus for " + database + " Station: " + stationID + "; " + stationName; |
JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, false); |
|
//Save resulting graph for use later |
@@ -691,12 +689,10 @@ |
* @param originalData double array of the original data. Column1 = years, column2 = annual flow values |
* @param fittedData double array of the fitted data during the same time period as the original data. Column1 = years, column2 = annual flow values |
* @param methodType the name of the method used to generate and project the data to be used in the legend of the graph |
- * @param graphTitle the graph title |
*/ |
private void graphFittedData(double[][] originalData, |
double[][] fittedData, |
- String methodType, |
- String graphTitle) throws IOException{ |
+ String methodType) throws IOException{ |
Graphing graphing = new Graphing(); |
|
//Convert graph x = original data, y = fitted data |
@@ -768,7 +764,8 @@ |
|
|
//Create the chart with the plot |
- JFreeChart chart = new JFreeChart("Data Correlelation for " + graphTitle, graphing.titleFont, plot, false); |
+ String graphTitle = "Data Correlation for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, false); |
|
try{ |
String path = mainFolder + File.separator + getFittedDataGraph(); |
@@ -783,12 +780,10 @@ |
* @param originalData double array of the original data. Column1 = years, column2 = annual flow values |
* @param predictedData double array of the future predicted data. Column1 = years, column2 = annual flow values |
* @param methodType the name of the method used to generate and project the data to be used in the legend of the graph |
- * @param graphTitle the graph title |
*/ |
private void graphPredictedData(double[][] originalData, |
double[][] predictedData, |
- String methodType, |
- String graphTitle) throws IOException{ |
+ String methodType) throws IOException{ |
Graphing graphing = new Graphing(); |
|
//Convert series into Dates |
@@ -855,7 +850,8 @@ |
graphing.setAxisPreferences(plot); |
|
//Create the chart with the plot |
- JFreeChart chart = new JFreeChart("Projected Data for " + graphTitle, graphing.titleFont, plot, true); |
+ String graphTitle = "Projected Data for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, true); |
|
//Set legend Font |
LegendTitle legendTitle = chart.getLegend(); |
@@ -873,11 +869,9 @@ |
* Graphs the drought length verses the return period for each lambda (drought deficit = lambda * droughtLimit) value on a scatter plot |
* @param originalData double array of the original data. Column1 = years, column2 = annual flow values |
* @param predictedData double array of the future predicted data. Column1 = years, column2 = annual flow values |
- * @param graphTitle the graph title |
*/ |
private void graphReturnPeriod(double[][] originalData, |
- double[][] predictedData, |
- String graphTitle) throws IOException{ |
+ double[][] predictedData) throws IOException{ |
DoubleMath doubleMath = new DoubleMath(); |
DoubleArray doubleArray = new DoubleArray(); |
Graphing graphing = new Graphing(); |
@@ -1004,7 +998,8 @@ |
graphing.setAxisPreferences(plot); |
|
//Create the chart with the plot |
- JFreeChart chart = new JFreeChart("Drought Recurrence Intervals for " + graphTitle, graphing.titleFont, plot, true); |
+ String graphTitle = "Drought Recurrence Intervals for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, true); |
|
//Set legend Font |
LegendTitle legendTitle = chart.getLegend(); |
@@ -1198,7 +1193,7 @@ |
pointer.setTextAnchor(TextAnchor.CENTER_RIGHT); |
plot.addAnnotation(pointer); |
|
- //Put the LDC line data, renderer, and axis into plot |
+ //Put the line data, renderer, and axis into plot |
plot.setDataset(3, dataset3); |
plot.setRenderer(3, currentRenderer3); |
|
@@ -1264,7 +1259,7 @@ |
} |
throw new IOException("Error encountered. Please see the following message for details: \n" + errorContents); |
} |
- public void run() throws IOException, InterruptedException { |
+ public void run() throws IOException, InterruptedException, Exception { |
//If no date input, make it the maximum of available data |
if(beginDate == null || beginDate.equalsIgnoreCase("")){ |
beginDate = "1900-01-01"; |
@@ -1278,7 +1273,7 @@ |
|
//Check if any flow data exists |
Data data = new Data(); |
- String[][] sortableData = data.extractFlowData(mainFolder, organizationName, stationID, beginDate, endDate, userData); |
+ String[][] sortableData = data.extractFlowData(mainFolder, database, organizationName, stationID, beginDate, endDate, userData); |
|
//If the user wants the datasets (public and user) merged then retrieve the second dataset (user) |
String[][] sortableData_user = new String[0][0]; |
@@ -1297,39 +1292,38 @@ |
if(sortedData_combined.length == 0){ |
ArrayList<String> errorMessage = new ArrayList<String>(); |
if(sortedData.length == 0){ |
- String database = "USGS"; |
- if(!organizationName.equals("USGS")){ |
- database = "STORET"; |
+ errorMessage.add("There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ if(database.equalsIgnoreCase("CDWR")){ |
+ errorMessage.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
} |
- errorMessage.add("There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
} |
if(sortedData_user.length == 0){ |
errorMessage.add("There is no available uploaded data for station '" + stationID + "' and the specified date range"); |
} |
- errorMessage.add("Error: Baseflow0001"); |
writeError(errorMessage); |
} |
|
//Perform drought analysis |
- String graphTitle = "Station: " + stationID + "-" + stationName + " By: USGS";// + organizationName; |
String[] droughtInfo = null; |
|
if(Double.compare(droughtLimit, 0) < 0){ |
//If no drought limit is provided (aka -1 is provided) then calculate the drought limit = average(annual flows) |
- droughtInfo = generalDroughtAnalysis(sortedData_combined, lambdaString, action, phiValues, thetaValues, graphTitle); |
+ droughtInfo = generalDroughtAnalysis(sortedData_combined, lambdaString, action, phiValues, thetaValues); |
}else{ |
//If a drought limit is provided (aka greater than or equal to zero) then use this as the drought limit |
- droughtInfo = generalDroughtAnalysis(sortedData_combined, droughtLimit, lambdaString, action, phiValues, thetaValues, graphTitle); |
+ droughtInfo = generalDroughtAnalysis(sortedData_combined, droughtLimit, lambdaString, action, phiValues, thetaValues); |
} |
|
//Get today's date for the source reference |
Date currentDate = new Date(); |
SimpleDateFormat sourceDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
String today = sourceDateFormat.format(currentDate); |
- if(organizationName.equalsIgnoreCase("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
this.dataSource = "Stream flow data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
this.dataSource = "Stream flow data courtesy of the U.S. Environmental Protection Agency, STORET. http://www.epa.gov/storet/index.html accessed: " + today; |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ this.dataSource = "Stream flow data courtesy of the Colorado Division of Water Resources, CDWR. http://www.dwr.state.co.us accessed: " + today; |
} |
this.len = String.valueOf(sortedData_combined.length); |
this.start = String.valueOf(sortedData_combined[0][0]); |
@@ -11,15 +11,16 @@ |
import org.apache.commons.math.ArgumentOutsideDomainException; |
|
/** |
-* Last Updated: 1-July-2014 |
+* Last Updated: 10-July-2014 |
* @author Tyler Wible |
* @since 13-June-2012 |
*/ |
public class guiFlood_Model { |
String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA";//The output location of the graph |
- String organizationName = "USGS";//"Colorado Dept. of Public Health & Environment";// |
- String stationID = "06764880";//"16557000";//"11501000";//"000028";// |
- String stationName = "South Platte River at Roscoe, Nebr."; |
+ String database = "USGS";//"CDWR";//"STORET";//"UserData";// |
+ String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";// |
+ String stationID = "06764880";//"16557000";//"11501000";//"CLAGRECO";//"000028";// |
+ String stationName = "South Platte River at Roscoe, Nebr.";//"Cache La Poudre Near Greeley";//"BIG THOMPSON R NEAR MOUTH";// |
String analysisType = "B17";//Which method to use for flood analysis (currently only B17 is supported) |
String beginDate = ""; |
String endDate = ""; |
@@ -28,7 +29,7 @@ |
boolean showLargeFloods = false; |
boolean plotref = true; |
boolean plottype = true; |
- String userData = "";//"Date\tFlow\n1999-04-29\t80000.3\n1999-05-09\t60.2\n1999-05-29\t20.1"; |
+ String userData = "";//"Date\tFlow\n1999-04-29\t80000.3\n1999-05-09\t60.2\n1999-05-29\t20.1"; |
boolean mergeDatasets = false;//true;// |
String mergeMethod = "user";//"public";//"max";//"average";//"min";// |
|
@@ -63,6 +64,9 @@ |
public void setMainFolder(String mainFolder) { |
this.mainFolder = mainFolder; |
} |
+ public void setDatabase(String database) { |
+ this.database = database; |
+ } |
public void setOrganizationName(String organizationName) { |
this.organizationName = organizationName; |
} |
@@ -146,7 +150,7 @@ |
} |
throw new IOException("Error encountered. Please see the following message for details: \n" + errorContents); |
} |
- public void run() throws ArgumentOutsideDomainException, IOException { |
+ public void run() throws ArgumentOutsideDomainException, IOException, Exception { |
//If no date input, make it the maximum of available data |
if(beginDate == null || beginDate.equalsIgnoreCase("")){ |
beginDate = "1900-01-01"; |
@@ -162,7 +166,7 @@ |
if(analysisType.equalsIgnoreCase("B17")){ |
//Check if any flow data exists |
Data data = new Data(); |
- double[][] peakFlowData = data.extractFloodData(mainFolder, organizationName, stationID, beginDate, endDate, userData); |
+ double[][] peakFlowData = data.extractFloodData(mainFolder, database, organizationName, stationID, beginDate, endDate, userData); |
|
//Check if merging the datasets is desired, if so get the user data |
double[][] peakFlowData_user = new double[0][0]; |
@@ -183,11 +187,10 @@ |
if(peakFlowData_combined.length == 0){ |
ArrayList<String> errorMessage = new ArrayList<String>(); |
if(peakFlowData.length == 0){ |
- String database = "USGS"; |
- if(!organizationName.equals("USGS")){ |
- database = "STORET"; |
+ errorMessage.add("There is no available flood data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ if(database.equalsIgnoreCase("CDWR")){ |
+ errorMessage.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
} |
- errorMessage.add("There is no available flood data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
} |
if(peakFlowData_user.length == 0){ |
errorMessage.add("There is no available uploaded flow data for station '" + stationID + "' and the specified date range"); |
@@ -195,14 +198,9 @@ |
writeError(errorMessage); |
} |
|
- String graphTitle = "Station: " + stationID + "-" + stationName + "; By " + organizationName; |
- if(graphTitle.length() > 75){ |
- graphTitle = stationID + "; By: " + organizationName; |
- } |
- |
//Run Bulletin 17 function and return graph |
Bulletin17B bulletin17B = new Bulletin17B(); |
- String[][] dataSummary = bulletin17B.b17(peakFlowData_combined, gg, MSERbar, mainFolder, graphTitle, showLargeFloods, plotref, plottype); |
+ String[][] dataSummary = bulletin17B.b17(peakFlowData_combined, gg, MSERbar, mainFolder, database, stationID, stationName, showLargeFloods, plotref, plottype); |
if(dataSummary[0][0].contains("Error")){ |
ArrayList<String> errorMessage = new ArrayList<String>(); |
errorMessage.add(dataSummary[0][0]); |
@@ -213,10 +211,12 @@ |
Date currentDate = new Date(); |
SimpleDateFormat sourceDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
String today = sourceDateFormat.format(currentDate); |
- if(organizationName.equalsIgnoreCase("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
this.dataSource = "Stream flow data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
- }else{ |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
this.dataSource = "Stream flow data courtesy of the U.S. Environmental Protection Agency, STORET. http://www.epa.gov/storet/index.html accessed: " + today; |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ this.dataSource = "Stream flow data and water quality test data courtesy of the Colorado Division of Water Resources, CDWR. http://www.dwr.state.co.us accessed: " + today; |
} |
this.len = String.valueOf(peakFlowData.length); |
this.start = String.valueOf(peakFlowData[0][0]); |
@@ -229,7 +229,7 @@ |
throw new IOException("Error: Flood analysis method specified is not 'B17'"); |
} |
} |
- public static void main(String[] args) throws ArgumentOutsideDomainException, IOException{ |
+ public static void main(String[] args) throws ArgumentOutsideDomainException, IOException, Exception{ |
guiFlood_Model floodModel = new guiFlood_Model(); |
|
//Set Inputs |
@@ -17,16 +17,17 @@ |
|
|
/** |
-* Last Updated: 1-July-2014 |
+* Last Updated: 10-July-2014 |
* @author Tyler Wible & Tyler Dell |
* @since 27-March-2013 |
*/ |
public class guiLOADEST_Model { |
//Inputs |
String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA/LOADEST"; |
- String organizationName = "USGS";//"Colorado Dept. of Public Health & Environment";// |
- String stationID = "06741510";//"EF-01";//"000028";// |
- String stationName = "BIG THOMPSON RIVER AT LOVELAND, CO."; |
+ String database = "USGS";//"CDWR";//"STORET";//"UserData";// |
+ String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";// |
+ String stationID = "06741510";//"CLAGRECO";//"000028";// |
+ String stationName = "BIG THOMPSON RIVER AT LOVELAND, CO.";//"Cache La Poudre Near Greeley";//"BIG THOMPSON R NEAR MOUTH";// |
String wqTest = "00600 Total nitrogen, water, unfiltered, milligrams per liter, mg/L"; |
int PTOPT = 1; // estimated values print option (0,1) |
int SEOPT = 2; // standard error option (1-3) |
@@ -196,6 +197,9 @@ |
public void setMainFolder(String mainFolder) { |
this.mainFolder = mainFolder; |
} |
+ public void setDatabase(String database) { |
+ this.database = database; |
+ } |
public void setOrganizationName(String organizationName) { |
this.organizationName = organizationName; |
} |
@@ -291,12 +295,12 @@ |
print_line.printf("%s" + "%n", "#"); |
print_line.printf("%s" + "%n", "# LOADEST Header File"); |
print_line.printf("%s" + "%n", "#"); |
- print_line.printf("%s" + "%n", "# " + stationID + " " + stationName + " " + "Agency: " + organizationName ); |
+ print_line.printf("%s" + "%n", "# " + stationID + " " + stationName + " Database: " + database + ", Supervising Organization: " + organizationName); |
print_line.printf("%s" + "%n", "#"); |
print_line.printf("%s" + "%n", "######################################################################"); |
|
// Inputs 1-4 Title, estimated values print option, standard error option, and load option |
- print_line.printf("%s" + "%n",stationID + " " +stationName + " " + "Agency: " + organizationName); |
+ print_line.printf("%s" + "%n",stationID + " " +stationName + " Database: " + database + ", Supervising Organization: " + organizationName); |
print_line.printf("%s" + "%n", PTOPT); |
print_line.printf("%s" + "%n", SEOPT); |
print_line.printf("%s" + "%n", LDOPT); |
@@ -399,7 +403,7 @@ |
print_line.printf("%s" + "%n", "#"); |
print_line.printf("%s" + "%n", "# LOADEST Calibration File"); |
print_line.printf("%s" + "%n", "#"); |
- print_line.printf("%s" + "%n", "# " + stationID + " " + stationName + " " + "Agency: " + organizationName ); |
+ print_line.printf("%s" + "%n", "# " + stationID + " " + stationName + " Database: " + database + ", Supervising Organization: " + organizationName ); |
print_line.printf("%s" + "%n", "#"); |
print_line.printf("%s" + "%n", "##########################################################################################################"); |
print_line.printf("%s" + "%n", "#"); |
@@ -708,7 +712,7 @@ |
|
//Check if any flow and water quality data exists |
Data data = new Data(); |
- Object[] returnArray1 = data.extractFlow_and_WQdata(mainFolder, organizationName, stationID, beginDate, endDate, userData, wqTest); |
+ Object[] returnArray1 = data.extractFlow_and_WQdata(mainFolder, database, organizationName, stationID, beginDate, endDate, userData, wqTest); |
String[][] sortableData = (String[][]) returnArray1[0]; |
String[][] WQdata = (String[][]) returnArray1[1]; |
|
@@ -732,14 +736,13 @@ |
String[][] WQdata_combined = doubleArray.mergeData(WQdata, WQdata_user, mergeMethod); |
|
//Check if any data exists |
- String database = "USGS"; |
- if(!organizationName.equals("USGS")){ |
- database = "STORET"; |
- } |
ArrayList<String> errorMessage = new ArrayList<String>(); |
if(sortedData_combined.length == 0){ |
if(sortedData.length == 0){ |
errorMessage.add("There is no available flow data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ if(database.equalsIgnoreCase("CDWR")){ |
+ errorMessage.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
+ } |
} |
if(sortedData_user.length==0){ |
errorMessage.add("There is no uploaded flow data for station '" + stationID + "' and the specified date range."); |
@@ -748,7 +751,7 @@ |
if(WQdata_combined.length == 0){ |
if(WQdata.length == 0){ |
errorMessage.add("There are no available '" + wqTest + "' water quality tests for station " + stationID+ " by: " + |
- organizationName + " and the specified date range"); |
+ database + " and the specified date range"); |
} |
if(WQdata_user.length==0){ |
errorMessage.add("There are no uploaded '" + wqTest + "' water quality tests for station " + stationID+ " and the specified date range"); |
@@ -881,10 +884,12 @@ |
Date currentDate = new Date(); |
SimpleDateFormat sourceDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
String today = sourceDateFormat.format(currentDate); |
- if(database.equals("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
this.dataSource = "Stream flow data and water quality test data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
this.dataSource = "Stream flow data and water quality test data courtesy of the U.S. Environmental Protection Agency, STORET. http://www.epa.gov/storet/index.html accessed: " + today; |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ this.dataSource = "Stream flow data and water quality test data courtesy of the Colorado Division of Water Resources, CDWR. http://www.dwr.state.co.us accessed: " + today; |
} |
this.start = sortedData[0][0]; |
this.end = sortedData[sortedData.length - 1][0]; |
@@ -39,16 +39,17 @@ |
import org.jfree.data.xy.XYSeriesCollection; |
|
/** |
-* Last Updated: 3-July-2014 |
+* Last Updated: 9-July-2014 |
* @author Tyler Wible |
* @since 24-June-2011 |
*/ |
public class guiTimeseries_Model { |
//Inputs |
String mainFolder = "C:/Projects/TylerWible/CodeDirectories/NetBeans/CSIP/data/CFA/Timeseries"; |
- String organizationName = "USGS";//"Colorado Dept. of Public Health & Environment";// |
- String stationID = "06764880";//"000028";// |
- String stationName = "South Platte River at Roscoe, Nebr.";//"BIG THOMPSON R NEAR MOUTH";// |
+ String database = "USGS";//"CDWR";//"STORET";//"UserData";// |
+ String organizationName = "USGS";//"Co. Division of Water Resources";//"Colorado Dept. of Public Health & Environment";// |
+ String stationID = "06764880";//"CLAGRECO";//"000028";// |
+ String stationName = "South Platte River at Roscoe, Nebr.";//"Cache La Poudre Near Greeley";//"BIG THOMPSON R NEAR MOUTH";// |
String wqTest = "flow";//"00600 Total nitrogen, water, unfiltered, milligrams per liter, mg/L"; |
String beginDate = ""; |
String endDate = ""; |
@@ -322,6 +323,9 @@ |
public void setMainFolder(String mainFolder) { |
this.mainFolder = mainFolder; |
} |
+ public void setDatabase(String database) { |
+ this.database = database; |
+ } |
public void setOrganizationName(String organizationName) { |
this.organizationName = organizationName; |
} |
@@ -482,7 +486,7 @@ |
String yAxisTitle, |
String units, |
boolean medianTF) throws ParseException { |
- //Change analysis period dates into calendar objects |
+ //Change analysis period dates into Date objects |
SimpleDateFormat desiredDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
Date period1Begin_date = new Date(); |
Date period1End_date = new Date(); |
@@ -713,8 +717,8 @@ |
plotTime = graphing.setTimeAxisPreferences(plotTime); |
|
//Create the chart with the plot and a legend |
- String title = "Time Series for Station: " + stationID + "; " + stationName; |
- JFreeChart chart = new JFreeChart(title, graphing.titleFont, plotTime, showLegend); |
+ String graphTitle = "Time Series for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plotTime, showLegend); |
|
//Set legend Font |
if(showLegend){ |
@@ -995,7 +999,7 @@ |
graphing.setCategoryAxisPreferences(plot); |
|
//Create the chart with the plot |
- String graphTitle = "Histogram for Station: " + stationID + "; " + stationName; |
+ String graphTitle = "Histogram for " + database + " Station: " + stationID + "; " + stationName; |
JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, false); |
|
//Save resulting graph for use later |
@@ -1163,8 +1167,8 @@ |
plot = graphing.setAxisPreferences(plot); |
|
//Create the charts out of the plots |
- String graph_title = "Monthly Averages for Station: " + stationID + "; " + stationName; |
- JFreeChart chart = new JFreeChart(graph_title, graphing.titleFont, plot, false); |
+ String graphTitle = "Monthly Averages for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, false); |
|
//Save monthly timeseries graph for use later |
try{ |
@@ -1252,8 +1256,8 @@ |
plot = graphing.setLogXaxisPreferences(plot); |
|
//Create the charts out of the plots |
- String graph_title = "CDF for " + timeStep + " data at Station: " + stationID + "; " + stationName; |
- JFreeChart chart = new JFreeChart(graph_title, graphing.titleFont, plot, false); |
+ String graphTitle = "CDF for " + database + " Station: " + stationID + "; " + stationName; |
+ JFreeChart chart = new JFreeChart(graphTitle, graphing.titleFont, plot, false); |
|
//Save monthly timeseries graph for use later |
try{ |
@@ -1303,7 +1307,7 @@ |
* @throws IOException |
* @throws InterruptedException |
*/ |
- public void run() throws IOException, InterruptedException, ParseException { |
+ public void run() throws IOException, InterruptedException, ParseException, Exception { |
//Inputs |
//assert args.length > 0; |
//String mainFolder = args[0]; |
@@ -1348,7 +1352,7 @@ |
String[][] sortableData = new String[0][2]; |
if(wqTest.equalsIgnoreCase("flow")){ |
//Check if any flow data exists |
- sortableData = data.extractFlowData(mainFolder, organizationName, stationID, beginDate, endDate, userData); |
+ sortableData = data.extractFlowData(mainFolder, database, organizationName, stationID, beginDate, endDate, userData); |
|
//Define other graph information |
graphUnits = "cfs"; |
@@ -1359,7 +1363,7 @@ |
showLine = true; |
}else{ |
//Search for WQ data |
- Object[] returnArray = data.extractWQdata(mainFolder, organizationName, stationID, beginDate, endDate, userData, wqTest); |
+ Object[] returnArray = data.extractWQdata(mainFolder, database, organizationName, stationID, beginDate, endDate, userData, wqTest); |
sortableData = (String[][]) returnArray[0]; |
graphUnits = (String) returnArray[1]; |
WQlabel = (String) returnArray[2]; |
@@ -1389,11 +1393,10 @@ |
if(sortedData_combined.length == 0){ |
ArrayList<String> errorMessage = new ArrayList<String>(); |
if(sortableData.length == 0){ |
- String database = "USGS"; |
- if(!organizationName.equals("USGS")){ |
- database = "STORET"; |
+ errorMessage.add("There is no available " + wqTest + " data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
+ if(database.equalsIgnoreCase("CDWR")){ |
+ errorMessage.add("The CDWR database is sensitive to the begin date used, try specifying a later begin date"); |
} |
- errorMessage.add("There is no available " + wqTest + " data in the " + database + " database for station '" + stationID + "' and the specified date range."); |
} |
if(sortedData_user.length == 0){ |
errorMessage.add("There is no available uploaded data for station '" + stationID + "' and the specified date range"); |
@@ -1524,10 +1527,12 @@ |
Date currentDate = new Date(); |
SimpleDateFormat sourceDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
String today = sourceDateFormat.format(currentDate); |
- if(organizationName.equals("USGS")){ |
+ if(database.equalsIgnoreCase("USGS")){ |
this.dataSource = "Stream flow data and water quality test data courtesy of the U.S. Geological Survey, National Water Information System: Web Interface. http://waterdata.usgs.gov/nwis, accessed: " + today; |
- }else{ |
+ }else if(database.equalsIgnoreCase("STORET")){ |
this.dataSource = "Stream flow data and water quality test data courtesy of the U.S. Environmental Protection Agency, STORET. http://www.epa.gov/storet/index.html accessed: " + today; |
+ }else if(database.equalsIgnoreCase("CDWR")){ |
+ this.dataSource = "Stream flow data courtesy of the Colorado Division of Water Resources, CDWR. http://www.dwr.state.co.us accessed: " + today; |
} |
this.len = String.valueOf(sortedData_combined.length); |
this.units = graphUnits; |