ratansunpy.utils package

Submodules

ratansunpy.utils.utils module

ratansunpy.utils.utils.SunSolidAngle(R: float) float[source]

Calculate the solid angle subtended by the Sun as seen from Earth.

Parameters:

R (float) – Radius of the Sun’s disc in arcseconds.

Returns:

Solid angle in degrees.

Return type:

float

Example:

>>> SunSolidAngle(960)
6.805218475785968e-05
ratansunpy.utils.utils.bwhm_to_sigma(bwhm: float) float[source]

Convert beam width at half maximum (BWHM) to the standard deviation (sigma).

Parameters:

bwhm (float) – Beam width at half maximum.

Returns:

Corresponding standard deviation (sigma).

Return type:

float

Example:

>>> bwhm_to_sigma(2.355) 
0.7071608181730225
ratansunpy.utils.utils.calculate_area(image: ndarray) float[source]

Calculate the area under a 1D curve or a 2D surface.

Parameters:

image (numpy.ndarray) – Array representing the image or curve.

Returns:

The calculated area.

Return type:

float

Example:

>>> calculate_area(np.ones(100))
99.0
ratansunpy.utils.utils.clipped_zoom(img, zoom_factor, **kwargs)[source]
ratansunpy.utils.utils.create_rectangle(size: int, width: float, height: float) ndarray[source]

Create a 2D rectangle of the given width and height within a square array.

Parameters:
  • size (int) – Size of the square array (size x size).

  • width (float) – Width of the rectangle.

  • height (float) – Height of the rectangle.

Returns:

2D array with the rectangle.

Return type:

numpy.ndarray

Example:

>>> create_rectangle(100, 50, 20).shape
(100, 100)
ratansunpy.utils.utils.create_sun_model(size: int, radius: float) ndarray[source]

Create a 2D circular model representing the Sun’s disc.

Parameters:
  • size (int) – Size of the square array (size x size).

  • radius (int) – Radius of the Sun’s disc in pixels.

Returns:

2D array with the circular Sun model.

Return type:

numpy.ndarray

Example:

>>> create_sun_model(100, 20).shape
(100, 100)
ratansunpy.utils.utils.error(scale_factor: float, experimental_data: ndarray, theoretical_data: ndarray) float[source]

Calculate the squared error between experimental and theoretical data.

Parameters:
  • scale_factor (float) – Scaling factor applied to experimental data.

  • experimental_data (numpy.ndarray) – Array of experimental data values.

  • theoretical_data (numpy.ndarray) – Array of theoretical data values.

Returns:

The squared error.

Return type:

float

Example:

>>> error(1, np.ones(100), np.zeros(100)) 
100.0
ratansunpy.utils.utils.flip_and_concat(values: ndarray, flip_values: bool = False) ndarray[source]

Flip and concatenate an array.

Parameters:
  • values (numpy.ndarray) – Array of values to be flipped and concatenated.

  • flip_values (bool) – If True, flips the sign of the flipped values.

Returns:

Concatenated array.

Return type:

numpy.ndarray

Example:

>>> flip_and_concat(np.array([1, 2, 3]), True)
array([-3, -2,  1,  2,  3])
ratansunpy.utils.utils.gauss1d(x: ndarray, amplitude: float, mean: float, sigma: float) ndarray[source]

Generate a 1D Gaussian distribution.

Parameters:
  • x (numpy.ndarray) – Array of x coordinates.

  • amplitude (float) – Amplitude of the Gaussian.

  • mean (float) – Mean of the Gaussian.

  • sigma (float) – Standard deviation of the Gaussian.

Returns:

1D Gaussian array.

Return type:

numpy.ndarray

Example:

>>> x = np.linspace(-1, 1, 100)
>>> gauss1d(x, 1, 0, 0.1).shape
(100,)
ratansunpy.utils.utils.gauss2d(x: ndarray | list, y: ndarray | list, amplitude_x: float, amplitude_y: float, mean_x: float, mean_y: float, sigma_x: float, sigma_y: float) ndarray[source]

Generate a 2D Gaussian distribution.

Parameters:
  • x (numpy.ndarray or list of floats) – Array of x coordinates.

  • y (numpy.ndarray or list of floats) – Array of y coordinates.

  • amplitude_x (float) – Amplitude along the x-axis.

  • amplitude_y (float) – Amplitude along the y-axis.

  • mean_x (float) – Mean of the Gaussian along the x-axis.

  • mean_y (float) – Mean of the Gaussian along the y-axis.

  • sigma_x (float) – Standard deviation along the x-axis.

  • sigma_y (float) – Standard deviation along the y-axis.

Returns:

2D Gaussian array.

Return type:

numpy.ndarray

Example:

>>> x = np.linspace(-1, 1, 100)
>>> y = np.linspace(-1, 1, 100)
>>> gauss2d(x, y, 1, 1, 0, 0, 0.1, 0.1).shape
(100, 100)
ratansunpy.utils.utils.gaussian_mixture(params: list[float], x: ndarray, y: ndarray) ndarray[source]

Model data as a mixture of 1D Gaussians and return the residuals.

Parameters:
  • params (list of floats) – List of Gaussian parameters [amplitude, mean, sigma, amplitude, mean, sigma, ….].

  • x (numpy.ndarray) – Array of x coordinates.

  • y (numpy.ndarray) – Array of observed data values.

Returns:

Residuals between the model and the observed data.

Return type:

numpy.ndarray

Example:

>>> params = [1, 0, 0.1, 0.5, 0.5, 0.1]
>>> x = np.linspace(-1, 1, 100)
>>> y = np.ones(100)
>>> gaussian_mixture(params, x, y).shape
(100,)
ratansunpy.utils.utils.get_project_root() Path[source]
ratansunpy.utils.utils.wavelet_denoise(data: ndarray, wavelet, level)[source]

Denoise a signal using wavelet decomposition.

Parameters:
  • data (numpy.ndarray) – Array of data values to be denoised.

  • wavelet (str) – Wavelet type to be used for decomposition.

  • level (int) – Level of decomposition.

Returns:

Denoised data.

Return type:

numpy.ndarray

Example:

>>> data = np.random.normal(0, 1, 100)
>>> wavelet_denoise(data, 'sym6', 2).shape
(100,)

Module contents