Skip to content

Commit a088f9a

Browse files
author
Jorge Prado Gonzalez
committed
flake8 code quality changes.
1 parent 65db331 commit a088f9a

7 files changed

Lines changed: 59 additions & 39 deletions

File tree

examples/07_km3net/01_convert_km3net.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def main(backend: str, triggered: str, HNL: str, OUTPUT_DIR: str) -> None:
2929
else:
3030
outdir = f"{EXAMPLE_OUTPUT_DIR}/{backend}"
3131
os.makedirs(outdir, exist_ok=True)
32-
print(60*'*')
32+
print(60 * "*")
3333
print(f"Saving to {outdir}")
34-
print(60*'*')
34+
print(60 * "*")
3535
if backend == "parquet":
3636
save_method = ParquetWriter(truth_table="truth")
3737
elif backend == "sqlite":

examples/07_km3net/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ The generated SQLite or Parquet file contains:
3838

3939
The output files can be read using Python.
4040

41-
- **If you chose to create a Parquet output**:
42-
You will find several `.parquet` files in the output folder, each corresponding to a different extracted table (e.g., a table with the true event information, a table with pulse information, etc.).
41+
- **If you chose to create a Parquet output**:
42+
You will find several `.parquet` files in the output folder, each corresponding to a different extracted table (e.g., a table with the true event information, a table with pulse information, etc.).
4343
To read one of these tables:
4444

4545
```python
@@ -48,8 +48,8 @@ The output files can be read using Python.
4848
df = pd.read_parquet("FILE_NAME.parquet")
4949
print(df.head())
5050

51-
- **If you chose to create an SQLite output**:
52-
In this case, you will find a single `.db` file per converted input, which contains all the tables inside.
51+
- **If you chose to create an SQLite output**:
52+
In this case, you will find a single `.db` file per converted input, which contains all the tables inside.
5353
To list the table names and preview their contents:
5454

5555
```python
@@ -85,4 +85,3 @@ or
8585
```bash
8686
python 01_convert_km3net.py --help
8787
```
88-

src/graphnet/data/extractors/km3net/km3netpulseextractor.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _extract_pulse_map(self, file: Any) -> pd.DataFrame:
6565
hits_array = hits.arrays(keys_to_extract, library="ak")
6666
hits_array["entry"] = ak.local_index(hits_array, axis=0)
6767
df = ak.to_dataframe(hits_array).reset_index(drop=True)
68-
68+
6969
# Add unique event ID
7070
unique_extended = [
7171
int(unique_id[index]) for index in df["entry"].values
@@ -77,7 +77,11 @@ def _extract_pulse_map(self, file: Any) -> pd.DataFrame:
7777
df = df[df["trig"] != 0]
7878

7979
# Final processing
80-
df = df.drop(["entry", "subentry"], axis=1) if "subentry" in df.columns else df.drop(["entry"], axis=1)
80+
df = (
81+
df.drop(["entry", "subentry"], axis=1)
82+
if "subentry" in df.columns
83+
else df.drop(["entry"], axis=1)
84+
)
8185
df = creating_time_zero(df)
8286
df = df.reset_index(drop=True)
8387

@@ -89,41 +93,45 @@ def _determine_unique_id(self, file: Any) -> np.ndarray:
8993
primaries = file.mc_trks[:, 0]
9094
nus_flavor = [12, 14, 16]
9195

92-
if (abs(np.array(primaries.pdgid)[0]) not in nus_flavor) and (abs(np.array(primaries.pdgid)[0]) > 0.1): # Muon
96+
if (abs(np.array(primaries.pdgid)[0]) not in nus_flavor) and (
97+
abs(np.array(primaries.pdgid)[0]) > 0.1
98+
): # Muon
9399
return create_unique_id_run_by_run(
94100
file_type="muon",
95101
run_id=np.array(file.run_id),
96102
evt_id=np.array(file.id),
97103
hnl_model="none",
98104
)
99-
elif (5914 in file.mc_trks.pdgid[0]) or (file.mc_trks.pdgid[0][0] == 0): # HNL
105+
elif (5914 in file.mc_trks.pdgid[0]) or (
106+
file.mc_trks.pdgid[0][0] == 0
107+
): # HNL
100108
try:
101109
model_hnl = file.header.model.interaction
102110
except Exception:
103111
model_hnl = "none"
104112
return create_unique_id_run_by_run(
105-
file_type="hnl",
106-
run_id=np.array(file.run_id),
107-
evt_id=np.array(file.id),
108-
hnl_model=model_hnl,
109-
)
113+
file_type="hnl",
114+
run_id=np.array(file.run_id),
115+
evt_id=np.array(file.id),
116+
hnl_model=model_hnl,
117+
)
110118
elif (abs(np.array(primaries.pdgid)[0]) in nus_flavor) and (
111119
5914 not in file.mc_trks.pdgid[0]
112120
): # Neutrino
113121
return create_unique_id_run_by_run(
114-
file_type="neutrino",
115-
run_id=np.array(file.run_id),
116-
evt_id=np.array(file.id),
117-
hnl_model="none",
118-
)
122+
file_type="neutrino",
123+
run_id=np.array(file.run_id),
124+
evt_id=np.array(file.id),
125+
hnl_model="none",
126+
)
119127
elif len(file.mc_trks.E[0]) == 0: # Events or Noise
120128
if file.header["calibration"] == "dynamical": # Data
121129
return create_unique_id_run_by_run(
122-
file_type="data",
123-
run_id=np.array(file.run_id),
124-
evt_id=np.array(file.id),
125-
hnl_model="none",
126-
)
130+
file_type="data",
131+
run_id=np.array(file.run_id),
132+
evt_id=np.array(file.id),
133+
hnl_model="none",
134+
)
127135
elif file.header["calibration"] == "statical": # Noise
128136
return create_unique_id_run_by_run(
129137
file_type="noise",

src/graphnet/data/extractors/km3net/km3nettruthextractor.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
assert_no_uint_values,
1313
filter_None_NaN,
1414
)
15+
1516
if has_km3net_package() or TYPE_CHECKING:
1617
import km3io as ki
1718

