python_interface package

Submodules

python_interface.defines module

class python_interface.defines.Params(InputConstantFunc)

Bases: object

write_to_json_file(filename: str = '..\\params\\constants.json')

python_interface.generate_data_pipeline module

class python_interface.generate_data_pipeline.GenData(pulsar_animator: PulsarAnimator)

Bases: object

This class create a simulation instance for the pulsar and generates the data upon calling

plot(freq_channels: list[float] | None = None, rot_phases: list[float] | None = None, tag: str = '_test_0', signal_time_bin: float = 0.09166666666666666, param_folder: str = './params/runtime/', payload_folder: str = '../params/payloads/', antenna_sensitivity: float = 0.5, prob_nbrfi: float = 0.5, prob_bbrfi: float = 0.5, scale_direction_randomness: float = 0.5, remove_drift_effect: bool = True, randomize: bool = True)

Plot the dispersion graph generated by the __call__ method

Parameters:
  • freq_channels (list[float], optional) – frequency channels. Defaults to None.

  • rot_phases (list[float], optional) – rotation phases. Defaults to None.

  • tag (str, optional) – tag for the data. Defaults to ‘_test_0’.

  • signal_time_bin (float, optional) – time resolution of the signal. Defaults to 33.0/360 ms.

  • param_folder (str, optional) – runtime parameters folder. Defaults to ‘./params/runtime/’.

  • payload_folder (str, optional) – Path to the folder where payloads are stored. Defaults to ‘../params/payloads/’.

  • antenna_sensitivity (float, optional) – antenna sensitivity. Defaults to 0.5.

  • prob_nbrfi (float, optional) – likelihood of NBRFI. Defaults to 0.5.

  • prob_bbrfi (float, optional) – likelihood of BBRFI. Defaults to 0.5.

  • scale_direction_randomness (float, optional) – fluctuation radius of the spark center from the line of sight. Defaults to 0.5.

  • remove_drift_effect (bool, optional) – if True, the drift of subpulse is gone. Defaults to True.

  • randomize (bool, optional) – if True, randomize the spark pattern and ism parameters. Defaults to True.

python_interface.generate_data_pipeline.build_pulsar_animator_from_file(file_path: str, rot_axis: ndarray = array([0, 0, 1]))

Builds a pulsar animator instance from a runtime file

Parameters:
  • file_path (str) – Path to the runtime file

  • rot_axis (np.ndarray, optional) – rotation axis. Defaults to np.array([0, 0, 1]).

Returns:

tuple of PulsarAnimator instance and direction

Return type:

tuple(PulsarAnimator, np.ndarray)

python_interface.generate_data_pipeline.generate_example_payloads_for_training(tag: str = 'example_pdt', num_payloads: int = 10, rot_phases=array([0, 5, 10, ..., 705, 710, 715]), freq_channels=array([0.25, 0.251, 0.252, ..., 0.847, 0.848, 0.849]), antenna_sensitivity: float = 0.5, prob_nbrfi: float = 0.5, prob_bbrfi: float = 0.5, scale_direction_randomness: float = 0.5, remove_drift_effect: bool = True, num_cpus: int = 10, param_folder='./params/runtime/', payload_folder: str = './params/payloads/', reinit_ray: bool = True, tag_index_offset: int = 0, plot_a_example: bool = True, randomize: bool = True)

Generate example payloads for training

Parameters:
  • tag (str, optional) – Tag for the data. Defaults to “example_pdt”.

  • num_payloads (int, optional) – Number of payloads to generate. Defaults to 10.

  • rot_phases (_type_, optional) – Rotation phases. Defaults to np.arange(0, 360 * 2, 5).

  • freq_channels (_type_, optional) – Frequency channels. Defaults to np.arange(0.25, 0.85, 0.001).

  • antenna_sensitivity (float, optional) – Antenna sensitivity. Defaults to 0.5.

  • prob_nbrfi (float, optional) – Likelihood of NBRFI. Defaults to 0.5.

  • prob_bbrfi (float, optional) – Likelihood of BBRFI. Defaults to 0.5.

  • scale_direction_randomness (float, optional) – Fluctuation radius of the spark center from the line of sight. Defaults to 0.5.

  • remove_drift_effect (bool, optional) – If True, the drift of subpulse is gone. Defaults to True.

  • num_cpus (int, optional) – Number of CPUs to use. Defaults to 10.

  • param_folder (str, optional) – Runtime parameters folder. Defaults to “./params/runtime/”.

  • payload_folder (str, optional) – Path to the folder where payloads are stored. Defaults to “./params/payloads/”.

  • reinit_ray (bool, optional) – If True, reinitialize ray. Defaults to True.

  • tag_index_offset (int, optional) – Offset for the tag index. Defaults to 0.

  • plot_a_example (bool, optional) – If True, plot an example. Defaults to True.

  • randomize (bool, optional) – If True, randomize the spark pattern and ism parameters. Defaults to True.

python_interface.generate_data_pipeline.generate_randomized_data_payloads(gendata_obj: GenData, tag: str, num_payloads: int, rot_phases=array([0, 1, 2, ..., 717, 718, 719]), freq_channels=array([0.5, 0.501, 0.502, ..., 1.597, 1.598, 1.599]), antenna_sensitivity: float = 0.5, prob_nbrfi: float = 0.5, prob_bbrfi: float = 0.5, scale_direction_randomness: float = 0.5, remove_drift_effect: bool = True, num_cpus: int = 10, param_folder='./params/runtime/', payload_folder: str = '../params/payloads/', reinit_ray: bool = True, tag_index_offset: int = 0, randomize: bool = True)

