Skip to content

Commit 13f6c80

Browse files
committed
Merge branch '0.10.x' of github.com:stonerlab/Stoner-PythonCode into 0.10.x
2 parents 55c66e6 + e126b72 commit 13f6c80

5 files changed

Lines changed: 90 additions & 20 deletions

File tree

.github/workflows/build_conda.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ jobs:
3333
user: phygbu
3434
label: main
3535
token: ${{ secrets.ANACONDA }} # Replace with the right name of your secret
36+
- name: Upload wheel
37+
env:
38+
TWINE_USERNAME: __token__
39+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
40+
run: |
41+
python -m pip install twine
42+
python setup.py sdist bdist_wheel
43+
twine upload dist/*

Stoner/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
Options = _Options()
3737

3838

39-
__version_info__ = ("0", "10", "12")
39+
__version_info__ = ("0", "10", "13")
4040
__version__ = ".".join(__version_info__)
4141

4242
__homepath__ = pathlib.Path(__file__).parent.resolve()

scripts/PCAR-New.ini

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
[Options]
2+
# This is the model used to fit the data - do not change!
23
model: Stoner.analysis.fitting.models.superconductivity.Strijkers
34
# Controls whether the data and fit are plotted or not.
45
show_plot: True
56
# Sets whether to print a nice report to the console
67
print_report: True
78
# Save the final result ?
8-
save_fit: False
9-
#
10-
# These are optional options that turn on various (experimental) bits of code
11-
#
9+
save_fit: True
10+
# #####################################################################################################################
11+
# These are optional options that turn on various (experimental) bits of code - only use once manual fitting is done
12+
# #####################################################################################################################
1213
#This turns on the normalisation
1314
normalise: False
1415
# This turns on the fitting a quadratic to the outer 10% to determine the normalisation
1516
# Don't use it unless you know why this might be sensible for your data !
1617
fancy_normaliser: False
18+
# This allows us to customise the normaliser used - default is just a quadratic - either a function in the global
19+
# namespace, or a fully dotted package.module.function name.
20+
#normaliser_function = quadratic_abs
21+
# This is the name of a function to use as a preprocessor - function must be in global namespace.
22+
#preprocessor = down_only
1723
# Turns on rescaling the V axis into mV
1824
# Only use if data not already correctly scaled.
1925
rescale_v: False
@@ -26,7 +32,7 @@ decompose: True
2632
fancy_result: True
2733
#
2834
# Can switch between a least-squares fitting algorithm based on the lmfit module, or othogonal distance regression "odr"
29-
method=differential_evolution
35+
method=odr
3036

3137
# These settings will read old style files directly
3238
[Data]
@@ -41,6 +47,8 @@ separator: ,
4147
v_scale:1000
4248
# Only need this if normalise is True and fancy_normaliser is False
4349
Normal_conductance: 0.0
50+
# Used to set the fraction of the x-range used to fit the background
51+
background_fraction=0.75
4452
# Set true to discard data at high bias
4553
discard: False
4654
# Bias limit to discard at

scripts/PCAR-New.py

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import configparser as ConfigParser
88
import pathlib
99
import inspect
10+
from importlib import import_module
1011

1112
import numpy as np
1213
from Stoner import Data
@@ -29,7 +30,7 @@ def load_config(self):
2930
f"Could not find the fitting ini file {inifile}!"
3031
)
3132

32-
tmp = cfg_data_from_ini(inifile, filename=False)
33+
tmp = cfg_data_from_ini(inifile)
3334
self.setas = tmp.setas.clone
3435
self.column_headers = tmp.column_headers
3536
self.metadata = tmp.metadata
@@ -77,7 +78,22 @@ def RescaleV(self):
7778
vscale = self.config.getfloat("Data", "v_scale")
7879
self.data[:, self.vcol] *= vscale
7980
print(f"Rescaled voltage data by {vscale}")
80-
return self
81+
return self
82+
83+
def Preprocess(self):
84+
"""Run an arbitart function over the data if the option is specified."""
85+
preprocessor_name = self.config.get(
86+
"Options", "preprocessor", fallback="_pass"
87+
)
88+
if "." in preprocessor_name:
89+
module = ".".join(preprocessor_name.split(".")[:-1])
90+
preprocessor = preprocessor_name.split(".")[-1]
91+
module = import_module(module)
92+
preprocessor = getattr(module, preprocessor)
93+
else:
94+
preprocessor = globals()[preprocessor_name]
95+
96+
return preprocessor(self)
8197

8298
def Normalise(self):
8399
"""Normalise the data if the relevant options are turned on in the config file.
@@ -92,24 +108,39 @@ def Normalise(self):
92108
if self.config.has_option(
93109
"Options", "fancy_normaliser"
94110
) and self.config.getboolean("Options", "fancy_normaliser"):
111+
fraction = 1 - self.config.getfloat(
112+
"Data", "background_fraction", fallback=0.1
113+
)
114+
normaliser_name = self.config.get(
115+
"Options", "normaliser_function", fallback="quadratic"
116+
)
117+
if "." in normaliser_name:
118+
module = ".".join(normaliser_name.split(".")[:-1])
119+
normaliser = normaliser_name.split(".")[-1]
120+
module = import_module(module)
121+
normaliser = getattr(module, normaliser)
122+
else:
123+
normaliser = globals()[normaliser_name]
95124
vmax, _ = self.max(self.vcol)
96125
vmin, _ = self.min(self.vcol)
97126
p, pv = self.curve_fit(
98-
quadratic,
99-
bounds=lambda x, y: (x > 0.9 * vmax) or (x < 0.9 * vmin),
127+
normaliser,
128+
bounds=lambda x, y: (x > fraction * vmax)
129+
or (x < fraction * vmin),
100130
)
131+
normaliser_repr = getattr(
132+
normaliser,
133+
"representation",
134+
f"{normaliser_name}(V,{','.join(p)})",
135+
).format(p)
101136
print(
102-
"Fitted normal conductance background of G="
103-
+ str(p[0])
104-
+ "V^2 +"
105-
+ str(p[1])
106-
+ "V+"
107-
+ str(p[2])
137+
f"Fitted normal conductance background of G={normaliser_repr}"
108138
)
109139
self["normalise.coeffs"] = p
110140
self["normalise.coeffs_err"] = np.sqrt(np.diag(pv))
141+
self["normaliser_name"] = normaliser_name
111142
self.apply(
112-
lambda x: x[self.gcol] / quadratic(x[self.vcol], *p),
143+
lambda x: x[self.gcol] / normaliser(x[self.vcol], *p),
113144
self.gcol,
114145
header=self.column_headers[self.gcol],
115146
)
@@ -192,7 +223,7 @@ def plot_results(self):
192223
def Fit(self):
193224
"""Run the fitting code."""
194225
# Run a pre-fitting data munge chain
195-
self.RescaleV().Discard().offset_correct().Decompose().Normalise()
226+
self.Preprocess().RescaleV().Discard().offset_correct().Decompose().Normalise()
196227
chi2 = self.p0.shape[0] > 1
197228

198229
method = getattr(self, self.method)
@@ -227,6 +258,29 @@ def Fit(self):
227258
fit.save(False)
228259

229260

261+
def quadratic_abs(x, a, b, c):
262+
"""A function that returns a quadratic expression, but in terms of abs(x)."""
263+
x = np.abs(x)
264+
return c + x * (b + a * x)
265+
266+
267+
def _pass(x):
268+
"""A do nothing preprocess function."""
269+
return x
270+
271+
272+
def down_only(data):
273+
"""Selects only the down sweep data - this is a hack that works becuase Set V is not noisy"""
274+
ix = np.where(np.diff(np.sign(np.diff(data["Set V"]))) != 0)[:2][0]
275+
dix = np.diff(ix) > 10
276+
dix = np.append(dix, True)
277+
ix = ix[dix]
278+
ix = ix[:2]
279+
280+
data.data = data.data[slice(*ix)]
281+
return data
282+
283+
230284
if __name__ == "__main__":
231285
d = working()
232286
d.load_config()

scripts/PCAR-chi^2.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ show_plot: True
66
print_report: True
77
# Save the final result ?
88
save_fit: False
9-
#
9+
# ################################################################################
1010
# These are optional options that turn on various (experimental) bits of code
11-
#
11+
# #################################################################################
1212
#This turns on the normalisation
1313
normalise: False
1414
# This turns on the fitting a quadratic to the outer 10% to determine the normalisation

0 commit comments

Comments
 (0)