Esempio n. 1
0
def mergeDssRecords(src, dest):
    try:
        srcHecDss = HecDss.open(src)
        destHecDss = HecDss.open(dest)
        srcTsMath = srcHecDss.read("/JNEL1/BLACK-JONESVILLE/FLOW//6Hour//")
        destTsMath = destHecDss.read("/JNEL1/BLACK-JONESVILLE/FLOW//6Hour//")
        tsMerged = destTsMath.mergeTimeSeries(srcTsMath)
        srcHecDss.write(tsMerged)
        srcHecDss.done()
        destHecDss.done()
    except Exception, e:
        print(e)
Esempio n. 2
0
def readFromCDEC(dssFileName, cdecFileName, daysBack):
    timeWindow = "T-" + str(daysBack) + "D, T+1D"
    dss = HecDss.open(dssFileName, timeWindow)
    cdec = CdecControlFrame(dss)
    cdec.loadStations(cdecFileName)
    status = cdec.retrieveData()
    print(status)
Esempio n. 3
0
def dssDataTransferMonthly(inFilePath, outFilePath, outFpart, startYr, startMon, numberOfMonths, transferMap=None):

    if numberOfMonths<1:
        return

    cleanDssCatalog(inFilePath)
    
    inFile =  HecDss.open(inFilePath)
    outFile = HecDss.open(outFilePath) 

    inFilePathList, inFileBpartList = generateCatalog(inFile)
    
    dssDataTransferMonthly2(inFile, inFilePathList, inFileBpartList, outFile, outFpart, startYr, startMon, numberOfMonths, transferMap)
            
    inFile.close()
    outFile.close()
Esempio n. 4
0
def readFromDss(filename, Fpart, startTime, endTime):
    dss = HecDss.open(filename, startTime, endTime)

    FOL01_LowerTierOut = dss.read(
        "//FOLSOM-RIVER OUTLETS - LOWER TIER/FLOW-DECISION//1HOUR/" + Fpart +
        "/")
    FOL02_UpperTierOut = dss.read(
        "//FOLSOM-RIVER OUTLETS - UPPER TIER/FLOW-DECISION//1HOUR/" + Fpart +
        "/").add(FOL01_LowerTierOut)
    FOL03_PowerPlantOut = dss.read(
        "//FOLSOM-POWER PLANT/FLOW-DECISION//1HOUR/" + Fpart +
        "/").add(FOL02_UpperTierOut)
    FOL04_MainSpillway = dss.read(
        "//FOLSOM-MAIN SPILLWAY/FLOW-DECISION//1HOUR/" + Fpart +
        "/").add(FOL03_PowerPlantOut)
    FOL05_EmergencySpillway = dss.read(
        "//FOLSOM-EMERGENCY SPILLWAY/FLOW-DECISION//1HOUR/" + Fpart +
        "/").add(FOL04_MainSpillway)
    FOL06_DikesOverflow = dss.read("//FOLSOM-OVERFLOW/FLOW-DECISION//1HOUR/" +
                                   Fpart + "/").add(FOL05_EmergencySpillway)
    FOL07_DamLeakageOverflow = dss.read(
        "//FOLSOM-DAM L&O/FLOW-DECISION//1HOUR/" + Fpart +
        "/").add(FOL06_DikesOverflow)

    d1 = {
        'FOL07_DamLeakageOverflow': FOL07_DamLeakageOverflow.getData(),
        'FOL06_DikesOverflow': FOL06_DikesOverflow.getData(),
        'FOL05_EmergencySpillway': FOL05_EmergencySpillway.getData(),
        'FOL04_MainSpillway': FOL04_MainSpillway.getData(),
        'FOL03_PowerPlantOut': FOL03_PowerPlantOut.getData(),
        'FOL02_UpperTierOut': FOL02_UpperTierOut.getData(),
        'FOL01_LowerTierOut': FOL01_LowerTierOut.getData()
    }

    return d1
def readDssFile(filename,startTime, endTime):
	dss = HecDss.open(filename, startTime, endTime)	
	
	pathEnd = "/FLOW-DECISION//1Hour/E504-NAT--0/"

	lower = dss.read("//FOLSOM-RIVER OUTLETS - LOWER TIER"+pathEnd)
	upper = dss.read("//FOLSOM-RIVER OUTLETS - UPPER TIER"+pathEnd)
	power = dss.read("//FOLSOM-POWER PLANT"+pathEnd)
	mainSpill = dss.read("//FOLSOM-MAIN SPILLWAY"+pathEnd)
	eSpill = dss.read("//FOLSOM-EMERGENCY SPILLWAY"+pathEnd)
	dikes = dss.read("//FOLSOM-OVERFLOW"+pathEnd)
	leakage = dss.read("//FOLSOM-DAM L&O"+pathEnd)

	# make data incremental (stackable)
	upper = upper.add(lower)
	power = power.add(upper)
	mainSpill = mainSpill.add(power)
	eSpill = eSpill.add(mainSpill)
	dikes = dikes.add(eSpill)
	leakage = leakage.add(dikes)
	#package up data, as dictionary, to return from function
	allData ={'lower':lower.getData(),
			  'upper':upper.getData(),
			  'power': power.getData(),
			  'mainSpill': mainSpill.getData(),
			  'eSpill': eSpill.getData(),
			  'dikes': dikes.getData(),
			  'leakage': leakage.getData()
			} 
	
	return allData
Esempio n. 6
0
def getPeakTimeData(sourceFile):
    # Read in hourly (or other periodic) LOCATION-TIME//MAX STAGE data from HEC-RAS DSS file. Store data in a pickle file for further use.
    # Example of data paths:
    # /E STONY CR DITCH E STONY CR DITCH//LOCATION-TIME//MAX STAGE/HUFFQII_100YR12H/
    dssFile = HecDss.open(sourceFile, True)
    pathNames = dssFile.getCatalogedPathnames("/*/*/LOCATION-TIME//MAX STAGE/HUFFQII_100YR12H/")
    dataDict = getDSSData(pathNames, dssFile)
    return dataDict
Esempio n. 7
0
def processDss():
    
    inDssPath   = ppath.normpath(_originalSvDssFile)
    outDssPath  = ppath.normpath(_shiftedSvDssFile)
    
    Tools.cleanDssCatalog(inDssPath)
    
    inFile =  HecDss.open(inDssPath)
    outFile = HecDss.open(outDssPath) 
    
    for variable_YR in range( _beginPastYR, _endPastYR + 1 ):
        
           
        Tools.copyDssToFuture(inFile, outFile, variable_YR, _sequentialYRs, _dssBufferYRs, _beginFutureYR )
    
    inFile.close()
    outFile.close()

    Param.logger.info("Finished processDss") 
Esempio n. 8
0
def getTimestageData(sourceFile):
    # Read in hourly (or other periodic) STAGE data from HEC-RAS DSS file. Store data in a pickle file for further use.
    # Example of data paths:
    # /E STONY CR DITCH E STONY CR DITCH/3.614/STAGE/01DEC2006/1HOUR/HUFFQII_100YR12H/
    # /E STONY CR DITCH E STONY CR DITCH/3.614/STAGE/01JAN2007/1HOUR/HUFFQII_100YR12H/
    # .get([file path], True) returns data from all dates
    dssFile = HecDss.open(sourceFile, True)
    pathNames = dssFile.getCatalogedPathnames("/*/*/STAGE/01DEC2006/1HOUR/HUFFQII_100YR12H/")
    dataDict = getDSSData(pathNames, dssFile)
    return dataDict
Esempio n. 9
0
def processDss():

    inDssPath = ppath.normpath(_originalSvDssFile)
    outDssPath = ppath.normpath(_shiftedSvDssFile)

    Tools.cleanDssCatalog(inDssPath)

    inFile = HecDss.open(inDssPath)
    outFile = HecDss.open(outDssPath)

    for variable_YR in range(_beginPastYR, _endPastYR + 1):

        Tools.copyDssToFuture(inFile, outFile, variable_YR, _sequentialYRs,
                              _dssBufferYRs, _beginFutureYR)

    inFile.close()
    outFile.close()

    Param.logger.info("Finished processDss")
Esempio n. 10
0
def ExtractDSStoExcel(configParams, verbose):

    print "\nExtractDSStoExcel(): dssFile %s\n" % configParams.dssFile

    try:
        try:
            dss = HecDss.open( configParams.dataDir + '/' +\
                               configParams.dssFile )

            datasets = Vector()

            pathNameList = dss.getPathnameList()

            # Subset the available dss file paths into those that
            # contain the dssPathIDs and dssDataType
            dssPaths = []
            for dssPathID in configParams.dssPathIDs:
                foundID = False
                for dssPath in pathNameList:
                    if foundID:
                        break
                    if dssPathID in dssPath and \
                       configParams.dssDataType in dssPath:
                        dssPaths.append(dssPath)
                        foundID = True
                        break

            # Extract data and add to Vector datasets
            for dssPath in dssPaths:
                data = dss.get(dssPath, True)

                if data.numberValues == 0:
                    print "%s %s %s\n" % ("ExtractDSStoExcel():", dssPath,
                                          'No Data')
                else:
                    print 'ExtractDSStoExcel(): %s numberValues = %d' % \
                        dssPath, data.numberValues

                    datasets.add(data)

            # Export the .xls file
            list = []
            list.append(datasets)
            table = HecDataTableToExcel.newTable()
            table.createExcelFile(list, outFile)

        except Exception, err:
            print "%s %s\n" % ("ExtractDSStoExcel(): Python Error", err)

        except JavaException, err:
            print "%s %s\n" % ("ExtractDStoExcelS(): Error", err.getMessage())