Generate randomized data payloads using the GenData class

Parameters:
  • gendata_obj (GenData) – Instance of the GenData class

  • tag (str) – tag for the data

  • num_payloads (int) – number of payloads to generate

  • rot_phases (list[float], optional) – rotation phases. Defaults to np.arange(0, 720 * 1, 1).

  • freq_channels (list[float], optional) – frequency channels. Defaults to np.arange(0.5, 1.6, 0.001).

  • antenna_sensitivity (float, optional) – antenna sensitivity. Defaults to 0.5.

  • prob_nbrfi (float, optional) – likelihood of NBRFI. Defaults to 0.5.

  • prob_bbrfi (float, optional) – likelihood of BBRFI. Defaults to 0.5.

  • scale_direction_randomness (float, optional) – fluctuation radius of the spark center from the line of sight. Defaults to 0.5.

  • remove_drift_effect (bool, optional) – if True, the drift of subpulse is gone. Defaults to True.

  • num_cpus (int, optional) – number of CPUs to use. Defaults to 10.

  • param_folder (str, optional) – runtime parameters folder. Defaults to “./params/runtime/”.

  • payload_folder (str, optional) – Path to the folder where payloads are stored. Defaults to “../params/payloads/”.

  • reinit_ray (bool, optional) – if True, reinitialize ray. Defaults to True.

  • tag_index_offset (int, optional) – offset for the tag index. Defaults to 0.

  • randomize (bool, optional) – if True, randomize the spark pattern and ism parameters. Defaults to True.

python_interface.generate_data_pipeline.make_spark_patterns_from_file(file_path: str, shift_spark_center_phase: bool = False)
python_interface.generate_data_pipeline.read_params_from_file(file_path: str)
python_interface.generate_data_pipeline.run_gen_data_in_parallel(gendata_obj: GenData, tag_list: list[str], rot_phases=array([0, 1, 2, ..., 717, 718, 719]), freq_channels=array([0.5, 0.501, 0.502, ..., 1.597, 1.598, 1.599]), antenna_sensitivity: float = 0.5, prob_nbrfi: float = 0.5, prob_bbrfi: float = 0.5, scale_direction_randomness: float = 0.5, num_cpus: int = 10, return_execution_time: bool = True, reinit_ray: bool = True, remove_drift_effect: bool = True, param_folder='./params/runtime/', payload_folder: str = '../params/payloads/', randomize: bool = True)

Run the GenData class instance in parallel

Parameters:
  • gendata_obj (GenData) – Instance of the GenData class

  • tag_list (list[str]) – List of tags for the data

  • rot_phases (_type_, optional) – Rotation phases. Defaults to np.arange(0, 720 * 1, 1).

  • freq_channels (_type_, optional) – Frequency channels. Defaults to np.arange(0.5, 1.6, 0.001).

  • antenna_sensitivity (float, optional) – Antenna sensitivity. Defaults to 0.5.

  • prob_nbrfi (float, optional) – Likelihood of NBRFI. Defaults to 0.5.

  • prob_bbrfi (float, optional) – Likelihood of BBRFI. Defaults to 0.5.

  • scale_direction_randomness (float, optional) – Fluctuation radius of the spark center from the line of sight. Defaults to 0.5.

  • num_cpus (int, optional) – Number of CPUs to use. Defaults to 10.

  • return_execution_time (bool, optional) – If True, return the execution time. Defaults to True.

  • reinit_ray (bool, optional) – If True, reinitialize ray. Defaults to True.

  • remove_drift_effect (bool, optional) – If True, the drift of subpulse is gone. Defaults to True.

  • param_folder (str, optional) – Runtime parameters folder. Defaults to “./params/runtime/”.

  • payload_folder (str, optional) – Path to the folder where payloads are stored. Defaults to “../params/payloads/”.

  • randomize (bool, optional) – If True, randomize the spark pattern and ism parameters. Defaults to True.

Returns:

Execution time if return_execution_time is True, else None

Return type:

float

python_interface.information_packet_formats module

class python_interface.information_packet_formats.Payload(freqs: list[float], bandwidths: list[float] | None = None)

Bases: object

This class is used to create a payload for the simulation. The payload is a dictionary that contains the following keys representing the data generated by the simulation: - freqs: list of frequencies - dataframe: list of flux values for each frequency - bandwidths: list of bandwidths for each frequency - description: dictionary containing the description of the payload

add_description(description: dict)
add_flux(radio_packet: list[list[float]])
assign_bandwidths_to_freqchannels(bandwidths: list[float])
assign_rot_phases(rot_phases: list[float])
plot(type: str = 'img')

Plots the dataframe

Parameters:

type (str, optional) – _description_. Defaults to ‘img’.

Returns:

returns the axes of the plot

Return type:

plt.axes

classmethod read_payload_from_jsonfile(filename: str)

Reads the payload from a json file and returns the Payload object

Parameters:

filename (str) – path to the json file

Returns:

Payload object

Return type:

Payload

return_payload_shape()
write_payload_to_jsonfile(file_name: str)

python_interface.pulsar_animator module

class python_interface.pulsar_animator.PulsarAnimator(rot_axis: list, mag_axis_tilt: float, period: float = 33)

Bases: object

This class animates a pulsar rotator as viewed from Earth. The frame of reference is the Earth’s celestial coordinate system

