Skip to content

Commit

Permalink
Added interaction type in rpacket_tracker (#2091)
Browse files Browse the repository at this point in the history
* rpacket_tracker returns dataframe

* added black formatting

* replaced variable i

* added rpacket_tracker_df as separate variable

* added preallocation step

* added non-preallocated-df generator function

* tests for df generator function

* renamed variables

* assert statements corrected

* added seed column in df

* added documentation for rpacket_tracker_df

* added doc str

* initial commit

* updated documention

* moved function to r_packet.py

* added block indexing to df

Co-authored-by: Wolfgang Kerzendorf <[email protected]>

* updated the df function

* added multiindexing

* shifted the df function call

* initial commit

* interaction type added

* removed unused imports

* added tests

* initial commit

* interaction type added

* Created a smart HDF Reader which can re-produce simulation object (#2052)

* Added functions to store and load a runner object

* Updated hardcode file name in runner_from_hdf

* Updated store_runner_to_hdf to append to file

* Added name and email to .mailmap

* runner hdf functions convert to cgs

* store_runner_to_hdf clears group before storing

* Storing units for astropy quantities

* Formatted code with black

* Added functions to store and load model objects

* Fixed typo and decoded string from bytes

* Fixed typo

* Added test for model_to_dict

* Formatted previous test code

* Added test for store_model_to_hdf

* Fixed formatting of model_to_hdf

* Fixed issue with test for model_to_dict

* Added test for runner_to_dict

* Fixed issue with single packet seed storage

* Updated test null value of single packet seed

* Added test for store_runner_to_hdf

* Updated to use isinstance and hasattr

* runner_to_dict returns dicts instead of iterators

* Reordered imports to match pep8 style

* Remove yaml_load_config_file (#2062)

* Remove yaml_load_config_file

* updated mailmap

* Updated __init__.py

* Modified Function Name in Config validator according to PEP8 (#2076)

Fix function name according pep8

* Added documetation on how to compare environment before update (#2082)

* Moved `trace_packet` to tardis tansport (#2083)

* Moved the trace_packet function to the transport module, renamed the function to remove continuum reference as it is generic

* Formatted to PEP 8

* Reformatted single_packet_loop for PEP 8

* removed old continuum trace packet files

* removed references to old files

* Added some docstrings

* Missed an old function call

* Fix broken links in workflow files and goverance md (#2084)

* Adding physics introduction to documentation (#2026)

* creating files and sections

* adding images

* writing intro to tardis physics and adding it to sidebar

* changing spectra page structure

* mostly complete draft of light and matter page

* spectrum page

* fixing up physics stuff

* fixing docstring

* Revert "fixing docstring"

This reverts commit e24cadd.

* andrew's changes

* a few more edits

* adding note about angstroms

* Improved arepo parser (#1941)

* Removed line profile as option

* Removed mapping to Cartesian grid

* Removed automatic plotting after profile creation

* Fixed typo in arepo plot

* Updated documentation

* [build docs]

* [build docs] Removed outputs from doc-notebook

* Updated tests with new models

* Removed deprecated keyword in snapshot loader

* Replaced wget with requests for testfile download

* Updated file retrieval for testing

* Fixed fixture request

* Added arepo data to refdata helper

* Updated refdata location in docs

* Updated paths in tests

* Update download_reference_data.sh

* Testing areop_parser_tests

* Fixed deleted reference file

* Arepo docs fix (#2088)

* [build-docs] Fixed link in arepo docs

* [build-docs] Changed filename in arepo docs

* [build-docs]

* [build-docs]

* [build-docs]

* [build docs]

* [build-docs] Changed refdata url

* [build_docs]

* Updated mailmap

* [build_docs] Updated url for refdata download

* Creating new docs building instructions (#2097)

* creating new docs building instructions

* typos, grammar, and text in hyperlinks

* added tests

* added documentation, black formatting

Co-authored-by: Wolfgang Kerzendorf <[email protected]>
Co-authored-by: Satwik Kambham <[email protected]>
Co-authored-by: aman kumar <[email protected]>
Co-authored-by: Rohith Varma Buddaraju <[email protected]>
Co-authored-by: Jaladh Singhal <[email protected]>
Co-authored-by: Jack O'Brien <[email protected]>
Co-authored-by: Isaac Smith <[email protected]>
Co-authored-by: AlexHls <[email protected]>
  • Loading branch information
9 people authored Aug 3, 2022
1 parent a97d35c commit 208cb92
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
7 changes: 5 additions & 2 deletions docs/io/output/rpacket_tracking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
" <li><b>mu</b> - Propagation Direction of the Packet (cosine of the angle the packet’s path makes with the radial direction)</li>\n",
" <li><b>energy</b> - Energy of the Packet</li>\n",
" <li><b>shell_id</b> - Current Shell Id where the Packet is present</li>\n",
" <li><b>interaction_type</b> - Last Interaction type of the packet</li>\n",
" </ol>\n",
" </body>\n",
"</html>"
Expand Down Expand Up @@ -209,6 +210,7 @@
" mu\n",
" energy\n",
" shell_id\n",
" interaction_type\n",
"```"
]
},
Expand Down Expand Up @@ -298,7 +300,7 @@
"id": "ea308a55",
"metadata": {},
"source": [
"Thus, all other properties (`r`, `nu`, `mu`, `energy`, `shell_id`) can be accessed accordingly."
"Thus, all other properties (`r`, `nu`, `mu`, `energy`, `shell_id`,`interaction_type`) can be accessed accordingly."
]
},
{
Expand Down Expand Up @@ -402,6 +404,7 @@
" <li><b>mu</b></li>\n",
" <li><b>energy</b></li>\n",
" <li><b>shell_id</b></li>\n",
" <li><b>interaction_type</b></li>\n",
" </ol>\n",
" </body>\n",
"</html>"
Expand Down Expand Up @@ -503,7 +506,7 @@
"id": "6921f480",
"metadata": {},
"source": [
"Thus, all other properties (`status`, `seed`, `r`, `nu`, `mu`, `shell_id`) can be accessed accordingly."
"Thus, all other properties (`status`, `seed`, `r`, `nu`, `mu`, `shell_id`,`interaction_type`) can be accessed accordingly."
]
}
],
Expand Down
9 changes: 9 additions & 0 deletions tardis/montecarlo/montecarlo_numba/numba_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def set_properties(
("mu", float64[:]),
("energy", float64[:]),
("shell_id", int64[:]),
("interaction_type", int64[:]),
("interact_id", int64),
]

Expand Down Expand Up @@ -460,6 +461,8 @@ class RPacketTracker(object):
Energy possessed by the RPacket at a particular shell
shell_id : int
Current Shell No in which the RPacket is present
interaction_type: int
Type of interaction the rpacket undergoes
interact_id : int
Internal counter for the interactions that a particular RPacket undergoes
"""
Expand All @@ -474,6 +477,7 @@ def __init__(self):
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.interact_id = 0

def track(self, r_packet):
Expand All @@ -485,20 +489,23 @@ def track(self, r_packet):
temp_mu = np.empty(temp_length, dtype=np.float64)
temp_energy = np.empty(temp_length, dtype=np.float64)
temp_shell_id = np.empty(temp_length, dtype=np.int64)
temp_interaction_type = np.empty(temp_length, dtype=np.int64)

temp_status[: self.length] = self.status
temp_r[: self.length] = self.r
temp_nu[: self.length] = self.nu
temp_mu[: self.length] = self.mu
temp_energy[: self.length] = self.energy
temp_shell_id[: self.length] = self.shell_id
temp_interaction_type[: self.length] = self.interaction_type

self.status = temp_status
self.r = temp_r
self.nu = temp_nu
self.mu = temp_mu
self.energy = temp_energy
self.shell_id = temp_shell_id
self.interaction_type = temp_interaction_type
self.length = temp_length

self.index = r_packet.index
Expand All @@ -509,6 +516,7 @@ def track(self, r_packet):
self.mu[self.interact_id] = r_packet.mu
self.energy[self.interact_id] = r_packet.energy
self.shell_id[self.interact_id] = r_packet.current_shell_id
self.interaction_type[self.interact_id] = r_packet.last_interaction_type
self.interact_id += 1

def finalize_array(self):
Expand All @@ -518,6 +526,7 @@ def finalize_array(self):
self.mu = self.mu[: self.interact_id]
self.energy = self.energy[: self.interact_id]
self.shell_id = self.shell_id[: self.interact_id]
self.interaction_type = self.interaction_type[: self.interact_id]


base_estimators_spec = [
Expand Down
3 changes: 2 additions & 1 deletion tardis/montecarlo/montecarlo_numba/r_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def rpacket_trackers_to_dataframe(rpacket_trackers):
Returns
-------
pandas.core.frame.DataFrame
Dataframe containing properties of RPackets as columns like status, seed, r, nu, mu, energy, shell_id
Dataframe containing properties of RPackets as columns like status, seed, r, nu, mu, energy, shell_id, interaction_type
"""
len_df = sum([len(tracker.r) for tracker in rpacket_trackers])
Expand All @@ -123,6 +123,7 @@ def rpacket_trackers_to_dataframe(rpacket_trackers):
("mu", np.float64),
("energy", np.float64),
("shell_id", np.int64),
("interaction_type", np.int64),
]
)
rpacket_tracker_ndarray = np.empty(len_df, df_dtypes)
Expand Down
16 changes: 14 additions & 2 deletions tardis/montecarlo/montecarlo_numba/tests/test_r_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,22 @@ def test_rpacket_trackers_to_dataframe(simulation_rpacket_tracking_enabled):
# check df shape and column names
assert rtracker_df.shape == (
sum([len(tracker.r) for tracker in sim.runner.rpacket_tracker]),
7,
8,
)
npt.assert_array_equal(
sim.runner.rpacket_tracker_df.columns.values,
np.array(["status", "seed", "r", "nu", "mu", "energy", "shell_id"]),
np.array(
[
"status",
"seed",
"r",
"nu",
"mu",
"energy",
"shell_id",
"interaction_type",
]
),
)

# check all data with rpacket_tracker
Expand All @@ -59,6 +70,7 @@ def test_rpacket_trackers_to_dataframe(simulation_rpacket_tracking_enabled):
rpacket.mu[rpacket_step_no],
rpacket.energy[rpacket_step_no],
rpacket.shell_id[rpacket_step_no],
rpacket.interaction_type[rpacket_step_no],
]
)
npt.assert_array_equal(rtracker_df.to_numpy(), np.array(expected_rtrackers))

0 comments on commit 208cb92

Please sign in to comment.