dfreproject.utils

Attributes

logger

Functions

get_device()

Utility function to get the currently available PyTorch device.

gradient2d(tensor)

Compute gradients (dy, dx) of a 2D tensor using centered differences.

estimate_memory_per_pixel(→ float)

Estimate memory usage per output pixel in bytes.

calculate_chunk_size(→ Tuple[int, int])

Calculate optimal chunk size based on memory constraints.

process_chunk(→ torch.Tensor)

Process a single chunk of the reprojection.

reproject_chunked(→ torch.Tensor)

Perform chunked reprojection.

Module Contents

dfreproject.utils.logger[source]
dfreproject.utils.get_device()[source]

Utility function to get the currently available PyTorch device.

Returns:

Available torch device (either cuda or cpu).

Return type:

torch.device

dfreproject.utils.gradient2d(tensor)[source]

Compute gradients (dy, dx) of a 2D tensor using centered differences.

dfreproject.utils.estimate_memory_per_pixel(reproject_instance, interpolation_mode: str) float[source]

Estimate memory usage per output pixel in bytes.

Parameters:
  • reproject_instance (Reproject) – An initialized Reproject instance.

  • interpolation_mode (str) – Interpolation mode being used.

Returns:

Estimated bytes per pixel.

Return type:

float

dfreproject.utils.calculate_chunk_size(reproject_instance, output_shape: Tuple[int, int], max_memory_mb: float, safety_factor: float, interpolation_mode: str = 'bilinear') Tuple[int, int][source]

Calculate optimal chunk size based on memory constraints.

Parameters:
  • reproject_instance (Reproject) – An initialized Reproject instance.

  • output_shape (Tuple[int, int]) – Shape of the output image (H, W).

  • max_memory_mb (float) – Maximum memory to use in megabytes.

  • safety_factor (float) – Safety factor (0-1) for memory calculation.

  • interpolation_mode (str) – Interpolation mode to use.

Returns:

Chunk size (chunk_height, chunk_width).

Return type:

Tuple[int, int]

dfreproject.utils.process_chunk(reproject_instance, y_start: int, y_end: int, x_start: int, x_end: int, interpolation_mode: str = 'bilinear') torch.Tensor[source]

Process a single chunk of the reprojection.

Parameters:
  • reproject_instance (Reproject) – An initialized Reproject instance.

  • y_start (int) – Y-axis range for the chunk.

  • y_end (int) – Y-axis range for the chunk.

  • x_start (int) – X-axis range for the chunk.

  • x_end (int) – X-axis range for the chunk.

  • interpolation_mode (str) – Interpolation mode.

Returns:

Reprojected chunk.

Return type:

torch.Tensor

dfreproject.utils.reproject_chunked(reproject_instance, max_memory_mb: float, safety_factor: float, interpolation_mode: str = 'bilinear', show_progress: bool = True) torch.Tensor[source]

Perform chunked reprojection.

Parameters:
  • reproject_instance (Reproject) – An initialized Reproject instance.

  • max_memory_mb (float) – Maximum memory to use in megabytes.

  • safety_factor (float) – Safety factor for memory calculation.

  • interpolation_mode (str) – Interpolation mode to use.

  • show_progress (bool) – Whether to log progress information.

Returns:

Full reprojected image.

Return type:

torch.Tensor