Source documentation¶
mujpy
– Main package¶
mujpy.mugui
– Main GUI class¶
-
class
mujpy.mugui.
mugui
[source]¶ Bases:
object
-
asymmetry
()[source]¶ defines self.time generates asymmetry end error without rebinning all are 2D numpy arrays, shape of time is (1,nbins), of asymm, asyme are (nruns, nbins)
- self._the_runs_ is a list of lists of musr2py instances *
inner list is for adding runs outer list is suites of runs
may be treated equally by a double for loop (single, no addition implies that k,j=0,0) returns 0 for ok and -1 for error
-
create_rundict
(k=0)[source]¶ creates a dictionary to identify and compare runs refactored for adding runs
-
fit
(model_in='daml')[source]¶ fit tab of mugui used to set: self.alpha.value, self.offset.value, forw and backw groups
fit and plot ranges, model versionto display: model name to activate: fit, plot and update buttons to select and load model (load from folder missing) to select parameters value, fix, function, fft subtract check
-
gui
()[source]¶ gui layout Executed only once It designs an external frame,
the logo and title header the tab structure.At the end (Araba.Phoenix) the method redefines self.gui as a Vbox named ‘whole’, that contains the entire gui structure
-
introspect
()[source]¶ print updated attributes of the class mugui after each fit in file “mugui.attributes.txt” in self.__startuppath__
-
output
()[source]¶ create an Output widget in fourth tab select by self.mainwindow.selected_index = 3
-
mujpy.aux
– Auxiliary functionalities¶
mujpy.aux.aux
– Various useful functions¶
-
mujpy.aux.aux.
autops
(data, fn, p0=0.0, p1=0.0)[source]¶ Automated phase correction from NMRglue by https://github.com/jjhelmus These functions provide support for automatic phasing of NMR data. ———- Automatic linear phase correction Parameters ———- data : ndarray
Array of NMR data.- fn : str or function
- Algorithm to use for phase scoring. Built in functions can be specified by one of the following strings: “acme”, “peak_minima”
- p0 : float
- Initial zero order phase in degrees.
- p1 : float
- Initial first order phase in degrees.
- ndata : ndarray
- Phased NMR data.
-
mujpy.aux.aux.
derange
(string)[source]¶ derange(string) reads string assuming 2, 3 or 4 csv values, integers or floats, or 2, 3 or 4 space separated values, integers or floats returns 2, 3 or 4 floats, or two negative values, if the string does not contain commas or spaces
-
mujpy.aux.aux.
derange_int
(string)[source]¶ derange(string) reads string assuming 2, 3 or 4 csv values, integers or floats, or 2, 3 or 4 space separated values, integers or floats returns 2, 3 or 4 floats, or two negative values, if the string does not contain commas or spaces
-
mujpy.aux.aux.
derun
(string)[source]¶ parses string, producing a list of runs; expects comma separated items looks for ‘l’,’l:m’,’l+n+m’ where l, m, n are integers rejects all other characters returns a list of lists of integer
-
mujpy.aux.aux.
get_grouping
(groupcsv)[source]¶ name = ‘forward’ or ‘backward’ grouping(name) is an np.array wth detector indices group.value[k] for k=0,1 is a shorthand csv like ‘1:3,5’ or ‘1,3,5’ etc. index is present mugui.mainwindow.selected_index out is mugui._output_ for error messages returns
- grouping, group, index
- group and index are changed only in case of errors
-
mujpy.aux.aux.
muvalid
(string, out, index)[source]¶ parse function CHECK WITH MUCOMPONENT, THAT USES A DIFFERENT SCHEME accepted functions are RHS of agebraic expressions of parameters p[i], i=0…ntot
-
mujpy.aux.aux.
muvalue
(lrun, string)[source]¶ Run suite fits: muvalue returns the value for the nint-th parameter of the lrun-th run according to string (corresponding flag=’l’). Large parameter change across the run suite requires different migrad start guesses.
-
mujpy.aux.aux.
muvaluid
(string)[source]¶ Run suite fits: muvaluid returns True/False checks the syntax for string function corresponding to flag=’l’. Meant for pars displaying large changes across the run suite, requiring different migrad start guesses.
-
mujpy.aux.aux.
muzeropad
(runs, out)[source]¶ runs is a string containing the run number utility of the suite tab, not a method future: 1) determine how many leading zeros for padding
read a file from data dir check number of digits before ‘.’ count number of digits in run zero padnow: 0) zeroth version pads a fixed number of zeros to 4 digits out in mugui is _output_, Textarea for printing messages
-
mujpy.aux.aux.
plotile
(x, xdim=0, offset=0)[source]¶ - xt = plotile(x,xdim,xoffset=0)
- e.g. x.shape = (1,1000) y.shape = (4,1000) xt = plotile(x,4) yt = plotile(y,offset=0.1)
-
mujpy.aux.aux.
ps
(data, p0=0.0, p1=0.0, inv=False)[source]¶ Linear phase correction Parameters ———- data : ndarray
Array of NMR data.- p0 : float
- Zero order phase in degrees.
- p1 : float
- First order phase in degrees.
- inv : bool, optional
- True for inverse phase correction
- ndata : ndarray
- Phased NMR data.
-
mujpy.aux.aux.
rebin
(x, y, strstp, pack, e=None)[source]¶ x,y[,e] are 2D arrays to be rebinned pack is the rebinning factor, e.g:
xb = array([x[0:pack].sum()/pack])- strstp = [start,stop] is a list of indices
- rebinning is done on slices of x,y[,e] such as x[start:stop]
use either xb,yb = rebin(x,y,strstp,pack) or xb,yb,eyb = rebin(x,y,strstp,pack,ey) # the 5th is y error Works also with pack = 1
- Now works for 1d array x and 2d ndarrays y, ey
xb, yb, eb are 2D arrays, e.g. xb.shape = (1,25000), yb.shape = (nruns,25000)
mujpy.mucomponents
– Fit functions¶
mujpy.mucomponents.mucomponents
– Main fit functions¶
-
class
mujpy.mucomponents.mucomponents.
mumodel
[source]¶ Bases:
object
-
_add_
(x, *argv)[source]¶ e.g. a blmg global model with argv will be a list parameter values (val1,val2.val3,val4,val5,val6, …) at this iteration _add_ DISTRIBUTES THESE PARAMETER VALUES
SINGLE OR SUITE OF RUNS WITH self._global_==False order driven by model e.g. blml see mugui int2_int, _add_ replicates the same loops
- loop over model components (bl & ml)
- loop over pars (component parameters, two and four, respectively)
- eval(pars) # pars is a string set by int2_int as keys
- use to plot as follows:
j = -1 yoffset = 0.05 for y,e in zip(self.asymm,self.asyme)
j += 1 plt.errorbar(x,y+j*yoffset,yerr=e) plt.plot(x,mumodel()._add_global(x,val1,val2.val3,val4,val5,val6,run=j)+j*yoffset)- UNIFIED WITH FFT, where, for each component f adds it
if self._fft_include_components[j] else 0. if if self._fft_include_da else f
WITH self._global_==True order driven by model, e.g. blml, global, global pars, local constants, local pars (see int2_int)
loop over global loop over model components (bl & ml)
- loop over global pars
- eval(pars)
- loop over runs
loop over local pars loop over model components (bl & ml)
- loop over local pars
- eval(pars)
- FINAL COMMMENT: eval implies both a python time overhead and a security break
- is there a way to avoid it, implementing free parameter functions?
-
_chisquare_
(*argv, axis=None)[source]¶ - Signature provided at Minuit invocation by
- optional argument forced_parameters=parnames where parnames is a tuple of parameter names e.g. parnames = (‘asym’,’field’,’phase’,’rate’)
Works also for global fits where sum (…,axis=None) yields the sum over all indices Provides partial chisquares over individual runs if invoked as
self._chisquare_(*argv,axis=1):
-
_fft_init
(include_components, include_da=True)[source]¶ saves the string of component flags used to generate a partial residue for FFT
-
_kg
(x, w, Gau_delta)[source]¶ auxiliary component for a static Gaussian Kubo Toyabe in longitudinal field, x [mus], w [mus-1], Gau_delta [mus-1] w = 2*pi*gamma_mu*L_field
-
_kgdyn
(x, w, Gau_delta, jump_rate, *argv)[source]¶ auxiliary dynamization of Gaussian Kubo Toyabe by G. Allodi N: number of sampling points; dt: time interval per bin [i.e. time base is t = dt*(0:N-1)] w [mus-1], Gau_delta [mus-1], jump_rate [MHz] (longitudinal field freq, dGaussian distribution, scattering frequency % alphaN: [optional argument] weighting coefficient alpha times N. Default=10
-
_load_data_
(x, y, _components_, _alpha_, e=1, _nglobals_=None, _locals_=None)[source]¶ , _load_data_(x,y,_components_,_alpha_,e,_nglobals_,_locals_,_ntruecomponents_) x, y, e are numpy arrays e = 1 yields unitary errors _components_ is a list [[method,[key,…,key]],…,[method,[key,…,key]]],
where method is an instantiation of a component, e.g. self.ml and value = eval(key) produces the parameter value_alpha_ is ditto _nglobals_ = index of global parameter in iminuit parameter list (only for global fits) _locals_ = values of local constants (e.g. B, T extrated form data file by musr2py), a 2D array for global fits
Strategy to accommodate single runs, multi run suites and global: for global y is 2D array self._global_ = True for single and multi y is 1D
-
bg
(x, asymmetry, Gau_rate)[source]¶ fit component for a Gaussian decay, x [mus], asymmetry, Gau_rate [mus-1]
-
bl
(x, asymmetry, Lor_rate)[source]¶ fit component for a Lorentzian decay, x [mus], asymmetry, Lor_rate [mus-1]
-
bs
(x, asymmetry, rate, beta)[source]¶ fit component for a stretched decay, x [mus], asymmetry, rate [mus-1], beta (>0)
-
jg
(x, asymmetry, field, phase, Gau_rate)[source]¶ fit component for a Bessel j0 precessing muon with Lorentzian decay, x [mus], asymmetry, field [T], phase [degrees], Lor_rate [mus-1]
-
jl
(x, asymmetry, field, phase, Lor_rate)[source]¶ fit component for a Bessel j0 precessing muon with Lorentzian decay, x [mus], asymmetry, field [T], phase [degrees], Lor_rate [mus-1]
-
kg
(x, asymmetry, L_field, Gau_delta, jump_rate)[source]¶ Gaussian Kubo Toyabe in longitudinal field, static or dynamic x [mus], asymmetry, L_field [T], Gau_delta [mus-1], jump_rate (MHz)
-
mg
(x, asymmetry, field, phase, Gau_rate)[source]¶ fit component for a precessing muon with Gaussian decay, x [mus], asymmetry, field [T], phase [degrees], Gau_rate [mus-1]
-