align_mag_axis_offset_to_spark_rot_axis()
static calculate_flux_amplitude_at_refframe_position(spark_pattern: list[SparkPatternGenerator], cartesian_coor: list, pulsar_rot_frame_basis: list[list], rot_phase: float)

This method calculates the flux at the specified point

Parameters:
  • spark_pattern (list[SparkPatternGenerator]) – List of radio hot spots or sparks

  • cartesian_coor (list) – vector representing the cartesian coordinate

  • pulsar_rot_frame_basis (list[list]) – pulsars static frame basis vectors where the pulsar’s rotation axis is alligned to the z axis

  • rot_phase (float) – rotation phase in degrees

Returns:

flux magnitude

Return type:

float

static calculate_radio_packet_at_direction(spark_patterns: list[SparkPatternGenerator], direction: list[float], pulsar_rot_frame_basis: list[list], rot_phase: float)

This method calculates a radio packet at a particular direction

Parameters:
  • spark_patterns (list[SparkPatternGenerator]) – List of radio hot spots or sparks

  • direction (list[float]) – vector representing the direction at which the packet is emitted

  • pulsar_rot_frame_basis (list[list]) – pulsars static frame basis vectors where the pulsar’s rotation axis is alligned to the z axis

  • rot_phase (float) – rotation phase in degrees

Returns:

radio packet as tuple containing list of flux values and corresponding center frequencies of the sparks

Return type:

(list,list)

generate_radio_packet(rot_phase: float, direction: list[float])

This method generates a tuple lists of radio flux values and the corresponding center frequencies of the sparks

Parameters:
  • rot_phase (float) – The rotation phase of the pulsar in degrees

  • direction (list[float]) – a vector specifying the line of sight towards Earth

Returns:

radio packet as tuple containing list of flux values and corresponding center frequencies of the sparks

Return type:

tuple[list,list]

generate_radio_packet_stream(rot_phases: list[float], direction: list[float])

This method calculates radio packets at a particular direction for the list of rotation phases

Parameters:
  • rot_phases (list[float]) – list of rotation phases in degrees

  • direction (list[float]) – vector representing the direction at which the packet is emitted

Returns:

payload object representing the radi data stream

Return type:

Payload

get_mag_axis_tilt()
get_rot_axis()
render_radiation_hotspots_on_surface(rot_phase: float, points: list[list])

This method renders the radio intensity profile throughout the sphere describing the pulsar surface

Parameters:
  • rot_phase (float) – rotation phase of the pulsar in degrees

  • points (list[list]) – interesting points on the surface to render the radio intensity

Returns:

rendered radio intensities

Return type:

list[float]

python_interface.pulsar_plotter module

class python_interface.pulsar_plotter.DrawTools

Bases: object

static draw_a_circle(res: int, radius: float = 1, center: tuple = (1, 0, 0), axis: tuple = (0, 0, 1), rotate: float = 0)
static draw_arrow(start=[0, 0, 0], direction=[1, 2, 3], length: float = 3, color: tuple = (0, 0, 1), arrow_props: tuple = (0.01, 0.03, 0.1))
static draw_circle_along_axis(res: int, radius: float = 1, center: tuple = (1, 0, 0), axis: tuple = (0, 0, 1), color: tuple = (0, 0, 1))
static draw_circles(res: int, radius: float = 1, axis: tuple = (0, 0, 1), color: tuple = (0, 0, 1))
draw_fixed_line(point2, color)
static draw_sphere_actor(res: int, position: tuple = (0.0, 0.0, 0.0), radius: float = 1, cmap=<matplotlib.colors.LinearSegmentedColormap object>)
static get_points_from_actor(actor: vtkActor)
static render_sphere_with_func(sphere_actor: vtkActor, render_method: Callable)
static rotate_actor_around_axis(actor: vtkActor, axis: tuple, angle: float)
class python_interface.pulsar_plotter.PlotPulsar3D(pulsar_animator: PulsarAnimator, telescope_position: tuple = (0, 50, 0), rot_phases: list = array([0, 10, 20, ..., 330, 340, 350]), res: int = 50, output_anim_folder: str = './output/')

Bases: object

This class is used to visualize the pulsar state in 3D using VTK. It allows for the creation of an interactive window where the user can rotate the pulsar and view its state from different angles. The class also provides methods to create frames for animation and capture frames for later use. The instance of the class can be called to start the visualization process.

add_actors(actors_list: list[vtkActor])
add_permanent_actors()
static build_pulsar_actors(pulsar_animator: PulsarAnimator, rot_phase: float = 0, res: int = 80)
capture_frame()
capture_frame_for_anim(path: str = './output/anims/', tag: str = 'test')
create_frame_for_notebook()
create_frames_for_animation(path: str = './output/anims/', tag: str = 'test', res: int = 50)
on_key_press(obj, event)
on_key_press_canvas(key, *args)
plot_method(rot_phase: float = 0, res: int = 50)
remove_actors(actors: list[vtkActor])
set_camera_as_telescope()
setup_stage()
vtk_render_to_numpy()
python_interface.pulsar_plotter.create_animation_from_runtime_file(runtime_folder_path: str, animation_folder_path: str, filename: str, rot_phases: list = array([0, 10, 20, ..., 330, 340, 350]), res: int = 50)

This function creates a pulsar animation using the provided runtime file and saves the frames to the specified folder. The animation is generated by rotating the pulsar and capturing frames at specified intervals.

