Example #1
0
def plotAtiMelt(selected):
    for a_and_b_parts in selected:
        # Make sure class level locDict and bList isnt being used to extend bList beyond the selected paths in the UI Locations Table.
        #         print '\na_and_b_parts: ', a_and_b_parts

        #         aPart = locDict[b]
        title = a_and_b_parts.replace("/", " ")

        sp = a_and_b_parts + "SWE/*/1DAY/SNOTEL/"
        sd = dssFile.get(sp, 1)

        tp = a_and_b_parts + "TEMPERATURE-AIR-AVG/*/1DAY/SNOTEL/"
        td = dssFile.get(tp, 1)

        pp = a_and_b_parts + "PRECIP-INC/*/1DAY/SNOTEL/"
        pd = dssFile.get(pp, 1)

        ap = a_and_b_parts + "ATI/*/1DAY/CALC/"
        ad = dssFile.get(ap, 1)

        mp = a_and_b_parts + "MELT-CUM/*/1DAY/CALC/"
        md = dssFile.get(mp, 1)
        #   print sd,td,pd,ad,md

        layout = Plot.newPlotLayout()

        #   thePlot.setPlotTitleVisible(Constants.TRUE)
        #   thePlot.setPlotTitleText("Outlet Releases")
        #thePlot.getPlotTitle().setFont("Arial Black")
        #   thePlot.getPlotTitle().setFontSize(18)

        topView = layout.addViewport()
        midView = layout.addViewport()
        btmView = layout.addViewport()

        topView.addCurve("Y1", td)
        topView.addCurve("Y2", md)

        midView.addCurve("Y1", pd)
        midView.addCurve("Y2", sd)

        btmView.addCurve("Y1", ad)
        thePlot = Plot.newPlot(title)
        thePlot.configurePlotLayout(layout)
        thePlot.showPlot()
        view1 = thePlot.getViewport(pd)
        axis = view1.getAxis("Y1")
        axis.setReversed(False)

        markerTemp = AxisMarker()
        markerTemp.axis = "Y"
        markerTemp.value = "32"
        view = thePlot.getViewport(td)
        view.addAxisMarker(markerTemp)
Example #2
0
def plot_outflowCurves(outflowCurves, curveProperties):

    thePlot = Plot.newPlot("Outflow Curves")
    layout = Plot.newPlotLayout()
    folView = layout.addViewport()

    propNames = curveProperties.get('key')
    propKeys = curveProperties.keys()
    propKeys.sort(reverse=True)
    for k in propKeys:
        row = curveProperties[k]
        curve = row[propNames.index('CurveData')]
        folView.addCurve("Y1", curve)

    folView.setAxisName("Y1", "Folsom")

    thePlot.configurePlotLayout(layout)

    thePlot.setPlotTitleVisible(Constants.TRUE)
    thePlot.setPlotTitleText("Outlet Releases")
    thePlot.getPlotTitle().setFontSize(18)

    thePlot.showPlot()

    propKeys = curveProperties.keys()
    print propKeys
    propNames = curveProperties.get('key')

    for key in propKeys:
        if key == "key":
            continue

        curve = thePlot.getCurve(curveProperties[key][0])
        row = curveProperties[key]
        #https://www.hec.usace.army.mil/confluence/dssvuedocs/latest/scripting-dssvue/plotting-basics#id-.PlottingBasicsv2020.1-G2dLineClass
        curve.setLineColor(row[propNames.index('LineColor')])
        curve.setLineStyle(row[propNames.index('LineStyle')])
        curve.setLineWidth(row[propNames.index('LineWeight')])
        curve.setSymbolsVisible(row[propNames.index('SymbolsVisible')])
        curve.setSymbolType(row[propNames.index('SymbolType')])
        curve.setSymbolSize(row[propNames.index('SymbolSize')])
        curve.setSymbolLineColor(row[propNames.index('SymbolLineColor')])
        curve.setSymbolFillColor(row[propNames.index('SymbolFillColor')])
        curve.setSymbolInterval(row[propNames.index('SymbolInterval')])
        curve.setSymbolSkipCount(row[propNames.index('SymbolSkipCount')])
        curve.setFirstSymbolOffset(row[propNames.index('FirstSymbolOffset')])
        curve.setFillPattern("Solid")
        curve.setFillColor(row[propNames.index('FillColor')])
        curve.setFillType("Below")
