# 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 Read data and plot (see Reading ASCII files for more about reading data)

    import jscatter as js
    # read data with 16 intermediate scattering functions from NSE measurement of protein diffusion
    i5=js.dL(js.examples.datapath+'/iqt_1hho.dat')
    p=js.grace()
    # plot the first 3 dataArrays
    p.plot(i5[:3])

Example create/change/…

    #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. dataArray Class

`dataArray` |

- 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)

## 2.2. Attribute Methods

`protectedNames` |

`dataArray.showattr` |
`dataArray.attr` |
`dataArray.getfromcomment` |
`dataArray.extract_comm` |
`dataArray.resumeAttrTxt` |
`dataArray.setattr` |
`dataArray.setColumnIndex` |
`dataArray.name` |
`dataArray.array` |
`dataArray.argmax` |
`dataArray.argmin` |

## 2.3. Fit Methods

`dataArray.fit` |
`dataArray.modelValues` |
`dataArray.setLimit` |
`dataArray.hasLimit` |
`dataArray.setConstrain` |
`dataArray.hasConstrain` |
`dataArray.makeErrPlot` |
`dataArray.makeNewErrPlot` |
`dataArray.killErrPlot` |
`dataArray.detachErrPlot` |
`dataArray.showlastErrPlot` |
`dataArray.savelastErrPlot` |
`dataArray.polyfit` |
`dataArray.interpolate` |
`dataArray.interpAll` |
`dataArray.interp` |

## 2.4. Housekeeping Methods

`dataArray.savetxt` |
`dataArray.isort` |
`dataArray.where` |
`dataArray.prune` |
`dataArray.merge` |
`dataArray.concatenate` |
`dataArray.addZeroColumns` |
`dataArray.addColumn` |
`dataArray.nakedCopy` |
`dataArray.regrid` |

## 2.5. Convenience

`zeros` |
`ones` |
`fromFunction` |