Parameters:
  • runtime_folder_path (str) – runtime folder path where the pulsar parameter file is located generated after simulation.

  • animation_folder_path (str) – folder path where the animation frames will be saved.

  • filename (str) – tag used to name the animation files.

  • rot_phases (list, optional) – List of rotation phases for the animation. Defaults to np.arange(0, 360, 10).

  • res (int, optional) – Resolution for the animation of the pulsar surface in latitudes and longitudes. Defaults to 50.

python_interface.pulsar_plotter.create_pulsar_animation(pulsar_animator: PulsarAnimator, animation_folder_path: str, tag: str, rot_phases: list = array([0, 10, 20, ..., 330, 340, 350]), telescope_direction: tuple = (1, 1, 1), res: int = 50)

This function creates a pulsar animation using the provided PulsarAnimator instance and saves the frames to the specified folder. The animation is generated by rotating the pulsar and capturing frames at specified intervals.

Parameters:
  • pulsar_animator (PulsarAnimator) – The PulsarAnimator instance used to generate the animation.

  • animation_folder_path (str) – The folder path where the animation frames will be saved.

  • tag (str) – A tag used to name the animation files.

  • rot_phases (list, optional) – List of rotation phases for the animation. Defaults to np.arange(0, 360, 10).

  • telescope_direction (tuple, optional) – The direction of the telescope. Defaults to (1, 1, 1).

  • res (int, optional) – Resolution for the animation of the pulsar surface in latitudes and longitudes. Defaults to 50.

python_interface.radio_packet_propagation module

class python_interface.radio_packet_propagation.InterstellarMedium(dm_homogeneous: float, scintillation_index_homo: float, std_dm=None, std_scintillation_index=None)

Bases: object

This class deals with the properties and modulation of the radio signals through ISM

calc_disperse_phase_shift(freq: float, freq_ref: float = 1, signal_time_bin: float = 1)

Calculates phase shift due to dispersion

Parameters:
  • freq (float) – frequency of the channel in GHz

  • freq_ref (float, optional) – the reference frequency in GHz. Defaults to 1.

  • signal_time_bin (float, optional) – time bin in millisecond. Defaults to 1.

Returns:

phase shift in degrees

Return type:

float

propagate_through(payload: Payload, signal_time_bin: float, average_over_period: bool = False)

This method propagates the payload along the ISM and returns dispersed payload

Parameters:
  • payload (Payload) – payload near the pulsar surface to be propagated

  • signal_time_bin (float) – time bin in millisecond

  • average_over_period (bool) – If True, the drift of subpulse is gone

Returns:

payload after propagation

Return type:

Payload

randomize_props()

Randomizes properties

python_interface.remote_functions module

python_interface.remote_functions.distribute_arguments_list(num_cpus: int, list_of_args: list)
python_interface.remote_functions.flatten_distributed_returns(distributed_result: list)

python_interface.signal_detection module

class python_interface.signal_detection.antenna(sensitivity: float = 0.1, prob_bbrfi: float = 1, prob_nbrfi: float = 1)

Bases: object

Digital twin of Antenna

python_interface.spark_pattern_generator module

class python_interface.spark_pattern_generator.SparkPatternGenerator(spark_id: int, spark_dimension: float = 0.1, spark_center: list[float, float] = [10, 0], spark_rotation_axis_polar_att0: list[float, float] = [45, 0], drift_vel: float = -0.027777777777777776, drift_phase: float = 0, spark_mid_freq: float = 125, spark_flux_power: float = 1, spark_cone_id: int = 0)

Bases: object

This class creates a function for calculating radio flux from a spark based on its position in the pulsars rotational frame of reference

apply_physics_model(pulsar_rot_frame_basis: list[list], pulsar_rot_phase: float, position: list[float, float, float])

This method should return spark amplitude at time t and position pos in the pulsar rotation frame

Parameters:
  • pulsar_rot_frame_basis (list[list]) – the basis vectors aligned with the rotation axis of the pulsar

  • pulsar_rot_phase (float) – rotation phase in degrees

  • position (list[float, float, float]) – flux emitted by the spark at this position

Returns:

flux

Return type:

float

calculate_magframe_basis_att(pulsar_rot_frame_basis: list[list], pulsar_rot_phase: float)

This method calculates the basis vectors aligned to the magnetic axis of the pulsar

Parameters:
  • pulsar_rot_frame_basis (list[list]) – the basis vectors aligned with the rotation axis of the pulsar

  • pulsar_rot_phase (float) – rotation phase in degrees

Returns:

magnetic frame basis vectors

Return type:

list[list]

calculate_spark_center_att(pulsar_rot_frame_basis: list[list], pulsar_rot_phase: float)

This method calculates the new spark position as it rotates with a drift velocity together with the pulsar’s rotation

Parameters:
  • pulsar_rot_frame_basis (list[list]) – the basis vectors aligned with the rotation axis of the pulsar

  • pulsar_rot_phase (float) – rotation phase in degrees

Returns:

a vector representing the new position of the spark

Return type:

list

classmethod create_patterened_spark_pattern(num_sparks: list[int], conal_latitudes: list[float], spark_rotation_axis_polar_att0: list[float, float] = [45, 0], drift_vel: float = -0.027777777777777776, spark_dimension: float = 0.3, spark_mid_freqs: list[float] | None = None, spark_flux_powers: list[float] | None = None)

This method generates a list of sparks arranged in nested cones