def makeOutflowPlot():
	filename = "C:\Temp\AR_Folsom_Simulation7.dss"
	t1 = "18Jan1986 2400"
	t2 = "18Mar1986 2400"
	dssData = readDssFile(filename,t1,t2)
	
	p = Plot.newPlot("Outflow Curves")

	p.addData(dssData['leakage'])
	p.addData(dssData['dikes'])
	p.addData(dssData['eSpill'])
	p.addData(dssData['mainSpill'])
	p.addData(dssData['power'])
	p.addData(dssData['upper'])
	p.addData(dssData['lower'])

	p.showPlot()

	setCurveProperties(p,dssData['upper'],'lightgreen','Solid')
	setCurveProperties(p,dssData['lower'],'lightblue','Solid')
	setCurveProperties(p,dssData['power'],'darkgreen','Solid')
	setCurveProperties(p,dssData['mainSpill'],'orange','Solid')
	setCurveProperties(p,dssData['eSpill'],	'red','Solid')
	setCurveProperties(p,dssData['dikes'], 'black','Solid')
	setCurveProperties(p,dssData['leakage'],'lightgray','Solid')

	if( not ListSelection.isInteractive()):
		p.stayOpen()
def makeOutflowPlot():
    filename = "C:\Temp\AR_Folsom_Simulation7.dss"
    t1 = "18Jan1986 2400"
    t2 = "18Mar1986 2400"
    dssData = readDssFile(filename, t1, t2)

    p = Plot.newPlot("Folsom simulation")
    p.addData(dssData['upper'])
    p.addData(dssData['lower'])

    p.showPlot()
    print("Hi")
    print(dssData)
    print(dssData['upper'])
Example #5
0
#  "location" and "version" will be replaced with the arguments passed in

#  Retrieve data
try :
  #  If you wanted to use a relative time window, you could do something like:
  #  dssFile = HecDss.open("C:/temp/sample.dss", "T-30D, T")
  dssFile = HecDss.open(sys.argv[1] + "\\sample.dss", "01MAY1992 2400", "20MAY1992 2400")
  flowPath = "/GREEN RIVER/" + location + "/FLOW//1HOUR/OBS/"
  precipPath = "/GREEN RIVER/" + location + "/PRECIP-INC//1HOUR/OBS/"
  precip = dssFile.get(precipPath)
  flow = dssFile.get(flowPath)
except java.lang.Exception, e :
  MessageBox.showError(e.getMessage(), "Error reading data")

# Create plot and viewports
plot = Plot.newPlot()
layout = Plot.newPlotLayout()
topView = layout.addViewport(15.)
bottomView = layout.addViewport(85.)

#  Add data
topView.addCurve("Y1", precip)
bottomView.addCurve("Y1", flow)
plot.configurePlotLayout(layout)
plot.setSize(600, 500)

#  Add title
plot.setPlotTitleText(location)
tit = plot.getPlotTitle()
tit.setFont("Arial Black")
tit.setFontSize(18)
from hec.script import Plot
from hec.heclib.dss import HecDss
thePlot = Plot.newPlot()  # create a Plot
dssFile = HecDss.open("C:/temp/mydb.dss")  # open the DSS file
flow = dssFile.get("/BASIN/LOC/FLOW/01NOV2002/1HOUR/OBS/")

#read a data set
thePlot.addData(flow)  # add the data set
thePlot.showPlot()  # show the plot
viewport0 = thePlot.getViewport(0)  # get the first viewport
yaxislabel = viewport0.getAxisLabel("Y1")  # get the Y1 axis label
yaxislabel.setForeground("blue")  # set the Y1 axis label text to blue
        'eSpill': eSpill.getData(),
        'dikes': dikes.getData(),
        'leakage': leakage.getData(),
    }
    return allData


def setCurveProperties(curve, color, fillType):
    curve.setFillColor(color)
    curve.setFillType(fillType)
    curve.setLineColor(color)


data = readData()
# make plot
plot = Plot.newPlot("Folsom Outflow")
plot.addData(data['leakage'])
plot.addData(data['dikes'])
plot.addData(data['eSpill'])
plot.addData(data['mainSpill'])
plot.addData(data['power'])
plot.addData(data['upper'])
plot.addData(data['lower'])

plot.showPlot()  # show the plot
# customize plot
setCurveProperties(plot.getCurve(data['lower']), 'lightgreen', 'Below')
setCurveProperties(plot.getCurve(data['upper']), 'lightblue', 'Below')
setCurveProperties(plot.getCurve(data['power']), 'darkgreen', 'Below')
setCurveProperties(plot.getCurve(data['mainSpill']), 'orange', 'Below')
setCurveProperties(plot.getCurve(data['eSpill']), 'red', 'Below')
Example #8
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
Example #9
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()
    datasets.append(stor)
    topcon = dssFile.get("/EF RUSSIAN/COYOTE/TOP CON STOR/01JAN2006/1DAY//")
    datasets.append(topcon)
    inflow = dssFile.get("/EF RUSSIAN/COYOTE/FLOW-RES IN/01MAR2006/1HOUR/SMOOTH/")
    datasets.append(inflow)
    outflow = dssFile.get("/EF RUSSIAN/COYOTE/FLOW-RES OUT/01MAR2006/1HOUR//")
    datasets.append(outflow)
    ukiah = dssFile.get("/RUSSIAN/NR UKIAH/FLOW/01MAR2006/1HOUR//")
    datasets.append(ukiah)
    hopland = dssFile.get("/RUSSIAN/NR HOPLAND/FLOW/01MAR2006/1HOUR//")
    datasets.append(hopland)
