-
-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Track boundary interaction #2736
Changes from all commits
adb441b
21d230d
4b8d71e
b200eb5
92a0e31
17c49cd
2eeb98b
c8ba959
0a92b03
3cb968f
76a1808
f85a271
c716200
ae6dc64
593297e
04cf212
be2326d
4289974
675deb7
ebba27a
9883bc7
7d799dc
1024f57
3c2d733
d31b199
939fbbe
f4ac83e
c1a0b92
8eafee1
e657f95
42c460d
2ce9cb9
826a2d9
3d2ff15
2b5c1f8
699cd4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
from numba import float64, int64, njit | ||
from numba import float64, int64, njit, from_dtype | ||
from numba.experimental import jitclass | ||
from numba.typed import List | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
boundary_interaction_dtype = np.dtype( | ||
[ | ||
("event_id", "int64"), | ||
("current_shell_id", "int64"), | ||
("next_shell_id", "int64"), | ||
] | ||
) | ||
|
||
|
||
rpacket_tracker_spec = [ | ||
("length", int64), | ||
("seed", int64), | ||
("index", int64), | ||
("status", int64[:]), | ||
|
@@ -15,7 +24,10 @@ | |
("energy", float64[:]), | ||
("shell_id", int64[:]), | ||
("interaction_type", int64[:]), | ||
("boundary_interaction", from_dtype(boundary_interaction_dtype)[:]), | ||
("num_interactions", int64), | ||
("boundary_interactions_index", int64), | ||
("event_id", int64), | ||
("extend_factor", int64), | ||
] | ||
|
||
|
@@ -53,17 +65,25 @@ class RPacketTracker(object): | |
""" | ||
|
||
def __init__(self, length): | ||
self.length = length | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this length variable, since If I kept this length, I would have to add another length variable for every track_interaction function. |
||
Initialize the variables with default value | ||
""" | ||
self.seed = np.int64(0) | ||
self.index = np.int64(0) | ||
self.status = np.empty(self.length, dtype=np.int64) | ||
self.r = np.empty(self.length, dtype=np.float64) | ||
self.nu = np.empty(self.length, dtype=np.float64) | ||
self.mu = np.empty(self.length, dtype=np.float64) | ||
self.energy = np.empty(self.length, dtype=np.float64) | ||
self.shell_id = np.empty(self.length, dtype=np.int64) | ||
self.interaction_type = np.empty(self.length, dtype=np.int64) | ||
self.status = np.empty(length, dtype=np.int64) | ||
self.r = np.empty(length, dtype=np.float64) | ||
self.nu = np.empty(length, dtype=np.float64) | ||
self.mu = np.empty(length, dtype=np.float64) | ||
self.energy = np.empty(length, dtype=np.float64) | ||
self.shell_id = np.empty(length, dtype=np.int64) | ||
self.interaction_type = np.empty(length, dtype=np.int64) | ||
self.boundary_interaction = np.empty( | ||
length, | ||
dtype=boundary_interaction_dtype, | ||
) | ||
self.num_interactions = 0 | ||
self.boundary_interactions_index = 0 | ||
self.event_id = 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wkerzendorf If I keep the name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be used for indexing purposes - essentially all of the analysis will be done on the dataframes |
||
self.extend_factor = 2 | ||
|
||
def extend_array(self, array, array_length): | ||
|
@@ -74,17 +94,19 @@ def extend_array(self, array, array_length): | |
return temp_array | ||
|
||
def track(self, r_packet): | ||
if self.num_interactions >= self.length: | ||
self.status = self.extend_array(self.status, self.length) | ||
self.r = self.extend_array(self.r, self.length) | ||
self.nu = self.extend_array(self.nu, self.length) | ||
self.mu = self.extend_array(self.mu, self.length) | ||
self.energy = self.extend_array(self.energy, self.length) | ||
self.shell_id = self.extend_array(self.shell_id, self.length) | ||
""" | ||
Track important properties of RPacket | ||
""" | ||
if self.num_interactions >= self.status.size: | ||
self.status = self.extend_array(self.status, self.status.size) | ||
self.r = self.extend_array(self.r, self.r.size) | ||
self.nu = self.extend_array(self.nu, self.nu.size) | ||
self.mu = self.extend_array(self.mu, self.mu.size) | ||
self.energy = self.extend_array(self.energy, self.energy.size) | ||
self.shell_id = self.extend_array(self.shell_id, self.shell_id.size) | ||
self.interaction_type = self.extend_array( | ||
self.interaction_type, self.length | ||
self.interaction_type, self.interaction_type.size | ||
) | ||
self.length = self.length * self.extend_factor | ||
|
||
self.index = r_packet.index | ||
self.seed = r_packet.seed | ||
|
@@ -99,14 +121,46 @@ def track(self, r_packet): | |
] = r_packet.last_interaction_type | ||
self.num_interactions += 1 | ||
|
||
def track_boundary_interaction(self, current_shell_id, next_shell_id): | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only function defined. I added that function. |
||
Track boundary interaction properties | ||
""" | ||
if self.boundary_interactions_index >= self.boundary_interaction.size: | ||
self.boundary_interaction = self.extend_array( | ||
self.boundary_interaction, | ||
self.boundary_interaction.size, | ||
) | ||
|
||
self.boundary_interaction[self.boundary_interactions_index][ | ||
"event_id" | ||
] = self.event_id | ||
self.event_id += 1 | ||
|
||
self.boundary_interaction[self.boundary_interactions_index][ | ||
"current_shell_id" | ||
] = current_shell_id | ||
|
||
self.boundary_interaction[self.boundary_interactions_index][ | ||
"next_shell_id" | ||
] = next_shell_id | ||
|
||
self.boundary_interactions_index += 1 | ||
|
||
def finalize_array(self): | ||
""" | ||
Change the size of the array from length ( or multiple of length ) to | ||
the actual number of interactions | ||
""" | ||
self.status = self.status[: self.num_interactions] | ||
self.r = self.r[: self.num_interactions] | ||
self.nu = self.nu[: self.num_interactions] | ||
self.mu = self.mu[: self.num_interactions] | ||
self.energy = self.energy[: self.num_interactions] | ||
self.shell_id = self.shell_id[: self.num_interactions] | ||
self.interaction_type = self.interaction_type[: self.num_interactions] | ||
self.boundary_interaction = self.boundary_interaction[ | ||
: self.boundary_interactions_index | ||
] | ||
|
||
|
||
def rpacket_trackers_to_dataframe(rpacket_trackers): | ||
|
@@ -186,6 +240,9 @@ class RPacketLastInteractionTracker(object): | |
""" | ||
|
||
def __init__(self): | ||
""" | ||
Initialize properties with default values | ||
""" | ||
self.index = -1 | ||
self.r = -1.0 | ||
self.nu = 0.0 | ||
|
@@ -194,15 +251,27 @@ def __init__(self): | |
self.interaction_type = -1 | ||
|
||
def track(self, r_packet): | ||
""" | ||
Track properties of RPacket and override the previous values | ||
""" | ||
self.index = r_packet.index | ||
self.r = r_packet.r | ||
self.nu = r_packet.nu | ||
self.energy = r_packet.energy | ||
self.shell_id = r_packet.current_shell_id | ||
self.interaction_type = r_packet.last_interaction_type | ||
|
||
# To make it compatible with RPacketTracker | ||
def finalize_array(self): | ||
""" | ||
Added to make RPacketLastInteractionTracker compatible with RPacketTracker | ||
""" | ||
pass | ||
|
||
# To make it compatible with RPacketTracker | ||
def track_boundary_interaction(self, current_shell_id, next_shell_id): | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is a function of different class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In that case, we also had two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
oh sorry didn't notice that |
||
Added to make RPacketLastInteractionTracker compatible with RPacketTracker | ||
""" | ||
pass | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That needs to be parameterized and not fixed. The ref-data directory needs to be a config option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't write that function. I just ran black on that file, and that was the change it made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change I made is from line 204 to 207.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay - talked to @officialasishkumar