Esempio n. 11
0
def _write_dss(input_):

    # Create time series container
    tsc = TimeSeriesContainer()

    # Get data from input file
    try:
        tsc.fullName = input_['fullname']
        tsc.interval = input_['interval']
        tsc.units = input_['units']
        tsc.type = input_['dsstype']
        data = input_['data']
        filepath = input_['filepath']
    except KeyError:
        _logger.exception('Incomplete data on the dss handler input file!')
        _logger.error('Exiting.')
        exit(1)
    _logger.debug('filepath: %s', filepath)

    # Get list of times and respective values
    times = []
    values = []
    for k, v in sorted(data.viewitems()):
        # t = datetime.strptime(k, '%Y-%m-%d %H:%M:%S')
        t = HecTime(k.strftime('%d%b%Y'), k.strftime('%H%M'))
        times.append(t.value())
        values.append(v)

    # Set list of times, values, and size of list
    tsc.times = times
    tsc.values = values
    tsc.numberValues = len(values)
    _logger.debug('tsc.times: %s', tsc.times)
    _logger.debug('tsc.values: %s', tsc.values)

    # Check if dss file already exists
    if op.isfile(filepath):
        _logger.warning('Deleting old file!')
        # Delete existing dss file
        try:
            os.remove(filepath)
        except OSError:
            _logger.warning('Warning! Deletion of old file failed.')
    # else:
    #     _logger.warning("File doesn't exist!")
    # Write new dss file
    dss_file = HecDss.open(filepath)
    dss_file.put(tsc)
    dss_file.done()
Esempio n. 12
0
def dssDataTransferMonthly(inFilePath,
                           outFilePath,
                           outFpart,
                           startYr,
                           startMon,
                           numberOfMonths,
                           transferMap=None):

    if numberOfMonths < 1:
        return

    cleanDssCatalog(inFilePath)

    inFile = HecDss.open(inFilePath)
    outFile = HecDss.open(outFilePath)

    inFilePathList, inFileBpartList = generateCatalog(inFile)

    dssDataTransferMonthly2(inFile, inFilePathList, inFileBpartList, outFile,
                            outFpart, startYr, startMon, numberOfMonths,
                            transferMap)

    inFile.close()
    outFile.close()
def storeToDss(_tsc, station, decodeInfo):
    global dssFilename, dssfile, locations, parameters
    if not dssfile:
        Heclib.zset("MLVL", "", 0)
        dssfile = HecDss.open(dssFilename)
    dd, decodeInfo = decodeInfo
    parts = ["" for i in range(8)]
    parts[A] = locations[station]["DSS_A-PART"]
    parts[B] = locations[station]["DSS_B-PART"]
    try:
        parts[B] += "-%s" % locations[station]["DSS_SUB-LOCATIONS"][dd]
    except:
        pass
    parts[F] = locations[station]["DSS_F-PART"]
    tsc = _tsc.clone()
    parts[C] = decodeInfo["DSS_PARAMETER"]
    try:
        parts[C] += "-%s" % locations[station]["DSS_SUB-PARAMETERS"][dd]
    except:
        pass
    if tsc.interval == IRREGULAR_INTERVAL:
        parts[E] = "IR-MONTH"
    else:
        parts[E] = Interval(tsc.interval).getInterval().upper().replace(
            "S", "").replace("MINUTE", "MIN").replace("MONTH", "MON")
    tsc.units = decodeInfo["DSS_UNIT"]
    tsc.type = decodeInfo["DSS_TYPE"]
    tsc.fullName = "/".join(parts)
    tsc.watershed = parts[A]
    try:
        tsc.location, tsc.subLocation = parts[B].split("-", 1)
    except:
        tsc.location = parts[B]
    try:
        tsc.parameter, tsc.subParameter = parts[C].split("-", 1)
    except:
        tsc.parameter = parts[B]
    tsc.fileName = dssFilename
    if outputLevel > NONE:
        log.output("Storing %s:%s (%d values)" %
                   (tsc.fileName, tsc.fullName, tsc.numberValues))
    dssfile.put(tsc)
Esempio n. 14
0
def _baselineHmc(parentTsc, dssFilePath, startDate, endDate):
    """
    Return the baseline timeseries between two dates.

    Note: ``parentTsc`` does not necessarily need to contain the baseline
    period. It's just used for the metadata.

    :param parentTsc: The timeseries for which the baseline period should be
                      extracted
    :type parentTsc: :class:`TimeSeriesContainer`
    :param dssFilePath: File path to HEC-DSS file to load data from
    :type dssFilePath: str
    :param startDate: Start of baseline period
    :type startDate: str
    :param endDate: End of baseline period
    :type endDate: str
    :return: Baseline timeseries
    :rtype: :class:`HecMath`
    """
    dssFile = HecDss.open(dssFilePath)
    return dssFile.read(parentTsc.fullName, str(startDate), str(endDate))
Esempio n. 15
0
def _read_dss(input_):

    # Get data from input file
    try:
        dsspaths = input_['dsspaths']
        filepath = input_['filepath']
        start_time = input_['start_time']
        end_time = input_['end_time']
    except KeyError:
        _logger.exception('Incomplete data on the dss handler input file!')
        _logger.error('Exiting.')
        exit(1)
    _logger.debug('dsspaths: %s', dsspaths)
    _logger.debug('filepath: %s', filepath)
    _logger.debug('start_time: %s', start_time)
    _logger.debug('end_time: %s', end_time)

    # Open dss file
    dssfile = HecDss.open(filepath)

    # Read data from dss
    data = {}
    for dsspath in dsspaths:

        # Get time series container from dss
        tsc = dssfile.get(dsspath)

        for t0, value in zip(tsc.times, tsc.values):

            t = _DSS_BEGIN + timedelta(minutes=t0)
            _logger.debug('%s: %s', t, value)

            # Get only data between start and end time
            if start_time <= t <= end_time:
                data[t] = value

    # Close dss file
    dssfile.done()

    return data
Esempio n. 16
0
def SaveToDSS(rawDataList,SaveLocation,espDays,URLSite):
	 #From raw data list, saves the list of ESP dataframes to file
	#  If saveLocation is a file, saves there.  saveLocation can also
	#  be a directory, in which case a default file name is written provided
	#  the espDays  argument is assigned	
	if SaveLocation[-3:].upper()=='DSS':
		outFileName =  ("%s" %(SaveLocation))
	else:
		outFileName = ("%s\\rfc_esp_flows_%sday.dss" % (SaveLocation,espDays))
	dssFile = HecDss.open(outFileName,1)

	ESP_Matrix = rawDataList[7:] #This is set for NW RFC's data. There is extra meta data that we do not need to parse through

	TimeStamp_Matrix = []
	for i in range(len(ESP_Matrix)):
		TempTimeStampData = ESP_Matrix[i][0]
		TimeStamp_Matrix.append(TempTimeStampData)
	#print(TimeStamp_Matrix)

	EnsembleDataValues = []
	for i in range(len(ESP_Matrix)):
		TempESP_Value = ESP_Matrix[i][1:]
		EnsembleDataValues.append(TempESP_Value)
	
	templateTsc = createTemplateTSC(ESP_Matrix)
	
	#NumMembers is the variable to represent the number of ensemble members. This currently has the minus 1 to remove the initial column that is labeling the second dimision of the data.
	NumMembers = len(ESP_Matrix[0])-1
	#NumTimeSteps is to denote how many time steps are with the data. 
	NumTimeSteps = len(ESP_Matrix)

	for colIndex in range(NumMembers):
		tsc = updateTSCfromESP(tsc = templateTsc, #update tsc object with data for this ESP trace
		                      values = GetEnsembleValues(ESP_Matrix,colIndex+1),
		                      colName = colIndex,
		                      SiteUrl = URLSite)
		dssFile.put(tsc)
	dssFile.done()
def write_to_dss(func,x1,x2,path,fileName):
    
    pdc = PairedDataContainer() # constructor
    pdc.fullName = path
    ylist = []
    xlist = []
    step = (x2-x1)/100.0
    x=x1
    while x <=x2 :
        ylist.append(func(x))
        xlist.append(x)
        x = x + step

    pdc.xOrdinates = xlist
    pdc.yOrdinates = [ylist]
    pdc.numberCurves = 1
    pdc.numberOrdinates = len(xlist)
    pdc.xparameter = "x"
    pdc.yparameter = "y"

    dss = HecDss.open(fileName)
    dss.put(pdc)
    dss.done()
