ConvertingScripts from Older Versions of the Stoner Package

THe Stoner package has gradually undergone several changes as additional functions have been added to keep the code base managable. This document summarizes the main changes from previous versions.

Python Version Support

  • Versions <= 0.5 supported Python 2.7 with some support for Python 3.x

  • Version 0.7 and 0.8 supported Python 2.7, 3.5 and 3.6

  • Version 0.9 supports Python 2.7, 3.5, 3.6 and 3.7. The final release of 0.9 also supports Python 3.8

  • Version 0.10 does not support Python 2.7 or 3.5. The supported versions of Python are 3.6, 3.7 and 3.8

Data class versus DataFile, AnalysisFile, PlotFile

Originally the package provided several subclasses of a DataFile class and the user was encouraged to make a superclass of all of them. Thus code would have:

import Stoner.Analysis as SA
import Stoner.Plot as SP
import Stoner.Core as SC

class Data(SC.AnalysisFile, SP.PlotFile, SC.DataFile):
    pass

This should now simply be replaced with:

from Stoner import Data

Stoner.PlotFormats and Stoner.Plot modules removed

The Stoner.Plot and Stoner.PlotFormats modules were replaced with the Stoner.plot package. Code that did:

from Stoner.PlotFormats import JTBStyle, TexFormatter

should now do:

from Stoner.plot.formats import JTBPlotStyle, TexFormatter

Most of the functionality of the Stoner.Plot module was in the PlotFile subclass and is now accessed via the Stoner.Data class. A few additional functions that used to be in Stoner.Plot are now in Stoner.plot.utils.

Stoner.Folders Module deprecated

The code around Stoner.DataFolder has been exte nsively rewritten and cleaned up in versions 0.9 onwards. Firstly, theold Stoner.Folders module is replaced with the Stoner.folders package, and the Stoner.DataFolder class is now directly importable from the root Stoner package. Thus:

from Stoner.Folders import DataFolder

becomes:

from Stoner import DataFolder

The Stoner.folders package contains many modules and subpackages to implement generic folder-like objects, but for end users of the package, the Stoner.DataFolder class is probably all that is required to be imported.

Stoner.Fit Module deprecated

The Stoner.Fit module contained a mixed bad of assorted fitting functions and lmfit.Model classes. These have been reorganised into a series of sub-modules of the Stoner.analysis package. Although this makes the import lines rather long, it groups the functions more logically by physics theme. Thus:

from Stoner.Fit import blochGrueneisen

becomes:

from Stoner.analysis.fitting.models.e_transport import blochGrueneisen

The Stoner.Fit module also contained various functions to make lmfit.Model classes from functions or from ini files - these functions are now in the Stoner.analysis.fitting.models package directly.

Stoner.FileFormats Module deprecated

The Stoner.FileFormats module was getting a bit big and unwieldy with many different file formats being implemented. It has now been superseded by the Stoner.formats package which groups the fileformats into different sub-modules.

Generally there is no particular reason to directly access the individual file format classes - the Stoner.Data class can access all the subclasses loaded in memory and so:

import Stoner.FileFormats

can simply be removed if the Stoner.Data is used.

Stoner.Image changes

The original write of the Stoner.Image package developed a subclass of numpy array wioth metadata - Stoner.Imnage.ImageArray but for many purposes is is more useful to have a class thatr wraps the image data and provides additional attributes and methods in parallel to the image data rather than having name collisions with the numpy methods and attributes. For this reason, the preferred class to work with is Stoner.ImageFile which is an analog of Stoner.Data. Generally the code can be transferred directly so:

from Stoner.Image import ImageArray

becomes:

from Stoner import ImageFile

Like Stoner.Image.ImageArray, Stoner.ImageFile can access key image processing functions from skimage, scipy.ndimage and the Stoner.Image.imagefuncs modules.

Deprecated Image functions

The following ImageArray/ImageFile methods should be swapped:

Stoner.DataFolder/Stoner.ImageFolder changes

Stoner.DataFolder and Stoner.ImageFolder are essentially similar objects for managing collections of Stoner.Data ad Stoner.ImageFile respectively.

Earlier versions of the Stoner package exposed the ability to call methods of the sotred Stoner.Data/ Stoner.ImageFile instances by calling a correspomnding method directly on the folder object. The problem with this is that if there is a name collision with a method intended to work directly on the Folder, it’s not clear what method is being called. To remove this problem, and to make it a little more explicit when accessing a method of the stored instances, the Stoner.DataFolder.each attribute is now provided. Thus code like:

fldr=DataFolder(“.”, pattern=”*.txt”, setas=”xy”) fldr.curve_fit(Linear)

now becomes:

fldr=DataFolder(".", pattern="*.txt", setas="xy")
fldr.each.curve_fit(Linear)

One of the frequently required operations is to loop through all the files in a folder and extract some of their metadata nd build that into a new table. This used to be done something like:

result=Data()
for data in fldr:
    result+=[data["thing_1"], data["thing_2"]]

The new Stoner.DataFolder.metadata attribute and Stoner.folders.metadata.MetadataProxy.slice() method allow this to be done directly:

result=fldr.metadata.slice(["thing_1","thing_2"], output="Data")