Parameters:
  • num_sparks (list[int]) – list of the number of sparks in each nested cone

  • conal_latitudes (list[float]) – corresponding conal latitudes in degrees

  • spark_rotation_axis_polar_att0 (list[float, float], optional) – The center point or the center axis of all the nested cones from the rotation axis. Defaults to [45, 0].

  • drift_vel (float, optional) – drift velocity of the sparks in degrees travelled per degree of rotation. Defaults to -10/360.

  • spark_dimension (float, optional) – spark size in radians. Defaults to 0.3.

  • spark_mid_freqs (list[float], optional) – corresponding list of mid or center freqs of the nested cones. Defaults to None.

  • spark_flux_powers (list[float], optional) – list of flux per spark in a nested cone. Defaults to None.

Returns:

list of sparks arranged in nested cones

Return type:

list[SparkPatternGenerator]

static find_perpendicular_basis_vectors(vector: list)

Returns basis vector perpendicular to the given vector. The basis directions are calculated by differentiating the phi and theta in polar coordinate system

Parameters:

vector (list) – a 3d vector

Returns:

returns two basis vectors orthogonal to the given vector in the perpendicula plane

Return type:

[list,list]

get_drift_vel()
get_spark_center()
get_spark_dimension()
get_spark_flux()
get_spark_freq()

This method returns the mid-frequency of the spark object

Returns:

mid frquency of the spark

Return type:

float

get_spark_rotation_axis_polar_att0()
randomize()
set_drift_vel(val: float)
set_spark_center(val: float, ind: int)
set_spark_rotation_axis_polar_att0(val: list[float, float])
class python_interface.spark_pattern_generator.SparkSpectralModel(model: int = 0, **kwargs)

Bases: object

This class deals with determining the spectral model of individual sparks

model_0(freq: float, spectral_index: float = -0.47, b: float = 0.21, center_freq: float = 1.3)

Spectral model describing simple power law

Parameters:
  • freq (float) – frequency in GHz

  • spectral_index (float, optional) – spectral index of the power lay or also denoted as alpha. Defaults to -0.47.

  • b (float, optional) – constant. Defaults to 0.21.

  • center_freq (float, optional) – Center frequency or mid frequency used to define the spark in GHz. Defaults to 1.3.

Returns:

Relative amplitude at that given frequency

Return type:

float

model_1(freq: float, curvature_parameter: float = 0, c: float = 1, spectral_index: float = -0.47, center_freq: float = 1.3)

Spectral model describing Log parabolic spectrum or LPS

Parameters:
  • freq (float) – frequency in GHz

  • curvature_parameter (float, optional) – curvature parameter. Defaults to 0.

  • c (float, optional) – offset. Defaults to 1.

  • spectral_index (float, optional) – spectral index for a = 0. Defaults to -0.47.

  • center_freq (float, optional) – Center frequency or mid frequency used to define the spark in GHz. Defaults to 1.3.

Returns:

Relative amplitude at that given frequency

Return type:

float

python_interface.spark_pattern_generator.extract_sparkpattern_parameters_from_sparklist(spark_list: list[SparkPatternGenerator])

This method extracts the spark pattern parameters from the list of spark objects

Parameters:

spark_list (list[SparkPatternGenerator]) – list of spark objects

Returns:

returns a tuple containing the spark group dictionary, number of sparks in each group, conal latitudes, spark rotation axis polar att0, drift velocity, spark dimension in radians, mid frequencies and flux powers

Return type:

tuple

Module contents

class python_interface.GenData(pulsar_animator: PulsarAnimator)

Bases: object

This class create a simulation instance for the pulsar and generates the data upon calling

plot(freq_channels: list[float] | None = None, rot_phases: list[float] | None = None, tag: str = '_test_0', signal_time_bin: float = 0.09166666666666666, param_folder: str = './params/runtime/', payload_folder: str = '../params/payloads/', antenna_sensitivity: float = 0.5, prob_nbrfi: float = 0.5, prob_bbrfi: float = 0.5, scale_direction_randomness: float = 0.5, remove_drift_effect: bool = True, randomize: bool = True)

Plot the dispersion graph generated by the __call__ method

Parameters:
  • freq_channels (list[float], optional) – frequency channels. Defaults to None.

  • rot_phases (list[float], optional) – rotation phases. Defaults to None.

  • tag (str, optional) – tag for the data. Defaults to ‘_test_0’.

  • signal_time_bin (float, optional) – time resolution of the signal. Defaults to 33.0/360 ms.

  • param_folder (str, optional) – runtime parameters folder. Defaults to ‘./params/runtime/’.

  • payload_folder (str, optional) – Path to the folder where payloads are stored. Defaults to ‘../params/payloads/’.

  • antenna_sensitivity (float, optional) – antenna sensitivity. Defaults to 0.5.

  • prob_nbrfi (float, optional) – likelihood of NBRFI. Defaults to 0.5.

  • prob_bbrfi (float, optional) – likelihood of BBRFI. Defaults to 0.5.

  • scale_direction_randomness (float, optional) – fluctuation radius of the spark center from the line of sight. Defaults to 0.5.

  • remove_drift_effect (bool, optional) – if True, the drift of subpulse is gone. Defaults to True.

  • randomize (bool, optional) – if True, randomize the spark pattern and ism parameters. Defaults to True.

class python_interface.Payload(freqs: list[float], bandwidths: list[float] | None = None)

Bases: object