def readData():
    startTime = "18Jan1986 2400"
    endTime = "18Mar1986 2400"
    dss = HecDss.open(R"C:\project\plot-dss-data\AR_Folsom_Simulation7.dss",
                      startTime, endTime)

    leakage = dss.read("//FOLSOM-DAM L&O/FLOW-DECISION//1Hour/E504-NAT--0/")
    eSpill = dss.read(
        "//FOLSOM-EMERGENCY SPILLWAY/FLOW-DECISION//1Hour/E504-NAT--0/")
    mainSpill = dss.read(
        "//FOLSOM-MAIN SPILLWAY/FLOW-DECISION//1Hour/E504-NAT--0/")
    dikes = dss.read("//FOLSOM-OVERFLOW/FLOW-DECISION//1Hour/E504-NAT--0/")
    power = dss.read("//FOLSOM-POWER PLANT/FLOW-DECISION//1Hour/E504-NAT--0/")
    lower = dss.read(
        "//FOLSOM-RIVER OUTLETS - LOWER TIER/FLOW-DECISION//1Hour/E504-NAT--0/"
    )
    upper = dss.read(
        "//FOLSOM-RIVER OUTLETS - UPPER TIER/FLOW-DECISION//1Hour/E504-NAT--0/"
    )
    # do math on data
    upper = upper.add(lower)
    power = power.add(upper)
    mainSpill = mainSpill.add(power)
    eSpill = eSpill.add(mainSpill)
    dikes = dikes.add(eSpill)
    leakage = leakage.add(dikes)
    # package up in dictionary
    allData = {
        'lower': lower.getData(),
        'upper': upper.getData(),
        'power': power.getData(),
        'mainSpill': mainSpill.getData(),
        'eSpill': eSpill.getData(),
        'dikes': dikes.getData(),
        'leakage': leakage.getData(),
    }
    return allData
Esempio n. 19
0
from hec.script import Plot
from hec.script.Constants import TRUE, FALSE
from hec.heclib.dss import HecDss
theFile = HecDss.open(r"C:\project\DSSVue-Example-Scripts\data\sample.dss")
thePath = "/AMERICAN/FOLSOM/FLOW-RES IN/01JAN2006/1DAY/OBS/"
flowDataSet = theFile.get(thePath)  # read a path name
thePlot = Plot.newPlot()  # create the plot
thePlot.addData(flowDataSet)  # add the flow data set to the plot
thePlot.showPlot()  # show the plot
viewport0 = thePlot.getViewport(0)  # get the first viewport
viewport0.setMinorGridYColor(
    "black")  # set the viewport's minor Y grid to black
viewport0.setMinorGridYVisible(TRUE)  # tell the minor Y grid to display
thePlot.stayOpen()
Esempio n. 20
0
# HEC-DSSVUE script to dump all of the DCD data to xlsx files.

import os
import java
from hec.heclib.dss import HecDss
from hec.dataTable import HecDataTableToExcel

print "Hi"

hecfile = HecDss.open("dcd_sep2016.dss", 1)  # must exist

#dest="excel"
dest = "csv"  # way faster on write and read, and slightly smaller.

if not os.path.exists(dest):
    os.makedirs(dest)

ABCs = {}
count = 0
for path in hecfile.getPathnameList():
    parts = path.split('/')
    parts[4] = ''
    ABC = "/".join(parts)  # really ABCEF
    if ABC in ABCs: continue
    ABCs[ABC] = 1
    print "Path: %s" % ABC

    data = hecfile.get(path, True)  # True to read full time series

    if dest == "excel":
        # Add Data
#from hec.script import *
from hec.heclib.dss import HecDss
from hec.dataTable import HecDataTableToExcel
import java
import sys
# Open the file and get the data
try:
    dir1 = sys.argv[1]
    dir2 = sys.argv[2]
    dssFile = HecDss.open(dir1 + "\\sample.dss",
                          "10MAR2006 2400, 09APR2006 2400")
    precip = dssFile.get("/AMERICAN/FOLSOM/PRECIPBASIN/01JAN2006/1DAY/OBS/")
    stor = dssFile.get("/AMERICAN/FOLSOM/ STOR-RES EOP/01JAN2006/1DAY/OBS/")
    topcon = dssFile.get("/AMERICAN/FOLSOM/TOP CON STOR/01JAN2006/1DAY/OBS/")
    sagca = dssFile.get(
        "/AMERICAN/FOLSOM-SAGCA/TOP CON STOR/01JAN2006/1DAY/OBS/")
    inflow = dssFile.get("/AMERICAN/FOLSOM/FLOW-RES IN/01JAN2006/1DAY/OBS/")
    outflow = dssFile.get("/AMERICAN/FOLSOM/FLOW-RES OUT/01JAN2006/1DAY/OBS/")
except java.lang.Exception, e:
    # Take care of any missing data or errors
    MessageBox.showError(e.getMessage(), "Error reading data")
# Add Data
datasets = java.util.Vector()
datasets.add(precip)
datasets.add(stor)
datasets.add(topcon)
datasets.add(sagca)
datasets.add(inflow)
datasets.add(outflow)
# For this code, jython sees a List before a Vector
#list = java.awt.List()
Esempio n. 22
0
def onePerParam(config, dssFilePath):
    plotted = 0  # Number of plots exported
    messages = []
    
    outputFolder = tbu.relativeFolder(config['output_folder'], dssFilePath)
    dssFile = HecDss.open(dssFilePath)
    
    minDate = HecTime(config['period']['start'])
    maxDate = HecTime(config['period']['end'])           

    colours = _coloursByLocation(config)

    for param, paramConfig in config['params'].iteritems():
        thePlot = Plot.newPlot()
        dataPaths = [
            "/%s/%s/%s//%s/%s/" % (config['site'].upper(), 
                                   location.upper(), 
                                   param.upper(), 
                                   config['interval'].upper(), 
                                   config['version'].upper())
            for location in config['locations']
        ]
        datasets = [dssFile.get(p, 1) for p in dataPaths]
        datasets = [d for d in datasets if d.numberValues > 0]
        if not datasets:
            messages.append("No data for parameter '%s'." % param)
            continue
        
        map(thePlot.addData, datasets)

        thePlot.showPlot()
        thePlot.setPlotTitleText(param)
        thePlot.setPlotTitleVisible(1)
        thePlot.setSize(int(config['width']), int(config['height']))

        # We can only access labels and curves at this point
        map(lambda d: thePlot.getLegendLabel(d).setText(d.location), datasets)

        for dataset in datasets:
            curve = thePlot.getCurve(dataset)
            curve.setLineColor("%s, %s, %s" % tuple(colours[dataset.location]))
            curve.setLineWidth(config['line']['width'])

        units = set(ds.units for ds in datasets)
        for vp_index, unit in enumerate(units):  # 1 viewport per distinct unit
            viewport = thePlot.getViewport(vp_index)
            viewport.getAxis("X1").setScaleLimits(minDate.value(), 
                                                  maxDate.value())
            viewport.getAxis("Y1").setLabel(unit)
            viewport.setMinorGridXVisible(1)
            viewport.setMinorGridYVisible(1)
            if paramConfig:
                if paramConfig['scale'].lower() == 'log':
                    viewport.setLogarithmic('Y1')  # This throws a warning message if y-values <= 0. We can't catch this as an exception. 

        thePlot.saveToJpeg(os.path.join(outputFolder, 
                           config['version'] + "_" + param),
                           95)
        thePlot.close()
        plotted += 1

    dssFile.done()
    return plotted, messages
from hec.heclib.dss import HecDss, DSSPathname
import java
import sys

filename = ""
print(len(sys.argv))

#  relative filename to VSCode workspace directory
# , assuming running in vscode with .vscode/tasks.json and scripts/go.bat
if len(sys.argv) == 2:
    filename = sys.argv[1] + "/data/sample.dss"
    print("filename = ", filename)

#  Open the file and get the data
try:
    dssFile = HecDss.open(filename)
    airTemp = dssFile.get("/GREEN RIVER/OAKVILLE/AIRTEMP/01MAY1992/1HOUR/OBS/")
    outflow = dssFile.get(
        "/GREEN RIVER/OAKVILLE/FLOW-RES OUT/01MAY1992/1HOUR/OBS/")
    dssFile.done()
except java.lang.Exception, e:
    #  Take care of any missing data or errors
    MessageBox.showError(e.getMessage(), "Error reading data")

#  Initialize the plot and add data
plot = Plot.newPlot("Oakville")
plot.addData(airTemp)
plot.addData(outflow)

#  Create plot
plot.setSize(600, 600)
Esempio n. 24
0
# .getCatalogedPathnames([path pattern]) retrieves all data addresses that match the pattern
# .get([file path], True) returns data from all dates

config = CompareConfig()
filePath = config.filePath  #G:/PROJECTS_non-FEMA/MWRD_ReleaseRate_Phase1/H&H/StonyCreek/
versionPath = config.versionPath  #Stony_V
dssFileName = config.dssRasFileName  #/HydraulicModels/ExistingConditions/STCR/STCR_DesignRuns/STCR_Design2.dss
versions = config.versions

