Skip to content

Commit

Permalink
Release 0.7b2 having fixed breakages from mixin re-ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
gb119 committed Feb 14, 2017
1 parent 8202a3a commit 64679ce
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 29 deletions.
24 changes: 10 additions & 14 deletions Stoner/Analysis.py
Expand Up @@ -1573,7 +1573,7 @@ def action(i,column,row):
action(i, column, self.data[i])
return self

def peaks(self, ycol=None, width=None, significance=None, xcol=None, peaks=True, troughs=False, poly=2, sort=False,modify=False):
def peaks(self, ycol=None, width=None, significance=None, xcol=None, peaks=True, troughs=False, poly=2, sort=False,modify=False,full_data=True):
"""Locates peaks and/or troughs in a column of data by using SG-differentiation.
Args:
Expand All @@ -1592,6 +1592,8 @@ def peaks(self, ycol=None, width=None, significance=None, xcol=None, peaks=True,
troughs (bool): select whether to measure troughs in data (default False)
sort (bool): Sor the results by significance of peak
modify (book): If true, then the returned object is a copy of self with only the peaks/troughs left in the data.
full_data (bool): If True (default) then all columns of the data at which peaks in the *ycol* column are found. *modify* true implies
*full_data* is also true. If *full_data* is False, then only the x-column values of the peaks are returned.
Returns:
If *modify* is true, then returns a the AnalysisMixin with the data set to just the peaks/troughs. If *modify* is false (default),
Expand All @@ -1604,7 +1606,9 @@ def peaks(self, ycol=None, width=None, significance=None, xcol=None, peaks=True,
"""