This class is used to create a payload for the simulation. The payload is a dictionary that contains the following keys representing the data generated by the simulation: - freqs: list of frequencies - dataframe: list of flux values for each frequency - bandwidths: list of bandwidths for each frequency - description: dictionary containing the description of the payload

add_description(description: dict)
add_flux(radio_packet: list[list[float]])
assign_bandwidths_to_freqchannels(bandwidths: list[float])
assign_rot_phases(rot_phases: list[float])
plot(type: str = 'img')

Plots the dataframe

Parameters:

type (str, optional) – _description_. Defaults to ‘img’.

Returns:

returns the axes of the plot

Return type:

plt.axes

classmethod read_payload_from_jsonfile(filename: str)

Reads the payload from a json file and returns the Payload object

Parameters:

filename (str) – path to the json file

Returns:

Payload object

Return type:

Payload

return_payload_shape()
write_payload_to_jsonfile(file_name: str)
class python_interface.PlotPulsar3D(pulsar_animator: PulsarAnimator, telescope_position: tuple = (0, 50, 0), rot_phases: list = array([0, 10, 20, ..., 330, 340, 350]), res: int = 50, output_anim_folder: str = './output/')

Bases: object

This class is used to visualize the pulsar state in 3D using VTK. It allows for the creation of an interactive window where the user can rotate the pulsar and view its state from different angles. The class also provides methods to create frames for animation and capture frames for later use. The instance of the class can be called to start the visualization process.

add_actors(actors_list: list[vtkActor])
add_permanent_actors()
static build_pulsar_actors(pulsar_animator: PulsarAnimator, rot_phase: float = 0, res: int = 80)
capture_frame()
capture_frame_for_anim(path: str = './output/anims/', tag: str = 'test')
create_frame_for_notebook()
create_frames_for_animation(path: str = './output/anims/', tag: str = 'test', res: int = 50)
on_key_press(obj, event)
on_key_press_canvas(key, *args)
plot_method(rot_phase: float = 0, res: int = 50)
remove_actors(actors: list[vtkActor])
set_camera_as_telescope()
setup_stage()
vtk_render_to_numpy()
class python_interface.PulsarAnimator(rot_axis: list, mag_axis_tilt: float, period: float = 33)

Bases: object

This class animates a pulsar rotator as viewed from Earth. The frame of reference is the Earth’s celestial coordinate system

align_mag_axis_offset_to_spark_rot_axis()
static calculate_flux_amplitude_at_refframe_position(spark_pattern: list[SparkPatternGenerator], cartesian_coor: list, pulsar_rot_frame_basis: list[list], rot_phase: float)

This method calculates the flux at the specified point

Parameters:
  • spark_pattern (list[SparkPatternGenerator]) – List of radio hot spots or sparks

  • cartesian_coor (list) – vector representing the cartesian coordinate

  • pulsar_rot_frame_basis (list[list]) – pulsars static frame basis vectors where the pulsar’s rotation axis is alligned to the z axis

  • rot_phase (float) – rotation phase in degrees

Returns:

flux magnitude

Return type:

float

static calculate_radio_packet_at_direction(spark_patterns: list[SparkPatternGenerator], direction: list[float], pulsar_rot_frame_basis: list[list], rot_phase: float)

This method calculates a radio packet at a particular direction

Parameters:
  • spark_patterns (list[SparkPatternGenerator]) – List of radio hot spots or sparks

  • direction (list[float]) – vector representing the direction at which the packet is emitted

  • pulsar_rot_frame_basis (list[list]) – pulsars static frame basis vectors where the pulsar’s rotation axis is alligned to the z axis

  • rot_phase (float) – rotation phase in degrees

Returns:

radio packet as tuple containing list of flux values and corresponding center frequencies of the sparks

Return type:

(list,list)

generate_radio_packet(rot_phase: float, direction: list[float])

This method generates a tuple lists of radio flux values and the corresponding center frequencies of the sparks

Parameters:
  • rot_phase (float) – The rotation phase of the pulsar in degrees

  • direction (list[float]) – a vector specifying the line of sight towards Earth

Returns:

radio packet as tuple containing list of flux values and corresponding center frequencies of the sparks

Return type:

tuple[list,list]

generate_radio_packet_stream(rot_phases: list[float], direction: list[float])

This method calculates radio packets at a particular direction for the list of rotation phases

Parameters:
  • rot_phases (list[float]) – list of rotation phases in degrees

  • direction (list[float]) – vector representing the direction at which the packet is emitted

Returns:

payload object representing the radi data stream

Return type:

Payload

get_mag_axis_tilt()
get_rot_axis()
render_radiation_hotspots_on_surface(rot_phase: float, points: list[list])

This method renders the radio intensity profile throughout the sphere describing the pulsar surface

Parameters:
  • rot_phase (float) – rotation phase of the pulsar in degrees

  • points (list[list]) – interesting points on the surface to render the radio intensity

Returns:

rendered radio intensities

Return type:

list[float]

class python_interface.SparkPatternGenerator(spark_id: int, spark_dimension: float = 0.1, spark_center: list[float, float] = [10, 0], spark_rotation_axis_polar_att0: list[float, float] = [45, 0], drift_vel: float = -0.027777777777777776, drift_phase: float = 0, spark_mid_freq: float = 125, spark_flux_power: float = 1, spark_cone_id: int = 0)

Bases: object

This class creates a function for calculating radio flux from a spark based on its position in the pulsars rotational frame of reference