dataToGet = []
dssFiles = []
for v in versions:
    dataToGet.append(["FLOW/" + config.startDate + "/*", "hydrograph_V" + v])
    dssFiles.append(versionPath + v + dssFileName)
for i in range(len(dataToGet)):
    dssFile = HecDss.open(dssFiles[i], True)
    pathNames = dssFile.getCatalogedPathnames("/*/*/" + dataToGet[i][0] + "/" +
                                              config.rasRunName + "/")
    dataDict = {}
    for item in range(len(pathNames)):
        dataFromFile = dssFile.get(pathNames[item], True)
        try:
            dataList = list(dataFromFile.values)
            dataDict.update({pathNames[item]: dataList})
        except Exception, e:
            for loc in range(len(dataFromFile.xOrdinates)):
                dataLocation = dataFromFile.xOrdinates[loc]  #[:8]
                dataValue = dataFromFile.yOrdinates[0][loc]  #[:8]
                splitPath = pathNames[item].split('/')
                splitPath[2] = str(dataLocation)
                fullLoc = "/".join(splitPath)
def writeTotalStorage(totStorage, fileName, filePath):
    csvfile = open(filePath + fileName + "_storage.csv", 'wb')
    for k in totStorage.keys():
        csvfile.write(k + ", " + str(totStorage[k]) + "\n")
    csvfile.close()


# obtain configuration details for HEC applications for
# python and jython scripts
import hecConfig
reload(hecConfig)
config = hecConfig.HecConfig()
#dssFilePath = config.getHmsProjectPath() + "/" + config.hmsProjectName + ".dss"
print("write DSS file: " + config.dssfile)
print("read DSS file: " + config.osDssFile)
dss = HecDss.open(config.dssfile)
soDss = HecDss.open(config.osDssFile)


# Read the subbasin information from the pickle file saved by the calling script (hecModel.py)
import pickle
dtf = open(config.getDataTransferFilePath(),'r+')
subbasins = pickle.load(dtf)
dtf.close()
totStorage = {}

acresPerSqMile = 640

# Build and save the outflow-storage curve for each sub basin
for subbasin in subbasins:
    if not subbasin['tableName'] == '':
from hec.plugins.dssvue.piXml import PiXmlTsExport
from java.io import File
from java.util import Vector
from hec.heclib.dss import HecDss

dssFilename = R"C:\project\DSSVue-Example-Scripts\data\sample.dss"
pixmlFilename = R"C:\tmp\out.pi.txt"

path = "//SACRAMENTO/PRECIP-INC/01JAN1877/1DAY/OBS/"

dss = HecDss.open(dssFilename)
dc = dss.get(path)

# PiXmlTsExport expects Vector array (Vector[])
v = Vector()
v2 = Vector()
v2.add(dc)
v.add(v2)

pi = PiXmlTsExport(v)
piFile = File(pixmlFilename)
pi.startExport(piFile)
Esempio n. 27
0
class UI:
    global dssFile
    mainWindow = ListSelection.getMainWindow()
    dssFileName = mainWindow.getDSSFilename()
    dssFile = HecDss.open(dssFileName)
    global frame, lbl_close, list_locations, chckbxShowLocationPlot, eventsTable, dm_events, dm_meltRate
    global swePaths, precipPaths, tempPaths, bList, meltRateTable, startDateField, endDateField

    frame = JFrame("Snow PAC - Parameter Aggregator & Calculator")
    #     frame.setUndecorated(True)
    frame.setBackground(Color.WHITE)
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
    frame.setBounds(100, 100, 1110, 775)

    contentPane = JPanel()
    contentPane.setBackground(Color.WHITE)
    contentPane.setBorder(EmptyBorder(5, 5, 5, 5))

    frame.setContentPane(contentPane)
    contentPane.setLayout(None)

    class MouseListener(MouseAdapter):
        #       @Override
        def mousePressed(self, e):
            global xx
            global xy
            xx = e.getX()
            xy = e.getY()

    class MouseMotionListener(MouseMotionAdapter):
        #       @Override
        def mouseDragged(self, arg0):
            x = arg0.getXOnScreen()
            y = arg0.getYOnScreen()
            frame.setLocation(x - xx, y - xy)

    mL = MouseListener()
    mML = MouseMotionListener()
    contentPane.addMouseListener(mL)
    contentPane.addMouseMotionListener(mML)

    if os.path.exists(img_dir + "/button.jpg"):
        btnIcon = ImageIcon(img_dir + "/button.jpg")
    else:
        btnIcon = ImageIcon(img_dir2 + "/button.jpg")

    scrollPane_events = JScrollPane()
    scrollPane_events.setBounds(270, 372, 403, 263)
    contentPane.add(scrollPane_events)

    scrollPane_locations = JScrollPane()
    scrollPane_locations.setBounds(270, 49, 403, 203)
    contentPane.add(scrollPane_locations)

    class deleteAction(AbstractAction):
        def actionPerformed(self, deleteEvent):
            # Get selected Rows and reverse list. Removes each row in list one at a time.
            # List is Reversed using [::-1], so it doesn't mess up the ordering as it deletes through the loop.
            for row in meltRateTable.getSelectedRows()[::-1]:
                dm_meltRate.removeRow(row)
                dm_meltRate.insertRow(row, [None, None])

    scrollPane_table = JScrollPane()
    scrollPane_table.setBounds(708, 49, 338, 586)
    contentPane.add(scrollPane_table)

    meltRateTable = JTable()
    scrollPane_table.setViewportView(meltRateTable)
    scrollPane_table.setBorder(LineBorder(Color(1, 1, 1), 2, True))
    meltRateTable.setFont(Font("Tahoma", Font.PLAIN, 11))

    columns = ("ATI (Deg F-Day)", "Meltrate (Inches/Deg F-Day)")
    data = []
    datarows = 100
    data.append([0, None])
    for i in range(datarows):
        data.append([None, None])
    dm_meltRate = DefaultTableModel(data, columns)

    meltRateTable.setModel(dm_meltRate)

    meltRateTable.getColumnModel().getColumn(0).setPreferredWidth(154)
    meltRateTable.getColumnModel().getColumn(1).setResizable(False)
    meltRateTable.getColumnModel().getColumn(1).setPreferredWidth(154)
    meltRateTable.setCellSelectionEnabled(True)

    #    Delete data from the table using the Delete Key.
    #     meltRateTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    inputMap = meltRateTable.getInputMap(JComponent.WHEN_FOCUSED)
    actionMap = meltRateTable.getActionMap()

    deleteActionStr = "delete"
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
                 deleteActionStr)
    actionMap.put(deleteActionStr, deleteAction())

    #     jLabelStartDate = JLabel()
    #     jLabelStartDate.setText("Optional Start Date:")
    #     jLabelStartDate.setToolTipText("Optional User Specified Date Range for Paired Data. If Specified, Will be Calculated for each Water Year.")
    #     jLabelStartDate.setBounds(420, 263, 120, 20);
    #     jLabelStartDate.setFont( Font("Tahoma", Font.PLAIN, 12))
    #     contentPane.add(jLabelStartDate)
    #
    #     startDateField = CalendarField();
    #     jLabelStartDate.setLabelFor(startDateField);
    #     startDateField.setMargin(Insets(0, 4, 0, 0));
    #     startDateField.setBounds(540, 263, 118, 22);
    #     startDateField.setFont(Font("Tahoma", Font.PLAIN, 12));
    #     startDateField.setToolTipText("Optional User Specified Date Range for Paired Data. If Specified, Will be Calculated for each Water Year.")
    #     contentPane.add(startDateField);
    #
    #     jLabelEndDate = JLabel()
    #     jLabelEndDate.setText("Optional End Date:")
    #     jLabelEndDate.setToolTipText("Optional User Specified Date Range for Paired Data. If Specified, Will be Calculated for each Water Year.")
    #     jLabelEndDate.setBounds(420, 293, 120, 20);
    #     jLabelEndDate.setFont( Font("Tahoma", Font.PLAIN, 12))
    #     contentPane.add(jLabelEndDate)
    #
    #     endDateField = CalendarField();
    #     jLabelEndDate.setLabelFor(endDateField);
    #     endDateField.setMargin(Insets(0, 4, 0, 0));
    #     endDateField.setBounds(540, 293, 118, 22);
    #     endDateField.setFont(Font("Tahoma", Font.PLAIN, 12));
    #     endDateField.setToolTipText("Optional User Specified Date Range for Paired Data. If Specified, Will be Calculated for each Water Year.")
    #     contentPane.add(endDateField);

    def recalcBtnSelect(event):
        global swePaths, precipPaths, tempPaths
        selectedLocations = list_locations.getSelectedValuesList()
        swePaths, precipPaths, tempPaths = Locations.getSelectedLocations(
            selectedLocations)
        pathsNoDPart, sList, pList, tList = CalcAtiMelt.processPathsLists(
            swePaths, precipPaths, tempPaths)
        dList = CalcAtiMelt.processPathsDatesList(pathsNoDPart)
        aList, mList = CalcAtiMelt.calcATIMelt(selectedLocations, sList, pList,
                                               tList, dList)

        # Write Melt-Cum and ATI Locations to DSS.
        CalcAtiMelt.writeAtiMelt(selectedLocations, dList, aList, mList)

        # Plot Locations if checkbox.selected = True.
        if chckbxShowLocationPlot.selected is True:
            #             print '\nPLOT TEAM ACTIVATE'
            PlotAtiMelt.plotAtiMelt(selectedLocations)

        # Use optional specified dates if fields are not blank.
