Skip to content
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

Move and Rename SDECData to VisualizationData #2928

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7d914fe
Rename sdecdata class to SimulationPacketData and shift it outside of…
KasukabeDefenceForce Jan 7, 2025
0116ae5
Update simulation packet data imports in sdec plot
KasukabeDefenceForce Jan 7, 2025
7246dad
Fix import from simulation packet data class
KasukabeDefenceForce Jan 7, 2025
41bc461
Function to create a dictionary containing virtual and real packet data
KasukabeDefenceForce Jan 7, 2025
a2be3fe
Update sdec plotter doc string
KasukabeDefenceForce Jan 7, 2025
77e045a
Replace sdecdata with new simulationpacketdata
KasukabeDefenceForce Jan 7, 2025
b0b9398
Reducing duplicate spectrum
KasukabeDefenceForce Jan 7, 2025
0e6eecf
Remove unnecessary else statements
KasukabeDefenceForce Jan 7, 2025
e7a4388
simplify vpacket_tracker access in SimulationPacketData in virtual mode
KasukabeDefenceForce Jan 7, 2025
2fcb4ac
Add create_packet_data_dict_from_hdf utility function
KasukabeDefenceForce Jan 7, 2025
9cf946f
Implement create_packet_data_dict_from_hdf in sdec and liv plot classes
KasukabeDefenceForce Jan 7, 2025
903f3e5
Update util function name for clarity
KasukabeDefenceForce Jan 7, 2025
821748a
Shift create packet data dict functions to plot_util.py
KasukabeDefenceForce Jan 7, 2025
480d9a4
Update imports from plot_util.py
KasukabeDefenceForce Jan 7, 2025
2c583b0
Remove unwanted if statements from from_hdf method
KasukabeDefenceForce Jan 7, 2025
33aa8af
Simplify paths to hdf files of different properties
KasukabeDefenceForce Jan 7, 2025
1a7684a
Add else statement to improve readability
KasukabeDefenceForce Jan 7, 2025
447d557
Rename simulation packet data to VisualizationData
KasukabeDefenceForce Jan 7, 2025
1db357e
Fix import error
KasukabeDefenceForce Jan 7, 2025
9b996fb
Shift time_explosion and velocity to visualization data class
KasukabeDefenceForce Jan 7, 2025
b499edf
Calculating velocity in init method
KasukabeDefenceForce Jan 7, 2025
24fb361
Calculate velocity if not given as input
KasukabeDefenceForce Jan 7, 2025
4d31d07
Calculate velocity if not specified in sim object
KasukabeDefenceForce Jan 7, 2025
b71e734
Update docstring
KasukabeDefenceForce Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tardis/visualization/plot_util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"""Utility functions to be used in plotting."""

import re

import numpy as np

from tardis.visualization.tools.simulation_packet_data import (
SimulationPacketData,
)


def axis_label_in_latex(label_text, unit, only_text=True):
"""
Expand Down Expand Up @@ -79,3 +84,63 @@
"""
color_tuple_255 = tuple([int(x * 255) for x in color_tuple[:3]])
return f"rgb{color_tuple_255}"

def create_packet_data_dict_from_simulation(sim):
"""
Create a dictionary containing virtual and real packet data based on simulation state.

Parameters
----------
sim : tardis.simulation.Simulation
TARDIS Simulation object produced by running a simulation

Returns
-------
dict
Dictionary containing 'virtual' and 'real' SimulationPacketData instances
"""
packet_data = {
"real": SimulationPacketData.from_simulation(sim, "real")
}
if sim.transport.transport_state.virt_logging:
packet_data["virtual"] = SimulationPacketData.from_simulation(sim, "virtual")
else:
packet_data["virtual"] = None

Check warning on line 108 in tardis/visualization/plot_util.py

View check run for this annotation

Codecov / codecov/patch

tardis/visualization/plot_util.py#L108

Added line #L108 was not covered by tests

return packet_data

