wums 0.1.2__tar.gz → 0.1.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: wums
3
- Version: 0.1.2
3
+ Version: 0.1.4
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
@@ -22,3 +22,8 @@ Requires-Dist: numpy
22
22
  Requires-Dist: uproot
23
23
 
24
24
  # WUMS: Wremnants Utilities, Modules, and other Stuff
25
+
26
+ The `wums` package can be pip installed:
27
+ ```bash
28
+ pip install wums
29
+ ```
wums-0.1.4/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # WUMS: Wremnants Utilities, Modules, and other Stuff
2
+
3
+ The `wums` package can be pip installed:
4
+ ```bash
5
+ pip install wums
6
+ ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "wums"
7
- version = "0.1.2"
7
+ version = "0.1.4"
8
8
  description = "."
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  license = { text = "MIT" }
@@ -36,3 +36,6 @@ dependencies = [
36
36
 
37
37
  [tool.setuptools.packages.find]
38
38
  where = ["."]
39
+
40
+ [tool.setuptools.package-data]
41
+ "wums" = ["Templates/index.php"]
@@ -0,0 +1,131 @@
1
+ <html>
2
+ <head>
3
+ <title><?php echo getcwd(); ?></title>
4
+ <style type='text/css'>
5
+ body {
6
+ font-family: "Candara", sans-serif;
7
+ font-size: 9pt;
8
+ line-height: 10.5pt;
9
+ }
10
+ div.pic h3 {
11
+ font-size: 11pt;
12
+ margin: 0.5em 1em 0.2em 1em;
13
+ }
14
+ div.pic p {
15
+ font-size: 11pt;
16
+ margin: 0.2em 1em 0.1em 1em;
17
+ }
18
+ div.pic {
19
+ display: block;
20
+ float: left;
21
+ background-color: white;
22
+ border: 1px solid #ccc;
23
+ padding: 2px;
24
+ text-align: center;
25
+ margin: 2px 10px 10px 2px;
26
+ -moz-box-shadow: 7px 5px 5px rgb(80,80,80); /* Firefox 3.5 */
27
+ -webkit-box-shadow: 7px 5px 5px rgb(80,80,80); /* Chrome, Safari */
28
+ box-shadow: 7px 5px 5px rgb(80,80,80); /* New browsers */
29
+ width: 320px;
30
+ }
31
+ a { text-decoration: none; color: rgb(80,0,0); }
32
+ a:hover { text-decoration: underline; color: rgb(255,80,80); }
33
+ div.dirlinks h2 { margin-bottom: 4pt; margin-left: -24pt; color: rgb(80,0,0); }
34
+ div.dirlinks { margin: 0 24pt; }
35
+ div.dirlinks a {
36
+ font-size: 11pt; font-weight: bold;
37
+ padding: 0 0.5em;
38
+ }
39
+ </style>
40
+ </head>
41
+ <body>
42
+ <h1><?php echo getcwd(); ?></h1>
43
+ <?php
44
+ $has_subs = true;
45
+ foreach (glob("*") as $filename) {
46
+ if (is_dir($filename) && !preg_match("/^\..*|.*private.*/", $filename)) {
47
+ $has_subs = true;
48
+ break;
49
+ }
50
+ }
51
+ if ($has_subs) {
52
+ print "<div class=\"dirlinks\">\n";
53
+ print "<h2>Directories</h2>\n";
54
+ print "<a href=\"../\">[parent]</a> ";
55
+ foreach (glob("*") as $filename) {
56
+ if (is_dir($filename) && ($_SERVER['PHP_AUTH_USER'] == 'gpetrucc' || !preg_match("/^\..*|.*private.*/", $filename))) {
57
+ print " <a href=\"$filename\">[$filename]</a>";
58
+ }
59
+ }
60
+ print "</div>";
61
+ }
62
+
63
+ foreach (array("00_README.txt", "README.txt", "readme.txt") as $readme) {
64
+ if (file_exists($readme)) {
65
+ print "<pre class='readme'>\n"; readfile($readme); print "</pre>";
66
+ }
67
+ }
68
+ ?>
69
+
70
+ <h2><a name="plots">Plots</a></h2>
71
+ <p><form>Filter: <input type="text" name="match" size="30" value="<?php if (isset($_GET['match'])) print htmlspecialchars($_GET['match']); ?>" /><input type="Submit" value="Go" /><input type="checkbox" name="regexp" <?php if ($_GET['regexp']) print "checked=\"checked\""?> >RegExp</input></form></p>
72
+ <div>
73
+ <?php
74
+ $displayed = array();
75
+ if ($_GET['noplots']) {
76
+ print "Plots will not be displayed.\n";
77
+ } else {
78
+ $other_exts = array('.pdf', '.cxx', '.eps', '.root', '.txt', '.log', '.dir', '.info', '.latex', '.html');
79
+ $filenames = glob("*.png"); sort($filenames);
80
+ foreach ($filenames as $filename) {
81
+ if (isset($_GET['match'])) {
82
+ if (isset($_GET['regexp']) && $_GET['regexp']) {
83
+ if (!preg_match('/.*'.$_GET['match'].'.*/', $filename)) continue;
84
+ } else {
85
+ if (!fnmatch('*'.$_GET['match'].'*', $filename)) continue;
86
+ }
87
+ }
88
+ array_push($displayed, $filename);
89
+ $brfname = str_replace("_","_&shy;",$filename);
90
+ print "<div class='pic'>\n";
91
+ print "<h3><a href=\"$filename\">$brfname</a></h3>";
92
+ print "<a href=\"$filename\"><img src=\"$filename\" style=\"border: none; width: 300px; \"></a>";
93
+ $others = array();
94
+ foreach ($other_exts as $ex) {
95
+ $other_filename = str_replace('.png', $ex, $filename);
96
+ if (file_exists($other_filename)) {
97
+ array_push($others, "<a class=\"file\" href=\"$other_filename\">[" . $ex . "]</a>");
98
+ if ($ex != '.txt') array_push($displayed, $other_filename);
99
+ }
100
+ }
101
+ if ($others) print "<p>Also as ".implode(', ',$others)."</p>";
102
+ print "</div>";
103
+ }
104
+ }
105
+ ?>
106
+ </div>
107
+ <div style="display: block; clear:both;">
108
+ <h2><a name="files">Other files</a></h2>
109
+ <ul>
110
+ <?php
111
+ foreach (glob("*") as $filename) {
112
+ if ($_GET['noplots'] || !in_array($filename, $displayed)) {
113
+ if (isset($_GET['match'])) {
114
+ if (isset($_GET['regexp']) && $_GET['regexp']) {
115
+ if (!preg_match('/.*'.$_GET['match'].'.*/', $filename)) continue;
116
+ } else {
117
+ if (!fnmatch('*'.$_GET['match'].'*', $filename)) continue;
118
+ }
119
+ }
120
+ if (is_dir($filename)) {
121
+ print "<li>[DIR] <a href=\"$filename\">$filename</a></li>";
122
+ } else {
123
+ print "<li><a href=\"$filename\">$filename</a></li>";
124
+ }
125
+ }
126
+ }
127
+ ?>
128
+ </ul>
129
+ </div>
130
+ </body>
131
+ </html>
@@ -19,8 +19,8 @@ def valsAndVariances(h1, h2, flow=True):
19
19
  )
20
20
 
21
21
 
22
- # Broadcast h1 to match the shape of h2
23
22
  def broadcastSystHist(h1, h2, flow=True, by_ax_name=True):
23
+ # Broadcast h1 to match the shape of h2
24
24
  if h1.ndim > h2.ndim or h1.shape == h2.shape:
25
25
  return h1
26
26
 
@@ -160,10 +160,6 @@ def relVariances(h1vals, h2vals, h1vars, h2vars, cutoff=1e-5):
160
160
  return (rel1, rel2)
161
161
 
162
162
 
163
- # TODO: Implement this rather than relying on pdf unc function
164
- # def rssHist(h):
165
-
166
-
167
163
  def sqrtHist(h):
168
164
  rootval = np.sqrt(h.values(flow=True))
169
165
  rooth = h.copy()
@@ -358,50 +354,6 @@ def mirrorHist(hvar, hnom, cutoff=1):
358
354
  return hnew
359
355
 
360
356
 
361
- def extendHistByMirror(hvar, hnom, downAsUp=False, downAsNomi=False):
362
- hmirror = mirrorHist(hvar, hnom)
363
- if downAsNomi:
364
- hvar, hmirror = hmirror, hvar
365
-
366
- mirrorAx = hist.axis.Integer(0, 2, name="mirror", overflow=False, underflow=False)
367
-
368
- if (
369
- hvar.storage_type == hist.storage.Weight
370
- and hnom.storage_type == hist.storage.Weight
371
- ):
372
- hnew = hist.Hist(
373
- *hvar.axes,
374
- mirrorAx,
375
- storage=hist.storage.Weight(),
376
- data=np.stack((hvar.view(flow=True), hmirror.view(flow=True)), axis=-1),
377
- )
378
- else:
379
- hnew = hist.Hist(
380
- *hvar.axes,
381
- mirrorAx,
382
- data=np.stack((hvar.values(flow=True), hmirror.values(flow=True)), axis=-1),
383
- )
384
-
385
- return hnew
386
-
387
-
388
- # add new axis and set values of old histogram to idx
389
- def addGenChargeAxis(h, idx):
390
- return addGenericAxis(
391
- h,
392
- hist.axis.Regular(2, -2.0, 2.0, underflow=False, overflow=False, name="qGen"),
393
- idx,
394
- add_trailing=False,
395
- flow=True,
396
- )
397
-
398
-
399
- def addSystAxis(h, size=1, offset=0, axname="systIdx"):
400
- return addGenericAxis(
401
- h, hist.axis.Regular(size, offset, size + offset, name=axname)
402
- )
403
-
404
-
405
357
  def addGenericAxis(h, axis, idx=None, add_trailing=True, flow=True):
406
358
  axes = [*h.axes, axis] if add_trailing else [axis, *h.axes]
407
359
  hnew = hist.Hist(*axes, storage=h.storage_type())
@@ -491,8 +443,8 @@ def makeAbsHist(h, axis_name, rename=True):
491
443
  return hnew
492
444
 
493
445
 
494
- # Checks if edges1 could be rebinned to edges2. Order is important!
495
446
  def compatibleBins(edges1, edges2):
447
+ # Checks if edges1 could be rebinned to edges2. Order is important!
496
448
  comparef = np.vectorize(lambda x: np.isclose(x, edges1).any())
497
449
  return np.all(comparef(edges2))
498
450
 
@@ -998,11 +950,13 @@ def set_flow(h, val="nearest"):
998
950
  return h
999
951
 
1000
952
 
1001
- # For converting the helicity scale hist to variations, keeping the gen axis to be fit
1002
- # If swap_axes = True, the new axis takes the place of the old gen axis in the ordering
953
+
1003
954
  def expand_hist_by_duplicate_axis(
1004
955
  href, ref_ax_name, new_ax_name, swap_axes=False, put_trailing=False, flow=True
1005
956
  ):
957
+ # For converting the helicity scale hist to variations, keeping the gen axis to be fit
958
+ # If swap_axes = True, the new axis takes the place of the old gen axis in the ordering
959
+
1006
960
  if ref_ax_name not in href.axes.name:
1007
961
  raise ValueError(f"Did not find axis {ref_ax_name} in hist!")
1008
962
 
@@ -5,6 +5,7 @@ import pathlib
5
5
  import pickle
6
6
  import re
7
7
  import shutil
8
+ import importlib.resources as pkg_resources
8
9
  import subprocess
9
10
  import sys
10
11
  import tempfile
@@ -185,71 +186,19 @@ def write_logfile(
185
186
  logf.write(f"{k}: {v}\n")
186
187
 
187
188
 
189
+ def write_indexfile(outpath, template_dir="Templates", indexname="index.php"):
190
+ with pkg_resources.files("wums").joinpath(f"{template_dir}/{indexname}").open("rb") as src:
191
+ with open(f"{outpath}/index.php", "wb") as dst:
192
+ shutil.copyfileobj(src, dst)
193
+
194
+
188
195
  def write_index_and_log(
189
196
  outpath,
190
197
  logname,
191
- template_dir=f"{pathlib.Path(__file__).parent}/Templates",
192
- yield_tables=None,
193
- analysis_meta_info=None,
198
+ template_dir="Templates",
199
+ analysis_meta_info={},
194
200
  args={},
195
- nround=2,
196
201
  wd=f"{pathlib.Path(__file__).parent}/../",
197
202
  ):
198
- indexname = "index.php"
199
- if "mit.edu" in socket.gethostname() and not (
200
- hasattr(args, "eoscp") and args.eoscp
201
- ):
202
- indexname = "index_mit.php"
203
-
204
- shutil.copyfile(f"{template_dir}/{indexname}", f"{outpath}/index.php")
205
- logname = f"{outpath}/{logname}.log"
206
-
207
- with open(logname, "w") as logf:
208
- meta_info = (
209
- "-" * 80
210
- + "\n"
211
- + f"Script called at {datetime.datetime.now()}\n"
212
- + f"The command was: {script_command_to_str(sys.argv, args)}\n"
213
- + "-" * 80
214
- + "\n"
215
- )
216
- logf.write(meta_info)
217
- meta_info = make_meta_info_dict(
218
- "notebooks",
219
- args=args,
220
- wd=wd,
221
- )
222
- logf.write(f"git hash: {meta_info['git_hash']}\n")
223
- logf.write(f"git diff: {meta_info['git_diff']}\n")
224
-
225
- if yield_tables:
226
- for k, v in yield_tables.items():
227
- logf.write(f"Yield information for {k}\n")
228
- logf.write("-" * 80 + "\n")
229
- logf.write(str(v.round(nround)) + "\n\n")
230
-
231
- if (
232
- "Unstacked processes" in yield_tables
233
- and "Stacked processes" in yield_tables
234
- ):
235
- if "Data" in yield_tables["Unstacked processes"]["Process"].values:
236
- unstacked = yield_tables["Unstacked processes"]
237
- data_yield = unstacked[unstacked["Process"] == "Data"][
238
- "Yield"
239
- ].iloc[0]
240
- ratio = (
241
- float(
242
- yield_tables["Stacked processes"]["Yield"].sum()
243
- / data_yield
244
- )
245
- * 100
246
- )
247
- logf.write(f"===> Sum unstacked to data is {ratio:.2f}%")
248
-
249
- if analysis_meta_info:
250
- for k, analysis_info in analysis_meta_info.items():
251
- logf.write("\n" + "-" * 80 + "\n")
252
- logf.write(f"Meta info from input file {k}\n")
253
- logf.write("\n" + "-" * 80 + "\n")
254
- logf.write(json.dumps(analysis_info, indent=5).replace("\\n", "\n"))
255
- logger.info(f"Writing file {logname}")
203
+ write_indexfile(outpath, template_dir)
204
+ write_logfile(outpath, logname, args, analysis_meta_info)
@@ -421,16 +421,16 @@ def get_custom_handler_map(keys):
421
421
  return handler_map
422
422
 
423
423
 
424
- # https://stackoverflow.com/questions/53122592/legend-with-vertical-line
425
424
  def update_prop(handle, orig):
425
+ # https://stackoverflow.com/questions/53122592/legend-with-vertical-line
426
426
  handle.update_from(orig)
427
427
  x, y = handle.get_data()
428
428
  handle.set_data([np.mean(x)] * 2, [0, 2 * y[0]])
429
429
 
430
430
 
431
431
  def padding(ncols, labels, handles, loc="auto"):
432
+ # if not all legend places are filled, add empty legend entries towards the center of the figure
432
433
  if len(labels) % ncols:
433
- # if not all legend places are filled, add empty legend entries towards the center of the figure
434
434
  rest = ncols - len(labels) % ncols
435
435
  nrows = int(np.ceil(len(labels) / ncols))
436
436
  for i in range(rest):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: wums
3
- Version: 0.1.2
3
+ Version: 0.1.4
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
@@ -22,3 +22,8 @@ Requires-Dist: numpy
22
22
  Requires-Dist: uproot
23
23
 
24
24
  # WUMS: Wremnants Utilities, Modules, and other Stuff
25
+
26
+ The `wums` package can be pip installed:
27
+ ```bash
28
+ pip install wums
29
+ ```
@@ -10,4 +10,5 @@ wums.egg-info/PKG-INFO
10
10
  wums.egg-info/SOURCES.txt
11
11
  wums.egg-info/dependency_links.txt
12
12
  wums.egg-info/requires.txt
13
- wums.egg-info/top_level.txt
13
+ wums.egg-info/top_level.txt
14
+ wums/Templates/index.php
wums-0.1.2/README.md DELETED
@@ -1 +0,0 @@
1
- # WUMS: Wremnants Utilities, Modules, and other Stuff
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes