2. dataArray¶
dataArray contain a single dataset.
- ndarray subclass containing matrix like data
- attributes are linked to the data e.g. from a measurement or simulation 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 or pickle.
dataArray creation can be from read ASCII files or ndarrays as data=js.dA(‘filename.dat’).
See dataArray
for details.
- For Beginners:
- The dataArray methods should not be used directly from this module.
- Instead create a dataArray and use the methods from this object.
Example:
#create from array or read from
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
data=js.dA(np.vstack([x,np.exp(-q**2*D*x),np.random.rand(len(x))*0.05])) # creates dataArray
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
The dataarray module can be run standalone in a new project.
2.1. Attributes¶
Array columns can be accessed as automatic generated attributes like .X,.Y,.eY (see protectedNames).
Corrsponding column indices are set by dataArray.setColumnIndex()
(default X,Y,eY = 0,1,2).
Attributes can be set like: data.aName= 1.2345
protectedNames |
Defined protected names which are not allowed as attribute names. |
dataArray.showattr ([maxlength, exclude]) |
Show data specific attributes with values as overview. |
dataArray.attr |
Show data specific attribute names as sorted list of attribute names. |
dataArray.getfromcomment (attrname) |
Extract a non number parameter from comment with attrname in front |
dataArray.extract_comm ([iname, deletechars, …]) |
Extracts not obvious attributes from comment and adds them to attributes. |
dataArray.resumeAttrTxt ([names, maxlength]) |
Resume attributes in text form. |
dataArray.setattr (objekt[, prepend, keyadd]) |
Set (copy) attributes from objekt. |
dataArray.setColumnIndex ([ix, iy, iey, iex, …]) |
Set the column index where to find X,Y,Z and and errors eY, eX, eZ….. |
dataArray.name |
Attribute name, mainly the filename of read data files. |
dataArray.array |
Strip of all attributes and return a simple ndarray. |
dataArray.argmax ([axis, out]) |
Return indices of the maximum values along the given axis. |
dataArray.argmin ([axis, out]) |
Return indices of the minimum values along the given axis of a. |
2.2. Fitting¶
dataArray.fit (model[, freepar, fixpar, …]) |
Least square fit to model that minimizes chi**2 (uses scipy.optimize). |
dataArray.modelValues (*args, **kwargs) |
Calculates modelValues of model after a fit |
dataArray.setLimit (*args, **kwargs) |
Set upper and lower limits for parameters in least square fit. |
dataArray.hasLimit |
Return existing limits. |
dataArray.setConstrain (*args) |
Set constrains for constrained minimization in fit. |
dataArray.hasConstrain |
Return list with defined constrained source code. |
dataArray.makeErrPlot (*args, **kwargs) |
dummy |
dataArray.makeNewErrPlot (*args, **kwargs) |
dummy |
dataArray.killErrPlot (*args, **kwargs) |
dummy |
dataArray.detachErrPlot (*args, **kwargs) |
dummy |
dataArray.showlastErrPlot (*args, **kwargs) |
dummy |
dataArray.savelastErrPlot (*args, **kwargs) |
dummy |
2.3. Housekeeping¶
dataArray.savetxt (name[, fmt]) |
Saves data in ASCII text file (optional gzipped). |
dataArray.isort ([col]) |
Sort along a column !!in place |
dataArray.where (condition) |
Copy with lines where condition is fulfilled. |
dataArray.prune ([lower, upper, number, …]) |
Reduce number of values between upper and lower limits by selection or averaging. |
dataArray.merge (others[, axis, isort]) |
Merges dataArrays to self !!NOT in place!! |
dataArray.concatenate (others[, axis, isort]) |
Concatenates the dataArray[s] others to self !NOT IN PLACE! |
dataArray.interpolate (X[, left, right, deg]) |
Piecewise interpolated values of Y at position X=X returning dataArray. |
dataArray.interpAll ([X, left, right]) |
Piecewise linear interpolated values of all columns at new X values. |
dataArray.interp (X[, left, right]) |
Piecewise linear interpolated values of Y at position X returning only Y (faster). |
dataArray.polyfit ([X, deg, function, efunction]) |
Interpolated values for Y at values X using a polyfit. |
dataArray.addZeroColumns ([n]) |
Copy with n new zero columns at the end !!NOT in place!! |
dataArray.addColumn ([n, values]) |
Copy with new columns at the end populated by values !!NOT in place!! |
dataArray.nakedCopy () |
Deepcopy without attributes, thus only the data. |
2.4. Convenience¶
zeros (*args, **kwargs) |
dataArray filled with zeros. |
ones (*args, **kwargs) |
dataArray filled with ones. |
fromFunction (function, X, *args, **kwargs) |
Evaluation of Y=function(X) for all X and returns a dataArray with X,Y |
-
jscatter.dataarray.
protectedNames
= ['X', 'Y', 'eY', 'eX', 'Z', 'eZ']¶ Defined protected names which are not allowed as attribute names.
-
dataarray.
zeros
(**kwargs)¶ dataArray filled with zeros.
Parameters: - shape : integer or tuple of integer
Shape of the new array, e.g., (2, 3) or 2.
Returns: - dataArray
Examples
js.zeros((3,20))
-
dataarray.
ones
(**kwargs)¶ dataArray filled with ones.
Parameters: - shape : integer or tuple of integer
Shape of the new array, e.g., (2, 3) or 2.
Returns: - dataArray
Examples
js.ones((3,20))
-
dataarray.
fromFunction
(X, *args, **kwargs)¶ Evaluation of Y=function(X) for all X and returns a dataArray with X,Y
Parameters: - function : function or lambda
function to evaluate with first argument as X[i] result is flattened (to be one dimensional)
- X : array N x M
X array function is evaluated along first dimension (N) e.g np.linspace or np.logspace
- *args,**kwargs : arguments passed to function
Returns: - dataArray with N x ndim(X)+ndim(function(X))
Examples
import jscatter as js result=js.fromFunction(lambda x,n:[1,x,x**(2*n),x**(3*n)],np.linspace(1,50),2) # X=(np.linspace(0,30).repeat(3).reshape(-1,3)*np.r_[1,2,3]) result=js.fromFunction(lambda x:[1,x[0],x[1]**2,x[2]**3],X) # ff=lambda x,n,m:[1,x[0],x[1]**(2*n),x[2]**(3*m)] X=(np.linspace(0,30).repeat(3).reshape(-1,3)*np.r_[1,2,3]) result1=js.fromFunction(ff,X,3,2) result2=js.fromFunction(ff,X,m=3,n=2) result1.showattr() result2.showattr()