apply_physics_model(pulsar_rot_frame_basis: list[list], pulsar_rot_phase: float, position: list[float, float, float])

This method should return spark amplitude at time t and position pos in the pulsar rotation frame

Parameters:
  • pulsar_rot_frame_basis (list[list]) – the basis vectors aligned with the rotation axis of the pulsar

  • pulsar_rot_phase (float) – rotation phase in degrees

  • position (list[float, float, float]) – flux emitted by the spark at this position

Returns:

flux

Return type:

float

calculate_magframe_basis_att(pulsar_rot_frame_basis: list[list], pulsar_rot_phase: float)

This method calculates the basis vectors aligned to the magnetic axis of the pulsar

Parameters:
  • pulsar_rot_frame_basis (list[list]) – the basis vectors aligned with the rotation axis of the pulsar

  • pulsar_rot_phase (float) – rotation phase in degrees

Returns:

magnetic frame basis vectors

Return type:

list[list]

calculate_spark_center_att(pulsar_rot_frame_basis: list[list], pulsar_rot_phase: float)

This method calculates the new spark position as it rotates with a drift velocity together with the pulsar’s rotation

Parameters:
  • pulsar_rot_frame_basis (list[list]) – the basis vectors aligned with the rotation axis of the pulsar

  • pulsar_rot_phase (float) – rotation phase in degrees

Returns:

a vector representing the new position of the spark

Return type:

list

classmethod create_patterened_spark_pattern(num_sparks: list[int], conal_latitudes: list[float], spark_rotation_axis_polar_att0: list[float, float] = [45, 0], drift_vel: float = -0.027777777777777776, spark_dimension: float = 0.3, spark_mid_freqs: list[float] | None = None, spark_flux_powers: list[float] | None = None)

This method generates a list of sparks arranged in nested cones

Parameters:
  • num_sparks (list[int]) – list of the number of sparks in each nested cone

  • conal_latitudes (list[float]) – corresponding conal latitudes in degrees

  • spark_rotation_axis_polar_att0 (list[float, float], optional) – The center point or the center axis of all the nested cones from the rotation axis. Defaults to [45, 0].

  • drift_vel (float, optional) – drift velocity of the sparks in degrees travelled per degree of rotation. Defaults to -10/360.

  • spark_dimension (float, optional) – spark size in radians. Defaults to 0.3.

  • spark_mid_freqs (list[float], optional) – corresponding list of mid or center freqs of the nested cones. Defaults to None.

  • spark_flux_powers (list[float], optional) – list of flux per spark in a nested cone. Defaults to None.

Returns:

list of sparks arranged in nested cones

Return type:

list[SparkPatternGenerator]

static find_perpendicular_basis_vectors(vector: list)

Returns basis vector perpendicular to the given vector. The basis directions are calculated by differentiating the phi and theta in polar coordinate system

Parameters:

vector (list) – a 3d vector

Returns:

returns two basis vectors orthogonal to the given vector in the perpendicula plane

Return type:

[list,list]

get_drift_vel()
get_spark_center()
get_spark_dimension()
get_spark_flux()
get_spark_freq()

This method returns the mid-frequency of the spark object

Returns:

mid frquency of the spark

Return type:

float

get_spark_rotation_axis_polar_att0()
randomize()
set_drift_vel(val: float)
set_spark_center(val: float, ind: int)
set_spark_rotation_axis_polar_att0(val: list[float, float])
class python_interface.SparkSpectralModel(model: int = 0, **kwargs)

Bases: object

This class deals with determining the spectral model of individual sparks

model_0(freq: float, spectral_index: float = -0.47, b: float = 0.21, center_freq: float = 1.3)

Spectral model describing simple power law

Parameters:
  • freq (float) – frequency in GHz

  • spectral_index (float, optional) – spectral index of the power lay or also denoted as alpha. Defaults to -0.47.

  • b (float, optional) – constant. Defaults to 0.21.

  • center_freq (float, optional) – Center frequency or mid frequency used to define the spark in GHz. Defaults to 1.3.

Returns:

Relative amplitude at that given frequency

Return type:

float

model_1(freq: float, curvature_parameter: float = 0, c: float = 1, spectral_index: float = -0.47, center_freq: float = 1.3)

Spectral model describing Log parabolic spectrum or LPS

Parameters:
  • freq (float) – frequency in GHz

  • curvature_parameter (float, optional) – curvature parameter. Defaults to 0.

  • c (float, optional) – offset. Defaults to 1.

  • spectral_index (float, optional) – spectral index for a = 0. Defaults to -0.47.

  • center_freq (float, optional) – Center frequency or mid frequency used to define the spark in GHz. Defaults to 1.3.

Returns:

Relative amplitude at that given frequency

Return type:

float

python_interface.create_animation_from_runtime_file(runtime_folder_path: str, animation_folder_path: str, filename: str, rot_phases: list = array([0, 10, 20, ..., 330, 340, 350]), res: int = 50)

This function creates a pulsar animation using the provided runtime file and saves the frames to the specified folder. The animation is generated by rotating the pulsar and capturing frames at specified intervals.

Parameters:
  • runtime_folder_path (str) – runtime folder path where the pulsar parameter file is located generated after simulation.

  • animation_folder_path (str) – folder path where the animation frames will be saved.

  • filename (str) – tag used to name the animation files.

  • rot_phases (list, optional) – List of rotation phases for the animation. Defaults to np.arange(0, 360, 10).

  • res (int, optional) – Resolution for the animation of the pulsar surface in latitudes and longitudes. Defaults to 50.