except java.lang.Exception, e :
    MessageBox.showError(e.getMessage(), "Error reading data")

#  Create the view ports
plot = Plot.newPlot("Lake Mendocino")
layout = Plot.newPlotLayout()
topView = layout.addViewport(10.)
middleView = layout.addViewport(60.)
bottomView = layout.addViewport(30.)

#  Add the data
topView.addCurve("Y1", precip)
middleView.addCurve("Y2", stor)
middleView.addCurve("Y2", topcon)
bottomView.addCurve("Y1", inflow)
bottomView.addCurve("Y1", outflow)
bottomView.addCurve("Y1", ukiah)
bottomView.addCurve("Y1", hopland)
plot.configurePlotLayout(layout)
startTime = "01Sep2021 2400"
endTime = "17Sep2021 2400"
dss = HecDss.open(
    R"C:\project\DSSVue-Example-Scripts\src\Y-axis\Savannah_CWMS-SHEF-data.dss",
    startTime, endTime)

HART1 = dss.get("/SAVANNAH/HARTWELL/ELEV-POOL/01JAN2019/1HOUR/OBS/")
RUSS1 = dss.get("/SAVANNAH/RUSSELL/ELEV-POOL/01JAN2019/1HOUR/OBS/")
THUR1 = dss.get("/SAVANNAH/THURMOND/ELEV-POOL/01JAN2019/1HOUR/OBS/")
# need to outsmart gfx2d -- make units differnet so there are separate y-axis values.
HART1.units += "1"
RUSS1.units += "2"
THUR1.units += "3"

myPlot = Plot.newPlot("PoolPlots")
layout = Plot.newPlotLayout()
Hartwell = layout.addViewport(34.)
Russell = layout.addViewport(33.)
Thurmond = layout.addViewport(33.)
print layout.getViewports()
print Hartwell, Russell, Thurmond
Hartwell.addCurve("Y1", HART1)
Russell.addCurve("Y1", RUSS1)
Thurmond.addCurve("Y1", THUR1)

myPlot.configurePlotLayout(layout)
myPlot.showPlot()
setupYAxis(myPlot, 0, "Hartwell", 655., 665.)
setupYAxis(myPlot, 1, "Russell", 470., 480.)
setupYAxis(myPlot, 2, "Thurmond", 312., 335)
# from hec.io import PairedDataContainer
# from hec.hecmath import TimeSeriesMath
# from hec.hecmath import PairedDataMath
from hec.heclib.dss import HecDss, DSSPathname
from hec.script.Constants import TRUE, FALSE
import java
import sys

dssFile = HecDss.open(sys.argv[1] + "\\sample.dss", "01MAY1992 2400",
                      "20MAY1992 2400")
flowPath = "/GREEN RIVER/GLENFIR/FLOW//1HOUR/OBS/"
precipPath = "/GREEN RIVER/GLENFIR/PRECIP-INC//1HOUR/OBS/"
precip = dssFile.get(precipPath)
flow = dssFile.get(flowPath)

plot = Plot.newPlot("Glenfir")
layout = Plot.newPlotLayout()
topView = layout.addViewport(15.)
bottomView = layout.addViewport(85.)

topView.addCurve("Y1", precip)
bottomView.addCurve("Y1", flow)
plot.configurePlotLayout(layout)
plot.setSize(600, 500)

