Skip to content

Commit c500208

Browse files
author
Kyle Beyer
committed
fix bug in err parsing where wrong label index is found
1 parent adc6c44 commit c500208

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/exfor_tools/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
get_db,
1010
filter_out_lab_angle,
1111
plot_angular_distributions,
12+
parse_angle,
13+
parse_inc_energy,
14+
parse_ex_energy,
15+
parse_differential_data,
16+
parse_angular_distribution,
1217
)
1318

1419
init_exfor_db()

src/exfor_tools/exfor_tools.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,12 @@ def parse_differential_data(
318318
),
319319
match_units=angDistUnits + percentUnits + noUnits,
320320
)
321-
icol = err_parser.firstMatch(data_set)
321+
322+
if label not in data_set.labels:
323+
raise ValueError(f"Subentry does not have a column called {label}")
324+
else:
325+
icol = data_set.labels.index(label)
326+
322327
if icol >= 0:
323328
err = err_parser.getColumn(icol, data_set)
324329
err_units = err[1]
@@ -517,7 +522,7 @@ def attempt_parse_subentry(
517522
err_treatment=err_treatment,
518523
)
519524
except Exception as e:
520-
print(f"Failed to parse subentry {subentry}:\n{e}")
525+
print(f"Failed to parse subentry {subentry}:\n\t{e}")
521526
failed_parses[subentry] = e
522527

523528
return measurements, dict(failed_parses)
@@ -584,8 +589,8 @@ def get_measurements_from_subentry(
584589
err_treatment = "cumulative"
585590
else:
586591
raise NotImplementedError(
587-
f"Subentry {subentry} has an ambiguous set of error labels:\n"
588-
+ "".join([f"{l}\n" for l in err_labels])
592+
f"Subentry {subentry} has an ambiguous set of error labels:\n\t\t"
593+
+ "".join([f"{l}, " for l in err_labels])
589594
)
590595
else:
591596
assert err_treatment is not None
@@ -964,23 +969,17 @@ def set_label(
964969

965970
# TODO when there is more than one measurement, make each subentry label correspond to its
966971
# corresponding color: https://matplotlib.org/1.5.0/examples/text_labels_and_annotations/rainbow_text.html
967-
yc = y
968972
if label_xloc_deg is None:
969973
if x[0] > 20 and x[-1] > 150:
970974
label_xloc_deg = -18
971-
# yc = y[ x < (x.min() + x.max()) / 2 ]
972975
if x[0] > 30 and x[-1] > 150:
973976
label_xloc_deg = 1
974-
# yc = y[ x < (x.min() + x.max()) / 2 ]
975977
elif x[-1] < 140:
976978
label_xloc_deg = 145
977-
yc = y[x > (x.min() + x.max()) / 2]
978979
else:
979980
label_xloc_deg = 175
980-
yc = y[x > (x.min() + x.max()) / 2]
981-
982-
label_yloc = np.mean(yc)
983981

982+
label_yloc = offset
984983
if log:
985984
label_yloc *= label_offset_factor
986985
else:
@@ -1011,7 +1010,7 @@ def set_label(
10111010
if i == len(measurements) - 1:
10121011
label += f"{m.subentry}"
10131012
else:
1014-
label += f"{m.subentry}, "
1013+
label += f"{m.subentry},\n"
10151014
if label_offset:
10161015
label += offset_text
10171016

0 commit comments

Comments
 (0)