def create_packet_data_dict_from_hdf(hdf_fpath, packets_mode=None):
"""
Create a dictionary containing virtual and real packet data from HDF file.

Parameters
----------
hdf_fpath : str
Valid path to the HDF file where simulation is saved
packets_mode : {'virtual', 'real', None}
Mode of packets to be considered. If None, both modes are returned.

Returns
-------
dict
Dictionary containing 'virtual' and 'real' SimulationPacketData instances
"""
if packets_mode not in [None, "virtual", "real"]:
raise ValueError(

Check warning on line 129 in tardis/visualization/plot_util.py

View check run for this annotation

Codecov / codecov/patch

tardis/visualization/plot_util.py#L128-L129

Added lines #L128 - L129 were not covered by tests
"Invalid value passed to packets_mode. Only "
"allowed values are 'virtual', 'real' or None"
)
if packets_mode == "virtual":
return {

Check warning on line 134 in tardis/visualization/plot_util.py

View check run for this annotation

Codecov / codecov/patch

tardis/visualization/plot_util.py#L133-L134

Added lines #L133 - L134 were not covered by tests
"virtual": SimulationPacketData.from_hdf(hdf_fpath, "virtual"),
"real": None
}
if packets_mode == "real":
return {

Check warning on line 139 in tardis/visualization/plot_util.py

View check run for this annotation

Codecov / codecov/patch

tardis/visualization/plot_util.py#L138-L139

Added lines #L138 - L139 were not covered by tests
"virtual": None,
"real": SimulationPacketData.from_hdf(hdf_fpath, "real")
}
return {

Check warning on line 143 in tardis/visualization/plot_util.py

View check run for this annotation

Codecov / codecov/patch

tardis/visualization/plot_util.py#L143

Added line #L143 was not covered by tests
"virtual": SimulationPacketData.from_hdf(hdf_fpath, "virtual"),
"real": SimulationPacketData.from_hdf(hdf_fpath, "real")
}
29 changes: 11 additions & 18 deletions tardis/visualization/tools/liv_plot.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import logging
import matplotlib.pyplot as plt

import astropy.units as u
import matplotlib.cm as cm
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import astropy.units as u
import plotly.graph_objects as go

import tardis.visualization.tools.sdec_plot as sdec
from tardis.util.base import (
atomic_number2element_symbol,
int_to_roman,
)
import tardis.visualization.tools.sdec_plot as sdec
from tardis.visualization import plot_util as pu

logger = logging.getLogger(__name__)
Expand All @@ -37,7 +38,6 @@
velocity : astropy.units.Quantity
Velocity array from the simulation.
"""

self.data = data
self.time_explosion = time_explosion
self.velocity = velocity
Expand All @@ -57,12 +57,8 @@
-------
LIVPlotter
"""

return cls(
dict(
virtual=sdec.SDECData.from_simulation(sim, "virtual"),
real=sdec.SDECData.from_simulation(sim, "real"),
),
pu.create_packet_data_dict_from_simulation(sim),
sim.plasma.time_explosion,
sim.simulation_state.velocity,
)
Expand Down Expand Up @@ -90,14 +86,11 @@
velocity = pd.concat(
[v_inner, pd.Series([v_outer.iloc[-1]])], ignore_index=True
).tolist() * (u.cm / u.s)
return cls(
dict(
virtual=sdec.SDECData.from_hdf(hdf_fpath, "virtual"),
real=sdec.SDECData.from_hdf(hdf_fpath, "real"),
),
time_explosion,
velocity,
)
return cls(

Check warning on line 89 in tardis/visualization/tools/liv_plot.py

View check run for this annotation

Codecov / codecov/patch

tardis/visualization/tools/liv_plot.py#L89

Added line #L89 was not covered by tests
pu.create_packet_data_dict_from_hdf(hdf_fpath),
time_explosion,
velocity,
)

def _parse_species_list(self, species_list, packets_mode, nelements=None):
"""
Expand Down
Loading
Loading