2. dataArray¶
dataArray contain a single matrix like dataset with attributes.
matrix like data with columns and rows
attributes are linked to the data e.g. from a measurement/simulation/fit parameters.
all numpy array functionality preserved as e.g. slicing, index tricks.
fit routine from scipy.optimize (leastsquare, differential-evolution,..)
read/write in human readable ASCII text including attributes (optional zipped).
For programmers: a ndarray subclass
dataArray creation can be from read ASCII files or ndarrays as data=js.dA(‘filename.dat’).
See dataArray
for details.
Hint for Beginners:
The dataArray methods should not be used directly from this module.
Instead create a dataArray and use the methods from this object as in the examples.
Example Read data and plot (see Reading ASCII files for more about reading data)
import jscatter as js
i5=js.dA(js.examples.datapath+'/iqt_1hho.dat',index=5) # read 5th data from file with multiple data
i5=js.dL(js.examples.datapath+'/iqt_1hho.dat')[5] # same as above (but read as dataList, then select 5th)
p=js.grace()
p.plot(i5)
Example create/change/…
import jscatter as js
import numpy as np
x=np.r_[0:10:0.5] # a list of values
D,A,q=0.45,0.99,1.2
# create dataArray from numpy array
data0 =js.dA(np.c_[x, x**2, A*np.sin(x)].T)
data=js.dA(np.vstack([x,np.exp(-q**2*D*x),np.random.rand(len(x))*0.05]))
data.D=D;data.A=A;data.q=q
data.Y=data.Y*data.A # change Y values
data[2]*=2 # change 3rd column
data.reason='just as a test' # add comment
data.Temperature=273.15+20 # add attribut
data.savetxt('justasexample.dat') # save data
data2=js.dA('justasexample.dat') # read data into dataArray
data2.Y=data2.Y/data2.A
# use a method (from fitting or housekeeping)
data2.interp(np.r_[1:2:0.01]) # for interpolation
Example fit
import jscatter as js
import numpy as np
data=js.dA(js.examples.datapath+'/exampledata0.dat') # load data into a dataArray
def parabola(q,a,b,c):
y = (q-a)**2+b*q+c
return y
data.fit( model=parabola ,freepar={'a':2,'b':4}, fixpar={'c':-20}, mapNames={'q':'X'})
data.showlastErrPlot()
The dataarray module can be run standalone in a new project.
2.1. dataArray Class¶
dataArray creating by data=js.dA(‘filename.dat’) or from numpy arrays.
Array columns can be accessed as automatic generated attributes like .X,.Y,.eY (see protectedNames). or by indexing as *data[0] -> .X *
Corresponding column indices are set by
setColumnIndex()
(default X,Y,eY = 0,1,2).Multidimensional fitting of 1D,2D,3D (.X,.Z,.W) data. .Y are used as function values at coordinates [.X,.Z,.W] in fitting.
Attributes can be set like: data.aName= 1.2345
Methods are used as data.methodname(arguments)