src.pulsarsa.tools package

Subpackages

Submodules

src.pulsarsa.tools.example_neural_nets module

class src.pulsarsa.tools.example_neural_nets.ImageToMaskNetv0(features: list[int] = [32, 16, 16, 32, 1], kernel_sizes: list[int] = [5, 3, 3, 5, 3])

Bases: Module

This is a simple cnn consisting of layers of 2D convolutions with different kernel sizes.

Parameters:

nn (_type_) – _description_

static cnn_slice(name: str, in_channels: int, num_kernels: int, kernel_size: int)
class src.pulsarsa.tools.example_neural_nets.ImageToMaskNetv1(kernel_zero_size: int = 9, num_kernels=8)

Bases: Module

A simple cnn consisting of parallel blocks of 2D convolutions with different kernel sizes. The kernel sizes are odd and increase in size as we go deeper into the network. The number of kernels is constant

parallel_method(x, name: str)
initialize_parallel_block_elements(name: str, in_channels: int, num_kernels: int, kernel__small_size: int, kernel_large_size: int)
static single_block(name: str, in_channels: int, num_kernels: int, kernel_size: int)
class src.pulsarsa.tools.example_neural_nets.ImageToMaskNetv2(kernel_zero_size: int = 9, num_kernels=8)

Bases: Module

This is a simple cnn consisting of parallel blocks of 2D convolutions with different kernel sizes. The kernel sizes are odd and increase in size as we go deeper into the network. The number of kernels is constant. The cnn uses depthwise separable convolutions. And the normalization is done using instance normalization instead of batch normalization. The activation function is ReLU.

parallel_method(x, name: str)
initialize_parallel_block_elements(name: str, in_channels: int, num_kernels: int, kernel__small_size: int, kernel_large_size: int)
static single_block(name: str, in_channels: int, num_kernels: int, kernel_size: int)
static depthwise_separable_conv(in_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=False)
class src.pulsarsa.tools.example_neural_nets.ImageToMaskNetv3

Bases: Module

This is a simple cnn inspired from UNet architecture. The network consists of an encoder and a decoder. The encoder consists of 2D convolutions with depthwise separable convolutions. The decoder consists of transposed convolutions. The network uses instance normalization instead of batch normalization. The activation function is ReLU. The output is a single channel image with sigmoid activation. The network is designed to take a single channel image as input and output a single channel image. The input image is downsampled by a factor of 2 in the encoder and upsampled by a factor of 2 in the decoder. The network uses skip connections between the encoder and decoder to preserve spatial information. The network is designed to be used for semantic segmentation tasks.

input_block(name: str, num_kernels: int = 9)
encoder_block(name: str, in_channels: int, num_kernels: int = 9)
learnable_decoder_block(name: str, in_channels: int, num_kernels: int = 9)
output_block(name: str, in_channels: int, num_kernels: int = 1)
static depthwise_separable_conv(in_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=False)
class src.pulsarsa.tools.example_neural_nets.ModUNetv2

Bases: Module

forward(x)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class src.pulsarsa.tools.example_neural_nets.ModUNetv3

Bases: Module

forward(x)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Module contents

# sphinx-hide

class src.pulsarsa.tools.NetworkBoard(model: Module, notebook: bool = False, lut_range: tuple[float, float] = (-0.1, 0.1), saved_network_path: str | None = None, plot_module: list[str] = ['conv2d', 'convtranspose2d', 'linear', 'norm2d', 'maxpool2d'], timer_interval: int = 1000, centered_input_node_index: int = 0, object_z_depth: int = 5, object_xy_depth: int = 5, debug_messages: bool = False)

Bases: DrawingBoard

This method is used to visualize the neural network model in 3D using VTK. It creates a 3D representation of the model’s layers and connections, allowing for interactive exploration of the network architecture. As of version 1.0 release it supports only 2D convolutional networks containing Conv2d, ConvTranspose2d, Linear, BatchNorm2d, InstanceNorm2d, GroupNorm and MaxPool2d layers.

class src.pulsarsa.tools.FilDataSource(data_path: str, metadata_path: str | None = None, position_column: str = 'position', time_window: int = 256, allow_randomness: bool = False)

Bases: object

Data source class to extract dispersion graphs from a .fil file based on provided metadata. If metadata is provided, it extracts pulse positions from the specified column using the __getitem__ method.

get_metadata(key)

Extract metadata information for the position index represented by the key

Parameters:

key (int) – index representing the row of the position column in metadata

Returns:

pandas.core.series.Series – returns the metadata row as a pandas Series

load_data()

Reads the header of fildata. This method is called during initialization.

gen_random_background_at_index(key: int, plot: bool = False)

Generates random background noise based on mean and std deviation of the dispersion graph at the specified index

Parameters:
  • key (int) – index representing the row of the position column in metadata

  • plot (bool, optional) – whether to plot the generated background noise graph. Defaults to False.

Returns:

np.ndarray – generated random background noise graph

extract_a_dispersion_graph(position: int, time_window: int, plot: bool = False)

Extracts the dispersion graph at position in the filterbank file

Parameters:
  • position (int) – position representing the timebin of the filterbank file

  • time_window (int) – width of the time window to extract

  • plot (bool, optional) – whether to plot the extracted dispersion graph. Defaults to False.

Returns:

np.ndarray – extracted dispersion graph

get_num_time_bins()

Calculates the total number of time bins in the filterbank file :returns: int – total number of time bins

get_signal_gaps_from_metadata()

Identifies positions in the metadata where there are large gaps between signals based on the time_window

Raises:

RuntimeError – If metadata is not provided

Returns:

np.ndarray – positions where large gaps are detected