ratansunpy.client package

Submodules

ratansunpy.client.client module

class ratansunpy.client.client.RATANClient[source]

Bases: BaseClient

Client for processing and analyzing data from the RATAN-600 radio telescope.

RATANClient class is a complex implementation that extends a base client class for handling and processing data related to solar observations using RATAN-600. The class provides a wide range of methods to acquire, process, and analyze solar data from FITS (Flexible Image Transport System) files obtained from a given URL. Here’s an overview of what each method does:

Key Components: 1. Initialization Parameters and Configuration:

  • base_url: URL template to fetch solar data.

  • regex_pattern: A regex pattern to match relevant data files.

  • convolution_template and quiet_sun_model: Loaded from Excel files; these are templates or models of solar data

that will be used in the analysis.

2.Data Acquisition and Filtering:
  • acquire_data: Uses a Scrapper class to form a list of data files for a given

time range, based on URL and regex pattern. - get_scans: Fetches data from acquired file URLs, processes the FITS files to extract relevant information, and returns a table with structured data.

  1. Data Processing and Analysis:

    3.1 Convolution and Efficiency Calculations:

    • convolve_sun: Simulates the convolution of a solar model with Gaussian and rectangular functions, then computes and returns the ratio of areas under these convolved functions.

    • antenna_efficiency: Calculates the antenna efficiency across various frequencies using the convolution data.

    3.2 Calibration:

    • calibrate_QSModel: Calibrates the quiet sun model data against observed scan data, adjusting for flux efficiency and other parameters

    3.3 Positional and Rotational Transformations:
    • heliocentric_transform: Converts solar latitude and longitude into heliocentric coordinates.

    • pozitional_rotation: Rotates positional data based on a given angle.

    • differential_rotation: Calculates the differential rotation rate of the sun based on latitude.

    • pozitional_angle: Computes the positional angle of the sun based on azimuth, solar declination, and solar P-angle.

    3.4 Active Regions and Peak Analysis:
    • active_regions_search: Identifies active regions on the sun by comparing observed data to known solar active region locations using wavelet denoising and peak detection.

    • make_multigauss_fit: Fits multiple Gaussian functions to data points, extracting amplitude, mean, and standard deviation for each detected peak.

    • gauss_analysis: Performs Gaussian analysis on identified active regions and associates various metrics (amplitude, mean, flux, etc.) with these regions.

base_url

Base URL template for accessing data files.

Type:

str

regex_pattern

Regular expression pattern to match file names.

Type:

str

convolution_template

Template for convolving the quiet Sun model, loaded from the Excel file.

Type:

pd.DataFrame

quiet_sun_model

Model for the quiet Sun brightness temperature, loaded from the Excel file.

Type:

pd.DataFrame

acquire_data(timerange: TimeRange) List[str][source]

Get all available urls for predefined TimeRange :param timerange: timerange for scan searching :type: TimeRange :return: url list: :rtype:

Searches for active regions in the solar spectrum data using wavelet denoising and peak detection and matching with NOAA active location.

Parameters:
  • srs – table from SRSCLient with informations about the NOAA active regions.

  • x – x coordinates

  • V – Stocks vector V

  • mask – masked interval

Returns:

Table with active regions: V value and coordinate for center of AR

Return type:

Table

antenna_efficiency(freq: List[float], R: float) List[float][source]

Calculates the antenna efficiency for each frequency.

Parameters:
  • freq

  • R

Returns:

base_url = 'http://spbf.sao.ru/data/ratan/%Y/%m/%Y%m%d_%H%M%S_sun+0_out.fits'
calibrate_QSModel(x: ndarray, scan_data: ndarray, solar_r: float, frequency: ndarray, flux_eficiency: ndarray) Tuple[ndarray, ndarray, ndarray][source]

Calibrates raw scan data with the quiet Sun model. :param x: Array of x coordinates :type: np.ndarray :param scan_data: Scan data array. :type: np.ndarray :param solar_r: Solar radius in arcseconds :type: float :param frequency: Array of frequencies. :type: np.ndarray :param flux_eficiency: Array of flux efficiencies for each frequency. :type: np.ndarray :return: calibrated scan: mask, Stocks component I, Stocks component V

compute_fluxes(x: ndarray, y: ndarray, ar_table: Table, mode: str = 'I') Table[source]

Calculate fluxes for active regions over specified intervals.

Parameters:
  • x (np.ndarray) – Array of x-coordinates, typically representing time or position.

  • y (np.ndarray) – Array of y-coordinates, representing the signal intensity. Supports 2D arrays.

  • ar_table (Table) – Table containing active region info, including ‘Interval’.

  • mode (str) – Mode of flux calculation, defaults to ‘I’.

Returns:

Table with active region info and calculated fluxes.

Return type:

Table

condition(year, month, data_match)[source]

Formats the data string based on the year and month. Used in Scrapper class :param year: The year of the data. :type year: str :param month: :type month: str :param data_match: data text from http content :type data_match: str :return: string with selected data

