-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from FAST-HEP/BK_implement_mapping_multiply
Add postprocessing steps that can ingest curator configs
- Loading branch information
Showing
8 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .functions import open_many | ||
|
||
|
||
__all__ = ["open_many"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pandas as pd | ||
from fast_curator import read | ||
|
||
|
||
def _get_cfg(cfg): | ||
if isinstance(cfg, list): | ||
return cfg | ||
return read.from_yaml(cfg) | ||
|
||
|
||
def prepare_datasets_scale_factor(curator_cfg, multiply_by=[], divide_by=[], dataset_col="dataset", eventtype="mc"): | ||
dataset_cfg = _get_cfg(curator_cfg) | ||
|
||
sfs = {} | ||
for dataset in dataset_cfg: | ||
if eventtype and dataset.eventtype not in eventtype: | ||
sfs[dataset.name] = 1 | ||
continue | ||
|
||
scale = 1 | ||
for m in multiply_by: | ||
scale *= float(getattr(dataset, m)) | ||
for d in divide_by: | ||
scale /= float(getattr(dataset, d)) | ||
sfs[dataset.name] = scale | ||
|
||
sfs = pd.Series(sfs, name=dataset_col) | ||
return sfs | ||
|
||
|
||
def make_dataset_map(curator_cfg, map_from="name", map_to="eventtype", | ||
default_from=None, default_to=None, error_all_missing=True): | ||
dataset_cfg = _get_cfg(curator_cfg) | ||
|
||
mapping = {} | ||
missing_from = 0 | ||
missing_to = 0 | ||
for dataset in dataset_cfg: | ||
if hasattr(dataset, map_from): | ||
key = getattr(dataset, map_from) | ||
else: | ||
key = default_from | ||
missing_from += 1 | ||
|
||
if hasattr(dataset, map_to): | ||
value = getattr(dataset, map_to) | ||
else: | ||
value = default_to | ||
missing_to += 1 | ||
|
||
mapping[key] = value | ||
if missing_from == len(dataset_cfg) and error_all_missing: | ||
msg = "None of the datasets contain the 'from' field, '%s'" | ||
raise RuntimeError(msg % map_from) | ||
|
||
if missing_to == len(dataset_cfg) and error_all_missing: | ||
msg = "None of the datasets contain the 'to' field, '%s'" | ||
raise RuntimeError(msg % map_to) | ||
|
||
return mapping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 0.6.5 | ||
current_version = 0.7.0 | ||
commit = True | ||
tag = False | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters