Index: wflow-py/WflowDeltashell/plotcsv.py =================================================================== diff -u -r50452938e2cd3d928bd73b7c26da2eb0ec4218e1 -r08a987702d1e404792fecefc8fbc97b005449a20 --- wflow-py/WflowDeltashell/plotcsv.py (.../plotcsv.py) (revision 50452938e2cd3d928bd73b7c26da2eb0ec4218e1) +++ wflow-py/WflowDeltashell/plotcsv.py (.../plotcsv.py) (revision 08a987702d1e404792fecefc8fbc97b005449a20) @@ -1,44 +1,141 @@ import csv # import the python csv library from Libraries.StandardFunctions import * from Libraries.ChartFunctions import * +import WflowDeltashell.wflib as wfl +import os -testfilepath = 'c:\\repos\\wflow-git\\examples\\wflow_rhine_sbm\\run_default\\prec.csv' +# Needed if this .net thing is not loaded yet +import clr +clr.AddReference("System.Windows.Forms") +from System.Windows.Forms import OpenFileDialog, DialogResult -column = 4 +def getcsvname(): + themodel = wfl.GetModelByPartialName('wflow') + + dialog = OpenFileDialog() + + if themodel: + dialog.InitialDirectory = os.path.join(themodel.DirectoryPath,themodel.DefaultOutputDirectoryName) + else: + dialog.InitialDirectory ="C:\\" + + dialog.Filter = "csv files (*.csv) | *.csv" + dialog.FilterIndex = 1 + dialog.RestoreDirectory = False + dialog.Title = "Select a WFlow result csv file: " + + if (dialog.ShowDialog() == DialogResult.OK): + thefile = dialog.FileName + + return thefile -#Read a CSV file -with open(testfilepath) as csvfile: # open the file test2.csv - lines = csv.reader(csvfile, delimiter=',') # read lines as collection of arrays - olines=[] - # print all values - for line in lines: - oline = [] - thecol = 0 - for field in line: - thecol = thecol + 1 - if thecol == 1: - oline.append(float(field)) - if thecol == column: - oline.append(float(field)) - - olines.append(oline) +def plotit(filename): + colors = [Color.Red,Color.Black, Color.Green, Color.Black, Color.Orange, Color.YellowGreen, Color.Azure,\ + Color.Cyan, Color.Brown, Color.Aquamarine, Color.CornflowerBlue, Color.DarkBlue, Color.BlanchedAlmond,\ + Color.LightYellow, Color.SlateGray] + + runid = os.path.basename(os.path.dirname(filename)) + + lineSeries = [] + + olines = wfl.readwfcsv(filename) -print olines + + for yval in range(1,len(olines[0])): + x = [[col[0],col[yval]] for col in olines] + + lineSeries.append(CreateLineSeries(x)) + + + lineSeries[-1].Color = colors[yval -1] + lineSeries[-1].Width = 1 + lineSeries[-1].PointerVisible = False + lineSeries[-1].PointerSize = 0 + lineSeries[-1].PointerColor = Color.Red + lineSeries[-1].PointerLineVisible = True + lineSeries[-1].PointerLineColor = colors[yval -1] + lineSeries[-1].Transparency = 0 + lineSeries[-1].ShowInLegend= True + lineSeries[-1].Title="Id: " + str(yval) + + chart = CreateChart(lineSeries) + + # Configure the chart + chart.TitleVisible = True + chart.Title = "run: " + runid + ": " + os.path.basename(filename) + chart.BackGroundColor = Color.White + chart.Legend.Visible = True + chart.Name = chart.Title + + + # Configure the bottom axis + chart.BottomAxis.Automatic = True + chart.BottomAxis.Title = "Timestep" + + # Configure the left axis + chart.LeftAxis.Title = os.path.basename(filename) + + + # Show the chart + view = OpenView(chart) + -lineSeries = CreateLineSeries(olines) -# Configure the line series -lineSeries.Color = Color.Red -lineSeries.Width = 1 -lineSeries.PointerVisible = True -lineSeries.PointerSize = 5 -lineSeries.PointerColor = Color.Red -lineSeries.PointerLineVisible = True -lineSeries.PointerLineColor = Color.DarkRed -lineSeries.Transparency = 50 +def complot(dirnames,file,ids): + colors = [Color.Red,Color.Black, Color.Green, Color.Black, Color.Orange, Color.YellowGreen, Color.Azure,\ + Color.Cyan, Color.Brown, Color.Aquamarine, Color.CornflowerBlue, Color.DarkBlue, Color.BlanchedAlmond,\ + Color.LightYellow, Color.SlateGray] + -chart = CreateChart([lineSeries]) -# Show the chart -OpenView(chart) \ No newline at end of file + cnt = 0 + lineSeries = [] + for dirname in dirnames: + runid = os.path.dirname(dirname) + + ftoread = os.path.join(dirname,file) + + if os.path.exists(ftoread): + olines = wfl.readwfcsv(os.path.join(dirname,file)) + + for yval in ids: + x = [[col[0],col[yval]] for col in olines] + + lineSeries.append(CreateLineSeries(x)) + + + lineSeries[-1].Color = colors[cnt] + lineSeries[-1].Width = 1 + lineSeries[-1].PointerVisible = False + lineSeries[-1].PointerSize = 0 + lineSeries[-1].PointerColor = Color.Red + lineSeries[-1].PointerLineVisible = True + lineSeries[-1].PointerLineColor = colors[cnt] + lineSeries[-1].Transparency = 0 + lineSeries[-1].ShowInLegend= True + lineSeries[-1].Title="Col: " + str(yval) + " Run: " + str(os.path.basename(runid)) + cnt = cnt + 1 + + casename = os.path.basename(os.path.dirname(os.path.dirname(dirname))) + chart = CreateChart(lineSeries) + + # Configure the chart + chart.TitleVisible = True + chart.Title = casename.upper() + ":" + os.path.basename(file) + chart.BackGroundColor = Color.White + chart.Legend.Visible = True + chart.Name = chart.Title + + + # Configure the bottom axis + chart.BottomAxis.Automatic = True + chart.BottomAxis.Title = "Timestep" + + # Configure the left axis + chart.LeftAxis.Title = os.path.basename(file) + + + # Show the chart + view = OpenView(chart) +