wums 0.1.4__py3-none-any.whl → 0.1.6__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.
wums/ioutils.py CHANGED
@@ -1,5 +1,9 @@
1
1
  import copyreg
2
2
  import pickle
3
+ import sys
4
+
5
+ import wums
6
+ sys.modules['narf.ioutils'] = sys.modules['wums.ioutils'] # backwards compatibility to use old files
3
7
 
4
8
  import boost_histogram as bh
5
9
  import h5py
wums/plot_tools.py CHANGED
@@ -6,6 +6,7 @@ import shutil
6
6
  import socket
7
7
  import sys
8
8
  import textwrap
9
+ import importlib
9
10
 
10
11
  import hist
11
12
  import matplotlib as mpl
@@ -600,14 +601,48 @@ def wrap_text(
600
601
  )
601
602
 
602
603
 
603
- def add_cms_decor(
604
- ax, label=None, lumi=None, loc=2, data=True, text_size=None, no_energy=False
604
+ def add_cms_decor(ax, *args, **kwargs):
605
+ add_decor(ax, "CMS", *args, **kwargs)
606
+
607
+
608
+ def add_decor(
609
+ ax, title, label=None, lumi=None, loc=2, data=True, text_size=None, no_energy=False
605
610
  ):
606
611
  text_size = get_textsize(ax, text_size)
612
+
613
+ if title in ["CMS", "ATLAS", "LHCb", "ALICE"]:
614
+ module = getattr(hep, title.lower())
615
+ make_text = module.text
616
+ make_label = module.label
617
+ else:
618
+ def make_text(text=None, **kwargs):
619
+ for key, value in dict(hep.rcParams.text._get_kwargs()).items():
620
+ if (
621
+ value is not None
622
+ and key not in kwargs
623
+ and key in inspect.getfullargspec(label_base.exp_text).kwonlyargs
624
+ ):
625
+ kwargs.setdefault(key, value)
626
+ kwargs.setdefault("italic", (False, True, False))
627
+ kwargs.setdefault("exp", title)
628
+ return hep.label.exp_text(text=text, **kwargs)
629
+
630
+ def make_label(**kwargs):
631
+ for key, value in dict(hep.rcParams.text._get_kwargs()).items():
632
+ if (
633
+ value is not None
634
+ and key not in kwargs
635
+ and key in inspect.getfullargspec(label_base.exp_text).kwonlyargs
636
+ ):
637
+ kwargs.setdefault(key, value)
638
+ kwargs.setdefault("italic", (False, True, False))
639
+ kwargs.setdefault("exp", title)
640
+ return hep.label.exp_label(**kwargs)
641
+
607
642
  if no_energy:
608
- hep.cms.text(ax=ax, text=label, loc=loc, fontsize=text_size)
643
+ make_text(ax=ax, text=label, loc=loc, fontsize=text_size)
609
644
  else:
610
- hep.cms.label(
645
+ make_label(
611
646
  ax=ax,
612
647
  lumi=lumi,
613
648
  lumi_format="{0:.3g}",
@@ -616,7 +651,32 @@ def add_cms_decor(
616
651
  data=data,
617
652
  loc=loc,
618
653
  )
619
-
654
+
655
+ # else:
656
+ # if loc==0:
657
+ # # above frame
658
+ # x = 0.0
659
+ # y = 1.0
660
+ # elif loc==1:
661
+ # # in frame
662
+ # x = 0.05
663
+ # y = 0.88
664
+ # elif loc==2:
665
+ # # upper left, label below title
666
+ # x = 0.05
667
+ # y = 0.88
668
+ # elif loc==2:
669
+ # #
670
+ # ax.text(
671
+ # x,
672
+ # y,
673
+ # args.title,
674
+ # transform=ax1.transAxes,
675
+ # fontweight="bold",
676
+ # fontsize=1.2 * text_size,
677
+ # )
678
+ # if label is not None:
679
+ # ax.text(0.05, 0.80, label, transform=ax.transAxes, fontstyle="italic")
620
680
 
621
681
  def makeStackPlotWithRatio(
622
682
  histInfo,
@@ -825,11 +885,11 @@ def makeStackPlotWithRatio(
825
885
  for x in (data_hist.sum(), hh.sumHists(stack).sum())
826
886
  ]
827
887
  varis = [
828
- x.variance if hasattr(x, "variance") else x ** 0.5
888
+ x.variance if hasattr(x, "variance") else x**0.5
829
889
  for x in (data_hist.sum(), hh.sumHists(stack).sum())
830
890
  ]
831
891
  scale = vals[0] / vals[1]
832
- unc = scale * (varis[0] / vals[0] ** 2 + varis[1] / vals[1] ** 2) ** 0.5
892
+ unc = scale * (varis[0] / vals[0] ** 2 + varis[1] / vals[1] ** 2)**0.5
833
893
  ndigits = -math.floor(math.log10(abs(unc))) + 1
834
894
  logger.info(
835
895
  f"Rescaling all processes by {round(scale,ndigits)} +/- {round(unc,ndigits)} to match data norm"
@@ -1780,3 +1840,44 @@ def make_summary_plot(
1780
1840
  ax1.xaxis.set_major_locator(ticker.LinearLocator(numticks=5))
1781
1841
 
1782
1842
  return fig
1843
+
1844
+
1845
+ def load_config(config_path):
1846
+ if config_path is None:
1847
+ return {}
1848
+ # load a python module
1849
+ spec = importlib.util.spec_from_file_location("config", config_path)
1850
+ config = importlib.util.module_from_spec(spec)
1851
+ spec.loader.exec_module(config)
1852
+ return config
1853
+
1854
+
1855
+ def read_axis_label(x, labels, with_unit=True):
1856
+ if x in labels:
1857
+ label = labels[x]
1858
+ if isinstance(label, str):
1859
+ return label
1860
+ elif with_unit:
1861
+ return f'{label["label"]} ({label["unit"]})'
1862
+ else:
1863
+ return label["label"]
1864
+ else:
1865
+ return x
1866
+
1867
+
1868
+ def get_axis_label(config, default_keys=None, label=None, is_bin=False):
1869
+ if label is not None:
1870
+ return label
1871
+
1872
+ if default_keys is None:
1873
+ return "Bin index"
1874
+
1875
+ labels = getattr(config, "axis_labels", {})
1876
+
1877
+ if len(default_keys) == 1:
1878
+ if is_bin:
1879
+ return f"{read_axis_label(default_keys[0], labels, False)} bin"
1880
+ else:
1881
+ return read_axis_label(default_keys[0], labels)
1882
+ else:
1883
+ return f"({', '.join([read_axis_label(a, labels, False) for a in default_keys])}) bin"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: wums
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: .
5
5
  Author-email: David Walter <david.walter@cern.ch>, Josh Bendavid <josh.bendavid@cern.ch>, Kenneth Long <kenneth.long@cern.ch>
6
6
  License: MIT
@@ -1,11 +1,11 @@
1
1
  wums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  wums/boostHistHelpers.py,sha256=F4SwQEVjNObFscfs0qrJEyOHYNKqUCmusW8HIF1o-0c,38993
3
- wums/ioutils.py,sha256=1o4cNXeoOzk8Hy0RePjOdCqpvJi0gOp_aa7NYhjmIVM,12209
3
+ wums/ioutils.py,sha256=ziyfQQ8CB3Ir2BJKJU3_a7YMF-Jd2nGXKoMQoJ2T8fo,12334
4
4
  wums/logging.py,sha256=zNnLVJUwG3HMvr9NeXmiheX07VmsnSt8cQ6R4q4XBk4,4534
5
5
  wums/output_tools.py,sha256=SHcZqXAdqL9AkA57UF0b-R-U4u7rzDgL8Def4E-ulW0,6713
6
- wums/plot_tools.py,sha256=67ZwcjQRsIbMYvktpG9suj-1hkya-QSuFqiuXm_Zq58,52766
6
+ wums/plot_tools.py,sha256=4iPx9Nr9y8c3p4ovy8XOS-xU_w11OyQEjISKkygxqcA,55918
7
7
  wums/Templates/index.php,sha256=9EYmfc0ltMqr5oOdA4_BVIHdSbef5aA0ORoRZBEADVw,4348
8
- wums-0.1.4.dist-info/METADATA,sha256=sK9B_JHD9dqzwjJakYGWdoTEPlExmJ1P2lWOaAwDgWY,843
9
- wums-0.1.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
- wums-0.1.4.dist-info/top_level.txt,sha256=DCE1TVg7ySraosR3kYZkLIZ2w1Pwk2pVTdkqx6E-yRY,5
11
- wums-0.1.4.dist-info/RECORD,,
8
+ wums-0.1.6.dist-info/METADATA,sha256=pTmIMc-rth2X53tju6Ef8WbJDda2zbr8isEqUpeqhDo,843
9
+ wums-0.1.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ wums-0.1.6.dist-info/top_level.txt,sha256=DCE1TVg7ySraosR3kYZkLIZ2w1Pwk2pVTdkqx6E-yRY,5
11
+ wums-0.1.6.dist-info/RECORD,,
File without changes