#         if startDateField.getText() and endDateField.getText() is not None:
#             pdStart, pdEnd = ProcessPD.getSpecifiedDates(startDateField, endDateField)
#         else:
        pdStart = None
        pdEnd = None

        # Create Paired Data for Selected Locations.
        ProcessPD.processPairedData(selectedLocations, dList, mList, aList,
                                    pdStart, pdEnd)

        # Populate the UI Paired Data Table.
        CalcPD.updatePDTable(dssFile, eventsTable, dm_events)

        # Close the DSS File.
        dssFile.close()

    def plotPDBtnSelect(event):
        selected_Events = eventsTable.getSelectedRows()
        # Print 'selected_Events: ', selected_Events
        # Sorting of the table by selecting the headers is doen by using: eventsTable.setAutoCreateRowSorter(True)
        # This sorts the table but does not update the table model.
        # To ensure sorting and selecting of resulting paths works properly,
        # we must convert our selection using: eventsTable.convertRowIndexToModel(event)
        selectedEvents = []
        for event in selected_Events:
            selectedEvents.append(eventsTable.convertRowIndexToModel(event))
#         print 'selectedEvents: ', selectedEvents
        PlotPD.plotPD(eventsTable, selectedEvents, dssFile)
        dssFile.close()

    def calcMeltRateBtnSelect(event):
        selected_Events = eventsTable.getSelectedRows()
        selectedEvents = []
        for event in selected_Events:
            selectedEvents.append(eventsTable.convertRowIndexToModel(event))
        meltRateList = CalcMeltRate.calcMeltRate(selectedEvents, eventsTable,
                                                 meltRateTable, dssFile)
        CalcMeltRate.updateTable(meltRateTable, meltRateList, dm_meltRate)
        dssFile.close()

    locDict, bList = Locations.getPaths(dssFile)
    locList = Locations.getList(locDict)

    list_locations = JList(locList)
    scrollPane_locations.setViewportView(list_locations)
    list_locations.setBorder(LineBorder(Color(0, 0, 0), 2, True))

    eventsTable = JTable()
    scrollPane_events.setViewportView(eventsTable)
    scrollPane_events.setBorder(LineBorder(Color(1, 1, 1), 2, True))
    eventsTable.setFont(Font("Tahoma", Font.PLAIN, 11))

    locationsList, eventsList = Locations.getPairedData(dssFile)

    columns = ("Location", "Event")
    data = []
    for l, e in zip(locationsList, eventsList):
        data.append([l, e])
    dm_events = DefaultTableModel(data, columns)

    eventsTable.setModel(dm_events)
    eventsTable.setAutoCreateRowSorter(True)

    eventsTable.getColumnModel().getColumn(0).setPreferredWidth(154)
    eventsTable.getColumnModel().getColumn(1).setResizable(False)
    eventsTable.getColumnModel().getColumn(1).setPreferredWidth(154)
    eventsTable.setRowSelectionAllowed(True)

    inputPanel = JPanel()
    inputPanel.setBorder(EmptyBorder(0, 0, 0, 0))
    inputPanel.setBackground(Color(255, 255, 255))
    inputPanel.setBounds(270, 11, 410, 27)
    contentPane.add(inputPanel)
    inputPanel.setLayout(None)
    inputPanel.setVisible(True)

    lbl_locations = JLabel(
        "DSS Locations that have PRECIP-INC, TEMPERATURE-AIR-AVG, and SWE. ")
    lbl_locations.setFont(Font("Tahoma", Font.PLAIN, 12))
    lbl_locations.setBounds(0, 11, 410, 15)
    inputPanel.add(lbl_locations)

    btnRecalc = JButton(btnIcon, actionPerformed=recalcBtnSelect)
    btnRecalc.setText("Calculate Paired Data")
    btnRecalc.setFont(Font("Tahoma", Font.BOLD, 12))
    btnRecalc.setForeground(Color.WHITE)
    btnRecalc.setBackground(Color.WHITE)
    btnRecalc.setBorderPainted(False)
    btnRecalc.setContentAreaFilled(False)
    btnRecalc.setFocusPainted(False)
    btnRecalc.setOpaque(True)
    btnRecalc.setVerticalTextPosition(SwingConstants.CENTER)
    btnRecalc.setHorizontalTextPosition(SwingConstants.CENTER)
    btnRecalc.setBounds(382, 293, 165, 54)
    contentPane.add(btnRecalc)

    leftPanel = JPanel()
    leftPanel.setBackground(Color.DARK_GRAY)
    leftPanel.setBounds(0, 0, 250, 780)
    contentPane.add(leftPanel)
    leftPanel.setLayout(None)

    lbl_castle = JLabel("")
    lbl_castle.setBounds(110, 678, 40, 25)
    leftPanel.add(lbl_castle)

    try:
        i_corps = ImageIO.read(File(img_dir + "/CorpsCastle.png"))
    except:
        i_corps = ImageIO.read(File(img_dir2 + "/CorpsCastle.png"))

    corpsCastle = i_corps.getScaledInstance(lbl_castle.getWidth(),
                                            lbl_castle.getHeight(),
                                            Image.SCALE_SMOOTH)

    lbl_castle.setVerticalAlignment(SwingConstants.TOP)
    lbl_castle.setIcon(ImageIcon(corpsCastle))

    lbl_logo = JLabel("")
    lbl_logo.setBounds(18, 294, 218, 148)
    leftPanel.add(lbl_logo)

    try:
        snowLogo = ImageIO.read(File(img_dir + "/melted-snowman.png"))
    except:
        snowLogo = ImageIO.read(File(img_dir2 + "/melted-snowman.png"))

    dssLogo = snowLogo.getScaledInstance(lbl_logo.getWidth(),
                                         lbl_logo.getHeight(),
                                         Image.SCALE_SMOOTH)

    lbl_logo.setVerticalAlignment(SwingConstants.TOP)
    lbl_logo.setIcon(ImageIcon(dssLogo))

    lbl_logo2 = JLabel("")
    lbl_logo2.setBounds(18, 11, 218, 148)
    leftPanel.add(lbl_logo2)

    try:
        snowPacLogo = ImageIO.read(File(img_dir + "/SnowPac.png"))
    except:
        snowPacLogo = ImageIO.read(File(img_dir2 + "/SnowPac.png"))

    snowPac = snowPacLogo.getScaledInstance(lbl_logo2.getWidth(),
                                            lbl_logo2.getHeight(),
                                            Image.SCALE_SMOOTH)

    lbl_logo2.setVerticalAlignment(SwingConstants.TOP)
    lbl_logo2.setIcon(ImageIcon(snowPac))

    #     lbl_close = JLabel("X")
    #
    #     class CloseClickListener(MouseAdapter):
    # #       @Override
    #         def mouseEntered(self):
    #             lbl_close.setBorder(LineBorder.createGrayLineBorder())
    # #       @Override
    #         def mouseExited(self):
    #             lbl_close.setBorder(None)
    # #       @Override
    #         def mouseClicked(self):
    #             lbl_close.setBorder(BorderFactory.createLineBorder(Color.red));
    #             sys.exit();

    #     cL = CloseClickListener()
    #     lbl_close.addMouseListener(cL)
    #
    #     lbl_close.setHorizontalAlignment(SwingConstants.CENTER);
    #     lbl_close.setForeground(Color(241, 57, 83));
    #     lbl_close.setFont(Font("Tahoma", Font.PLAIN, 18));
    #     lbl_close.setBounds(1071, 0, 37, 27);
    #     contentPane.add(lbl_close);

    lblPxf = JLabel("Base Temperature (F):")
    lblPxf.setToolTipText("The temperature at which melt will occur.")
    lblPxf.setFont(Font("Tahoma", Font.PLAIN, 12))
    lblPxf.setBounds(400, 263, 132, 15)
    contentPane.add(lblPxf)

    textField_8 = JTextField()
    textField_8.setFont(Font("Tahoma", Font.PLAIN, 12))
    textField_8.setToolTipText("The temperature at which melt will occur.")
    textField_8.setText("32.0")
    textField_8.setBounds(548, 263, 40, 20)
    contentPane.add(textField_8)
    textField_8.setColumns(10)

    chckbxShowLocationPlot = JCheckBox("Plot Locations")
    chckbxShowLocationPlot.setToolTipText(
        "Will plot the Temp, Precip, SWE, ATI, and Melt for each selected location."
    )
    chckbxShowLocationPlot.setSelected(True)
    chckbxShowLocationPlot.setBackground(Color.WHITE)
    chckbxShowLocationPlot.setFont(Font("Tahoma", Font.PLAIN, 12))
    chckbxShowLocationPlot.setBounds(547, 310, 120, 23)
    contentPane.add(chckbxShowLocationPlot)

    lblEvents = JLabel("Paired Data")
    lblEvents.setBounds(270, 346, 72, 15)
    contentPane.add(lblEvents)
    lblEvents.setFont(Font("Tahoma", Font.PLAIN, 12))

    #     lblAtiThreshold = JLabel("ATI Threshold:");
    #     lblAtiThreshold.setToolTipText("Some Melt Events are small & can be ignored. The ATI Threshold is a value that must be reached for the event to be listed.");
    #     lblAtiThreshold.setFont(Font("Tahoma", Font.PLAIN, 12));
    #     lblAtiThreshold.setBounds(500, 610, 82, 15);
    #     contentPane.add(lblAtiThreshold);

    #     textField_9 = JTextField();
    #     textField_9.setFont(Font("Tahoma", Font.PLAIN, 12));
    #     textField_9.setText("0.0");
    #     textField_9.setToolTipText("Some Melt Events are small & can be ignored. The ATI Threshold is a value that must be reached for the event to be listed.");
    #     textField_9.setColumns(10);
    #     textField_9.setBounds(600, 608, 60, 20);
    #     contentPane.add(textField_9);

    btnPlot = JButton(btnIcon, actionPerformed=plotPDBtnSelect)
    btnPlot.setText("Plot Paired Data")
    btnPlot.setFont(Font("Tahoma", Font.BOLD, 12))
    btnPlot.setForeground(Color.WHITE)
    btnPlot.setBackground(Color.WHITE)
    btnPlot.setBorderPainted(False)
    btnPlot.setContentAreaFilled(False)
    btnPlot.setFocusPainted(False)
    btnPlot.setOpaque(False)
    btnPlot.setVerticalTextPosition(SwingConstants.CENTER)
    btnPlot.setHorizontalTextPosition(SwingConstants.CENTER)
    btnPlot.setBounds(385, 657, 163, 54)
    contentPane.add(btnPlot)

    lblAtimeltrateTable = JLabel("ATI-Meltrate Table")
    lblAtimeltrateTable.setFont(Font("Tahoma", Font.PLAIN, 12))
    lblAtimeltrateTable.setBounds(708, 10, 410, 15)
    contentPane.add(lblAtimeltrateTable)

    lblAtimeltrateTable2 = JLabel(
        "The first ATI value should be 0. ATI values must be ascending.")
    lblAtimeltrateTable2.setFont(Font("Tahoma", Font.PLAIN, 11))
    lblAtimeltrateTable2.setBounds(708, 30, 410, 15)
    contentPane.add(lblAtimeltrateTable2)

    btnCalculateMeltrate = JButton(btnIcon,
                                   actionPerformed=calcMeltRateBtnSelect)
    btnCalculateMeltrate.setText("Calculate Meltrate")
    btnCalculateMeltrate.setFont(Font("Tahoma", Font.BOLD, 12))
    btnCalculateMeltrate.setToolTipText(
        "Calculate Meltrate for ATI values in the ATI-Meltrate Table. Calculation will performed on the Paired Data Records Selected in the Paired Data Table."
    )
    btnCalculateMeltrate.setForeground(Color.WHITE)
    btnCalculateMeltrate.setBackground(Color.WHITE)
    btnCalculateMeltrate.setBorderPainted(False)
    btnCalculateMeltrate.setContentAreaFilled(False)
    btnCalculateMeltrate.setFocusPainted(False)
    btnCalculateMeltrate.setOpaque(False)
    btnCalculateMeltrate.setVerticalTextPosition(SwingConstants.CENTER)
    btnCalculateMeltrate.setHorizontalTextPosition(SwingConstants.CENTER)
    btnCalculateMeltrate.setBounds(792, 657, 163, 54)
    contentPane.add(btnCalculateMeltrate)

    frame.setVisible(True)
    dssFile.close()
