Wave:API: Difference between revisions

From BlueM
Jump to navigation Jump to search
(added example4)
(update examples to Wave v1.140.0)
Line 19: Line 19:
'More complex example showcasing some more advanced techniques
'More complex example showcasing some more advanced techniques
Dim Wave1 As New BlueM.Wave.Wave()
Dim Wave1 As New BlueM.Wave.Wave()
Dim myFile As BlueM.Wave.FileFormatBase
Dim myFile As BlueM.Wave.FileFormats.FileFormatBase
Dim ts As BlueM.Wave.TimeSeries
Dim ts As BlueM.Wave.TimeSeries


'read a file
'read a file
myFile = BlueM.Wave.FileFactory.getFileInstance("path\to\file")
myFile = BlueM.Wave.FileFormats.FileFactory.getFileInstance("path\to\file")
'check the available time series
'check the available time series
For Each sInfo As BlueM.Wave.FileFormatBase.SeriesInfo In myFile.SeriesList
For Each sInfo As BlueM.Wave.FileFormats.FileFormatBase.SeriesInfo In myFile.SeriesList
Console.WriteLine(sInfo.Name)
Console.WriteLine(sInfo.Name)
Next
Next
Line 82: Line 82:
'import time series from a CSV file with custom import settings
'import time series from a CSV file with custom import settings
Dim file As String = "path\to\file.csv"
Dim file As String = "path\to\file.csv"
Dim csv As New BlueM.Wave.CSV(file)
Dim csv As New BlueM.Wave.FileFormats.CSV(file)


'set import settings
'set import settings
Line 97: Line 97:


Console.WriteLine(String.Format("File contains {0} time series:", csv.FileTimeSeries.Count))
Console.WriteLine(String.Format("File contains {0} time series:", csv.FileTimeSeries.Count))
For Each sInfo As BlueM.Wave.FileFormatBase.SeriesInfo In csv.SeriesList
For Each sInfo As BlueM.Wave.FileFormats.FileFormatBase.SeriesInfo In csv.SeriesList
     Console.WriteLine(sInfo.Name)
     Console.WriteLine(sInfo.Name)
Next
Next

Revision as of 10:47, 3 October 2022

Wave.png Wave | Download | Development

The Wave API provides a few methods for reading time series from files, manipulating and displaying them.

To access the API, include a reference to Wave.exe (or to the Wave project if you have the source code) in your .NET project.

Below are some examples.

Example1

'Load a time series file and display it in Wave
Dim Wave1 As New BlueM.Wave.Wave()
Wave1.Import_File("path\to\file") 'depending on the file format, this may display an import dialog
Wave1.Show()

Example2

'More complex example showcasing some more advanced techniques
Dim Wave1 As New BlueM.Wave.Wave()
Dim myFile As BlueM.Wave.FileFormats.FileFormatBase
Dim ts As BlueM.Wave.TimeSeries

'read a file
myFile = BlueM.Wave.FileFormats.FileFactory.getFileInstance("path\to\file")
'check the available time series
For Each sInfo As BlueM.Wave.FileFormats.FileFormatBase.SeriesInfo In myFile.SeriesList
	Console.WriteLine(sInfo.Name)
Next
'select all series for import
myFile.selectAllSeries()
'read the selected time series from the file
myFile.readFile()

'loop over all series read from the file and print some information about them
For Each ts In myFile.FileTimeSeries.Values
	Console.WriteLine("Series title: " & ts.Title)
	Console.WriteLine("Extent: " & ts.StartDate & " - " & ts.EndDate)
	Console.WriteLine("Max value: " & ts.Maximum)
	Console.WriteLine("Min value: " & ts.Minimum)
Next

'get one particular time series
ts = myFile.getTimeSeries("S1  _1AB")

'cut the time series
ts.Cut(New DateTime(1959, 1, 1), New DateTime(1960, 1, 1))

'loop over the nodes of the time series
Dim d As DateTime
Dim v As Double
For Each node As KeyValuePair(Of DateTime, Double) In ts.Nodes
	d = node.Key
	v = node.Value
Next

'Display the series in Wave
Wave1.Import_Series(ts)
Wave1.Show()

Example3

'Create your own time series and display it in Wave
Dim Wave1 As New BlueM.Wave.Wave()
'create a new time series
Dim ts As New BlueM.Wave.TimeSeries("my series")
ts.Unit = "m3/s"
ts.Interpretation = Wave.TimeSeries.InterpretationEnum.BlockRight
'add some nodes to the time series
ts.AddNode(New DateTime(2000, 1, 1), 10)
ts.AddNode(New DateTime(2000, 1, 2), 20)
ts.AddNode(New DateTime(2000, 1, 3), 30)
ts.AddNode(New DateTime(2000, 1, 4), 15)
'Display the series in Wave
Wave1.Import_Series(ts)
Wave1.Show()

Example4

'import time series from a CSV file with custom import settings
Dim file As String = "path\to\file.csv"
Dim csv As New BlueM.Wave.FileFormats.CSV(file)

'set import settings
csv.IsColumnSeparated = True
csv.Separator = New BlueM.Wave.Character(";")
csv.UseUnits = True
csv.iLineHeadings = 1
csv.iLineUnits = 2
csv.iLineData = 3
csv.Dateformat = "dd.MM.yyyy HH:mm"

'read series info with new import settings
csv.readSeriesInfo()

Console.WriteLine(String.Format("File contains {0} time series:", csv.FileTimeSeries.Count))
For Each sInfo As BlueM.Wave.FileFormats.FileFormatBase.SeriesInfo In csv.SeriesList
    Console.WriteLine(sInfo.Name)
Next

'select all time series for import and then read the file
csv.selectAllSeries()
csv.readFile()

Console.WriteLine(String.Format("Read {0} time series:", csv.FileTimeSeries.Count))
For Each ts As BlueM.Wave.TimeSeries In csv.FileTimeSeries.Values
    Console.WriteLine("Timeseries: " & ts.Title)
Next

'Display the first time series
Dim Wave1 As New BlueM.Wave.Wave()
Wave1.Import_Series(csv.FileTimeSeries.Values.First)
Wave1.Show()