Automate SciDAVis with Python Scripting
When the same analysis runs every week — import the new data file, fit the same peak model, export the figure — clicking through the menus stops being cute. SciDAVis embeds a Python interpreter: you can drive tables, graphs, fits, and exports from script code typed into a Note window. This guide gets you from zero to a batch-fitting script. Every API call shown here is verified against the official SciDAVis scripting documentation; anything that varies by version is explicitly marked as pseudocode.
Version note: written for v2.9.x (SourceForge binaries are 2.8). Python 3 scripting support landed in the 1.23 era, so both current builds behave as described. If your build lacks Python entirely (the interpreter choice is missing — see Step 1), your copy was compiled without Python support.
Step 1 — Enable Python and open the script console
- Choose Scripting → Scripting Language from the menu and double-click Python in the dialog. (If Python isn’t listed, your installation was built without scripting support.)
- Create a Note window (File → New → New Notes, or the equivalent New menu entry). This is your script console.
- Type
print("Hello World!"), put the cursor on that line, and press Ctrl+J (or right-click → Execute). The output appears below the line. Congratulations — you’re scripting.
Two execution modes, worth learning on day one:
- Ctrl+J (Execute) runs statements: assignments, loops, function definitions, API calls.
- Ctrl+Enter (Evaluate) evaluates a single expression and prints its value — handy as a calculator, e.g.
5*sin(pi/2).
a^b is bitwise xor, not power — use a**b. And if you use non-ASCII characters (e.g. µ or ° in axis titles) in a Python 3 build, put # coding=utf8 at the top of the note.Step 2 — Talk to your project: tables, graphs, notes
Scripts access the windows of your project by name:
t = table("Table1")
m = matrix("Matrix1")
g = graph("Graph1")
n = note("Notes1")
And create new ones:
t = newTable("tony", 5, 2) # empty table, 5 rows, 2 columns
g = newGraph() # empty graph window
n = newNote("momo") # empty note
New objects land in the active folder. The lookup functions search the active folder first, then the whole project.
Step 3 — Read and write table cells
Columns are addressed by name (string) or 1-based number; rows are 1-based, exactly as displayed:
t = table("Table1")
print(t.cell(1, 1)) # value of column 1, row 1
t.setCell(1, 2, 3.14) # write into column 1, row 2
print(t.numRows(), t.numCols())
t.colName(1) # read a column's name
t.setColName(1, "time") # rename it
t.notifyChanges() # refresh dependent graphs after edits
Always call t.notifyChanges() after scripted edits, or your graphs won’t redraw. For text (non-numeric) columns, the parallel calls are t.text(col, row) / t.setText(col, row, string).
Step 4 — Import files and create plots in code
The import dialog’s options exist as a method (mirrors File → Import Ascii; see the import guide):
t = table("Table1")
t.importASCII("/path/to/data.csv", sep=",", ignore=1, renameCols=True)
Create a plot from table columns with the plot() command — the third argument is the plot type (0 = Line, 1 = Symbols, 2 = Line and Symbols, 3 = Columns, 4 = Area, 5 = Pie, 6 = Vertical drop lines, 7 = Splines and Symbols, 8 = Vertical steps, 9 = Histogram, 10 = Rows):
g = plot(table("Table1"), (2, 3), 2) # columns 2,3 as Line+Symbols
l = g.activeLayer()
l.setTitle("Calibration run 12")
l.setXTitle("Time (s)")
l.setYTitle("Voltage (V)")
l.setLegend("sensor A")
Add further curves to a layer with l.insertCurve(table, column), count them with l.numCurves(), and add whole layers with g.addLayer().
Step 5 — Fit curves from a script
The fitting engine from the Fit Wizard is scriptable. Minimal example — Gaussian fit on a curve, with automatic initial guesses:
f = GaussFit(graph("Graph1").activeLayer(), "table1_2")
f.guessInitialValues()
f.fit()
print(f.results()) # fitted parameters
print(f.errors()) # their standard errors
print(f.chiSquare(), f.rSquare())
Verified fit classes: LinearFit, PolynomialFit, ExponentialFit, TwoExpFit, ThreeExpFit, GaussFit, GaussAmpFit, LorentzFit, SigmoidalFit, NonLinearFit, and PluginFit. For a custom model, use NonLinearFit with a muParser formula string:
f = NonLinearFit(layer, curve)
f.setFormula("y0 + A*exp(-((x-xc)/w)^2)")
f.setParameters("y0", "A", "xc", "w")
f.setInitialValues(0.1, 5.0, 12.0, 1.5)
f.fit()
Useful knobs before calling fit(): setInterval(from, to) to restrict the x-range, setMaximumIterations(n), setTolerance(t), and setAlgorithm() (choices include scaled/unscaled Levenberg–Marquardt and Nelder–Mead simplex). Results can also go straight into new tables via f.parametersTable("params") and f.covarianceMatrix("cov").
Step 6 — Export figures in bulk
Layers and whole graphs export directly (same formats as Graph → Export Graph; see the export guide):
g = graph("Graph1")
g.exportToSVG("/path/to/figure.svg")
g.exportToEPS("/path/to/figure.eps")
l = g.activeLayer()
l.exportImage("/path/to/figure.png", filetype="PNG", quality=100)
Step 7 — Put it together: a batch workflow
The pattern below is pseudocode — the exact table/loop API calls it uses are the verified ones above, but adapt names and curve titles to your project, and check behavior against the scripting docs of your installed version:
for each table name in my list:
open/select the table; import its CSV with
importASCII(...)create a plot with
plot(table, columns, type)build a
GaussFit on the active layer’s curvecall
guessInitialValues(), then fit()append
f.results() / f.errors() to a summary tableexport the graph with
exportToSVG()End result: one SVG per dataset plus a single table of fitted parameters — the weekly report writes itself.
The two most common batch-script bugs: forgetting t.notifyChanges() after writing cells (graphs show stale data), and curve-name mismatches — the fit constructor takes the curve title as shown in the legend (e.g. "table1_2"), not the column name.
Next steps
- New to the concepts? Read importing data and curve fitting first — the GUI versions of what you just scripted.
- Publishing the output? See exporting publication-quality figures.
- Need the program itself? It’s on the download page.
