xarpes 0.6.3__py3-none-any.whl → 0.6.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xarpes/__init__.py +1 -1
- xarpes/functions.py +165 -2
- xarpes/selfenergies.py +96 -0
- {xarpes-0.6.3.dist-info → xarpes-0.6.5.dist-info}/METADATA +1 -1
- {xarpes-0.6.3.dist-info → xarpes-0.6.5.dist-info}/RECORD +8 -8
- {xarpes-0.6.3.dist-info → xarpes-0.6.5.dist-info}/LICENSE +0 -0
- {xarpes-0.6.3.dist-info → xarpes-0.6.5.dist-info}/WHEEL +0 -0
- {xarpes-0.6.3.dist-info → xarpes-0.6.5.dist-info}/entry_points.txt +0 -0
xarpes/__init__.py
CHANGED
xarpes/functions.py
CHANGED
|
@@ -236,7 +236,6 @@ def fit_least_squares(p0, xdata, ydata, function, resolution=None, yerr=None,
|
|
|
236
236
|
return pfit, pcov, success
|
|
237
237
|
|
|
238
238
|
|
|
239
|
-
|
|
240
239
|
def download_examples():
|
|
241
240
|
"""Downloads the examples folder from the main xARPES repository only if it
|
|
242
241
|
does not already exist in the current directory. Prints executed steps and a
|
|
@@ -625,4 +624,168 @@ def chi2kink_logistic(x, a, b, c, d):
|
|
|
625
624
|
expz = np.exp(z[mneg])
|
|
626
625
|
phi[mneg] = a + b * expz / (1.0 + expz)
|
|
627
626
|
|
|
628
|
-
return phi
|
|
627
|
+
return phi
|
|
628
|
+
|
|
629
|
+
def _in_ipython():
|
|
630
|
+
try:
|
|
631
|
+
from IPython import get_ipython
|
|
632
|
+
except Exception:
|
|
633
|
+
return False
|
|
634
|
+
return get_ipython() is not None
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
class _LineBuffer:
|
|
638
|
+
"""Capture text as lines, keeping only head + tail and total count."""
|
|
639
|
+
def __init__(self, head=10, tail=10):
|
|
640
|
+
from collections import deque
|
|
641
|
+
self.head = int(head)
|
|
642
|
+
self.tail = int(tail)
|
|
643
|
+
self._head_lines = []
|
|
644
|
+
self._tail_lines = deque(maxlen=self.tail)
|
|
645
|
+
self._partial = ""
|
|
646
|
+
self._n_lines = 0
|
|
647
|
+
|
|
648
|
+
def feed(self, text):
|
|
649
|
+
if not text:
|
|
650
|
+
return
|
|
651
|
+
|
|
652
|
+
# Normalize carriage returns (progress bars etc.)
|
|
653
|
+
text = str(text).replace("\r", "\n")
|
|
654
|
+
|
|
655
|
+
# Prepend any partial line from previous write.
|
|
656
|
+
text = self._partial + text
|
|
657
|
+
parts = text.split("\n")
|
|
658
|
+
|
|
659
|
+
# If text does not end with '\n', last part is partial.
|
|
660
|
+
self._partial = parts.pop() # may be "" if ended with newline
|
|
661
|
+
|
|
662
|
+
for line in parts:
|
|
663
|
+
# Record completed line
|
|
664
|
+
self._n_lines += 1
|
|
665
|
+
if len(self._head_lines) < self.head:
|
|
666
|
+
self._head_lines.append(line)
|
|
667
|
+
else:
|
|
668
|
+
if self.tail > 0:
|
|
669
|
+
self._tail_lines.append(line)
|
|
670
|
+
|
|
671
|
+
def finalize(self):
|
|
672
|
+
# If there is an unfinished line, treat it as a line.
|
|
673
|
+
if self._partial.strip() != "":
|
|
674
|
+
self.feed("\n") # forces it into completed lines
|
|
675
|
+
self._partial = ""
|
|
676
|
+
|
|
677
|
+
def summary(self):
|
|
678
|
+
self.finalize()
|
|
679
|
+
|
|
680
|
+
n = self._n_lines
|
|
681
|
+
if n == 0:
|
|
682
|
+
return ""
|
|
683
|
+
|
|
684
|
+
# If total small, reconstruct from head + tail if possible
|
|
685
|
+
if n <= self.head + self.tail:
|
|
686
|
+
# We didn't keep all middle lines, but if n <= head+tail we kept all.
|
|
687
|
+
# For n <= head, tail may be empty; for n > head, tail contains rest.
|
|
688
|
+
out = list(self._head_lines)
|
|
689
|
+
if n > len(self._head_lines):
|
|
690
|
+
out.extend(list(self._tail_lines))
|
|
691
|
+
return "\n".join(out)
|
|
692
|
+
|
|
693
|
+
omitted = n - self.head - self.tail
|
|
694
|
+
head_txt = "\n".join(self._head_lines)
|
|
695
|
+
tail_txt = "\n".join(list(self._tail_lines))
|
|
696
|
+
return (
|
|
697
|
+
f"{head_txt}\n"
|
|
698
|
+
f"... ({omitted} lines omitted) ...\n"
|
|
699
|
+
f"{tail_txt}"
|
|
700
|
+
)
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
def trim_notebook_output(print_lines=10, *, enabled=True, clear=True,
|
|
704
|
+
capture_stderr=True, sleep_s=0.05):
|
|
705
|
+
"""Context manager: show live prints, then keep only head/tail in notebooks.
|
|
706
|
+
|
|
707
|
+
In plain scripts (no IPython), this is a no-op.
|
|
708
|
+
"""
|
|
709
|
+
from contextlib import contextmanager
|
|
710
|
+
|
|
711
|
+
@contextmanager
|
|
712
|
+
def _ctx():
|
|
713
|
+
if (not enabled) or (print_lines is None):
|
|
714
|
+
yield
|
|
715
|
+
return
|
|
716
|
+
|
|
717
|
+
n = int(print_lines)
|
|
718
|
+
if n <= 0:
|
|
719
|
+
yield
|
|
720
|
+
return
|
|
721
|
+
|
|
722
|
+
# Only do this in IPython environments; scripts should print normally.
|
|
723
|
+
if not _in_ipython():
|
|
724
|
+
yield
|
|
725
|
+
return
|
|
726
|
+
|
|
727
|
+
import sys
|
|
728
|
+
import time
|
|
729
|
+
|
|
730
|
+
buf = _LineBuffer(head=n, tail=n)
|
|
731
|
+
|
|
732
|
+
stdout_orig = sys.stdout
|
|
733
|
+
stderr_orig = sys.stderr
|
|
734
|
+
|
|
735
|
+
class _TeeStream:
|
|
736
|
+
def __init__(self, real_stream, buffer):
|
|
737
|
+
self._real = real_stream
|
|
738
|
+
self._buf = buffer
|
|
739
|
+
|
|
740
|
+
def write(self, text):
|
|
741
|
+
# Live output
|
|
742
|
+
try:
|
|
743
|
+
self._real.write(text)
|
|
744
|
+
self._real.flush()
|
|
745
|
+
except Exception:
|
|
746
|
+
pass
|
|
747
|
+
# Capture
|
|
748
|
+
self._buf.feed(text)
|
|
749
|
+
|
|
750
|
+
def flush(self):
|
|
751
|
+
try:
|
|
752
|
+
self._real.flush()
|
|
753
|
+
except Exception:
|
|
754
|
+
pass
|
|
755
|
+
|
|
756
|
+
# Some libraries ask for these:
|
|
757
|
+
def isatty(self):
|
|
758
|
+
return False
|
|
759
|
+
|
|
760
|
+
@property
|
|
761
|
+
def encoding(self):
|
|
762
|
+
return getattr(self._real, "encoding", "utf-8")
|
|
763
|
+
|
|
764
|
+
sys.stdout = _TeeStream(stdout_orig, buf)
|
|
765
|
+
if capture_stderr:
|
|
766
|
+
sys.stderr = _TeeStream(stderr_orig, buf)
|
|
767
|
+
|
|
768
|
+
try:
|
|
769
|
+
yield
|
|
770
|
+
finally:
|
|
771
|
+
# Restore streams first.
|
|
772
|
+
sys.stdout = stdout_orig
|
|
773
|
+
sys.stderr = stderr_orig
|
|
774
|
+
|
|
775
|
+
# Let Jupyter finish rendering any queued output.
|
|
776
|
+
if sleep_s:
|
|
777
|
+
time.sleep(float(sleep_s))
|
|
778
|
+
|
|
779
|
+
# Clear cell output and print summary.
|
|
780
|
+
summary = buf.summary()
|
|
781
|
+
if clear:
|
|
782
|
+
try:
|
|
783
|
+
from IPython.display import clear_output
|
|
784
|
+
clear_output(wait=True)
|
|
785
|
+
except Exception:
|
|
786
|
+
pass
|
|
787
|
+
|
|
788
|
+
if summary:
|
|
789
|
+
print(summary)
|
|
790
|
+
|
|
791
|
+
return _ctx()
|
xarpes/selfenergies.py
CHANGED
|
@@ -1711,6 +1711,7 @@ class SelfEnergy:
|
|
|
1711
1711
|
|
|
1712
1712
|
return spectrum, model, omega_range, alpha_select, cost, params
|
|
1713
1713
|
|
|
1714
|
+
|
|
1714
1715
|
@staticmethod
|
|
1715
1716
|
def _merge_defaults(defaults, override_dict=None, override_kwargs=None):
|
|
1716
1717
|
"""Merge defaults with dict + kwargs overrides (kwargs win)."""
|
|
@@ -2147,6 +2148,101 @@ class SelfEnergy:
|
|
|
2147
2148
|
return spectrum_out, alpha_select, fit_curve, guess_curve, chi2kink_result
|
|
2148
2149
|
|
|
2149
2150
|
|
|
2151
|
+
@staticmethod
|
|
2152
|
+
def _trimmed_stdout(print_lines):
|
|
2153
|
+
"""Optionally tee stdout+stderr and replace final output with head/tail."""
|
|
2154
|
+
from contextlib import contextmanager
|
|
2155
|
+
|
|
2156
|
+
@contextmanager
|
|
2157
|
+
def _ctx():
|
|
2158
|
+
if print_lines is None:
|
|
2159
|
+
yield
|
|
2160
|
+
return
|
|
2161
|
+
|
|
2162
|
+
n = int(print_lines)
|
|
2163
|
+
import sys
|
|
2164
|
+
import io
|
|
2165
|
+
|
|
2166
|
+
class _Tee:
|
|
2167
|
+
def __init__(self, out_stream, err_stream, nlines):
|
|
2168
|
+
self.out_stream = out_stream
|
|
2169
|
+
self.err_stream = err_stream
|
|
2170
|
+
self.nlines = int(nlines)
|
|
2171
|
+
self.buf = io.StringIO()
|
|
2172
|
+
|
|
2173
|
+
def write(self, text):
|
|
2174
|
+
# Jupyter sometimes calls write with empty strings
|
|
2175
|
+
if text is None:
|
|
2176
|
+
return
|
|
2177
|
+
if self.nlines > 0:
|
|
2178
|
+
self.out_stream.write(text)
|
|
2179
|
+
self.out_stream.flush()
|
|
2180
|
+
self.buf.write(text)
|
|
2181
|
+
|
|
2182
|
+
def flush(self):
|
|
2183
|
+
self.out_stream.flush()
|
|
2184
|
+
|
|
2185
|
+
def err_write(self, text):
|
|
2186
|
+
if text is None:
|
|
2187
|
+
return
|
|
2188
|
+
if self.nlines > 0:
|
|
2189
|
+
self.err_stream.write(text)
|
|
2190
|
+
self.err_stream.flush()
|
|
2191
|
+
self.buf.write(text)
|
|
2192
|
+
|
|
2193
|
+
def err_flush(self):
|
|
2194
|
+
self.err_stream.flush()
|
|
2195
|
+
|
|
2196
|
+
def cleaned(self):
|
|
2197
|
+
lines = self.buf.getvalue().splitlines()
|
|
2198
|
+
if self.nlines <= 0:
|
|
2199
|
+
return ""
|
|
2200
|
+
|
|
2201
|
+
if len(lines) <= 2 * self.nlines:
|
|
2202
|
+
return "\n".join(lines)
|
|
2203
|
+
|
|
2204
|
+
head = lines[:self.nlines]
|
|
2205
|
+
tail = lines[-self.nlines:]
|
|
2206
|
+
omitted = len(lines) - 2 * self.nlines
|
|
2207
|
+
mid = f"... ({omitted} lines omitted) ..."
|
|
2208
|
+
return "\n".join(head + [mid] + tail)
|
|
2209
|
+
|
|
2210
|
+
stdout_orig = sys.stdout
|
|
2211
|
+
stderr_orig = sys.stderr
|
|
2212
|
+
|
|
2213
|
+
tee = _Tee(stdout_orig, stderr_orig, n)
|
|
2214
|
+
|
|
2215
|
+
class _ErrProxy:
|
|
2216
|
+
def write(self, text):
|
|
2217
|
+
tee.err_write(text)
|
|
2218
|
+
|
|
2219
|
+
def flush(self):
|
|
2220
|
+
tee.err_flush()
|
|
2221
|
+
|
|
2222
|
+
try:
|
|
2223
|
+
sys.stdout = tee
|
|
2224
|
+
sys.stderr = _ErrProxy()
|
|
2225
|
+
yield
|
|
2226
|
+
finally:
|
|
2227
|
+
sys.stdout = stdout_orig
|
|
2228
|
+
sys.stderr = stderr_orig
|
|
2229
|
+
|
|
2230
|
+
try:
|
|
2231
|
+
from IPython.display import clear_output
|
|
2232
|
+
clear_output(wait=True)
|
|
2233
|
+
except Exception:
|
|
2234
|
+
pass
|
|
2235
|
+
|
|
2236
|
+
cleaned = tee.cleaned()
|
|
2237
|
+
if cleaned:
|
|
2238
|
+
print(cleaned)
|
|
2239
|
+
else:
|
|
2240
|
+
# Avoid a "blank cell" surprise.
|
|
2241
|
+
print("(output trimmed; nothing captured from stdout/stderr)")
|
|
2242
|
+
|
|
2243
|
+
return _ctx()
|
|
2244
|
+
|
|
2245
|
+
|
|
2150
2246
|
@staticmethod
|
|
2151
2247
|
def _el_el_self_energy(enel_range, k_BT, lambda_el, W, power):
|
|
2152
2248
|
"""Electron–electron contribution to the self-energy."""
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
xarpes/__init__.py,sha256=
|
|
1
|
+
xarpes/__init__.py,sha256=DFt2W5mUNCCXIJt4Q_h3xsCQn0U9nqO_3C1bEguzLnw,756
|
|
2
2
|
xarpes/bandmap.py,sha256=1B5GbRXFdBPqnmeKPJW0mzlz-IUoLD-28rxrThpp4co,34664
|
|
3
3
|
xarpes/constants.py,sha256=XOdgSzyrmHr5xocHZfmcFHHoVAa1G05a305hm3XOTtY,504
|
|
4
4
|
xarpes/distributions.py,sha256=pC8V5MlZDNFdooMonFREEASiN5QodHiyKc2ehnxMKvQ,23498
|
|
5
|
-
xarpes/functions.py,sha256=
|
|
5
|
+
xarpes/functions.py,sha256=oVAdNY0g44h7h6bXI8IYCiNbXfrLvBk7xD79ZQnbhno,25404
|
|
6
6
|
xarpes/mdcs.py,sha256=WRKSfGlRVKBssJp9FIHcAFsINVunPkmW9fBnFjqBHYI,42844
|
|
7
7
|
xarpes/plotting.py,sha256=lGCReHcXhYLQXR5ns3EHFjCQjJ9Sc-HifV7n4BnWby4,5189
|
|
8
|
-
xarpes/selfenergies.py,sha256=
|
|
8
|
+
xarpes/selfenergies.py,sha256=stbKhpDt49F8QTancIpOhgpTrdRvTvCBhvH770p0y-U,84176
|
|
9
9
|
xarpes/settings_parameters.py,sha256=yOYvgEiDeDiLzzLkvysCTiVwqg6fKIkN48B-WSad728,1912
|
|
10
10
|
xarpes/settings_plots.py,sha256=X-qteB2fIbBKOAcLMvMYDfQ8QdlUeA5xYQqF_Nyb4uA,1562
|
|
11
|
-
xarpes-0.6.
|
|
12
|
-
xarpes-0.6.
|
|
13
|
-
xarpes-0.6.
|
|
14
|
-
xarpes-0.6.
|
|
15
|
-
xarpes-0.6.
|
|
11
|
+
xarpes-0.6.5.dist-info/entry_points.txt,sha256=917UR-cqFTMMI_vMqIbk7boYSuFX_zHwQlXKcj9vlCE,79
|
|
12
|
+
xarpes-0.6.5.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
13
|
+
xarpes-0.6.5.dist-info/WHEEL,sha256=jPMR_Dzkc4X4icQtmz81lnNY_kAsfog7ry7qoRvYLXw,81
|
|
14
|
+
xarpes-0.6.5.dist-info/METADATA,sha256=sgr0wwth6Z-sAC4JaIlDXV_PCg9jFX8_F6ZracOhZO4,7154
|
|
15
|
+
xarpes-0.6.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|