convolution_template = x, solarR = 750.0    3.0938    3.2813  ...   15.6563   16.9688   17.1563 0             0.000000  1.005630  1.005766  ...  1.007845  1.007125  1.007156 1             2.254778  1.005581  1.005717  ...  1.007810  1.007108  1.007138 2             4.509555  1.005526  1.005666  ...  1.007772  1.007078  1.007123 3             6.764333  1.005473  1.005613  ...  1.007720  1.007045  1.007104 4             9.019111  1.005420  1.005556  ...  1.007666  1.007018  1.007059 ..                 ...       ...       ...  ...       ...       ...       ... 882        1988.713900  0.003226  0.003282  ...  0.017368  0.014721  0.013982 883        1990.968677  0.003204  0.003267  ...  0.017328  0.014686  0.013947 884        1993.223455  0.003178  0.003258  ...  0.017320  0.014664  0.013903 885        1995.478233  0.003163  0.003248  ...  0.017199  0.014639  0.013854 886        1997.733010  0.003150  0.003231  ...  0.017071  0.014646  0.013774  [887 rows x 66 columns]
convolve_sun(sigma_horiz: float, sigma_vert: float, R: float)[source]

Performs convolution of the Sun model with Gaussian and rectangular functions.

Parameters:
  • sigma_horiz (float)

  • sigma_vert (float)

  • R (float)

Returns:

differential_rotation(Lat: ndarray) ndarray[source]

Calculates the differential rotation of the Sun based on latitude. :param Lat: Latitude array in degrees :type: np.ndarray :return:

filter(url_list)[source]
find_ar_intervals_using_peaks(x: ndarray, y: ndarray, ar_table: Table) Table[source]

Identify intervals around active region centers using peak detection

Parameters:
  • x (np.ndarray) – Array of x-coordinates, typically representing time or position

  • y (np.ndarray) – Array of y-coordinates, representing the signal intensity

  • ar_table (Table) – Table with active region info, including ‘Number’ and ‘Latitude’

Returns:

Table with active region numbers and calculated intervals

Return type:

Table

form_data(file_urls)[source]
form_srstable_with_time_shift(processed_file: HDUList) Table[source]

Create table with AR info with SRSClient with correct NOAA coordinates for RATAN time difference

Parameters:

processed_file – calibrate RATAN fits

Type:

fits.HDUList

Returns:

modified NOAA table with ARs

Return type:

Table

gauss_analysis(x, scan_data, ar_info)[source]

Analyzes active regions by fitting Gaussian functions and calculating associated metrics. :param x: x coordinates of the data (arcsec). :param scan_data: scan with radio data :type: np.ndarray :param ar_info: Table with information about active regions. :type: Table :return: Table with ARs parameters from Radio data at each frequency :rtype: Table

get_ar_info(pr_data: str | HDUList, bad_freq: list[float] | None = None, **kwargs) Table[source]

Retrieve Extract active region information from processed FITS data.

Parameters:
  • pr_data (Union[str, fits.hdu.hdulist.HDUList]) – Path to FITS file, URL, or FITS HDUList with processed data.

  • kwargs – Additional keyword arguments for processing options.

Returns:

FITS HDUList containing frequency data and active region information.

Return type:

Table

get_ar_info_from_processed(pr_data: str | HDUList, bad_freq: list[float] | None = None) HDUList[source]

Compute ar parameters (total flux, maximum amplitude, width (in arcsec)) info from a processed FITS HDUList and NOAA active regions coordnate info :param pr_data: string with path to file or direct url to source fits or fits file :type pr_data: str or fits.hdu.hdulist.HDUList :param bad_freq: list of bd frequencies excluded from computation :type bad_freq: list of float :return: astropy table with local sources info :rtype: Table

>>> raw_fits_data_path = get_project_root() / 'data' / '20170903_121257_sun+0_out.fits'
>>> ratan_client = RATANClient()
>>> hdul = ratan_client.get_ar_info_from_processed(str(raw_fits_data_path))
>>> assert hdul[1].data[0]['Number'] == 2673
>>> assert hdul[1].data[0]['TotalFlux'].shape == (84,)
>>> assert hdul[1].data[0]['MaxAmplitude'].shape == (84,)
>>> assert hdul[1].data[0]['MaxLat'].shape == (84,)
>>> assert hdul[1].data[0]['MinLat'].shape == (84,)
get_data(timerange)[source]
get_local_sources_info_from_processed(pr_data: str | HDUList, bad_freq: list[float] | None = None) Table[source]

Compute local sources info from a processed FITS HDUList and NOAA active regions coordnate info :param pr_data: string with path to file or direct url to source fits or fits file :type pr_data: str or fits.hdu.hdulist.HDUList :param bad_freq: list of bd frequencies excluded from computation :type bad_freq: list of float :return: astropy table with local sources info :rtype: Table

get_scans(timerange)[source]
heliocentric_transform(Lat: ndarray, Long: ndarray, SOLAR_R: float, SOLAR_B: float) Tuple[ndarray, ndarray][source]

