mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 14:50:25 +01:00
feat: CObs format added and complex Corr print improved. (#200)
This commit is contained in:
parent
b62a18643e
commit
8736d1cd3c
3 changed files with 19 additions and 3 deletions
|
@ -998,8 +998,6 @@ class Corr:
|
||||||
content_string += "Description: " + self.tag + "\n"
|
content_string += "Description: " + self.tag + "\n"
|
||||||
if self.N != 1:
|
if self.N != 1:
|
||||||
return content_string
|
return content_string
|
||||||
if isinstance(self[0], CObs):
|
|
||||||
return content_string
|
|
||||||
|
|
||||||
if print_range[1]:
|
if print_range[1]:
|
||||||
print_range[1] += 1
|
print_range[1] += 1
|
||||||
|
@ -1010,7 +1008,7 @@ class Corr:
|
||||||
else:
|
else:
|
||||||
content_string += str(i + print_range[0])
|
content_string += str(i + print_range[0])
|
||||||
for element in sub_corr:
|
for element in sub_corr:
|
||||||
content_string += '\t' + ' ' * int(element >= 0) + str(element)
|
content_string += f"\t{element:+2}"
|
||||||
content_string += '\n'
|
content_string += '\n'
|
||||||
return content_string
|
return content_string
|
||||||
|
|
||||||
|
|
|
@ -1023,6 +1023,14 @@ class CObs:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'CObs[' + str(self) + ']'
|
return 'CObs[' + str(self) + ']'
|
||||||
|
|
||||||
|
def __format__(self, format_type):
|
||||||
|
if format_type == "":
|
||||||
|
significance = 2
|
||||||
|
format_type = "2"
|
||||||
|
else:
|
||||||
|
significance = int(float(format_type.replace("+", "").replace("-", "")))
|
||||||
|
return f"({self.real:{format_type}}{self.imag:+{significance}}j)"
|
||||||
|
|
||||||
|
|
||||||
def _format_uncertainty(value, dvalue, significance=2):
|
def _format_uncertainty(value, dvalue, significance=2):
|
||||||
"""Creates a string of a value and its error in paranthesis notation, e.g., 13.02(45)"""
|
"""Creates a string of a value and its error in paranthesis notation, e.g., 13.02(45)"""
|
||||||
|
|
|
@ -1297,6 +1297,16 @@ def test_f_string_obs():
|
||||||
print(f"{o1:-1}")
|
print(f"{o1:-1}")
|
||||||
print(f"{o1: 8}")
|
print(f"{o1: 8}")
|
||||||
|
|
||||||
|
def test_f_string_cobs():
|
||||||
|
o_real = pe.pseudo_Obs(0.348, 0.0123, "test")
|
||||||
|
o_imag = pe.pseudo_Obs(0.348, 0.0123, "test")
|
||||||
|
o1 = pe.CObs(o_real, o_imag)
|
||||||
|
print(f"{o1}")
|
||||||
|
print(f"{o1:3}")
|
||||||
|
print(f"{o1:+3}")
|
||||||
|
print(f"{o1:-1}")
|
||||||
|
print(f"{o1: 8}")
|
||||||
|
|
||||||
def test_compute_drho_fails():
|
def test_compute_drho_fails():
|
||||||
obs = pe.input.json.load_json("tests/data/compute_drho_fails.json.gz")
|
obs = pe.input.json.load_json("tests/data/compute_drho_fails.json.gz")
|
||||||
obs.gm()
|
obs.gm()
|
||||||
|
|
Loading…
Add table
Reference in a new issue