plot.setPlotTitleText("Glenfir")
tit = plot.getPlotTitle()
tit.setFont("Arial Black")
tit.setFontSize(18)
plot.setPlotTitleVisible(TRUE)
from hec.script import Plot
from hec.heclib.dss import HecDss
theFile = HecDss.open("myFile.dss")# open myFile.dss
precipPath = "/BASIN/LOC/FLOW/01NOV2002/1HOUR/OBS/"
stagePath = "/BASIN/LOC/FLOW/01NOV2002/1HOUR/OBS/"
flowPath = "/BASIN/LOC/FLOW/01NOV2002/1HOUR/OBS/"
precipData = theFile.get(precipPath)# read the precip
stageData = theFile.get(stagePath)# read the stage
flowData = theFile.get(flowPath)# read the flow
thePlot = Plot.newPlot()# create a new Plot
layout = Plot.newPlotLayout()# create a new PlotLayout
topView = layout.addViewport(30)# get the top viewport
bottomView = layout.addViewport(70)# get the bottom viewport
topView.addCurve("Y1", precipData)# add the precip to top
bottomView.addCurve("Y1", stageData)# add the stage to bottom
bottomView.addCurve("Y2", flowData)# add the flow to bottom
thePlot.configurePlotLayout(layout)# configure the plot
thePlot.showPlot()# show the plot
Example #14
0
    sd = dssFile.get(sp, 1)

    tp = "/" + aPart + "/" + b + "/TEMPERATURE-AIR-AVG/*/1DAY/SNOTEL/"
    td = dssFile.get(tp, 1)

    pp = "/" + aPart + "/" + b + "/PRECIP-INC/*/1DAY/SNOTEL/"
    pd = dssFile.get(pp, 1)

    ap = "/" + aPart + "/" + b + "/ATI/*/1DAY/CALC/"
    ad = dssFile.get(ap, 1)

    mp = "/" + aPart + "/" + b + "/MELT-CUM/*/1DAY/CALC/"
    md = dssFile.get(mp, 1)
    #   print sd,td,pd,ad,md

    layout = Plot.newPlotLayout()

    #   thePlot.setPlotTitleVisible(Constants.TRUE)
    #   thePlot.setPlotTitleText("Outlet Releases")
    #thePlot.getPlotTitle().setFont("Arial Black")
    #   thePlot.getPlotTitle().setFontSize(18)

    topView = layout.addViewport()
    midView = layout.addViewport()
    btmView = layout.addViewport()

    topView.addCurve("Y1", td)
    topView.addCurve("Y2", md)

    midView.addCurve("Y1", pd)
    midView.addCurve("Y2", sd)
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")

#  Initialize the plot and set viewport size in precent
plot = Plot.newPlot("Folsom - American River Basin")
layout = Plot.newPlotLayout()
topView = layout.addViewport(10.)
middleView = layout.addViewport(60.)
bottomView = layout.addViewport(30.)

#  Add Data in specific viewports
topView.addCurve("Y1", precip)
middleView.addCurve("Y2", stor)
middleView.addCurve("Y2", topcon)
middleView.addCurve("Y2", sagca)
bottomView.addCurve("Y1", inflow)
bottomView.addCurve("Y1", outflow)

panel = plot.getPlotpanel()
prop = panel.getProperties()
Example #16
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()
Example #17
0
from hec.script import Plot,MessageBox
from hec.heclib.dss import HecDss
import java

try :
  myDss = HecDss.open("C:/temp/sample.dss")
  flow = myDss.get("/MISSISSIPPI/ST. LOUIS/FLOW//1DAY/OBS/", 1)

  if flow.numberValues == 0 :
    MessageBox.showError("No Data", "Error")
  else :
    plot = Plot.newPlot("Mississippi")
    plot.addData(flow)
    plot.showPlot()
    plot.stayOpen()
except Exception, e :
    MessageBox.showError(' '.join(e.args), "Python Error")
except java.lang.Exception, e :
    MessageBox.showError(e.getMessage(), "Error")
finally :
  myDss.done()
    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)
plot.setLocation(100, 100)
plot.showPlot()

#  Change the plot
outCurve = plot.getCurve(outflow)
outCurve.setLineColor("darkgreen")

#  Save the plot and close
plot.saveToPng("C:/temp/Oakville.png")
#plot.close()  #  Do this if you only want the plot as a .png and not on screen
Example #19
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
Example #20
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
Example #21
0
dssFile = HecDss.open(path + "7_PMF_P50_fc_H550.dss", "02Jan2000 0600",
                      "03Jan2000 0600")
Q_out550 = dssFile.read("//DS-19/FLOW//5MIN/RUN:7_PMF_P50_FC_H550/")
Elev_550 = dssFile.read("//DS-19/ELEVATION//5MIN/RUN:7_PMF_P50_FC_H550/")

datasets = []
datasets.append(Precip)
datasets.append(Q_in250)
datasets.append(Q_out250)
datasets.append(Elev_250)
datasets.append(Q_out400)
datasets.append(Elev_400)
datasets.append(Q_out550)
datasets.append(Elev_550)

plot = Plot.newPlot("DS-19 Most Reasonable PMF - Adopted")
plot.stayOpen()
layout = Plot.newPlotLayout()
TopView = layout.addViewport(30.)
#lp = LegendPanel(None,LegendPanel.VERTICAL_LAYOUT)
#lp.setLegendPosition(LegendPanel.VIEWPORT_LEGEND_UPPER_LEFT)
#lp.addViewport(TopView)

#lp = plot.getLegend()
#print 'name = ',lp.getClass().getName()

#print dir (lp)
#print type(lp)
#lp.setLegendPosition(LegendPanel.VIEWPORT_LEGEND_UPPER_LEFT)

#LegendPanel.this._parent.moveLegendToPosition(LegendPanel.VIEWPORT_LEGEND_UPPER_LEFT)