Esempio n. 28
0
#filePath = "C:/Users/Nicki/IdeaProjects/"
#dssFileName = filePath + "optimizer-hecras-integration/src/HEC-RASModels/STCR/STCR_DesignRuns/" \
#                                   "STCR_Design2.dss"
#dataPath = filePath + "ISWS_MWRDGC_WSRR/"
filePath = "C:/Users/nschiff2/Documents/MWRDGC_WSRR/Watershed_progs/StonyCreek/Stony_V9.0/"
dssFileName = filePath + "HydraulicModels/ExistingConditions/STCR/STCR_DesignRuns/STCR_Design2.dss"
dataPath = "C:/Users/nschiff2/ISWS_MWRDGC_WSRR/"

dataToGet = [["STAGE/01DEC2006/1HOUR", "timestage"], ["LOCATION-ELEV//MAX STAGE", "maxstage"],
             ["LOCATION-TIME//MAX STAGE", "peaktime"]]
#dataToGet = [["LOCATION-ELEV//MAX STAGE", "maxstage"], ["LOCATION-TIME//MAX STAGE", "peaktime"]]
#config = BankStation_config()
#dssFile = HecDss.open(config.dssFileName, True)
#dssFile = HecDss.open("C:/Users/Nicki/IdeaProjects/optimizer-hecras-integration/src/HEC-RASModels/STCR/"
#                      "STCR_DesignRuns/STCR_Design2.dss", True)
dssFile = HecDss.open(dssFileName, True)
for i in range(len(dataToGet)):
    pathNames = dssFile.getCatalogedPathnames("/*/*/" + dataToGet[i][0] + "/HUFFQII_100YR12H/");
    #dataDict = getDSSData(pathNames, dssFile)
    dataDict = {}
    for item in range(len(pathNames)):
        dataFromFile = dssFile.get(pathNames[item], True)
        #print("jjjjjjjjjjjjjj")
        #print(pathNames)
        #print(dataFromFile)
        #print("kkkkkkkkkkkkkkk")
        #print(type(dataFromFile))
        #for loc in range(len(dataFromFile)):
        try:
            dataList = list(dataFromFile.values)
            dataDict.update({pathNames[item]: dataList})
Esempio n. 29
0
def onePerParam(config, dssFilePath):
    plotted = 0  # Number of plots exported
    messages = []
    outputFolder = tbu.relativeFolder(config['output_folder'],
                                      config['config_file'])
    minDate = HecTime(config['period']['start'])
    maxDate = HecTime(config['period']['end'])
    dssFile = HecDss.open(dssFilePath, str(minDate), str(maxDate))
    colours = _coloursByLocation(config)

    for param, paramConfig in config['params'].iteritems():
        plot = Plot.newPlot()
        dataPaths = [
            "/%s/%s/%s//%s/%s/" % (config['site'].upper(),
                                   location.upper(),
                                   param.upper(),
                                   config['interval'].upper(),
                                   config['version'].upper())
            for location in config['locations']
        ]
        datasets = [dssFile.get(p) for p in dataPaths]
        datasets = [d for d in datasets if d.numberValues > 0]
        if not datasets:
            messages.append("No data for parameter '%s'." % param)
            continue
        map(plot.addData, datasets)

        plot.showPlot()
        plot.setPlotTitleText(param)
        plot.setPlotTitleVisible(1)
        plot.setSize(int(config['width']), int(config['height']))

        # We can only access labels and curves at this point
        map(lambda d: plot.getLegendLabel(d).setText(d.location), datasets)

        # Style curves
        for dataset in datasets:
            curve = plot.getCurve(dataset)
            curve.setLineColor('{}, {}, {}'.format(*colours[dataset.location]))
            curve.setLineWidth(config['line']['width'])
            if config['line']['markers']:
                curve.setSymbolsVisible(1)
                curve.setSymbolType('Circle')
                curve.setSymbolLineColor('{}, {}, {}'
                                         .format(*colours[dataset.location]))
                curve.setSymbolFillColor('{}, {}, {}'
                                         .format(*colours[dataset.location]))

        # Axes scales
        units = set(ds.units for ds in datasets)
        for vp_index, unit in enumerate(units):  # 1 viewport per distinct unit
            viewport = plot.getViewport(vp_index)
            viewport.getAxis("X1").setScaleLimits(minDate.value(),
                                                  maxDate.value())
            viewport.getAxis("Y1").setLabel(unit)
            viewport.setMinorGridXVisible(1)
            viewport.setMinorGridYVisible(1)
            if paramConfig:
                if paramConfig['scale'].lower() == 'log':
                    viewport.setLogarithmic('Y1')  # This throws a warning message if y-values <= 0. We can't catch this as an exception.
            # Horizontal threshold lines
            thresholds = _get_thresholds(datasets[0], dssFilePath, config)
            for marker in _thresholdMarkers(thresholds):
                viewport.addAxisMarker(marker)

        # Export plot
        plot.saveToJpeg(os.path.join(outputFolder,
                        param + "-" + config['version']),
                        95)
        plot.close()
        plotted += 1

    dssFile.done()
    return plotted, messages