python_interface.create_pulsar_animation(pulsar_animator: PulsarAnimator, animation_folder_path: str, tag: str, rot_phases: list = array([0, 10, 20, ..., 330, 340, 350]), telescope_direction: tuple = (1, 1, 1), res: int = 50)

This function creates a pulsar animation using the provided PulsarAnimator instance and saves the frames to the specified folder. The animation is generated by rotating the pulsar and capturing frames at specified intervals.

Parameters:
  • pulsar_animator (PulsarAnimator) – The PulsarAnimator instance used to generate the animation.

  • animation_folder_path (str) – The folder path where the animation frames will be saved.

  • tag (str) – A tag used to name the animation files.

  • rot_phases (list, optional) – List of rotation phases for the animation. Defaults to np.arange(0, 360, 10).

  • telescope_direction (tuple, optional) – The direction of the telescope. Defaults to (1, 1, 1).

  • res (int, optional) – Resolution for the animation of the pulsar surface in latitudes and longitudes. Defaults to 50.

python_interface.generate_randomized_data_payloads(gendata_obj: GenData, tag: str, num_payloads: int, rot_phases=array([0, 1, 2, ..., 717, 718, 719]), freq_channels=array([0.5, 0.501, 0.502, ..., 1.597, 1.598, 1.599]), antenna_sensitivity: float = 0.5, prob_nbrfi: float = 0.5, prob_bbrfi: float = 0.5, scale_direction_randomness: float = 0.5, remove_drift_effect: bool = True, num_cpus: int = 10, param_folder='./params/runtime/', payload_folder: str = '../params/payloads/', reinit_ray: bool = True, tag_index_offset: int = 0, randomize: bool = True)

Generate randomized data payloads using the GenData class

Parameters:
  • gendata_obj (GenData) – Instance of the GenData class

  • tag (str) – tag for the data

  • num_payloads (int) – number of payloads to generate

  • rot_phases (list[float], optional) – rotation phases. Defaults to np.arange(0, 720 * 1, 1).

  • freq_channels (list[float], optional) – frequency channels. Defaults to np.arange(0.5, 1.6, 0.001).

  • antenna_sensitivity (float, optional) – antenna sensitivity. Defaults to 0.5.

  • prob_nbrfi (float, optional) – likelihood of NBRFI. Defaults to 0.5.

  • prob_bbrfi (float, optional) – likelihood of BBRFI. Defaults to 0.5.

  • scale_direction_randomness (float, optional) – fluctuation radius of the spark center from the line of sight. Defaults to 0.5.

  • remove_drift_effect (bool, optional) – if True, the drift of subpulse is gone. Defaults to True.

  • num_cpus (int, optional) – number of CPUs to use. Defaults to 10.

  • param_folder (str, optional) – runtime parameters folder. Defaults to “./params/runtime/”.

  • payload_folder (str, optional) – Path to the folder where payloads are stored. Defaults to “../params/payloads/”.

  • reinit_ray (bool, optional) – if True, reinitialize ray. Defaults to True.

  • tag_index_offset (int, optional) – offset for the tag index. Defaults to 0.

  • randomize (bool, optional) – if True, randomize the spark pattern and ism parameters. Defaults to True.

python_interface.run_gen_data_in_parallel(gendata_obj: GenData, tag_list: list[str], rot_phases=array([0, 1, 2, ..., 717, 718, 719]), freq_channels=array([0.5, 0.501, 0.502, ..., 1.597, 1.598, 1.599]), antenna_sensitivity: float = 0.5, prob_nbrfi: float = 0.5, prob_bbrfi: float = 0.5, scale_direction_randomness: float = 0.5, num_cpus: int = 10, return_execution_time: bool = True, reinit_ray: bool = True, remove_drift_effect: bool = True, param_folder='./params/runtime/', payload_folder: str = '../params/payloads/', randomize: bool = True)

Run the GenData class instance in parallel

Parameters:
  • gendata_obj (GenData) – Instance of the GenData class

  • tag_list (list[str]) – List of tags for the data

  • rot_phases (_type_, optional) – Rotation phases. Defaults to np.arange(0, 720 * 1, 1).

  • freq_channels (_type_, optional) – Frequency channels. Defaults to np.arange(0.5, 1.6, 0.001).

  • antenna_sensitivity (float, optional) – Antenna sensitivity. Defaults to 0.5.

  • prob_nbrfi (float, optional) – Likelihood of NBRFI. Defaults to 0.5.

  • prob_bbrfi (float, optional) – Likelihood of BBRFI. Defaults to 0.5.

  • scale_direction_randomness (float, optional) – Fluctuation radius of the spark center from the line of sight. Defaults to 0.5.

  • num_cpus (int, optional) – Number of CPUs to use. Defaults to 10.

  • return_execution_time (bool, optional) – If True, return the execution time. Defaults to True.

  • reinit_ray (bool, optional) – If True, reinitialize ray. Defaults to True.

  • remove_drift_effect (bool, optional) – If True, the drift of subpulse is gone. Defaults to True.

  • param_folder (str, optional) – Runtime parameters folder. Defaults to “./params/runtime/”.

  • payload_folder (str, optional) – Path to the folder where payloads are stored. Defaults to “../params/payloads/”.

  • randomize (bool, optional) – If True, randomize the spark pattern and ism parameters. Defaults to True.

Returns:

Execution time if return_execution_time is True, else None

Return type:

float