Skip to content

Commit

Permalink
remove returns
Browse files Browse the repository at this point in the history
  • Loading branch information
Aske-Rosted committed Dec 6, 2024
1 parent 51da4b0 commit 3e21f7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/graphnet/models/graphs/nodes/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ def _construct_nodes(self, x: torch.Tensor) -> Data:
cluster_class = cluster_and_pad(
x=x, cluster_columns=self._cluster_indices
)
array = cluster_class.add_percentile_summary(
cluster_class.add_percentile_summary(
summarization_indices=self._summarization_indices,
percentiles=self._percentiles,
)
if self._add_counts:
array = cluster_class.add_counts()
cluster_class.add_counts()
array = cluster_class.clustered_x
else:
self.error(
f"""{self.__class__.__name__} was not instatiated with
Expand Down
19 changes: 6 additions & 13 deletions src/graphnet/models/graphs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,22 @@ class cluster_and_pad:
will hold the padded data for quick calculation of aggregate statistics.
Example:
clustered_x = cluster_and_pad(x = single_event_as_array,
cluster_and_pad(x = single_event_as_array,
cluster_columns = [0,1,2])
# Creates a cluster matrix and a padded matrix,
# the cluster matrix will contain the unique values of the cluster columns,
# no additional aggregate statistics are added yet.
clustered_x_with_percentiles = cluster_class.add_percentile_summary(
summarization_indices = [3,4,5], percentiles = [10,50,90])
cluster_class.add_percentile_summary(summarization_indices = [3,4,5],
percentiles = [10,50,90])
# Adds the 10th, 50th and 90th percentile of columns 3,4
# and 5 in the input data to the cluster matrix.
clustered_x_with_percentiles_and_std = cluster_class.add_std(column = 4)
cluster_class.add_std(column = 4)
# Adds the standard deviation of column 4 in the input data
# to the cluster matrix.
x = cluster_class.clustered_x
# Gets the clustered matrix with all the aggregate statistics.
"""

def __init__(self, x: np.ndarray, cluster_columns: List[int]) -> None:
Expand Down Expand Up @@ -242,7 +244,6 @@ def __init__(self, x: np.ndarray, cluster_columns: List[int]) -> None:
for i in range(len(self._counts)):
self._padded_x[i, : self._counts[i]] = x[: self._counts[i]]
x = x[self._counts[i] :]
return self.clustered_x

def _add_column(
self, column: np.ndarray, location: Optional[int] = None
Expand All @@ -269,7 +270,6 @@ def _calculate_charge_sum(self, charge_index: int) -> np.ndarray:
), "Charge sum has already been calculated, \
re-calculation is not allowed"
self._charge_sum = self._padded_x[:, :, charge_index].sum(axis=1)
return self._charge_sum

def _calculate_charge_weights(self, charge_index: int) -> np.ndarray:
"""Calculate the weights of the charge."""
Expand All @@ -285,7 +285,6 @@ def _calculate_charge_weights(self, charge_index: int) -> np.ndarray:
self._padded_x[:, :, charge_index]
/ self._charge_sum[:, np.newaxis]
)
return self._charge_weights

def add_charge_threshold_summary(
self,
Expand Down Expand Up @@ -343,7 +342,6 @@ def add_charge_threshold_summary(
len(self.clustered_x), -1
)
self._add_column(selections, location)
return self.clustered_x

def add_percentile_summary(
self,
Expand Down Expand Up @@ -380,12 +378,10 @@ def add_percentile_summary(
len(self.clustered_x), -1
)
self._add_column(percentiles_x, location)
return self.clustered_x

def add_counts(self, location: Optional[int] = None) -> np.ndarray:
"""Add the counts of the sensor to the summarization features."""
self._add_column(np.log10(self._counts), location)
return self.clustered_x

def add_sum_charge(self, location: Optional[int] = None) -> np.ndarray:
"""Add the sum of the charge to the summarization features."""
Expand All @@ -394,7 +390,6 @@ def add_sum_charge(self, location: Optional[int] = None) -> np.ndarray:
), "Charge sum has not been calculated, \
please run calculate_charge_sum"
self._add_column(self._charge_sum, location)
return self.clustered_x

def add_std(
self,
Expand All @@ -414,7 +409,6 @@ def add_std(
self._add_column(
np.nanstd(self._padded_x[:, :, column] * weights, axis=1), location
)
return self.clustered_x

def add_mean(
self,
Expand All @@ -427,7 +421,6 @@ def add_mean(
np.nanmean(self._padded_x[:, :, column] * weights, axis=1),
location,
)
return self.clustered_x


def ice_transparency(
Expand Down

0 comments on commit 3e21f7f

Please sign in to comment.