Esempio n. 30
0
        if startDateTS:
            startDateTimeTS = datetime.datetime.strptime(
                startDateTS, '%Y-%m-%d')
        else:
            startDateTimeTS = datetime.datetime.strptime(date, '%Y-%m-%d')
        startDateTS = startDateTimeTS.strftime("%Y-%m-%d")

        if startTimeTS:
            startDateTimeTS = datetime.datetime.strptime(
                '%s %s' % (startDateTS, startTimeTS), '%Y-%m-%d %H:%M:%S')
        startTimeTS = startDateTimeTS.strftime("%H:%M:%S")

        print 'Start DSSTOCSV.py on ', date, '@', time, tag, HEC_HMS_MODEL_DIR
        print ' With Custom starting', startDateTS, '@', startTimeTS

        myDss = HecDss.open(DSS_OUTPUT_FILE)
        fileName = DISCHARGE_CSV_FILE.rsplit('.', 1)
        # str .format not working on this version
        fileName = '%s-%s%s.%s' % (fileName[0], date, '.' + tag if tag else '',
                                   fileName[1])
        DISCHARGE_CSV_FILE_PATH = os.path.join(OUTPUT_DIR, fileName)
        print 'Open Discharge CSV ::', DISCHARGE_CSV_FILE_PATH
        csvWriter = csv.writer(open(DISCHARGE_CSV_FILE_PATH, 'w'),
                               delimiter=',',
                               quotechar='|')

        flow = myDss.get('//HANWELLA/FLOW//1HOUR/RUN:RUN 1/', 1)

        if flow.numberValues == 0:
            MessageBox.showError('No Data', 'Error')
        else:
Esempio n. 31
0
dataToGet = []
dssFiles = {}
dataDict = {}
infile = open(filePath + "multipanel_plot_data_addresses.txt", 'rb')
dataAddresses = list(infile)
for i in range(len(dataAddresses)):
    dataAddresses[i] = dataAddresses[i].strip(('\r\n'))
print(dataAddresses)
# for v in versions:
#     for a in dataAddresses:
#         dataToGet.append([dataAddresses[a] + "FLOW/" + config.startDate + "/*", "hydrograph_V" + v])
#         dssFiles.append(versionPath + v + dssFileName)
for v in versions:
    dssFile = (versionPath + v + dssFileName)
    dssFiles[v] = HecDss.open(dssFile, True)
    dataDict[v] = {}
    for a in dataAddresses:
        pathNames = dssFiles[v].getCatalogedPathnames(a + "FLOW/" + config.startDate + "/*/" + config.rasRunName + "/")
        print(len(pathNames))
        for item in range(len(pathNames)):
            dataFromFile = dssFiles[v].get(pathNames[item], True)
            # try:
            dataList = list(dataFromFile.values)
            dataDict[v].update({a: dataList})
            # except Exception, e:
            #     for loc in range(len(dataFromFile.xOrdinates)):
            #         dataLocation = dataFromFile.xOrdinates[loc]#[:8]
            #         dataValue = dataFromFile.yOrdinates[0][loc]#[:8]
            #         splitPath = pathNames[item].split('/')
            #         splitPath[2] = str(dataLocation)
Esempio n. 32
0
from datetime import datetime
from OrderedDict27 import OrderedDict
from collections import defaultdict
from hec.io import PairedDataContainer
from hec.heclib.dss import HecDss
import CalcPD
from javax.swing import JOptionPane

dssFile = HecDss.open(r"C:\jy\SnowMelt\snotel_3v6.dss")
EoY = datetime.strptime('30Sep', '%d%b').date()


def getSpecifiedDates(startTextField, endTextField):
    try:
        pdStart = startTextField.getText()
        pdEnd = endTextField.getText()
        pdStartDate = datetime.strptime(pdStart, '%d %b %Y').date()
        pdEndDate = datetime.strptime(pdEnd, '%d %b %Y').date()
    except:
        JOptionPane.showMessageDialog(None,
                                      "Unable to Process Specified Dates.",
                                      "Optional Dates Error",
                                      JOptionPane.WARNING_MESSAGE)
        pdStart = None
        pdEnd = None
    return pdStart, pdEnd


def createWaterYearList(dList):
    wyLists = []
    # Check if first date is before Sep30 to get a partial Water Year.
    if opt in ("-c","--csv"):
        CSV=arg
    elif opt in ("-n","--path"):
        PAT=arg
    elif opt in ("-t","--ts"):
        TS=True
    elif opt in ("-p","--pd"):
        PD=True
    else:
        assert False, "Unhandled Option"

if (len(args) == 0):
    print 'Specify dssfile'
    sys.exit(2)

dss = HecDss.open(args[0],1)

if (TS):
    print "path,startTime,endTime,interval,parameter,quality,subLocation,subParameter,timeZoneId,timeZoneRawOffset,type,units,pairs"
elif (PD):
    print "path,mon,datum,labels,numberCurves,numberOrdinates,offset,shift,transformType,data,xtype,ytype,yunits"
elif (DATA):
    print "fullName,location,subVersion,version,watershed"
elif (LIST):
    print "pathname"

if(CSV):
    print CSV
    csvfile=open(CSV,'rb')
    reader=csv.reader(csvfile,delimiter=',')
    print reader
Esempio n. 34
0
from javax.swing import JOptionPane
from hec.heclib.dss import HecDss
from hec.script import Plot
import java

try : 
  try :
    myDss = HecDss.open("C:/temp/sample.dss")
    flow = myDss.get("/RUSSIAN/NR UKIAH/FLOW/01MAR2006/1HOUR//")
    plot = Plot.newPlot("Russian River at Ukiah")
    plot.addData(flow)
    plot.showPlot()
  except Exception, e :
    JOptionPane.showMessageDialog(None, ' '.join(e.args), "Python Error", JOptionPane.ERROR_MESSAGE)
  except java.lang.Exception, e :
    MessageBox.showError(e.getMessage(), "Java Error")
finally :
  myDss.done()
Esempio n. 35
0
    "--csvfp",
    help=
    "file-path to csv file. csv rainfall file to be converted into DSS format."
)
parser.add_option(
    "--dssfp",
    help="file-path to dss file. where converted dss file should be saved.")

(options, args) = parser.parse_args()
if not options.csvfp and options.dssfp:
    print 'Missing required parameters!'
    print 'Required parameters: dssfp, csvfp'

NUM_METADATA_LINES = 3
try:
    converted_dss = HecDss.open(options.dssfp)

    csv_reader = csv.reader(open(options.csvfp, 'r'),
                            delimiter=',',
                            quotechar='|')
    csv_list = list(csv_reader)

    num_locations = len(csv_list[0]) - 1
    num_values = len(csv_list) - NUM_METADATA_LINES  # Ignore Metadata
    location_ids = csv_list[1][1:]

    for i in range(0, num_locations):
        precipitations = []
        for j in range(NUM_METADATA_LINES, num_values + NUM_METADATA_LINES):
            p = float(csv_list[j][i + 1])
            precipitations.append(p)
Esempio n. 36
0
        type= "TABLE"
        stages = [0, 0.4, 0.5, 1.0, 2.0, 5.0, 10.0, 12.0]
        flows = [0, 0.1, 3, 11, 57, 235, 1150, 3700]
        pdc = PairedDataContainer()
        pdc.watershed = watershed
        pdc.location = loc
        pdc.fullName= "//%s/%s-%s///%s/" % \
                      ( loc, xParam, yParam, type)
        pdc.xOrdinates = stages
        pdc.yOrdinates = [flows]
        pdc.numberCurves = 1
        pdc.numberOrdinates = len(stages)
        pdc.labelsUsed = False
        pdc.xunits = "ACRE-FT"
        pdc.yunits = "CFS"
        pdc.xtype = "UNT"
        pdc.ytype = "UNT"
        pdc.xparameter = xParam
        pdc.yparameter = yParam
        pdc.transformType = 2
        dssFilePath=config.getHmsProjectPath() + "/" + config.hmsProjectName + ".dss"
        myDss = HecDss.open(dssFilePath)
        myDss.put(pdc)
        myDss.done()
except Exception, e:
    print(type(e))
    MessageBox.showError(' '.join(e.args), "Python Error")
except java.lang.Exception, e:
    print(type(e))
    MessageBox.showError(e.getMessage(), "Error")
