common¶
common.calcfunctions¶
Module Description¶
This module provides calculation functions for the package.
- add_integral_edges_to_x_axis(x: Union[list, ndarray], integral_edges: Union[list, ndarray]) ndarray [source]¶
Add integral edges to the x-axis values and return the sorted unique array.
Parameters¶
- xlist or np.ndarray
Input array representing the x-axis values.
- integral_edgeslist or np.ndarray
Integral edges to be added to the x-axis values.
Returns¶
- np.ndarray
Sorted unique array of the x-axis values with integral edges.
- apply_KDE(input_data: DataFrame, bounds: list | tuple | numpy.ndarray = [0.5, 1.5], show_plots: bool = True, data_in_relative_values: bool = False) tuple[numpy.ndarray, numpy.ndarray] [source]¶
Apply Kernel Density Estimation (KDE) on input data and calculate relevant statistics.
Parameters¶
- input_datapd.DataFrame
Input data for KDE estimation.
- boundsnp.ndarray, optional
Bounds of the KDE estimation range. Default is (0.5, 1.5).
- show_plotsbool, optional
Flag to indicate whether to show the resulting plots. Default is True.
- data_in_relative_valuesbool, optional
Flag to indicate whether the input data is in relative values. Default is False.
Returns¶
- tuple[np.ndarray, np.ndarray]
Tuple containing the x-axis values, log densities, and calculated statistics.
Notes¶
This function applies Kernel Density Estimation (KDE) on the input data using a Gaussian kernel and bandwidth of 0.05.
It calculates the log densities and relevant statistics based on the KDE estimation.
If show_plots is True, it displays the KDE plot along with relevant annotations and fills the area within +/- one standard deviation.
Example¶
# Example usage xaxis_values, log_densities, statistics = apply_KDE(input_data, bounds=(0.2, 1.8), show_plots=True)
- calculate_power_spectral_density(antenna_inst, galactic_map_inst, lst_range: list, freq_Mhz_range: list, latitude: float, impedance_func: Optional[interp1d] = None, update_antenna_conventions: dict = {}, transform_hpmaps2_local_cs: bool = False, nside_transform: int = 512, distort_antenna_map: float = 0, distort_galactic_map: float = 0) DataFrame [source]¶
Calculate the power spectral density of the sky signal as received by an antenna.
Parameters¶
- antenna_instAntenna
Instance of the antenna model used to receive the signal.
- galactic_map_instGalacticMap
Instance of the galactic map model used to generate the sky signal.
- lst_rangeList[float]
List of local sidereal times (in hours) at which to calculate the power spectral density.
- freq_Mhz_rangeList[float]
List of frequencies (in MHz) at which to calculate the power spectral density.
- latitudefloat
Latitude of the observer in degrees.
- impedance_funcOptional[interp1d], default None
Interpolation function representing the antenna’s impedance as a function of frequency. If not provided, a unity impedance function is assumed.
- update_antenna_conventionsDict[str, Union[str, float]], default {}
Dictionary of update arguments to pass to the Data2hpmap constructor when creating the antenna map instance. See the Data2hpmap documentation for details.
- transform_hpmaps2_local_csbool, default False
If True, transform the galactic map and antenna map to the local coordinate system defined by the observer’s latitude and the local sidereal time. This approach is not recommended due to the high computational cost of transforming the galactic map. The default is to use the galactic coordinate system and create a static antenna map.
- nside_transformint, default 512
Temporary NSIDE upgrade of the galactic map when using transform_hpmaps2_local_cs=True. A lower value will increase speed, but the galactic map in local coordinates will have higher numerical errors.
Returns¶
- pd.DataFrame
Dataframe with the calculated power spectral density values. The columns correspond to frequencies, and the rows correspond to local sidereal times.
- calculate_truncated_stats(data: ndarray, lower_percentile: float, upper_percentile: float) tuple [source]¶
Calculates the truncated mean and standard deviation of the given data within the specified percentiles.
- Parameters
data (np.ndarray): Input data array. lower_percentile (float): Lower percentile threshold. upper_percentile (float): Upper percentile threshold.
- Returns
tuple: A tuple containing the truncated mean and standard deviation.
- correct_energy_of_one_sided_spectrum(spectrum: ndarray) ndarray [source]¶
Corrects the energy of a one-sided spectrum.
- Parameters
spectrum (np.ndarray): One-sided spectrum array.
- Returns
np.ndarray: Corrected one-sided spectrum array.
- dB2PowerAmp(dB)[source]¶
Converts the given value from decibel scale to power amplitude scale.
Parameters¶
- dBfloat
Value to be converted in decibel scale.
Returns¶
- float
Value converted to power amplitude scale.
- dB2VoltageAmp(dB)[source]¶
Converts the given value from decibel scale to voltage amplitude scale.
Parameters¶
- dBfloat
Value to be converted in decibel scale.
Returns¶
- float
Value converted to voltage amplitude scale.
- get_and_plot_calibration_results(slopes_DF: DataFrame, intercepts_DF: DataFrame, title: str = '', labels: str = '') tuple[float, float, float] [source]¶
Calculate and plot calibration results.
Parameters¶
- slopes_DFDataFrame
DataFrame containing slopes for each frequency.
- intercepts_DFDataFrame
DataFrame containing intercepts for each frequency.
- titlestr, optional
Title for the plot (default is an empty string).
- labelsstr or list, optional
Labels for the plot legend. If empty string, labels will be extracted from the index of slopes_DF. If None, no labels will be displayed. (default is an empty string).
Returns¶
- total_central_valuefloat
Total central value of the calibration results.
- bounds_total_central_valuefloat
Bounds of the total central value.
- get_bootstrap_CI(data, B=5000, alpha=0.3174, statistic_func=<function median>)[source]¶
Calculates the bootstrap confidence interval for the median of the given data.
Parameters¶
- datanumpy.ndarray
One-dimensional array containing the data.
- Bint, optional (default = 1000)
The number of bootstrap samples.
- alphafloat, optional (default = 0.32)
The level of significance, i.e., the proportion of the confidence interval to be calculated.
Returns¶
- tuple
Lower and upper bounds of the confidence interval.
- get_energy_from_one_sided_spectrum(rspectrum: ndarray) float [source]¶
Calculates the energy from a one-sided spectrum.
- Parameters
rspectrum (np.ndarray): One-sided spectrum array.
- Returns
float: Energy calculated from the one-sided spectrum.
- get_energy_from_one_sided_spectrum_corrected4one_side(r2spectrum: ndarray) float [source]¶
Calculates the energy from a one-sided spectrum with correction for one side.
- Parameters
r2spectrum (np.ndarray): One-sided spectrum array.
- Returns
float: Energy calculated from the one-sided spectrum with correction.
- get_energy_from_time_trace(time_trace: ndarray) float [source]¶
Calculates the energy from a time trace.
- Parameters
time_trace (np.ndarray): Time trace array.
- Returns
float: Energy calculated from the time trace.
- get_energy_from_two_sided_spectrum(spectrum: ndarray) float [source]¶
Calculates the energy from a two-sided spectrum.
- Parameters
spectrum (np.ndarray): Two-sided spectrum array.
- Returns
float: Energy calculated from the spectrum.
- get_fitted_voltage_cal_params_and_noise_offsets_from_concat_sim_dfs(concatenated_df: DataFrame, power_rec_DF: DataFrame) tuple [source]¶
Calculate the fitted voltage calibration parameters and noise offsets from concatenated simulation and recorded power DataFrames.
Parameters¶
- concatenated_dfpd.DataFrame
Concatenated simulation DataFrame with multi-level index.
- power_rec_DFpd.DataFrame
Recorded power DataFrame with frequency columns.
Returns¶
- tuple
A tuple containing two DataFrames: - First DataFrame: Fitted voltage calibration parameters with frequency columns. - Second DataFrame: Noise offsets with frequency columns.
- get_fitted_voltage_calibration_params_and_noise_offsets(power_sim_DF: DataFrame, power_rec_DF: DataFrame) tuple [source]¶
Calculate the fitted voltage calibration parameters and noise offsets.
- Parameters
- power_sim_DFpd.DataFrame
Simulated power DataFrame with frequency columns.
- power_rec_DFpd.DataFrame
Recorded power DataFrame with frequency columns.
- Returns
- tuple
A tuple containing two DataFrames: - First DataFrame: Fitted voltage calibration parameters with frequency columns. - Second DataFrame: Noise offsets with frequency columns.
- get_frequency_independent_calibration_param(slopes_DF: DataFrame, show_plots: bool = False) tuple [source]¶
Calculate the frequency-independent calibration parameters.
Parameters¶
- slopes_DFpd.DataFrame
DataFrame containing slopes for each frequency.
- show_plotsbool, optional
Flag indicating whether to show plots, by default False.
Returns¶
- tuple
A tuple containing the statistics of the frequency-independent calibration Parameters - Total central value - Lower bound of the central value - Upper bound of the central value
- get_stats_of_freq_dependent_cal_parameters_from_multiple_sim_datasets(slopes_DF: DataFrame) tuple [source]¶
Calculate the statistics of frequency-dependent calibration parameters from multiple simulation datasets.
Parameters¶
- slopes_DFarray-like
The input DataFrame containing slopes for each frequency.
Returns¶
- freq_dependent_slopesndarray
Array of mean slopes for each frequency.
- boundsndarray
Array of standard deviations of slopes for each frequency.
- integrate_on_a_part_of_an_array(x: Union[list, ndarray], interp_func: interp1d, lower_integral_boundary: float, upper_integral_boundary: float) float [source]¶
Perform numerical integration on a specific part of an array using the given interpolation function.
Parameters¶
- xlist or np.ndarray
Array representing the x-axis values.
- interp_funcinterp1d
Interpolation function that maps x-values to y-values.
- lower_integral_boundaryfloat
Lower boundary of the integral.
- upper_integral_boundaryfloat
Upper boundary of the integral.
Returns¶
- float
Result of the numerical integration.
- integrate_spectral_density(sd_DF, integrated_MHz_bands, integrating_method='quad', point=None)[source]¶
Compute the integrated spectral density for each row of a given pandas DataFrame across specified frequency bands.
Parameters¶
- sd_DFpandas DataFrame
DataFrame with spectral density values as the data and frequency bins as the columns.
- integrated_MHz_bandslist or numpy.ndarray
List or array of floats representing the edges of the frequency bands to integrate over, in units of MHz.
- integrating_methodstr, optional
Integration method to use. Options are “quad” (default) or “on_discontinuous_function”.
- pointlist, numpy.ndarray or None, optional
Points to use in the integration method if “quad” is chosen. Defaults to None.
Returns¶
- pandas DataFrame
DataFrame with the integrated spectral density for each row of the input DataFrame across each frequency band specified by the integrated_MHz_bands parameter.
Raises¶
- ValueError
If the input DataFrame has fewer than 2 frequency bins.
Examples¶
>>> df = pd.DataFrame({'f1': [1, 2, 3], 'f2': [4, 5, 6]}) >>> integrate_spectral_density(df, [1.5, 4.5]) 1.5 4.5 0 2.621005 9.453482
- linspace_with_middle_value(middle: float, radius: float, num_samples: int) ndarray [source]¶
Generates a 1-D array of evenly spaced values centered around a middle value.
- Parameters
middle (float): The middle value. radius (float): The radius around the middle value. num_samples (int): The number of samples to generate.
- Returns
np.ndarray: An array of evenly spaced values.
- powerAmp2dB(powerAmp)[source]¶
Converts the given value from power amplitude scale to decibel scale.
Parameters¶
- powerAmpfloat
Value to be converted in power amplitude scale.
Returns¶
- float
Value converted to decibel scale.
- robust_regression(x_arr, y_arr)[source]¶
Calculates the robust regression coefficients for the given data using the HuberT norm.
Parameters¶
- x_arrnumpy.ndarray
One-dimensional array containing the predictor data.
- y_arrnumpy.ndarray
One-dimensional array containing the response data.
Returns¶
- numpy.ndarray
Array containing the intercept and slope of the regression model.
- time_trace_df_2_spectra_df(time_trace_df, DSC=0, sampling_frequency_MHz=250)[source]¶
Converts a time trace DataFrame to a spectral density DataFrame using FFT.
Parameters¶
- time_trace_dfpandas.DataFrame
DataFrame containing the time trace data. The signal should be stored in columns.
- DSCint, optional (default = 0)
The data start column, i.e., the index of the first column containing the signal.
- sampling_frequency_MHzfloat, optional (default = 250)
Sampling frequency of the signal in MHz.
Returns¶
- pandas.DataFrame
DataFrame containing the spectral density of the signal. The frequency values are stored in the columns.
- voltageAmp2dB(voltageAmp)[source]¶
Converts the given value from voltage amplitude scale to decibel scale.
Parameters¶
- voltageAmpfloat
Value to be converted in voltage amplitude scale.
Returns¶
- float
Value converted to decibel scale.
- voltage_squared_spectral_density(antenna_map: array, galactic_map: array, frequency_MHz: float) float [source]¶
Calculate the voltage squared spectral density for a given antenna map and galactic map at a specific frequency.
Parameters¶
- antenna_mapnp.array
Array representing the antenna map.
- galactic_mapnp.array
Array representing the galactic map.
- frequency_MHzfloat
Frequency in MHz.
Returns¶
- float
Result of the voltage squared spectral density calculation.
common.helpfunctions¶
Module Description¶
This module provides some Python helping functions for the package.
- class AppendOnlyIfMore(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
Action
Custom action class for argparse that appends values to a list only if more than one value is provided.
Parameters¶
- parserargparse.ArgumentParser
The argument parser object.
- namespaceargparse.Namespace
The namespace object where the parsed values are stored.
- valuesList[str]
The list of values provided for the option.
- option_stringstr, optional
The option string.
Returns¶
None
Notes:¶
This action class is designed to be used with the argparse module.
It appends values to the list attribute specified by ‘dest’ only if more than one value is provided.
If only one value is provided, it replaces the list attribute with that single value.
It is intended for use with options that can accept multiple values.
Example¶
# Example usage parser = argparse.ArgumentParser() parser.add_argument(”–values”, action=AppendOnlyIfMore, default=[], dest=”values”, nargs=”+”) args = parser.parse_args() print(args.values)
- class Data2hpmap(data, phi=None, theta=None, shift_phi=0, flip_theta=False, flip_phi=False, in_degrees=False, add_invisible_sky=False)[source]¶
Bases:
object
Interpolates a pandas DataFrame onto a healpix map. Supports half-sky and full-sky DataFrames, and includes options to shift and flip the data.
Parameters¶
- datapandas DataFrame or 2D array
The input data. If a pandas DataFrame is provided, the index and column names will be used as the phi and theta values, respectively. If a 2D array is provided, phi and theta must be specified.
- phiarray_like, optional
The phi values corresponding to the columns of the input data. Ignored if data is a pandas DataFrame. Default is None.
- thetaarray_like, optional
The theta values corresponding to the rows of the input data. Ignored if data is a pandas DataFrame. Default is None.
- shift_phifloat, optional
The amount to shift the phi values by (in radians). Default is 0.
- flip_thetabool, optional
Whether to flip the theta values. Default is False.
- flip_phibool, optional
Whether to flip the phi values. Default is False.
- in_degreesbool, optional
Whether the input phi and theta values are in degrees. Default is False.
- add_invisible_skybool, optional
Whether to add an invisible sky below the input data (for half-sky maps). Default is False.
Returns¶
None
Raises¶
- ValueError
If the input data is not a pandas DataFrame and phi and theta are not provided.
Notes¶
This class uses the scipy.interpolate.RegularGridInterpolator function to interpolate the data onto a healpix map. The interpolated map can be obtained using the get_map method.
Examples¶
>>> import numpy as np >>> import pandas as pd >>> data = np.random.randn(10, 20) >>> phi = np.linspace(0, 2*np.pi, 20, endpoint=False) >>> theta = np.linspace(0, np.pi/2, 10) >>> df = pd.DataFrame(data, index=theta, columns=phi) >>> hp_map = Data2hpmap(df, shift_phi=np.pi/4).get_map(nside=64)
- get_grid_df() DataFrame [source]¶
Returns the input data as a pandas DataFrame, with the rows corresponding to the phi values and the columns corresponding to the theta values.
Returns¶
- pd.DataFrame
The input data as a pandas DataFrame.
- get_interp_func()[source]¶
Get the interpolation function.
Returns¶
- callable
The interpolation function.
Notes¶
The interpolation function is a RegularGridInterpolator object that can be used to interpolate the data onto a regular grid. The function takes a tuple (phi, theta) as input, where phi and theta are arrays of the same shape, and returns the interpolated values at the corresponding (phi, theta) positions.
- get_map(nside: int = 64, rotator: type = [[(None, None)], [array([0., 0., 0.])], [False]]) ndarray [source]¶
Interpolate the input data onto a full-sky map with the specified nside and rotator.
Parameters¶
- nsideint, optional
The resolution parameter for the HEALPix map. Defaults to 64.
- rotatortype(Rotator), optional
The rotator to use to rotate the interpolated map. Defaults to Rotator(rot=[0, 0]).
Returns¶
- np.ndarray
The interpolated HEALPix map.
- GetXMLRoot(XMLFile)[source]¶
Reads an XML file and returns the root element of the parsed XML tree.
Parameters¶
- XMLFilestr
Path to the XML file to be read.
Returns¶
- rootxml.etree.ElementTree.Element
Root element of the parsed XML tree.
- abs_fft(timeTrace: Union[ndarray, Series], fs: float = 250.0, window: float = 1.0) ndarray [source]¶
Compute one-sided Fourier transform of a time series.
Parameters¶
- timeTracenp.ndarray or pd.Series
Time series to transform.
- fsfloat, optional
Sampling frequency, by default 250.0.
- windowfloat, optional
Window to apply to the time series before transforming, by default 1.0.
Returns¶
- np.ndarray
One-sided Fourier transform.
Raises¶
- ValueError
If input time series is not a numpy array or pandas Series.
- add_deviation(mu: float, error: float) float [source]¶
Add a random deviation to a value based on a fractional error.
Parameters¶
- mufloat
The mean value.
- errorfloat
The fractional error of the value.
Returns¶
- new_mufloat
The new mean value with the deviation added.
- autoscale_y(ax: Axes, margin: float = 0.1) None [source]¶
Rescales the y-axis based on the visible data given the current xlim of the axis. Credit: Dan Hickstein
- Parameters:
ax (matplotlib.axes.Axes): The matplotlib axes object. margin (float): The fraction of the total height of the y-data to pad the upper and lower ylims.
- Returns:
None
- bin_df_rows(df: DataFrame, binning_column: str, bins: Union[list, ndarray]) DataFrame [source]¶
Bin DataFrame rows based on a given column.
Parameters¶
- dfpd.DataFrame
Input DataFrame.
- binning_columnstr
Column to bin on.
- binslist or np.ndarray
Bins to use for binning.
Returns¶
- pd.DataFrame
Binned DataFrame.
- compare_maps(map_dict: dict, main_title: str = '', rotation_parameters: Optional[list] = None, coord: list = ['G'], mask: list = False, projection_type: str = 'mollweide', cmap: str = 'jet', show_plot_comparison: bool = True, verbose: bool = False, figsize: Tuple = (6, 6.5)) dict [source]¶
Compare maps in a dictionary using matplotlib and return an integrated comparison dictionary.
Parameters¶
- map_dictdict
A dictionary containing maps to compare.
- main_titlestr, optional (default=””)
The title for the entire comparison plot.
- rotation_parameterslist, optional (default=None)
List of longitude and latitude values for rotating the plot.
- coordlist, optional (default=[‘G’])
Coordinate system to be used. Can be one of [‘G’, ‘H’, ‘C’, ‘S’].
- masklist, optional (default=False)
Whether to apply a mask to the maps.
- projection_typestr, optional (default=”mollweide”)
The type of projection to use for the plot.
- cmapstr, optional (default=”jet”)
The color map to use for the plot.
- show_plot_comparisonbool, optional (default=True)
Whether to display the plot.
- verbosebool, optional (default=False)
Whether to print verbose output during the function execution.
Returns¶
- dict
An integrated comparison dictionary.
Raises¶
None
- concatenate_simulated_dfs(dir_path: str, spec_substring: str = '') DataFrame [source]¶
Concatenate simulated DataFrames from CSV files.
Parameters¶
- dir_pathstr
Directory path containing the CSV files.
- spec_substringstr, optional
Substring to filter specific CSV files (default is an empty string).
Returns¶
- pd.DataFrame
Concatenated DataFrame containing the simulated data.
- convert_xml_string_to_floats(xml_string)[source]¶
Converts an XML string containing whitespace-separated float values to a NumPy array of float values.
Parameters¶
- xml_stringstr
XML string containing whitespace-separated float values.
Returns¶
- floatsndarray
NumPy array of float values extracted from the XML string.
- create_local_mask(nside: int, rotation_parameters: Tuple[float, float]) ndarray [source]¶
Creates a mask that is True for pixels above the equator and False for those below.
Parameters¶
- nsideint
The nside parameter for the Healpix map.
- rotation_parameterstuple of float
A tuple containing the Galactic longitude and latitude (in degrees) used to rotate the map.
Returns¶
- np.ndarray
A boolean array with True for pixels above the equator and False for those below.
- create_rotation_parameters(lst: float, latitude: float) Tuple[float, float] [source]¶
Creates a tuple of Galactic longitude and latitude (in degrees) from local sidereal time and latitude.
Parameters¶
- lstfloat
The local sidereal time in hours.
- latitudefloat
The latitude of the observer in degrees.
Returns¶
- tuple of float
A tuple containing the Galactic longitude and latitude (in degrees).
- create_rotator(lst: Optional[float], latitude: Optional[float], coord: List[str] = ['G'], inv: bool = False) Rotator [source]¶
Creates a Rotator object for converting between Galactic and celestial (e.g., equatorial) coordinates.
Parameters¶
- lstfloat or None
The local sidereal time in hours. If None, defaults to 0.
- latitudefloat or None
The latitude of the observer in degrees. If None, defaults to 0.
- coordlist of str, optional
A list of two strings indicating the input and output coordinate systems. Defaults to [“G”] (Galactic).
- invbool, optional
Whether to perform an inverse rotation. Defaults to False.
Returns¶
- Rotator
A Rotator object that can be used to convert between Galactic and celestial coordinates.
- del_keys(d: dict, keys: Union[str, List[str]]) None [source]¶
Remove one or more keys from a dictionary.
Parameters¶
- ddict
The dictionary to modify.
- keysstr or List[str]
The key(s) to remove from the dictionary.
- distort_array(arr: ndarray, rstd: float = 0.5) ndarray [source]¶
Distort the values of a NumPy array by adding Gaussian noise.
Parameters¶
- arrnp.ndarray
The input NumPy array.
- rstdfloat, optional
The relative standard deviation of the Gaussian noise.
Returns¶
- np.ndarray
The distorted array.
Notes:¶
This function adds Gaussian noise to the values of the input array.
The amount of noise is controlled by the relative standard deviation (rstd).
A higher rstd value results in more distortion.
The function handles both masked and unmasked arrays.
For masked arrays, the distortion is only applied to unmasked values.
Example:¶
# Example usage arr = np.array([1, 2, 3, 4, 5]) distorted_arr = distort_array(arr, rstd=0.5) print(distorted_arr)
- dropnans(arr: ndarray) ndarray [source]¶
Drop NaN values from the array.
Parameters¶
- arrarray-like
Input array.
Returns¶
- array
Array with NaN values removed.
- fig_to_image(fig)[source]¶
Converts a Matplotlib figure object to a NumPy array of RGB values.
Parameters¶
- figmatplotlib.figure.Figure object
Matplotlib figure object to be converted.
Returns¶
- image_from_plotndarray
3D NumPy array of RGB values representing the image.
- find_closest_index(arr: ndarray, value: float) int [source]¶
Find the index of the closest value in an array to a given value.
Parameters¶
- arrnp.ndarray
Input array.
- valuefloat
Target value.
Returns¶
- int
Index of the closest value.
- find_index_on_CDF(log_dens: ndarray, X: ndarray, p: float) int [source]¶
Returns the index of the array X such that the cumulative distribution function (CDF) of log_dens evaluated on X is closest to p.
Parameters¶
- log_densnp.ndarray
Array of log-density values.
- Xnp.ndarray
The array of values to evaluate the CDF on.
- pfloat
The probability threshold.
Returns¶
- int
The index of the array X such that the CDF of log_dens evaluated on X is closest to p.
- generate_one_sided_random_phase(size: int) ndarray [source]¶
Generate one-sided random phase for a given size.
Parameters¶
- sizeint
Size of the phase array.
Returns¶
- np.ndarray
One-sided random phase array.
- hpmap2grid(m: List, xsize: int = 1000) Tuple [source]¶
Interpolate a HEALPix map onto a regular grid.
Parameters¶
- mList
HEALPix map array.
- xsizeint, optional (default=1000)
The size of the x-axis of the interpolated map.
Returns¶
- PHInumpy.ndarray
2D array of azimuthal angles (longitude).
- THETAnumpy.ndarray
2D array of polar angles (colatitude).
- grid_mapnumpy.ndarray
Interpolated map.
- integrate_hpmap(m: List) float [source]¶
Integrate the HEALPix map over the sky.
Parameters¶
- mList
HEALPix map array.
Returns¶
- fluxfloat
The integrated flux of the map.
- mkdir(directory)[source]¶
Create a directory if it doesn’t already exist.
Parameters¶
- directorystr
Directory path to be created.
Returns¶
None
Notes:¶
This function checks if the directory already exists.
If the directory doesn’t exist, it creates a new directory.
If the directory already exists, it prints a message indicating that the directory already exists.
Example:¶
# Example usage mkdir(“path/to/directory”)
- my_modulo(arr, modulo)[source]¶
Compute the modulo of each element in an array, except for elements that are equal to the modulo.
Parameters¶
- arrarray_like
The input array.
- moduloscalar
The modulo value.
Returns¶
- ndarray
The output array with the same shape as the input array.
Examples¶
>>> my_modulo([1, 2, 3, 4, 5, 6, 7], 3) array([1, 2, 0, 1, 2, 0, 1])
- one_sided_2_complex_two_sided(one_sided_abs: ndarray, one_sided_phase: Optional[ndarray] = None) ndarray [source]¶
Convert one-sided amplitude and phase to complex two-sided array.
Parameters¶
- one_sided_absnp.ndarray
One-sided amplitude array.
- one_sided_phasenp.ndarray or None, optional
One-sided phase array. If None, random phase will be generated, by default None.
Returns¶
- np.ndarray
Complex two-sided array.
- one_sided_2_two_sided(spectrum: ndarray, sign: int = 1) ndarray [source]¶
Convert a one-sided power spectrum into a two-sided power spectrum.
Parameters¶
- spectrumnumpy.ndarray
One-sided power spectrum.
- signint, optional (default=1)
The sign to use when computing the negative frequencies in the two-sided spectrum.
Returns¶
- two_sided_spectrumnumpy.ndarray
Two-sided power spectrum.
- print_map_properties(map_: ndarray) None [source]¶
Prints properties of a Healpix map.
Parameters¶
- mapnp.ndarray
A one-dimensional array representing the map.
Returns¶
None
- read_hw_file(hw_file_path: str, return_tabulated: bool = False, return_interp_func: bool = True, interp_args: dict = {}) dict [source]¶
Reads an XML file containing hierarchical data, extracts data into a nested dictionary of NumPy arrays and/or interpolation functions.
Parameters¶
- hw_file_pathstr
Path to the XML file to be read.
- return_tabulatedbool, optional
If True, returns data in a nested dictionary of NumPy arrays, else returns data in a nested dictionary of interpolation functions. Default is False.
- return_interp_funcbool, optional
If True, returns data in a nested dictionary of interpolation functions, else returns data in a nested dictionary of NumPy arrays. Default is True.
- interp_argsdict, optional
Dictionary of optional arguments to be passed to the interp1d function of NumPy. Default is an empty dictionary.
Returns¶
- xml_dictdict
A nested dictionary containing the extracted data. If return_tabulated is True, values in the dictionary are NumPy arrays. Else, values are interpolation functions.
- rotate_default_hpmap_array_from_galactic2local_coordinates(m: ndarray, lst: Optional[float], latitude: Optional[float], inv: bool = False, nside_transform: int = 512) ndarray [source]¶
Rotates a Healpix map from Galactic to local coordinates.
Parameters¶
- mnp.ndarray
A one-dimensional array representing the map.
- lstfloat or None
The local sidereal time in hours. If None, defaults to 0.
- latitudefloat or None
The latitude of the observer in degrees. If None, defaults to 0.
- update_antenna_coordinates(data, phi=None, theta=None, flip_theta=False, flip_phi=False, shift_phi=0, add_invisible_sky=False, in_degrees=False)[source]¶
Update the antenna coordinates represented by a DataFrame.
This function modifies the input DataFrame representing antenna coordinates based on the provided parameters.
Parameters¶
- datapandas.DataFrame or numpy.ndarray
Input data representing antenna coordinates. If a DataFrame is provided, it is deep-copied to ensure data integrity. If a numpy ndarray is provided, the ‘phi’ and ‘theta’ parameters must also be provided to create a DataFrame.
- philist, numpy.ndarray, optional
List or array representing phi values (azimuth angles). Required when ‘data’ is an ndarray.
- thetalist, numpy.ndarray, optional
List or array representing theta values (zenith angles). Required when ‘data’ is an ndarray.
- flip_thetabool, optional
If True, flip the theta values. Default is False.
- flip_phibool, optional
If True, flip the phi values. Default is False.
- shift_phifloat, optional
Shift the phi values by the specified angle (in radians). Default is 0.
- add_invisible_skybool, optional
If True, add an invisible sky sector by mirroring the existing data. Default is False.
- in_degreesbool, optional
If True, treat the input angles in degrees, otherwise, radians. Default is False.
Returns¶
- pandas.DataFrame
A modified DataFrame containing the updated antenna coordinates.
Notes¶
This function updates the input data to match the specified coordinate adjustments. It handles flipping, shifting, and periodicity of the input data based on the given parameters.
Raises¶
- ValueError
Raised if the input data is not a pandas DataFrame and ‘phi’ or ‘theta’ are not provided.
Example¶
# Create a DataFrame with antenna coordinates data = pd.DataFrame([[1, 2], [3, 4]], index=[0.0, 0.5], columns=[0.0, 1.0])
# Update the antenna coordinates updated_data = update_antenna_coordinates(data, flip_phi=True)