Transforms solar coordinates to a heliocentric system. :param Lat: Latitude array in degrees :type: np.ndarray :param Long: Longitude array in degrees :type: np.ndarray :param SOLAR_R: Solar radius. :type: float :param SOLAR_B: Solar B angle :type: float :return: Heliocentric x and y coordinates. :rtype: Tuple[np.ndarray, np.ndarray]

make_multigauss_fit(x: ndarray, y: ndarray, peak_info: Table) Tuple[float, float, float][source]

Fits multiple Gaussian functions to detected peaks. :param x: x values of the data. :type: np.ndarray :param y: y values of the data. :type: np.ndarray :param peak_info: astropy Table with information about peaks. :return: width, value and coordinate for center of AR. :rtype: Tuple[float, float, float]

pozitional_angle(AZIMUTH: float, SOL_DEC: float, SOLAR_P: float) float[source]

Calculates the positional angle of the sun based on azimuth, solar declination, and solar P-angle.

Parameters:
  • AZIMUTH – Azimuth angle.

  • SOL_DEC – Solar declination angle.

  • SOLAR_P – Solar P-angle

Type:

float

Type:

float

Type:

float

Returns:

Positional angle of the sun

Return type:

float

pozitional_rotation(Lat: ndarray, Long: ndarray, angle: float) Tuple[ndarray, ndarray][source]

Rotates positional data by a given angle.

Parameters:
  • Lat – Latitude array in degrees

  • Long – Longitude array in degrees

  • angle – Rotation angle in degrees.

Type:

np.ndarray

Type:

np.ndarray

Type:

float

Returns:

Rotated X and Y coordinates

Return type:

Tuple[np.ndarray, np.ndarray]

process_fits_data(path_to_file: str, bad_freq: list[float] | None = None, save_path: str | None = None, save_with_original: bool = False, save_raw: bool = False) Tuple[HDUList, HDUList][source]

Process FITS data from a given URL or file_path from the disk, optionally saving the original and processed data to a file, and return the processed data as a FITS HDUList object.

Parameters:
  • path_to_file (str) – The URL of the FITS file to process or path to file at disk.

  • bad_freq (list of float) – A list of bad frequencies to exclude from the data acquisition.

  • save_path (Optional[str]) – Path to save the processed FITS data. If None, the processed FITS object is returned.

  • save_with_original (bool) – Whether to save the original data or not.

  • save_raw – Whether to save raw FITS data or not. :type save_raw: bool

Returns:

The raw and processed FITS data object.

Return type:

Tuple[fits.HDUList, fits.HDUList]

Example:

>>> ratan_client = RATANClient()
>>> raw, processed = ratan_client.process_fits_data('http://spbf.sao.ru/data/ratan/2017/09/20170903_121257_sun+0_out.fits')
>>> isinstance(processed, fits.HDUList)
True
process_fits_with_period(timerange: TimeRange, **kwargs) Tuple[List[HDUList], List[HDUList]][source]

Process fits files with a period by urls taken from http://spbf.sao.ru/ and return list of raw fits files and processed fits, all kwargs from process_fits_data are available,

such as option for saving processed fits and raw fits to directory.

Parameters:
  • timerange – Period of time for which scans will be downloaded and processed

  • kwargs – keyword arguments valid for process _fits_data

Returns:

Tuple[List[fits.HDUList], List[fits.HDUList]]

Example:


>>> time_range = TimeRange("2017-09-03", "2017-09-04")
>>> ratan_client = RATANClient()
>>> _, list_phdul = ratan_client.process_fits_with_period(time_range)
>>> isinstance(list_phdul, list)
True
quiet_sun_model = Unnamed: 0       freq  T_brightness 0             0   1.400000  49418.635189 1             1   1.448649  48858.340961 2             2   1.497297  48311.044957 3             3   1.545946  47776.300045 4             4   1.594595  47253.679371 ..          ...        ...           ... 995         995  49.805405   5400.867144 996         996  49.854054   5397.418371 997         997  49.902703   5393.975977 998         998  49.951351   5390.539945 999         999  50.000000   5387.110257  [1000 rows x 3 columns]
regex_pattern = '((\\d{6,8})[^0-9].*[^0-9]0_out.fits)'
class ratansunpy.client.client.SRSClient[source]

Bases: BaseClient

acquire_data(timerange: TimeRange) list[str][source]

Function for collecting data with predefined timerange

Parameters:

timerange (TimeRange) – TimeRange object with time span for ARs searching

Returns:

list of urls with txt files.

Return type:

list of string

base_url = 'ftp://ftp.ngdc.noaa.gov/STP/swpc_products/daily_reports/solar_region_summaries/%Y/%m/%Y%m%dSRS.txt'
extract_lines(content: str) object[source]
form_data(file_urls)[source]
get_data(timerange)[source]

Function for collecting data with predefined timerange :param timerange: :type timerange: TimeRange :return: data table :rtype: Table

parse_lat_col(column, latitude_column)[source]
parse_latitude(value)[source]
parse_location(column)[source]
parse_longitude(value)[source]
proccess_lines(date, key, lines)[source]

Module contents