_=self._col_args(scalar=False,xcol=xcol,ycol=ycol)
xcol,ycol=_.xcol,_.ycol[0]
xcol,ycol=_.xcol,_.ycol
if isinstance(ycol,Iterable):
ycol=ycol[0]
if width is None: # Set Width to be length of data/20
width = len(self) / 20
assert poly >= 2, "poly must be at least 2nd order in peaks for checking for significance of peak or trough"
Expand All @@ -1624,20 +1628,13 @@ def peaks(self, ycol=None, width=None, significance=None, xcol=None, peaks=True,
elif isinstance(significance, int): # integer significance is inverse to floating
significance = _np_.max(_np_.abs(d2))/significance # Base an apriori significance on max d2y/dx2 / 20

i = _np_.arange(len(self))
d2_interp = interp1d(_np_.arange(len(d2)), d2,kind='cubic')
# Ensure we have some X-data
if xcol == None:
full_data=True
xdata = i

elif isinstance(xcol,bool) and not xcol:
full_data=False
xdata = i
if xcol is None:
xdata = _np_.arange(len(self))
else:
full_data=False
xdata = self.column(xcol)
xdata = interp1d(i, xdata,kind="cubic")
xdata = interp1d(_np_.arange(len(self)), xdata,kind="cubic")


possible_peaks = _np_.array(_threshold(0, d1, rising=troughs, falling=peaks))
Expand All @@ -1657,9 +1654,8 @@ def peaks(self, ycol=None, width=None, significance=None, xcol=None, peaks=True,
elif full_data:
ret=self.interpolate(xdat,kind="cubic",xcol=False)
else:
ret=xdata(possible_peaks+index_offset)
ret=xdat
self.setas=setas
print(setas)
# Return - but remembering to add back on the offset that we took off due to differentials not working at start and end
return ret

Expand Down
5 changes: 4 additions & 1 deletion Stoner/Core.py
Expand Up @@ -1067,6 +1067,8 @@ def __new__(cls, input_array, *args,**kargs):
# Finally, we must return the newly created object:
obj.i=i
obj.setas._row=_row and len(obj.shape)==1
#Set shared mask - stops some deprication warnings
obj._shared_mask=True
return obj

def __array_finalize__(self, obj):
Expand Down Expand Up @@ -1401,6 +1403,7 @@ class DataFile(metadataObject):
already saved to disc. This is the default filename used by the :py:meth:`Stoner.Core.DataFile.load`
and :py:meth:`Stoner.Core.DataFile.save`.
mask (array of booleans): Returns the current mask applied to the numerical data equivalent to self.data.mask.
mime_type (list of str): The possible mime-types of data files represented by each matching filename pattern in :py:attr:`Datafile.pattern`.
patterns (list): A list of filename extenion glob patterns that matrches the expected filename patterns for a DataFile (*.txt and *.dat")
priority (int): Used to indicathe order in which subclasses of :py:class:`DataFile` are tried when loading data. A higher number means a lower
priority (!)
Expand All @@ -1413,7 +1416,7 @@ class DataFile(metadataObject):
dtype (numpoy dtype): Returns the datatype stored in the :py:attr:`DataFile.data` attribute.
T (:py:class:`DataArray`): Transposed version of the data.
subclasses (list): Returns a list of all the subclasses of DataFile currently in memory, sorted by
their py:attr:`Stoner.Core.DataFile.priority. Each entry in the list consists of the
their py:attr:`Stoner.Core.DataFile.priority`. Each entry in the list consists of the
string name of the subclass and the class object.
"""

Expand Down
2 changes: 1 addition & 1 deletion Stoner/Image/core.py
Expand Up @@ -161,7 +161,7 @@ def __array_finalize__(self, obj):
more info and examples
"""
if obj is None: return
self.metadata = getattr(obj, 'metadata', None)
self.metadata = getattr(obj, 'metadata', {})
self.filename = getattr(obj, 'filename', None)

def __array_wrap__(self, out_arr, context=None):
Expand Down
14 changes: 9 additions & 5 deletions Stoner/Util.py
Expand Up @@ -140,11 +140,12 @@ def annotate_fit(self,model,x=None,y=None,z=None,prefix=None,text_only=False,**k
y (float): y co-ordinate of the label
z (float): z co-ordinbate of the label if the current axes are 3D
prefix (str): The prefix placed ahead of the model parameters in the metadata.
text_only (bool): If False (default), add the text to the plot and return the current object, otherwise,
return just the text and don't add to a plot.
text_only (bool): If False (default), add the text to the plot and return the current object, otherwise,
return just the text and don't add to a plot.
Returns:
A copy of the current Data instance if text_only is False, otherwise returns the text.
(Datam, str): A copy of the current Data instance if text_only is False, otherwise returns the text.
If *prefix* is not given, then the first prefix in the metadata lmfit.prefix is used if present,
otherwise a prefix is generated from the model.prefix attribute. If *x* and *y* are not specified then they
Expand Down Expand Up @@ -271,8 +272,11 @@ def split_up_down(data, col=None, folder=None):
width = len(a) / 10
if width % 2 == 0: # Ensure the window for Satvisky Golay filter is odd
width += 1
peaks = list(a.peaks(col, width,xcol=False, peaks=True, troughs=False))
troughs = list(a.peaks(col, width, xcol=False, peaks=False, troughs=True))
setas=a.setas.clone
a.setas=""
peaks = list(a.peaks(col, width,xcol=None, peaks=True, troughs=False,full_data=False))
troughs = list(a.peaks(col, width, xcol=None, peaks=False, troughs=True,full_data=False))
a.setas=setas
if len(peaks) > 0 and len(troughs) > 0: #Ok more than up down here
order = peaks[0] < troughs[0]
elif len(peaks) > 0: #Rise then fall
Expand Down
2 changes: 1 addition & 1 deletion Stoner/__init__.py
Expand Up @@ -10,5 +10,5 @@
from .Util import Data
from .Folders import DataFolder

__version_info__ = ('0', '7', 'b1')
__version_info__ = ('0', '7', 'b2')
__version__ = '.'.join(__version_info__)
2 changes: 1 addition & 1 deletion doc/Stoner.rst
Expand Up @@ -90,7 +90,7 @@ Instrument Formats

BigBlueFile
FmokeFile
QDSquidVSMFile
QDFile
RigakuFile
VSMFile
MokeFile
Expand Down
8 changes: 4 additions & 4 deletions doc/UserGuide/datafile.rst
Expand Up @@ -55,8 +55,8 @@ Base Classes and Generic Formats
but has not been extensively tested.
:py:class:`Stoner.FileFormats.TDMSFile`
Loads a file saved in the National Instruments TDMS format
:py:class:`Stoner.FileFormats.QDSquidVSMFile`
Loads data from a Quantum Design SQUID VSM as used on the I10 Beamline in Diamond and in our labs.
:py:class:`Stoner.FileFormats.QDFile`
Loads data from various Quantum Design instruments, cincluding PPMS, MPMS and SQUID VSM.
:py:class:`Stoner.FileFormats.OVFFile`
OVF files are output by a variety of micomagnetics simulators. The standard was designed for the OOMMF code. This class will handle rectangualr mesh files with text or binary formats, versions 1.0 and 2.0

Expand Down Expand Up @@ -144,8 +144,8 @@ from disk::

data=Stoner.Core.DataFile()<<open("File on Disk.txt")

Constructing :py:class:`DataFile`s from Scratch
-----------------------------------------------
Constructing :py:class:`DataFile` s from Scratch
------------------------------------------------------------

The constructor :py:class:`DataFile`, :py:meth:`DataFile.__init__` will try its best to guess what your intention
was in constructing a new instance of a DataFile. First of all a constructor function is called based on the number of positional
Expand Down
2 changes: 1 addition & 1 deletion doc/UserGuide/plotfile.rst
Expand Up @@ -10,7 +10,7 @@ publication ready figures. The :py:class:`PlotMixin` is included as apart of the
Quick Plots
===========

:py:class:`PlotMixin` is intended to help you make plots that look reasonably good with as little hassle as possible.
The :py:class:`PlotMixin` class is intended to help you make plots that look reasonably good with as little hassle as possible.
In common with many graph plotting programmes, it has a concept of declaring columns of data to be used for 'x', 'y' axes and
for containing error bars. This is done with the :py:attr:`DataFile.setas` attribute (see :ref:`setas` for full details). Once this is done, the plotting
methods will use these to try to make a sensible plot.::
Expand Down
2 changes: 1 addition & 1 deletion tests/Stoner/test_Folders.py
Expand Up @@ -64,7 +64,7 @@ def test_Operators(self):
print("Starting....")
self.assertEqual((fl+1)*2,len(fldr2),"Failed + operator with DataFolder on DataFolder")
print("Passed 2")
fldr-="Untitled-0"
fldr-="Untitled"
self.assertEqual(len(fldr),fl,"Failed to remove Untitled-0 from DataFolder by name.")
print("Passed 3")
fldr-="New-XRay-Data.dql"
Expand Down

0 comments on commit 64679ce

Please sign in to comment.