Description

class src.GenData(pulsar_animator: PulsarAnimator)

Bases: object

This class create a simulation instance for the pulsar and generates the data upon calling. Things to note: is that the earth’s direction in the pulsar referrence frame is always the same as the magnetic axis given that the scale_direction_randomness is set to 0. If not then a random direction is generated from a gaussian distribution of vector points centered around the magnetic axis.

generate_payload_at_aquisition_frequency(payload_raw: Payload)
generate_random_direction(scale_direction_randomness: float = 0.5)

Generates a random direction away from the magnetic axis defined by the scale_direction_randomness parameter. If set to 0, the direction will be the same as the magnetic axis.

Parameters:

scale_direction_randomness (float, optional) – _description_. Defaults to 0.5.

Returns:

direction of the new magnetic axis

Return type:

np.ndarray

generate_random_ism_obj()

Generates a random interstellar medium object

Returns:

Returns an instance of the InterstellarMedium class with randomized attributes

Return type:

InterstellarMedium

generate_random_spark_pattern(num_cones: int, avg_spark_dimension: float, avg_spark_per_cone_length: float, avg_spark_pattern_center_tilt: float, avg_drift_vel: float)

Generates a random spark pattern The spark pattern is generated by creating a list of spark patterns and then creating a list of spark spectrum models

Parameters:
  • num_cones (int) – number of cones

  • avg_spark_dimension (float) – Average spark dimension in radians

  • avg_spark_per_cone_length (float) – Average number of sparks per conal circumference

  • avg_spark_pattern_center_tilt (float) – tilt of the spark pattern center from the rotation axis in degrees

  • avg_drift_vel (float) – average drift velocity of the spark pattern

Returns:

tuple of spark pattern list and spark spectrum model list

Return type:

tuple(list,list)

plot(freq_channels: list[float] = None, rot_phases: list[float] = 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.

randomize_existing_spark_pattern()

Randomizes the existing spark pattern

randomize_existing_spark_pattern_centers()

Randomizes the spark centers of the existing spark pattern

randomize_existing_spark_pattern_conal_latitudes()

Randomizes the conal latitudes of the existing spark pattern

randomize_existing_spark_pattern_drift_vels()

Randomizes the drift velocities of the existing spark pattern

randomize_existing_spark_pattern_rot_axis()

Randomizes the rotation axis of the existing spark pattern

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

Bases: object

This class is used to store radio packet data.

add_description(description: dict)

This function adds a description to the payload. The description is a dictionary with the keys ‘Pulsar’, ‘NBRFI’, ‘BBRFI’. The values of the dictionary are the descriptions of the pulsar, NBRFI and BBRFI respectively.

Parameters:

description (dict) – dictionary with the keys ‘Pulsar’, ‘NBRFI’, ‘BBRFI’. The values of the dictionary are the number of the pulsar, NBRFI and BBRFI respectively.

add_flux(radio_packet: list[list[float]])

This function adds the flux to the dataframe. The flux is a list of lists, where each list is a row of the dataframe. The first element of the list is the flux and the second element is the frequency. The function checks if the frequencies of the radio packet match the frequencies of the payload. If they do, it adds the flux to the dataframe. If they don’t, it raises an error.

Parameters:

radio_packet (list[list[float]]) – list of lists, where each list is a row of the dataframe. The first element of the list is the flux and the second element is the frequency.

assign_bandwidths_to_freqchannels(bandwidths: list[float])

This function assigns bandwidths to the freqs

Parameters:

bandwidths (list[float]) – list of bandwidths.

Note

The bandwidths are assigned to the frequencies in the same order as the frequencies. The bandwidths list length must match the length of the frequencies.

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 src.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 src.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

add_spark(spark_gen: ~src.pulsar_simulation.spark_pattern_generator.SparkPatternGenerator, spark_spectrum_model: ~src.pulsar_simulation.spark_pattern_generator.SparkSpectralModel = <src.pulsar_simulation.spark_pattern_generator.SparkSpectralModel object>)

This method adds a spark at the pulsar surface

Parameters:
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)

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 perpendicular plane

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

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]

update_pulsar_state_vectors(rot_phase: float)

This function calculates the state vectors of the pulsar

Parameters:

rot_phase (float) – rotation phase in degrees

class src.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, spark_flux_powers: list[float] = 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/phase 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 src.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

src.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)

src.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.

src.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.

src.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.

src.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.

src.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