19+
1820
class KM3NeTTruthExtractor(KM3NeTExtractor):
1921
"""Class for extracting the truth information from a file."""
2022

@@ -150,11 +152,11 @@ def _extract_event_attributes(
150152
raise ValueError("File type not recognized")
151153

152154
unique_id = create_unique_id_run_by_run(
153-
file_type=file_type,
154-
run_id=np.array(file.run_id),
155-
evt_id=np.array(file.id),
156-
hnl_model=model_hnl,
157-
)
155+
file_type=file_type,
156+
run_id=np.array(file.run_id),
157+
evt_id=np.array(file.id),
158+
hnl_model=model_hnl,
159+
)
158160

159161
return {
160162
"run_id": run_id,
@@ -359,7 +361,9 @@ def _extract_truth_dataframe(self, file: Any) -> Any:
359361
##############################################################
360362
# MUON-FILE####################################################
361363
##############################################################
362-
if (abs(np.array(primaries.pdgid)[0]) not in nus_flavor) and (abs(np.array(primaries.pdgid)[0]) > 0.1):
364+
if (abs(np.array(primaries.pdgid)[0]) not in nus_flavor) and (
365+
abs(np.array(primaries.pdgid)[0]) > 0.1
366+
):
363367
primaries_jshower = ki.tools.best_jshower(file.trks)
364368
primaries_jmuon = ki.tools.best_jmuon(file.trks)
365369
dict_truth = self._construct_truth_dictionary(
@@ -374,7 +378,9 @@ def _extract_truth_dataframe(self, file: Any) -> Any:
374378
###############################################################
375379
# HNL-FILE######################################################
376380
###############################################################
377-
elif (5914 in file.mc_trks.pdgid[0]) or (file.mc_trks.pdgid[0][0] == 0):
381+
elif (5914 in file.mc_trks.pdgid[0]) or (
382+
file.mc_trks.pdgid[0][0] == 0
383+
):
378384
primaries_jshower = ki.tools.best_jshower(file.trks)
379385
primaries_jmuon = ki.tools.best_jmuon(file.trks)
380386
dict_truth = self._construct_truth_dictionary(

src/graphnet/data/extractors/km3net/utilities/km3net_utilities.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
import pandas as pd
77

88

9-
10-
119
def create_unique_id_run_by_run(
1210
file_type: str,
1311
run_id: List[int],
1412
evt_id: List[int],
1513
hnl_model: str,
16-
)->List[int]:
14+
) -> List[int]:
1715
"""Create a unique ID for each event based on its parameters.
1816
1917
Args:
@@ -33,11 +31,18 @@ def create_unique_id_run_by_run(
3331
}
3432

3533
hnl_type_dict = {
36-
'none': 0, #possibility of adding hnl models to break run-filetype degeneracy
34+
"none": 0, # possibility of adding hnl models to break run-filetype degeneracy
3735
}
3836
unique_id = []
3937
for i in range(len(run_id)):
40-
unique_id.append(int(str(run_id[i]) + str(evt_id[i]) + str(file_type_dict[file_type]) + str(hnl_type_dict[hnl_model])))
38+
unique_id.append(
39+
int(
40+
str(run_id[i])
41+
+ str(evt_id[i])
42+
+ str(file_type_dict[file_type])
43+
+ str(hnl_type_dict[hnl_model])
44+
)
45+
)
4146

4247
return unique_id
4348

src/graphnet/data/readers/km3netreader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# km3net specific imports
1919
if has_km3net_package() or TYPE_CHECKING:
20-
import km3io as ki # pyright: reportMissingImports=false
20+
import km3io as ki # pyright: reportMissingImports=false
2121

2222

2323
class KM3NeTReader(GraphNeTFileReader):

src/graphnet/utilities/imports.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def has_jammy_flows_package() -> bool:
4646
)
4747
return False
4848

49+
4950
def has_km3net_package() -> bool:
5051
"""Check whether the `km3net` packages are available."""
5152
try:
@@ -58,6 +59,7 @@ def has_km3net_package() -> bool:
5859
)
5960
return False
6061

62+
6163
def requires_icecube(test_function: Callable) -> Callable:
6264
"""Decorate `test_function` for use only if `icecube` module is present."""
6365

0 commit comments

Comments
 (0)