Esempio n. 37
0
    accessed 3/24/2016"""
    if num != 0:
        return str(round(num, -int(math.floor(math.log10(abs(num))) - (sigfigs - 1))))
    else:
        return str(0.0)  # Can't take the log of 0

dataToGet = []
dssFiles = []
diffLocs = []
for v in versions:
    dataToGet.append(["LOCATION-ELEV//MAX STAGE", "peakElev_V" + v])
    dssFiles.append(versionPath + v + dssFileName) #(versionPath + i + " - Copy" + dssFileName)
    dataToGet.append(["LOCATION-TIME//MAX STAGE", "peakTime_V" + v])
    dssFiles.append(versionPath + v + dssFileName) #(versionPath + i + " - Copy" + dssFileName)
for j in range(len(dataToGet)):
    dssFile = HecDss.open(dssFiles[j], True)
    pathNames = dssFile.getCatalogedPathnames("/*/*/" + dataToGet[j][0] + "/" + config.rasRunName + "/")
    dataDict = {}
    for item in range(len(pathNames)):
        dataFromFile = dssFile.get(pathNames[item], True)
        try:
            dataList = list(dataFromFile.values)
            dataDict.update({pathNames[item]: dataList})
        except Exception, e:
            for loc in range(len(dataFromFile.xOrdinates)):
                dataLocation = dataFromFile.xOrdinates[loc]#[:8]
                dataValue = dataFromFile.yOrdinates[0][loc]#[:8]
                splitPath = pathNames[item].split('/')
                splitPath[2] = str(roundSigfigs(dataLocation, 7))
                fullLoc = "/".join(splitPath)
                dataDict.update({fullLoc: dataValue})
#Create and display a table
from hec.script import Plot, MessageBox
from hec.dataTable import HecDataTableFrame
# from hec.io import TimeSeriesContainer
# from hec.io import PairedDataContainer
# from hec.hecmath import TimeSeriesMath
# from hec.hecmath import PairedDataMath
from hec.heclib.dss import HecDss
import java
import sys
#  Open the file and get the data
try:  
  dssFile = HecDss.open(sys.argv[1] + "\\sample.dss", "10MAR2006 2400, 09APR2006 2400")
  precip = dssFile.get("/AMERICAN/FOLSOM/PRECIP-BASIN/01JAN2006/1DAY/OBS/")
  stor = dssFile.get("/AMERICAN/FOLSOM/ STOR-RES EOP/01JAN2006/1DAY/OBS/")
  topcon = dssFile.get("/AMERICAN/FOLSOM/TOP CON STOR/01JAN2006/1DAY/OBS/")
  sagca = dssFile.get("/AMERICAN/FOLSOM-SAGCA/TOP CON STOR/01JAN2006/1DAY/OBS/")
  inflow = dssFile.get("/AMERICAN/FOLSOM/FLOW-RES IN/01JAN2006/1DAY/OBS/")
  outflow = dssFile.get("/AMERICAN/FOLSOM/FLOW-RES OUT/01JAN2006/1DAY/OBS/")
except java.lang.Exception, e :
  #  Take care of any missing data or errors
   MessageBox.showError(e.getMessage(), "Error reading data")


table = HecDataTableFrame.newTable("Folsom - American River Basin")

#  Add Data
table.addData(precip)
table.addData(stor)
table.addData(topcon)
table.addData(sagca)
Esempio n. 39
0
    if opt in ("-c","--csv"):
        CSV=arg
    elif opt in ("-n","--path"):
        PATH=arg
    elif opt in ("-t","--ts"):
        TS=True
    elif opt in ("-p","--pd"):
        PD=True
    else:
        assert False, "Unhandled Option"

if (len(args) == 0):
    print 'Specify dssfile'
    sys.exit(2)

dss = HecDss.open(args[0],1)

if(CSV):
    csvfile=open(CSV,'rb')
    df=pd.read_csv(CSV)
    mon=df[0]
    print mon
    reader=csv.reader(csvfile,delimiter=',')
    if (TS):
        tsc = TimeSeriesContainer()
        tsc.fullName=PATH
else:
    assert False,"Need to Supply a CSV File"

#paths=["//AAC PWP/FLOW_DIV(KAF)/01JAN1920/1MON//"]
#paths=["//AAC PWP/FLOW_DIV(KAF)/01JAN1920/1MON//","/GWUPD_FINAL/SOURCE_D687/FLOW_LOC(KAF)/01JAN1920/1MON/ACCRETION SJR-TUOLOMNE T\O/","/GWUPD_FINAL/SOURCE_GW-1/FLOW_LOC/01JAN2000/1MON/C2VSIM/"]
Esempio n. 40
0
def paramPerPage(config, dssFilePath):
    """
    Plot timeseries, 1 location per plot, 1 parameter per page.

    Also adds specified thresholds.
    """

    plotted = 0  # Number of plots exported
    messages = []

    outputFolder = tbu.relativeFolder(config['output_folder'],
                                      config['config_file'])

    minDate = HecTime(config['period']['start'])
    maxDate = HecTime(config['period']['end'])

    dssFile = HecDss.open(dssFilePath, str(minDate), str(maxDate))

    for param, paramConfig in config['params'].iteritems():
        plots = []
        dataPaths = [
            '/{}/{}/{}//{}/{}/'.format(config['site'].upper(),
                                       loc.upper(),
                                       param.upper(),
                                       config['interval'].upper(),
                                       config['version'].upper())
            for loc in config['locations']
        ]
        datasets = [dssFile.get(dp) for dp in dataPaths]
        datasets = [d for d in datasets if d.numberValues > 0]
        if not datasets:
            messages.append("No data for parameter '{}'.".format(param))
            continue

        for dataset in datasets:
            plot = Plot.newPlot(param)
            layout = Plot.newPlotLayout()
            layout.setHasLegend(0)
            vp = layout.addViewport()
            vp.addCurve('Y1', dataset)
            plot.configurePlotLayout(layout)
            plots.append(plot)

        # Format normal data curves
        ymin, ymax = float('+inf'), float('-inf')
        for dataset, plot in zip(datasets, plots):
            plot.setPlotTitleText("{0.parameter} at {0.location}".format(dataset))
            plot.setPlotTitleVisible(1)
            plot.setLocation(-10000, -10000)
            plot.setSize(config['width'], config['height'])
            plot.setLegendLabelText(dataset, dataset.location)
            panelProp = plot.getPlotpanel().getProperties()
            panelProp.setViewportSpaceSize(0)

            curve = plot.getCurve(dataset)
            curve.setLineColor('{}, {}, {}'.format(*config['line']['colour']))
            curve.setLineWidth(config['line']['width'])
            if config['line']['markers']:
                curve.setSymbolsVisible(1)
                curve.setSymbolType('Circle')
                curve.setSymbolLineColor('{}, {}, {}'.format(*config['line']['colour']))
                curve.setSymbolFillColor('{}, {}, {}'.format(*config['line']['colour']))
            vp = plot.getViewport(dataset.fullName)
            vp.setMinorGridXVisible(1)
            vp.getAxis('Y1').setLabel(dataset.units)
            if _paramScale(param, config) == 'log':
                vp.setLogarithmic('Y1')  # This throws a warning message if y-values <= 0. We can't catch this as an exception.
            # Horizontal lines
            thresholds = _get_thresholds(dataset, dssFilePath, config)
            for marker in _thresholdMarkers(thresholds):
                vp.addAxisMarker(marker)
            # Vertical lines
            if _baselinePeriod(dataset.location, config):
                vp.addAxisMarker(_baselineMarker(dataset.location, config))
            ymin = min(ymin, vp.getAxis('Y1').getScaleMin())
            ymax = max(ymax, vp.getAxis('Y1').getScaleMax())

        for dataset, plot in zip(datasets, plots):
            plot.showPlot()
            plot.setSize(config['width'], config['height'])
            # Set all y-axes same limits
            vp = plot.getViewports()[0]
            vp.getAxis('Y1').setScaleLimits(ymin, ymax)
            vp.getAxis('X1').setScaleLimits(minDate.value(), maxDate.value())

            plot.saveToJpeg(os.path.join(outputFolder,
                            "TH plot-{0.parameter}-{0.version}-{0.location}"
                            .format(dataset)), 95)
            plot.close()
            plotted += 1

    dssFile.done()
    return plotted, messages
Esempio n. 41
0
# .get([file path], True) returns data from all dates

config = CompareConfig()
filePath = config.filePath
dssFileName = config.dssRasFileName
dataPath = config.versionPath

print(config.scriptPath + "version.txt")
vFile = open(config.scriptPath + "version.txt")
vList = pickle.load(vFile)
vFile.close()
version = vList[0]
dataToGet = [["STAGE/" + config.startDate + "/*", "timestage"], ["LOCATION-ELEV//MAX STAGE", "maxstage"],
             ["LOCATION-TIME//MAX STAGE", "peaktime"]]
print(dataPath + version + dssFileName)
dssFile = HecDss.open(dataPath + version + dssFileName, True)
for i in range(len(dataToGet)):
    pathNames = dssFile.getCatalogedPathnames("/*/*/" + dataToGet[i][0] + "/" + config.rasRunName + "/")
    dataDict = {}
    for item in range(len(pathNames)):
        dataFromFile = dssFile.get(pathNames[item], True)
        try:
            dataList = list(dataFromFile.values)
            dataDict.update({pathNames[item]: dataList})
        except:
            for loc in range(len(dataFromFile.xOrdinates)):
                dataLocation = dataFromFile.xOrdinates[loc]#[:8]
                dataValue = dataFromFile.yOrdinates[0][loc]#[:8]
                splitPath = pathNames[item].split('/')
                splitPath[2] = str(dataLocation)
                fullLoc = "/".join(splitPath)