P-AIRCARS Utils Module

This module contains all basic functionalities required for the pipeline.

paircars.utils.basic_utils module

paircars.utils.basic_utils.angular_separation_equatorial(ra1, dec1, ra2, dec2)[source]

Calculate angular seperation between two equatorial coordinates

Parameters:
  • ra1 (float) – RA of the first coordinate in degree

  • dec1 (float) – DEC of the first coordinate in degree

  • ra2 (float) – RA of the second coordinate in degree

  • dec2 (float) – DEC of the second coordinate in degree

Returns:

Angular distance in degree

Return type:

float

paircars.utils.basic_utils.average_timestamp(timestamps)[source]

Compute the average timestamp using astropy from a list of ISO 8601 strings.

Parameters:

timestamps (list) – timestamps (list of str): List of timestamp strings in ‘YYYY-MM-DDTHH:MM:SS’ format.

Returns:

Average timestamp in ‘YYYY-MM-DDTHH:MM:SS’ format.

Return type:

str

paircars.utils.basic_utils.average_with_padding(array, chanwidth, axis=0, pad_value=nan)[source]

Averages an array along a specified axis with a given chunk width (chanwidth), padding the array if its size along that axis is not divisible by chanwidth.

Parameters:
  • array (ndarray) – Input array to average.

  • chanwidth (int) – Width of chunks to average.

  • axis (int) – Axis along which to perform the averaging.

  • pad_value (float) – Value to pad with if padding is needed (default: np.nan).

Returns:

Array averaged along the specified axis.

Return type:

ndarray

paircars.utils.basic_utils.capture_all_output()[source]
paircars.utils.basic_utils.ceil_to_multiple(n, base)[source]

Round up to the next multiple

Parameters:
  • n (float) – The number

  • base (float) – Whose multiple will be

Returns:

The modified number

Return type:

float

paircars.utils.basic_utils.check_permission(path)[source]

check read, write, execute permission of a file or directory

Parameters:

path (str) – File or directory path

Returns:

Whether hand permission or not

Return type:

bool

paircars.utils.basic_utils.check_port_status(port)[source]

Check port status

Parameters:

port (int) – Port number

Returns:

Port free status

Return type:

int

paircars.utils.basic_utils.create_datadir(datadir='')[source]

Create data directory

Parameters:

datadir (str, optional) – User provided custom data directory

paircars.utils.basic_utils.filter_outliers(data, threshold=5, max_iter=3)[source]

Filter outliers and perform cubic spline fitting

Parameters:
  • y (numpy.array) – Y values

  • threshold (float) – Threshold of filtering

  • max_iter (int) – Maximum number of iterations

Returns:

Clean Y-values

Return type:

numpy.array

paircars.utils.basic_utils.get_cachedir()[source]

Get cache directory

paircars.utils.basic_utils.get_datadir()[source]

Get package data directory

Returns:

Data directory

Return type:

str

paircars.utils.basic_utils.get_free_port(start_port=4200, end_port=4300)[source]

Get free port

Parameters:
  • start_port (int, optional) – Start port range

  • end_port (int, optional) – End port range

Returns:

Free port

Return type:

int

paircars.utils.basic_utils.internet_available(timeout=10)[source]

Check internet connection

paircars.utils.basic_utils.interpolate_nans(data)[source]

Linearly interpolate NaNs in 1D array.

paircars.utils.basic_utils.mjdsec_to_timestamp(mjdsec, str_format=0)[source]

Convert CASA MJD seceonds to CASA timestamp

Parameters:
  • mjdsec (float) – CASA MJD seconds

  • str_format (int) – Time stamp format (0: yyyy-mm-ddTHH:MM:SS.ff, 1: yyyy/mm/dd/HH:MM:SS.ff, 2: yyyy-mm-dd HH:MM:SS)

Returns:

CASA time stamp in UTC at ISOT format

Return type:

str

paircars.utils.basic_utils.print_banner(msg, pad=0, max_width=50, no_print=False)[source]
paircars.utils.basic_utils.ra_dec_to_deg(ra_hms, dec_dms)[source]

Convert RA and Dec from hms and dms format to degrees

Parameters:
  • ra_hms (str) – Right Ascension in ‘hms’ format

  • dec_dms (str) – Declination in ‘dms’ format

Returns:

RA and Dec in degrees

Return type:

tuple

paircars.utils.basic_utils.ra_dec_to_hms_dms(ra_deg, dec_deg)[source]

Convert RA and Dec in degrees to hms and dms format

Parameters:
  • ra_deg (float) – Right Ascension in degrees.

  • dec_deg (float) – Declination in degrees.

Returns:

RA in h:m:s format, Dec in d:m:s format (e.g., ‘1h5m0s’, ‘1d5m0s’).

Return type:

tuple

paircars.utils.basic_utils.split_into_chunks(lst, target_chunk_size)[source]

Split a list into equal number of elements

Parameters:
  • lst (list) – List of numbers

  • target_chunk_size (int) – Number of elements per chunk

Returns:

Chunked list

Return type:

list

paircars.utils.basic_utils.suppress_output()[source]

Supress CASA terminal output

paircars.utils.basic_utils.timestamp_to_mjdsec(timestamp, date_format=0)[source]

Convert timestamp to mjd second.

Parameters:
  • timestamp (str) – Time stamp to convert

  • date_format (int, optional) –

    Datetime string format

    0: ‘YYYY/MM/DD/hh:mm:ss’

    1: ‘YYYY-MM-DDThh:mm:ss’

    2: ‘YYYY-MM-DD hh:mm:ss’

    3: ‘YYYY_MM_DD_hh_mm_ss’

Returns:

Return correspondong MJD second of the day

Return type:

float

paircars.utils.basic_utils.wait_for_port(host, port, timeout=60)[source]

Waiting for port

Parameters:
  • port (int) – Port number

  • timeout (int, optional) – Timeout in seconds

paircars.utils.basic_utils.weighted_mean(x, xerr)[source]

Calculate weighted mean

Parameters:
  • x (numpy.array) – Data array

  • xerr (numpy.array) – Error array

Returns:

  • float – Weighted mean

  • float – Weighted error

paircars.utils.calibration module

paircars.utils.calibration.calc_bw_smearing_freqwidth(msname, full_FoV=False, FWHM=True)[source]

Function to calculate spectral width to produce bandwidth smearing

Parameters:
  • msname (str) – Name of the measurement set

  • full_FoV (bool, optional) – Consider smearing within solar disc or full FoV

  • FWHM (bool, optional) – If using full FoV, consider upto FWHM or first null

Returns:

Spectral width in MHz

Return type:

float

paircars.utils.calibration.calc_time_smearing_timewidth(msname, full_FoV=False, FWHM=True)[source]

Calculate maximum time averaging to avoid time smearing over full FoV.

Parameters:
  • msname (str) – Measurement set name

  • full_FoV (bool, optional) – Consider smearing within solar disc or full FoV

  • FWHM (bool, optional) – If using full FoV, consider upto FWHM or first null

Returns:

delta_t_max – Maximum allowable time averaging in seconds.

Return type:

float

paircars.utils.calibration.fill_nan_gains(x, data)[source]

Interpolate nan gains across frequency

Parameters:
  • x (numpy.array) – 1D array of freqs

  • data (numpy.array) – 1D array of complex gains

Returns:

1D array of nan filled interpolated gains

Return type:

numpy.array

paircars.utils.calibration.fluxcal_caltable(caltable, attn=10)[source]

Function to scale scale MWA bandpass table for attenuation (Digital gain corrections should already been applied)

Parameters:
  • caltable (str) – Name of the caltable

  • attn (float, optional) – Attenuation in dB

Returns:

Flux calibrated caltable

Return type:

str

paircars.utils.calibration.get_cal_flag_info(caltable)[source]

Get flag information of the caltable

Parameters:

caltable (str) – Caltable

Returns:

  • list – Flagged channel list

  • list – Flagged antenna list

  • list – Flagged timestamp list

  • float – Total flag fraction

  • float – Channel flag fraction

  • float – Antenna flag fraction

  • float – Time flag fraction

paircars.utils.calibration.get_caltable_metadata(caltable)[source]

Function to get caltable metadata.

Parameters:

caltable (str) – Name of the caltable

Returns:

A python dictionary with keywords MSNAME, JonesType, Channel 0 frequency (MHz), Central channel frequency (MHz), Channel width (kHz), Bandwidth (MHz), Start time, End time

Return type:

dict

paircars.utils.calibration.get_nearest_bandpass_table(caltable_list, freq)[source]

Function to get nearest bandpass table of a given frequency

Parameters:
  • caltable_list (list) – List of bandpass table

  • freq (float) – Frequency in MHz

Returns:

Name of the nearest bandpass table

Return type:

str

paircars.utils.calibration.get_nearest_gaincal_table(caltable_list, timestamp)[source]

Function to get nearest gaincal table of a given time

Parameters:
  • caltable_list (list) – List of gaincal table

  • timestamp (str) – Timestamp (format : ‘YYYY/MM/DD/hh:mm:ss’)

Returns:

Name of the nearest gaincal table

Return type:

str

paircars.utils.calibration.get_psf_size(msname, chan_number=-1)[source]

Function to calculate PSF size in arcsec

Parameters:
  • msname (str) – Name of the measurement set

  • chan_number (int, optional) – Channel number

Returns:

PSF size in arcsec

Return type:

float

paircars.utils.calibration.get_quartical_soltype(quartical_table)[source]

Get quartical solution types

Parameters:

quartical_table (str) – Quartical table

Returns:

Solutions types

Return type:

list

paircars.utils.calibration.get_quartical_table_metadata(caltable)[source]

Function to get metadata of a quartical table.

Parameters:

caltable (str) – Name of the caltable

Returns:

A python dictionary with keywords JonesType, Channel 0 frequency (MHz), Central channel frequency (MHz), Channel width (kHz), Bandwidth (MHz), Start time, End time

Return type:

dict

paircars.utils.calibration.interpolate_bpass(caltables, overwrite=False)[source]

Interpolate bandpass/crossphase tables for missing frequency solutions

Parameters:
  • caltables (list) – List of bandpass/crossphase tables

  • overwrite (bool, optional) – Overwrite the input tables or not

Returns:

Output bandpass/crossphase tables

Return type:

list

paircars.utils.calibration.interpolate_quartical(caltables, overwrite=False)[source]

Function to interpolate quartical caltable

Parameters:
  • caltables (list) – Name of the full Jones QuartiCal caltable caltables

  • overwrite (bool, optional) – Overwrite the input caltable (if not, a new caltable will be written)

Returns:

New caltable name

Return type:

str

paircars.utils.calibration.max_time_solar_smearing(msname)[source]

Max allowable time averaging to avoid solar motion smearing.

Parameters:

msname (str) – Measurement set name

Returns:

t_max – Maximum time averaging in seconds.

Return type:

float

paircars.utils.calibration.merge_caltables(caltables, merged_caltable, append=False, keepcopy=False)[source]

Merge multiple same type of caltables

Parameters:
  • caltables (list) – Caltable list

  • merged_caltable (str) – Merged caltable name

  • append (bool, optional) – Append with exisiting caltable

  • keepcopy (bool, opitonal) – Keep input caltables or not

Returns:

Merged caltable

Return type:

str

paircars.utils.calibration.quartical_matrix_normalize(caltable, overwrite=False)[source]

Function to make matrix normalization (Normalization of full Jones solutions) Note : for mathematical expression, look at equation 21 of Kansabanik et al. 2022, ApJ, 932:110

Parameters:
  • caltable (str) – Name of the full Jones QuartiCal caltable

  • overwrite (bool, optional) – Overwrite the input caltable (if not, a new caltable will be written)

Returns:

New caltable name

Return type:

str

paircars.utils.calibration.scale_bandpass(bandpass_table, cal_attn, target_attn)[source]

Scale a bandpass calibration table using attenuation data.

Parameters:
  • bandpass_table (str) – Input bandpass calibration table.

  • cal_attn (float) – Calibrator attenuation

  • target_attn (float) – Target attenuation

Returns:

Name of the output table.

Return type:

str

paircars.utils.calibration.solint_in_float(solint)[source]

Convert solution interval to seconds

Parameters:

solint (str) – Solution interval

Returns:

Solution interval in seconds

Return type:

float

paircars.utils.calibration.uvrange_casa_to_quartical(msname, uvrange='')[source]

Get quartical uv-range from CASA format uv-range

Parameters:
  • msname (str) – Measurement set

  • uvrange (str) – UV-range in CASA format

Returns:

  • float – Minimum UV in meter

  • float – Maximum UV in meter

paircars.utils.casatasks module

paircars.utils.casatasks.calc_normzlized_crosscorr(data, flag, ant1, ant2, time)[source]

Calculate normalized cross correlation

Parameters:
  • data (numpy.array) – Data array

  • flag (numpy.array) – Flag array

  • ant1 (numpy.array) – Antenna 1 array

  • ant2 (numpy.array) – Antenna 2 array

  • time (numpy.array) – Time array

Returns:

  • numpy.array – Normalized data (only if writeto_file is False)

  • numpy.array – New flag (only if writeto_file is False)

paircars.utils.casatasks.check_scan_in_caltable(caltable, scan)[source]

Check scan number available in caltable or not

Parameters:
  • caltable (str) – Name of the caltable

  • scan (int) – Scan number

Returns:

Whether scan is present in the caltable or not

Return type:

bool

paircars.utils.casatasks.normalized_crosscorr_ms(msname, datacolumn='DATA')[source]

Perform normalized cross-correlation of the measurement set

Parameters:
  • msname (str) – Measurement set

  • datacolumn (str, optional) – Data column to normalize

Returns:

Normalized measurement set

Return type:

str

paircars.utils.casatasks.reset_weights_and_flags(msname='', restore_flag=True, force_reset=False, n_threads=-1)[source]

Reset weights and flags for the ms

Parameters:
  • msname (str) – Measurement set

  • restore_flag (bool, optional) – Restore flags or not

  • force_reset (bool, optional) – Force reset

paircars.utils.casatasks.single_mstransform(msname='', outputms='', width=1, timebin='', datacolumn='DATA', spw='', corr='', timerange='', numsubms='auto', n_threads=-1)[source]

Perform mstransform

Parameters:
  • msname (str) – Name of the measurement set

  • outputms (str) – Output ms name

  • width (int, optional) – Number of channels to average

  • timebin (str, optional) – Time to average

  • datacolumn (str, optional) – Data column to split

  • spw (str, optional) – Spectral window

  • corr (str, optional) – Correlation to split

  • timerange (str, optional) – Time range

  • n_threads (int, optional) – Number of CPU threads

Returns:

Output measurement set name

Return type:

str

paircars.utils.crossphasecal module

paircars.utils.crossphasecal.create_blank_table(msname, caltable)[source]

Create a blank bandpass table

Parameters:
  • msname (str) – Name of the measurement set

  • caltable (str) – Caltable name

Returns:

Blank caltable name

Return type:

str

paircars.utils.crossphasecal.create_crossphase_table(msname, caltable, freqs, crossphase, flags)[source]

Create cross phase CASA caltable

Parameters:
  • msname (str) – Measurement set

  • caltable (str) – Caltable name

  • freqs (numpy.array) – Frequency list

  • crossphase (numpy.array) – Crossphase array

  • flags (numpy.array) – Flags

Returns:

Caltable name

Return type:

str

paircars.utils.crossphasecal.crossphasecal(msname, caltable, uvrange='', gaintable='', chanwidth=1, n_threads=-1)[source]

Function to calculate MWA cross hand phase

Parameters:
  • msname (str) – Name of the measurement set

  • caltable (str) – Name of the caltable

  • uvrange (str, optional) – UV-range for calibration

  • gaintable (str, optional) – Previous gaintable

  • chanwidth (int, optional) – Channels to average

  • n_threads (int, optional) – Number of CPU threads to use

Returns:

Name of the caltable

Return type:

str

paircars.utils.crossphasecal.fitted_crossphase(freqs, crossphase)[source]

Fit cos/sin components of crossphase vs frequency with increasing-degree polynomials, choose the best by residual std, and reconstruct phase.

Parameters:
  • freqs (array-like) – Frequency values (same length as crossphase).

  • crossphase (array-like) – Cross-phase in degrees (can include NaNs).

Returns:

Fitted cross-phase in degrees (NaNs outside valid span).

Return type:

np.ndarray

paircars.utils.ds_utils module

paircars.utils.ds_utils.cal_norm_crosscorr(msname, ant1, ant2)[source]

Function to obtain normalised cross correlation amplitude

Parameters:
  • msname (str) – Measurement set

  • ant1 (int) – Antenna 1

  • ant2 (int) – Antenna 2

Returns:

  • np.array – Normalized cross-correlation of polarization XX

  • np.array – Normalized cross-correlation of real part of polarization XY

  • np.array – Normalized cross-correlation of imaginary part of polarization XY

  • np.array – Normalized cross-correlation of polarization YY

paircars.utils.ds_utils.cal_sun_solid_angle(freq)[source]

Function to calculate the diameter of the Sun at a given frequency (White 2016)

Parameters:

freq (float) – Frequency in MHz

Returns:

Solid angle of the Sun

Return type:

float

paircars.utils.ds_utils.calc_T_pickup(freq)[source]

Function to calculate ground pickup temperature (Oberoi et al. 2017)

Parameters:

freq (float) – Frequency in MHz

Returns:

Pickup temperature in K

Return type:

float

paircars.utils.ds_utils.calc_T_rec(freq)[source]

Function to calculate receiver temperature based on Noise Temperature of Phased Array Radio Telescope: The Murchison Widefield Array and the Engineering Development Array, Ung et al, 2020, IEEE

Parameters:

freq (float) – Frequency in MHz

Returns:

Receiver temperature in K

Return type:

float

paircars.utils.ds_utils.calc_dynamic_spectrum(msname, metafits, outdir, n_threads=-1)[source]

Function to calculate MWA dynamic spectrum of the Sun

Parameters:
  • msname (str) – Measurement set

  • metafits (str) – Metafits file

  • outdir (str) – Name of the output directory

  • n_threads (int, optional) – Number of CPU threads to use

Returns:

  • str – Output dynamic spectrum file name

  • str – Output normalised cross-correlation file name

paircars.utils.ds_utils.get_short_baselines(msname, max_uv=100.0, nmax=6)[source]

Get list of shortest baselines

Parameters:
  • msname (str) – Measurement set

  • max_uv (float) – Maximum UV in lambda

  • nmax (int) – Number of baselines

Returns:

List of baselines

Return type:

list

paircars.utils.flagging module

paircars.utils.flagging.calc_flag_fraction(msname='', field='', scan='', n_threads=-1)[source]

Function to calculate the fraction of total data flagged.

Parameters:
  • msname (str) – Name of the measurement set

  • field (str, optional) – Field names

  • scan (str, optional) – Scan names

Returns:

Fraction of the total data flagged

Return type:

float

paircars.utils.flagging.do_flag_backup(msname, flagtype='flagdata')[source]

Take a flag backup

Parameters:
  • msname (str) – Measurement set name

  • flagtype (str, optional) – Flag type

paircars.utils.flagging.flag_outside_uvrange(vis, uvrange, flagbackup=True, n_threads=-1)[source]

Flag outside the given uv range

Parameters:
  • vis (str) – Measurement set name

  • uvrange (str) – UV-range

  • flagbackup (bool, optional) – Flag backup

paircars.utils.flagging.flag_quartical_table(caltable, threshold=10.0)[source]

Flag quartical caltable

Parameters:
  • caltable (str) – Caltable name

  • threshold (float) – Flagging threshold

Returns:

Flagged caltable name

Return type:

str

paircars.utils.flagging.flagsummary(msname, summary_file)[source]

Save flag summary

Parameters:
  • msname (str) – Measurement set name

  • summary_file (str) – Summary file name

Returns:

Summary file

Return type:

str

paircars.utils.flagging.get_chans_flag(msname='', field='', n_threads=-1)[source]

Get flag/unflag channel list

Parameters:
  • msname (str) – Measurement set name

  • field (str, optional) – Field name or ID

Returns:

  • list – Unflag channel list

  • list – Flag channel list

paircars.utils.flagging.get_chans_flag_per_time(msname)[source]

Get flagged channel fraction per time

Parameters:

msname (str) – Measurement set

Returns:

  • list – Timestamps (in MJD seconds)

  • list – Channel flag fractions

paircars.utils.flagging.get_unflagged_antennas(msname='', scan='', n_threads=-1)[source]

Get unflagged antennas of a scan

Parameters:
  • msname (str) – Name of the measurement set

  • scan (str) – Scans

Returns:

  • numpy.array – Unflagged antenna names

  • numpy.array – Flag fraction list

paircars.utils.flagging.uvbin_flag(msname, uvbin_size=10, datacolumn='data', mode='rflag', threshold=10.0, flagbackup=True)[source]

Perform uv-bin flag

Parameters:
  • msname (str) – Measurement set

  • uvbin_size (float, optional) – UV-bin size in wavelength

  • datacolumn (str, optional) – Data column

  • mode (str, optional) – Flag mode (rflag or tfcrop)

  • threshold (float, optional) – Flagging threshold

  • flagbackup (bool, optional) – Flag backup

paircars.utils.image_utils module

paircars.utils.image_utils.calc_dyn_range(imagename, modelname, residualname, fits_mask='')[source]

Calculate dynamic ranges.

Parameters:
  • imagename (list or str) – Image FITS file(s)

  • modelname (list or str) – Model FITS file(s)

  • residualname (list ot str) – Residual FITS file(s)

  • fits_mask (str, optional) – FITS file mask

Returns:

  • model_flux (float) – Total model flux.

  • dyn_range_rms (float) – Max/RMS dynamic range.

  • rms (float) – RMS of the image

paircars.utils.image_utils.calc_solar_image_stat(imagename, disc_size=50)[source]

Calculate solar image dynamic range

Parameters:
  • imagename (str) – Fits image name

  • disc_size (float, optional) – Solar disc size in arcmin (default : 50)

Returns:

  • float – Maximum value

  • float – Minimum value

  • float – RMS values

  • float – Total value

  • float – Mean value

  • float – Median value

  • float – RMS dynamic range

  • float – Min-max dynamic range

paircars.utils.image_utils.create_circular_mask(msname, cellsize, imsize, mask_radius=20)[source]

Create fits solar mask

Parameters:
  • msname (str) – Name of the measurement set

  • cellsize (float) – Cell size in arcsec

  • imsize (int) – Imsize in number of pixels

  • mask_radius (float) – Mask radius in arcmin

Returns:

Fits mask file name

Return type:

str

paircars.utils.image_utils.create_circular_mask_array(data, radius, center_x=None, center_y=None)[source]

Creating circular mask of a Numpy array

Parameters:
  • data (numpy.array) – 2D numpy array

  • radius (int) – Radius in pixels

Returns:

Mask array

Return type:

numpy.array

paircars.utils.image_utils.cutout_image(fits_file, output_file, x_deg=2)[source]

Cutout central part of the image

Parameters:
  • fits_file (str) – Input fits file

  • output_file (str) – Output fits file name (If same as input, input image will be overwritten)

  • x_deg (float, optional) – Size of the output image in degree

Returns:

Output image name

Return type:

str

paircars.utils.image_utils.filter_images(imagelist, min_time_sep=60.0)[source]

Select images with maximum bandwidth, then for each frequency keep images separated by at least min_time_sep seconds.

Parameters:
  • imagelist (list) – Image list

  • min_time_sep (float, optional) – Minimum time seperation in seconds

Returns:

Filtered image list

Return type:

list

paircars.utils.image_utils.generate_tb_map(imagename, outfile='')[source]

Function to generate brightness temperature map

Parameters:
  • imagename (str) – Name of the flux calibrated image

  • outfile (str, optional) – Output brightess temperature image name

Returns:

Output image name

Return type:

str

paircars.utils.image_utils.make_freqavg_image(wsclean_images, outfile_name, keep_wsclean_images=True)[source]

Convert WSClean images into a frequency averaged image

Parameters:
  • wsclean_images (list) – List of WSClean images.

  • outfile_name (str) – Name of the output file.

  • keep_wsclean_images (bool, optional) – Whether to retain the original WSClean images (default: True).

Returns:

Output image name.

Return type:

str

paircars.utils.image_utils.make_stokes_wsclean_imagecube(wsclean_images, outfile_name, keep_wsclean_images=True)[source]

Convert WSClean images into a Stokes cube image.

Parameters:
  • wsclean_images (list) – List of WSClean images.

  • outfile_name (str) – Name of the output file.

  • keep_wsclean_images (bool, optional) – Whether to retain the original WSClean images (default: True).

Returns:

Output image name.

Return type:

str

paircars.utils.image_utils.make_timeavg_image(wsclean_images, outfile_name, keep_wsclean_images=True)[source]

Convert WSClean images into a time averaged image

Parameters:
  • wsclean_images (list) – List of WSClean images.

  • outfile_name (str) – Name of the output file.

  • keep_wsclean_images (bool, optional) – Whether to retain the original WSClean images (default: True).

Returns:

Output image name.

Return type:

str

paircars.utils.imaging module

paircars.utils.imaging.calc_cellsize(msname, num_pixel_in_psf)[source]

Calculate pixel size in arcsec

Parameters:
  • msname (str) – Name of the measurement set

  • num_pixel_in_psf (float) – Number of pixels in one PSF

Returns:

Pixel size in arcsec

Return type:

int

paircars.utils.imaging.calc_field_of_view(msname, FWHM=True)[source]

Calculate optimum field of view in arcsec.

Parameters:
  • msname (str) – Measurement set name

  • FWHM (bool, optional) – Upto FWHM, otherwise upto first null

Returns:

Field of view in arcsec

Return type:

float

paircars.utils.imaging.calc_maxuv(msname, chan_number=-1)[source]

Calculate maximum UV

Parameters:
  • msname (str) – Name of the measurement set

  • chan_number (int, optional) – Channel number

Returns:

  • float – Maximum UV in meter

  • float – Maximum UV in wavelength

paircars.utils.imaging.calc_minuv(msname, chan_number=-1)[source]

Calculate minimum UV

Parameters:
  • msname (str) – Name of the measurement set

  • chan_number (int, optional) – Channel number

Returns:

  • float – Minimum UV in meter

  • float – Minimum UV in wavelength

paircars.utils.imaging.calc_multiscale_scales(msname, num_pixel_in_psf, chan_number=-1, max_scale=16)[source]

Calculate multiscale scales

Parameters:
  • msname (str) – Name of the measurement set

  • num_pixel_in_psf (float) – Number of pixels in one PSF

  • max_scale (float, optional) – Maximum scale in arcmin

Returns:

Multiscale scales in pixel units

Return type:

list

paircars.utils.imaging.calc_npix_in_psf(weight, robust=0.0)[source]

Calculate number of pixels in a PSF (could be fractional)

Parameters:
  • weight (str) – Image weighting scheme

  • robust (float, optional) – Briggs weighting robust parameter (-1 to +1)

Returns:

Number of pixels in a PSF

Return type:

float

paircars.utils.imaging.calc_psf(msname, chan_number=-1)[source]

Function to calculate PSF size in arcsec

Parameters:
  • msname (str) – Name of the measurement set

  • chan_number (int, optional) – Channel number

Returns:

PSF size in arcsec

Return type:

float

paircars.utils.imaging.calc_sun_dia(freqMHz)[source]

Function to calculate the diameter of the Sun at a given frequency (White 2016)

Parameters:

freq (float) – Frequency in MHz

Returns:

Diameter of the Sun in arcmin

Return type:

float

paircars.utils.imaging.calc_uvtaper(msname)[source]

Calculate UV-taper

Parameters:

msname (str) – Measurement set

Returns:

UV-taper in lambda at highest frequency

Return type:

float

paircars.utils.imaging.get_fft_size(n)[source]

Give the best number larger than the given number for best FFT performance

paircars.utils.imaging.get_multiscale_bias(freq, bias_min=0.6, bias_max=0.9, minfreq=100, maxfreq=200)[source]

Get frequency dependent multiscale bias

Parameters:
  • freq (float) – Frequency in MHz

  • bias_min (float, optional) – Minimum bias at minimum L-band frequency

  • bias_max (float, optional) – Maximum bias at maximum L-band frequency

  • minfreq (float, optional) – Minimum frequency range in MHz

  • maxfreq (float, optional) – Maximum frequency range in MHz

Returns:

Multiscale bias patrameter

Return type:

float

paircars.utils.imaging.get_optimal_image_interval(msname, temporal_tol_factor=0.1, spectral_tol_factor=0.1, chan_range='', timestamp_range='', flag_central_chan=False, max_nchan=-1, max_ntime=-1)[source]

Get optimal image spectral temporal interval such that total flux max-median in each chunk is within tolerance limit

Parameters:
  • msname (str) – Name of the measurement set

  • temporal_tol_factor (float, optional) – Tolerance factor for temporal variation (default : 0.1, 10%)

  • spectral_tol_factor (float, optional) – Tolerance factor for spectral variation (default : 0.1, 10%)

  • chan_range (str, optional) – Channel range

  • timestamp_range (str, optional) – Timestamp range

  • flag_central_chan (bool, optional) – Flag central channel

  • max_nchan (int, optional) – Maxmium number of spectral chunk

  • max_ntime (int, optional) – Maximum number of temporal chunk

Returns:

  • int – Number of time intervals to average

  • int – Number of channels to averages

paircars.utils.imaging.is_fft_good(n)[source]

Whether this number is good for FFTW or not

paircars.utils.killjob_utils module

paircars.utils.killjob_utils.kill_localscheduler(jobid)[source]

Kill local scheduler

Parameters:

jobid (int) – P-AIRCARS job ID

paircars.utils.killjob_utils.kill_port(port)[source]

Kill a running port

Parameters:

port (int) – Port number

paircars.utils.killjob_utils.kill_slurmscheduler(jobid)[source]

Kill local scheduler

Parameters:

jobid (int) – P-AIRCARS job ID

paircars.utils.killjob_utils.terminate_process_and_children(pid, grace_period=3.0)[source]

Try to gracefully terminate a process tree, then force kill if needed.

paircars.utils.logger_utils module

class paircars.utils.logger_utils.LogTailHandler(logfile, logger)[source]

Bases: FileSystemEventHandler

Continuous logging

on_modified(event)[source]

Called when a file or directory is modified.

Parameters:

event (DirModifiedEvent or FileModifiedEvent) – Event representing file/directory modification.

class paircars.utils.logger_utils.RemoteLogger(job_id='default', log_id='run_default', log_type='master', remote_link='', password='')[source]

Bases: Handler

Remote logging handler for posting log messages to a web endpoint.

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

class paircars.utils.logger_utils.SmartDefaultsHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Bases: ArgumentDefaultsHelpFormatter

class paircars.utils.logger_utils.StreamToLogger(logger, log_level=20)[source]

Bases: object

flush()[source]
write(message)[source]
paircars.utils.logger_utils.clean_shutdown(observer)[source]
paircars.utils.logger_utils.create_logger(logname, logfile)[source]

Create logger.

Parameters:
  • logname (str) – Name of the log

  • logfile (str, optional) – Log file name

Returns:

  • logger – Python logging object

  • str – Log file name

paircars.utils.logger_utils.generate_password(length=6)[source]

Generate secure 6-character password with letters, digits, and symbols

paircars.utils.logger_utils.get_emails()[source]
paircars.utils.logger_utils.get_logger_safe()[source]

Returns a logger that - Uses Prefect logger if inside a task/flow - Falls back to simple print-style logger otherwise

paircars.utils.logger_utils.get_logid(logfile)[source]

Get log id for remote logger from logfile name

paircars.utils.logger_utils.get_remote_logger_password()[source]
paircars.utils.logger_utils.init_logger(logname, logfile, log_type='task', jobname='', password='')[source]

Initialize a remote logger with watchdog-based tailing.

Parameters:
  • logname (str) – Logger name.

  • logfile (str) – Path to the local logfile to also monitor.

  • logtype (str, optional) – Log type (only allowed values: master | subflow | task)

  • jobname (str, optional) – Remote logger job ID.

  • password (str) – Password used for remote authentication.

Returns:

Observer object

Return type:

observer

paircars.utils.ms_metadata module

paircars.utils.ms_metadata.baseline_names(msname)[source]

Get baseline names

Parameters:

msname (str) – Measurement set name

Returns:

Baseline names list

Return type:

list

paircars.utils.ms_metadata.calc_fractional_bandwidth(msname)[source]

Calculate fractional bandwidh

Parameters:

msname (str) – Name of measurement set

Returns:

Fraction bandwidth in percentage

Return type:

float

paircars.utils.ms_metadata.check_datacolumn_valid(msname, datacolumn='DATA')[source]

Check whether a data column exists and valid

Parameters:
  • msname (str) – Measurement set

  • datacolumn (str, optional) – Data column string in table (e.g.,DATA, CORRECTED_DATA’, MODEL_DATA, FLAG, WEIGHT, WEIGHT_SPECTRUM, SIGMA, SIGMA_SPECTRUM)

Returns:

Whether valid data column is present or not

Return type:

bool

paircars.utils.ms_metadata.get_bad_ants(msname='', fieldnames=[], n_threads=-1)[source]

Get bad antennas

Parameters:
  • msname (str) – Name of the ms

  • fieldnames (list, optional) – Fluxcal field names

Returns:

  • list – Bad antenna list

  • str – Bad antenna string

paircars.utils.ms_metadata.get_chunk_size(msname, mem_limit=-1, only_autocorr=False)[source]

Get time chunk size for a memory limit

Parameters:
  • msname (str) – Measurement set

  • mem_limit (int, optional) – Memory limit

  • only_autocorr (bool, optional) – Only aut-correlation

Returns:

Number of chunks

Return type:

int

paircars.utils.ms_metadata.get_column_size(msname, only_autocorr=False)[source]

Get datacolumn size (Note: this is true datasize in memory)

Parameters:
  • msname (str) – Measurement set

  • only_autocorr (bool, optional) – Only auto-correlations

Returns:

A single datacolumn data size in GB

Return type:

float

paircars.utils.ms_metadata.get_common_spw(spw1, spw2)[source]

Return common spectral windows in merged CASA string format.

Parameters:
  • spw1 (str) – First spectral window (0:xx~yy)

  • spw2 (str) – Second spectral window (0:xx1~yy1)

Returns:

Merged spectral window

Return type:

str

paircars.utils.ms_metadata.get_ms_scan_size(msname, scan, only_autocorr=False)[source]

Get measurement set scan size

Parameters:
  • msname (str) – Measurement set

  • scan (int) – Scan number

  • only_autocorr (bool, optional) – Only for auto-correlations

Returns:

Size in GB

Return type:

float

paircars.utils.ms_metadata.get_ms_scans(msname)[source]

Get scans of the measurement set

Parameters:

msname (str) – Measurement set

Returns:

Scan list

Return type:

list

paircars.utils.ms_metadata.get_ms_size(msname, only_autocorr=False)[source]

Get measurement set total size on-disk (Note: it could be smaller than actual data size, because of data compression)

Parameters:
  • msname (str) – Measurement set name

  • only_autocorr (bool, optional) – Only auto-correlation

Returns:

Size in GB

Return type:

float

paircars.utils.ms_metadata.get_observatory_coord(msname)[source]

Get observatory coordinate

Parameters:

msname (str) – Measurement set

Returns:

  • float – Latitude in degrees

  • float – Longitude in degrees

  • float – Height in meters

paircars.utils.ms_metadata.get_observatory_name(msname)[source]

Get observatory name

Parameters:

msname (str) – Measurement set

Returns:

Observatory name in all upper case

Return type:

str

paircars.utils.ms_metadata.get_phasecenter(msname, fieldID=0)[source]

Get phasecenter of the measurement set

Parameters:
  • msname (str) – Name of the measurement set

  • fieldID (int, optional) – Zero based field ID

Returns:

  • float – RA in degree

  • float – DEC in degree

paircars.utils.ms_metadata.get_pol_names(msname, fullpol=True)[source]

Get correlation names

Parameters:
  • msname (str) – Measurement set

  • fullpol (bool, optional) – Full polarization products or not

Returns:

List of cross correlation product names

Return type:

list

paircars.utils.ms_metadata.get_refant(msname='', field='', n_threads=-1)[source]

Get reference antenna

Parameters:
  • msname (str) – Name of the measurement set

  • field (str, optional) – Field name

Returns:

Reference antenna

Return type:

str

paircars.utils.ms_metadata.get_timeranges(msname, time_interval, time_window, quack_timestamps=-1, only_disk=False)[source]

Get time ranges for a scan with certain time intervals

Parameters:
  • msname (str) – Name of the measurement set

  • time_interval (float) – Time interval in seconds between two time chunks

  • time_window (float) – Time window in seconds of a single time chunk

  • quack_timestamps (int, optional) – Number of timestamps ignored at the start and end of each scan

  • only_disk (bool, optional) – Whether select timestamps with disk visibilties

Returns:

List of time ranges

Return type:

list

paircars.utils.ms_metadata.get_uvrange_exclude(uvrange)[source]

Get uv-range(s) excluding the given uv-range

Parameters:

uvrange (str) – UV-range in CASA format

Returns:

List of uvranges excluding the given uv-range

Return type:

list

paircars.utils.ms_metadata.scans_in_timerange(msname='', timerange='')[source]

Get scans in the given timerange

Parameters:
  • msname (str) – Measurement set

  • timerange (str) – Time range with date and time

Returns:

Scan dict for timerange

Return type:

dict

paircars.utils.mwa_ploting_utils module

paircars.utils.mwa_ploting_utils.enhance_offlimb(sunpy_map, do_sharpen=True)[source]

Enhance off-disk emission

Parameters:
  • sunpy_map (sunpy.map) – Sunpy map

  • do_sharpen (bool, optional) – Sharpen images

Returns:

Off-disk enhanced emission

Return type:

sunpy.map

paircars.utils.mwa_ploting_utils.get_aia_map(obs_date, obs_time, workdir, obs_end_date='', obs_end_time='', aia_wavelength=193, ncpu=1)[source]

Get SDO AIA map

Parameters:
  • obs_date (str) – Observation date in yyyy-mm-dd format

  • obs_time (str) – Observation time in hh:mm format

  • workdir (str) – Work directory

  • obs_end_date (str, optional) – Observation end date in yyyy-mm-dd format

  • obs_end_time (str, optional) – Observation end time in hh:mm format

  • aia_wavelength (float, optional) – Wavelength, options: 94, 131, 171, 193, 211, 304, 335 Å

  • ncpu (int, optional) – Number of CPU to use for parallel download

Returns:

AIA fits files

Return type:

list

paircars.utils.mwa_ploting_utils.get_all_euv_maps(mwa_fits_images, workdir, wavelength=195, ncpu=1)[source]

Get all EUV maps for all MWA fits images

Parameters:
  • mwa_fits_images (list, str) – MWA FITS images list

  • workdir (str) – Work directory

  • wavelength (float, optional) – GOES SUVI/ SDO AIA wavelength, options: 94, 131, 171, 195(193), 284, 304 Å

  • ncpu (int, optional) – Number of CPU threads to use

Returns:

List of sunpy fits image names in same order of input images

Return type:

list

paircars.utils.mwa_ploting_utils.get_map_cached(mapfile)[source]
paircars.utils.mwa_ploting_utils.get_mwamap(fits_image, do_sharpen=False)[source]

Make MWA sunpy map

Parameters:
  • fits_image (str) – MWA fits image

  • do_sharpen (bool, optional) – Sharpen the image

Returns:

Sunpy map

Return type:

sunpy.map

paircars.utils.mwa_ploting_utils.get_suvi_map(obs_date, obs_time, workdir, obs_end_date='', obs_end_time='', suvi_wavelength=195, ncpu=1, keep_suvi_fits=False)[source]

Get GOES SUVI map

Parameters:
  • obs_date (str) – Observation date in yyyy-mm-dd format

  • obs_time (str) – Observation time in hh:mm format

  • workdir (str) – Work directory

  • obs_end_date (str) – Observation end date in yyyy-mm-dd format

  • obs_end_time (str) – Observation end time in hh:mm format

  • suvi_wavelength (float, optional) – Wavelength, options: 94, 131, 171, 195, 284, 304 Å

  • ncpu (int, optional) – Number of CPU threads to use for parallel download

  • keep_suvi_fits (bool, optional) – Keep SUVI fits file or not

Returns:

List of Sunpy SUVIMap

Return type:

list

paircars.utils.mwa_ploting_utils.make_ds_plot(dsfiles, plot_file=None, plot_quantity='TB', showgui=False)[source]

Make dynamic spectrum plot

Parameters:
  • dsfile (list) – DS files list

  • plot_file (str, optional) – Plot file name to save the plot

  • plot_quantity (str, optional) – Plot quantity (TB or flux)

  • showgui (bool, optional) – Show GUI

Returns:

Plot name

Return type:

str

paircars.utils.mwa_ploting_utils.make_mwa_overlay(mwa_image, euv_fits, workdir, plot_file_prefix, plot_mwa_colormap=True, enhance_offdisk=False, contour_levels=[0.05, 0.1, 0.2, 0.4, 0.6, 0.8], euv_image_scaling=0.5, do_sharpen_euv=True, xlim=[-2500, 2500], ylim=[-2500, 2500], extensions=['png'], outdirs=[], showgui=False, verbose=False)[source]

Make overlay of MWA image on GOES SUVI/ SDO AIA image

Parameters:
  • mwa_image (str) – MWA image

  • euv_fits (EUV image fits) – GOES SUVI/ SDO AIA EUV image fits

  • workdir (str) – Work directory

  • plot_file_prefix (str) – Plot file prefix name

  • plot_mwa_colormap (bool, optional) – Plot MWA map colormap

  • enhance_offdisk (bool, optional) – Enhance off-disk emission

  • contour_levels (list, optional) – Contour levels in fraction of peak

  • euv_image_scaling (float, optional) – EUV image pixel scaling (should be smaller than 1.0)

  • do_sharpen_euv (bool, optional) – Do sharpen EUV images

  • xlim (list, optional) – X-axis limit in arcsec

  • tlim (list, optional) – Y-axis limit in arcsec

  • extensions (list, optional) – Image file extensions

  • outdirs (list, optional) – Output directories for each extensions

  • verbose (bool, optinal) – Verbose output

Returns:

Plot file names

Return type:

list

paircars.utils.mwa_ploting_utils.plot_B_jones_freq_vs_gain(all_freqs, all_gains, all_ants, all_ant_names, ncols, nrows, pols, prefix, output_prefix, quantities=['amp', 'phase'], plot_all_ants=True)[source]

Plot freq vs. gain

paircars.utils.mwa_ploting_utils.plot_G_jones_time_vs_gain(all_times, all_gains, all_ants, all_ant_names, ncols, nrows, pols, prefix, output_prefix, quantities=['amp', 'phase'])[source]

Plot time vs. gain

paircars.utils.mwa_ploting_utils.plot_caltable_diagnostics(caltables, outfile_prefix, quantities=['amp', 'phase'], plot_all_ants=True)[source]

Plot diagonistic plot of casa caltables

Parameters:
  • caltables (list) – Caltable names

  • outfile_prefix (str) – Output plot file name prefix

  • quantities (list) – Quantities to plot (amp, phase)

  • plot_all_ants (bool, optional) – Plot all antennas or only the single one

Returns:

  • int – Success messsage

  • str – Output file

paircars.utils.mwa_ploting_utils.plot_goes_full_timeseries(msname, workdir, plot_file_prefix=None, extension='png', showgui=False)[source]

Plot GOES full time series on the day of observation

Parameters:
  • msname (str) – Measurement set

  • workdir (str) – Work directory

  • plot_file_prefix (str, optional) – Plot file name prefix

  • extension (str, optional) – Save file extension

  • showgui (bool, optional) – Show GUI

Returns:

Plot file name

Return type:

str

paircars.utils.mwa_ploting_utils.plot_hpc_collage(fits_images, draw_limb=True, power=0.5, xlim=[-3200, 3200], ylim=[-3200, 3200], outfile='collage.png', showgui=False)[source]

Plot a collage for spectral fits files

Parameters:
  • fits_images (list) – Fits images list

  • draw_limb (bool, optionnal) – Plot solar limb

  • power (float, optional) – Power stretch

  • xlim (list) – X-axis limit in arcseconds

  • ylim (list) – Y-axis limit in arcseconds

  • outfile (str, optional) – Output file name

  • showgui (bool, optional) – Show GUI

Returns:

Output file name

Return type:

str

paircars.utils.mwa_ploting_utils.plot_in_hpc(fits_image, draw_limb=False, extensions=['png'], outdirs=[], plot_range=[], power=0.5, xlim=[-3200, 3200], ylim=[-3200, 3200], contour_levels=[], showgui=False)[source]

Function to convert MWA image into Helioprojective co-ordinate

Parameters:
  • fits_image (str) – Name of the fits image

  • draw_limb (bool, optional) – Draw solar limb or not

  • extensions (list, optional) – Output file extensions

  • outdirs (list, optional) – Output directories for each extensions

  • plot_range (list, optional) – Plot range

  • power (float, optional) – Power stretch

  • xlim (list) – X axis limit in arcsecond

  • ylim (list) – Y axis limit in arcsecond

  • contour_levels (list, optional) – Contour levels in fraction of peak, both positive and negative values allowed

  • showgui (bool, optional) – Show GUI

Returns:

  • outfiles – Saved plot file names

  • sunpy.Map – MWA image in helioprojective co-ordinate

paircars.utils.mwa_ploting_utils.plot_ms_diagnostics(msname, outdir, ncpu=1, total_mem=1, verbose=False)[source]

Plot diagonistics plots for measurement set

Parameters:
  • msname (str) – Measurement set

  • outdir (str, optional) – Output directory

  • ncpu (int, optional) – Number of CPU threads

  • total_mem (float, optional) – Total memory in GB

  • verbose (bool, optional) – Verbose output

Returns:

  • int – Success message

  • list – Output plot file list

paircars.utils.mwa_ploting_utils.plot_quartical_tables(caltables, output_prefix, ncols=3, nrows=3)[source]

Plot quartical gaintables

Parameters:
  • caltables (list) – Quartical caltable list

  • output_prefix (str) – Output files names prefix

  • ncols (int, optional) – Number of columns in the plot

  • nrows (int, optional) – Number of rows in the plot

Returns:

  • int – Success message

  • list – Plot file names

paircars.utils.mwa_ploting_utils.rename_mwasolar_image(imagename, imagetype='image', imagedir='', pol='', cutout_rsun=10.0, make_plots=True, pol_selfcal=True, cal_sol=True)[source]

Rename and move image to image directory

Parameters:
  • imagename (str) – Image name

  • imagetype (str, optional) – Image type (image, model, residual)

  • imagedir (str, optional) – Image directory (default given image directory)

  • pol (str, optional) – Stokes parameters

  • cutout_rsun (float, optional) – Cutout in solar radii from center (default: 10.0 solar radii)

  • make_plots (bool, optional) – Make radio map plot in helioprojective coordinates

  • pol_selfcal (bool, optional) – Whether polarisation self-calibration solutions are applied

  • cal_sol (bool, optional) – Whether calibration solutions are applied or not

Returns:

New imagename with full path

Return type:

str

paircars.utils.mwa_ploting_utils.save_in_hpc(fits_image, outdir='', xlim=[], ylim=[])[source]

Save solar image in helioprojective coordinates

Parameters:
  • fits_image (str) – FITS image name

  • outdir (str, optional) – Output directory

  • xlim (list) – X axis limit in arcsecond

  • ylim (list) – Y axis limit in arcsecond

Returns:

FITS image in helioprojective coordinate

Return type:

str

paircars.utils.mwa_utils module

paircars.utils.mwa_utils.download_MWA_metafits(OBSID, outdir='.', max_tries=5)[source]

Download MWA metafits file for a given OBSID.

Parameters:
  • OBSID (int) – MWA observation ID

  • outdir (str) – Output directory

  • max_tries (int, optional) – Maximum trials

Returns:

Path to metafits file or None if failed

Return type:

str or None

paircars.utils.mwa_utils.freq_to_MWA_coarse(freq)[source]

Frequency to MWA coarse channel conversion.

Parameters:

freq (float) – Frequency in MHz

Returns:

MWA coarse channel number

Return type:

int

paircars.utils.mwa_utils.get_MWA_OBSID(msname)[source]

Get MWA OBSID from ms

Parameters:

msname (str) – Measurement set

Returns:

OBSid

Return type:

int

paircars.utils.mwa_utils.get_MWA_coarse_bands(msname, flag_central_chan=False)[source]

Get MWA coarse channel bands.

Parameters:
  • msname (str) – Name of the measurement set

  • flag_central_chan (bool, optional) – Flag central channel or not

Returns:

(start_chan, end_chan, good_chan_list)

Return type:

list of tuples

paircars.utils.mwa_utils.get_MWA_coarse_chan(msname)[source]

Get MWA coarse channel number

Parameters:

msname (str) – Measurement set

Returns:

Coarse channel numbers corresponding of the measurement set

Return type:

list

paircars.utils.mwa_utils.get_bad_chans(msname, flag_central_chan=False)[source]

Get bad channels to flag

Parameters:
  • msname (str) – Name of the ms

  • flag_central_chan (bool, optional) – Flag central channel

Returns:

SPW string of bad channels

Return type:

str

paircars.utils.mwa_utils.get_gleam_uvrange(msname)[source]

Get UV-range for GLEAM model

Parameters:

msname (str) – Measurement set

Returns:

UV-range in CASA format

Return type:

str

paircars.utils.mwa_utils.get_good_chans(msname)[source]

Get good channel range of MWA

Parameters:

msname (str) – Name of the ms

Returns:

SPW string

Return type:

str

paircars.utils.mwa_utils.get_mwa_bad_ants(metafits)[source]

Function to determine non-working MWA tiles for a observation

Parameters:

metafits (str) – Name of the metafits file

Returns:

Non-working antenna names

Return type:

str

paircars.utils.mwa_utils.get_ncoarse(msname)[source]

Get number of coarse channels

Parameters:

msname (str) – Measurement set

Returns:

Number of coarse channels

Return type:

int

paircars.utils.mwa_utils.get_selfcal_ntimes(msname)[source]

Number of timestamps to include in one self-calibration chunk It is determined based on the fact that MWA Phase-I provide ~2000 spectroscopic snapshot UV points with in 100lambda

Parameters:

msname (str) – Measurement set

Returns:

Number of time chunks

Return type:

int

paircars.utils.mwa_utils.get_selfcal_uvrange(msname)[source]

Get UV-range for self-calibration

Parameters:

msname (str) – Measurement set

Returns:

UV-range in CASA format

Return type:

str

paircars.utils.mwapb_utils module

paircars.utils.mwapb_utils.B2IQUV(B, iau_order=False)[source]

Convert sky brightness matrix to I, Q, U, V

Parameters:
  • B (numpy.array) – Brightness matrix array

  • iau_order (bool, optional) – Whether brightness matrix is in IAU or MWA convention

Returns:

Stokes dictionary

Return type:

dict

paircars.utils.mwapb_utils.all_sky_beam_interpolator(sweet_spot_num, freq, resolution, ncpu=-1, MWA_PB_file='', sweet_spot_file='', iau_order=False)[source]

Calculate all sky beam interpolation for given sweet spot pointing

Parameters:
  • sweet_spot_num (int) – Sweet spot number

  • freq (float) – Frequency in MHz

  • resolution (float) – Spatial resolution in degree

  • ncpu (int, optional) – Number of CPU threads to use

  • MWA_PB_file (str, optional) – MWA primary beam file

  • sweet_spot_file (str, optional) – MWA sweet spot file name

  • iau_order (bool, optional) – PB Jones in IAU order or not

Returns:

All sky primary beam Jones array

Return type:

numpy.array

paircars.utils.mwapb_utils.get_IQUV(filename, stokesaxis=4)[source]

Get IQUV from a fits file

paircars.utils.mwapb_utils.get_azza_from_fits(filename, metafits)[source]

Get azimuith and zenith angle arrays from fits file

Parameters:
  • filename (str) – Name of the fits file

  • metafits (str) – Metafits file

Returns:

{‘za_rad’: theta,’astro_az_rad’: phi}

Return type:

dict

paircars.utils.mwapb_utils.get_coarse_resolution(freq)[source]

Get coarse sptial resolution based on frequency

Parameters:

freq (float) – Frequency in MHz

Returns:

Spatial resolution in degree

Return type:

float

paircars.utils.mwapb_utils.get_fringe(msname, freq, metafits, resolution=1, n_threads=1, baseline=[])[source]

Function to calculate all sky fringe of a baseline

Parameters:
  • msname (str) – Name of the measurement set

  • freq (float) – Frequency in MHz

  • metafits (str) – Name of the metafits file

  • resolution (float, optional) – Beam resolution in degree (default : 1deg)

  • n_threads (int, optional) – Number of cpu threads use for parallel computing

  • baseline (list, optional) – Antenna list of a baseline

Returns:

All-sky fringe array in sky coornidinate

Return type:

np.array

paircars.utils.mwapb_utils.get_haslam(freq, scaling=-2.55)[source]

Get the Haslam 408 MHz all sky map extrapolated to desired frequency.

Parameters:
  • freq (float) – Frequency in MHz

  • scaling (float, optional) – Power law index for extrapolation (default : -2.55)

Returns:

A python dictionary i) Haslam map at given frequency in 10xK unit ii) RA in degree iii) DEC in degree

Return type:

dict

paircars.utils.mwapb_utils.get_image_info(image)[source]

Get the image data and its coordinates

Parameters:

image (str) – Name of the image

Returns:

A python dictionary
  1. Map

  2. RA in degree

  3. DEC in degree

Return type:

dict

paircars.utils.mwapb_utils.get_inst_pols(stokes, iau_order=True)[source]

Return instrumental polaristations matrix (Vij)

paircars.utils.mwapb_utils.get_jones_array(alt_arr, az_arr, freq, gridpoint, ncpu=-1, interpolated=True, MWA_PB_file='', sweet_spot_file='', iau_order=False)[source]

Get primary beam jones matrix

Parameters:
  • alt_arr (numpy.array) – Flattened altitude array in degrees

  • az_arr (numpy.array) – Flattened azimuth array in degrees

  • freq (float) – Frequency in MHz

  • gridpoint (int) – Gridpoint number

  • ncpu (int, optional) – Number of CPU threads to use

  • interpolated (bool, optional) – Use spatially interpolated beams or not

  • MWA_PB_file (str, optional) – Primary beam file name

  • sweet_spot_file (str, optional) – MWA sweet spot file name

  • iau_order (bool, optional) – IAU order of the beam

Returns:

Jones array (shape : coordinate_arr_shape, 2 ,2)

Return type:

numpy.array

paircars.utils.mwapb_utils.get_pb_radec(ra, dec, freq, metafits, ncpu=-1, MWA_PB_file='', sweet_spot_file='', iau_order=False)[source]

Function to get MWA primary beam at specific RA, DEC

Parameters:
  • ra (str) – RA either in degree or ‘hh:mm:ss’ or ‘%fh%fm%fs’ format

  • dec (str) – DEC either in degree or ‘dd:mm:ss’ or ‘%fd%fm%fs’format

  • freq (float) – Frequency in MHz

  • metafits (str) – MWA metafits file

  • ncpu (int, optional) – Number of CPU threads

  • MWA_PB_file (str, optional) – MWA primary beam file path

  • sweet_spot_file (str, optional) – Sweetspot file name

  • iau_order (bool, optional) – Beam Jones in IAU order or not

Returns:

  • int – Success message (0 or 1)

  • np.array – Jones matrix

  • float – Stokes I beam value

  • float – XX power beam value

  • float – YY power beam value

paircars.utils.mwapb_utils.horz2eq(az, ZA, obstime)[source]

Convert from horizontal (az, ZA) to equatorial (RA, dec)grid2eq = horz2eq(az_grid, za_grid, obstime)

Parameters:
  • az (np.array) – Grid of azes onto which we map sky

  • za (np.array) – Grid of ZAs onto which we map sky

  • obstime (str) – Time of the observation in ‘yyyy-mm-dd hh:mm:ss’ format

Returns:

A python dictionary {‘RA’ : degress, ‘DEC’ : degrees}

Return type:

dict

paircars.utils.mwapb_utils.makeAZZA_dOMEGA(npix, projection='SIN')[source]

Make azimuth and zenith angle arrays for a square image of side npix

Parameters:
  • npix (int) – Number of pixels of the grid

  • projection (str, optional) – SIN or ZEA

Returns:

  • list – Azimuth angles in radians

  • list – Zenith angle in radians

  • int – Total number of pixels above the horizon

  • float – Differential solid angle (dOMEGA)

paircars.utils.mwapb_utils.make_primarybeammap(msname, metafits, baselines=[], freq=0, obstime='', resolution=1, iau_order=True, MWA_PB_file='', sweet_spot_file='', n_threads=1, calc_fringe_temp=False)[source]
Parameters:
  • msname (str) – Measurement set

  • metafits (str) – Metafits file

  • freq (float, optional) – Frequency in MHz

  • obstime (str, optional) – Time of the observation in ‘yyyy-mm-dd hh:mm:ss’ format (If not given automatically obtain from metafits file)

  • resolution (float, optional) – Beam resolution in degree (default : 1deg)

  • iau_order (bool, optional) – Beam in IAU order or not

  • MWA_PB_file (str, optional) – MWA primary beam file path

  • sweet_spot_file (str, optional) – MWA sweet spot file

  • n_threads (int, optional) – Number of cpu threads use for parallel computing

  • calc_fringe_temp (bool, optional) – Calculate temperature contribution of the baseline

Returns:

  • float – Sum of full Beam*Sky (XX)

  • float – Sum of full Beam (XX)

  • float – Antenna temperature (XX)

  • float – Total beam area (XX)

  • float – Sum of full Beam*Sky (YY)

  • float – Sum of full Beam (YY)

  • float – Antenna temperature (YY)

  • float – Total beam area (YY)

paircars.utils.mwapb_utils.map_sky(skymap, RA, dec, az_grid, za_grid, obstime='')[source]

Reprojects Haslam map onto an input az, ZA grid.

Parameters:
  • skymap (np.array) – Haslam map in RA DEC

  • RA (np.array) – 1D range of RAs (deg)

  • dec (np.array) – 1D range of decs (deg)

  • az_grid (np.array) – Grid of azes onto which we map sky

  • za_grid (np.array) – Grid of ZAs onto which we map sky

  • obstime (str, optional) – Time of the observation in ‘yyyy-mm-dd hh:mm:ss’ format

Returns:

Sky map

Return type:

numpy.array

paircars.utils.mwapb_utils.map_sky_haslam(skymap, RA, dec, az_grid, za_grid, obstime='')[source]

Reprojects Haslam map onto an input az, ZA grid.

Parameters:
  • skymap (np.array) – Haslam map in RA DEC

  • RA (np.array) – 1D range of RAs (deg)

  • dec (np.array) – 1D range of decs (deg)

  • az_grid (np.array) – Grid of azes onto which we map sky

  • za_grid (np.array) – Grid of ZAs onto which we map sky

  • obstime (str, optional) – Time of the observation in ‘yyyy-mm-dd hh:mm:ss’ format

Returns:

Sky map array

Return type:

numpy.array

paircars.utils.prefect_logger_utils module

paircars.utils.prefect_setup_utils module

paircars.utils.prefect_setup_utils.get_prefect_env(scheduler_name='local')[source]

Get environment variables of prefect

Parameters:

scheduler_name (str, optional) – Scheduler name

Returns:

Environment dictionary

Return type:

dict

paircars.utils.prefect_setup_utils.prefect_config(port, postgres_port, scheduler_name='local')[source]

Configure prefect

Parameters:
  • port (int) – Free port

  • postgres_port (int) – Postgres server port

  • scheduler_name (str, optional) – Scheduler name

Returns:

  • str – Configuration file name

  • dict – Configuration dictionary

paircars.utils.prefect_setup_utils.prefect_server_status(scheduler_name='local')[source]

Get prefect server status

Parameters:

scheduler_name (str, optional) – Scheduler name

paircars.utils.prefect_setup_utils.save_prefect_env_to_file(scheduler_name='local')[source]

Save current Prefect server env config to a .env file for reuse.

Parameters:

scheduler_name (str, optional) – Scheduler name

Returns:

  • str – Profile file

  • str – Environment file

  • str – Dashboard file

paircars.utils.prefect_setup_utils.show_prefect_config(scheduler_name='local')[source]

Print the effective Prefect config in this environment.

Parameters:

scheduler_name (str, optional) – Scheduler name

paircars.utils.prefect_setup_utils.start_prefect_server(port, postgres_port, show_config=False, scheduler_name='local')[source]

Start prefect server if it is not running

Parameters:
  • port (int) – Free port number

  • postgres_port (int) – Postgres port

  • show_config (bool, optional) – Show configuration of prefect server

  • scheduler_name (str, optional) – Scheduler name

Returns:

  • 0, config_file, profile_path, env_file, dashboard, pid_file

  • int – Success message

  • str – Configuration file

  • str – Profile file

  • str – Environment file

  • str – Dashboard file

  • str – Server process ID file

paircars.utils.prefect_setup_utils.stop_prefect_server(scheduler_name='local')[source]

Stop prefect server running in the current installation Note: it will only stop prefect server which is running from the current installation For this pipeline, a port between 4260 to 5250 is chosen for P-AIRCARS.

Parameters:

scheduler_name (str, optional) – Scheduler name

Returns:

Success message

Return type:

int

paircars.utils.prefect_setup_utils.write_prefect_profile(scheduler_name='local')[source]

Save prefect profile

Parameters:

scheduler_name (str, optional) – Scheduler name

Returns:

Profile file

Return type:

str

paircars.utils.proc_manage_utils module

paircars.utils.proc_manage_utils.detect_best_interface(scheduler_ip=None)[source]

Automatically detect best IPv4 network interface for Dask.

Parameters:

scheduler_ip (str, optional) – If provided, ensures selected interface can route to this IP.

Returns:

Best interface name or None if not found.

Return type:

str or None

paircars.utils.proc_manage_utils.get_jobid()[source]

Get Job ID with millisecond-level uniqueness.

Returns:

Job ID in the format YYYYMMDDHHMMSSmmm (milliseconds)

Return type:

int

paircars.utils.proc_manage_utils.get_local_dask_cluster(dask_dir, cpu_frac=0.8, mem_frac=0.8, min_mem=2, max_worker=-1, spill_frac=0.7, wait_time=10.0, verbose=True)[source]

Create a local Dask cluster

Parameters:
  • dask_dir (str) – Dask temporary directory

  • cpu_frac (float, optional) – CPU fraction to use

  • mem_frac (float, optional) – Fraction of total memory to use

  • min_mem (float, optional) – Minimum required per job memory in GB

  • max_worker (int, optional) – Maximum worker

  • spill_frac (float, optional) – Spill to disk at this fraction

  • wait_time (float, optional) – Wait time in seconds

  • verbose (bool, optional) – Verbose (details of cluster)

Returns:

  • client (dask.distributed.Client) – Dask client

  • cluster (dask.distributed.LocalCluster) – Dask cluster

  • str – Dask directory

  • int – Number of workers

paircars.utils.proc_manage_utils.get_scheduler_name()[source]

Get job scheduler available

Returns:

Scheduler name (local, pbs, slurm)

Return type:

str

paircars.utils.proc_manage_utils.get_total_nodes(partition=None)[source]

Get total nodes

Parameters:

partitiion (str, optional) – Partition or queue (depending on type of scheduler)

Returns:

Total node number

Return type:

int

paircars.utils.proc_manage_utils.get_total_worker(client)[source]

Get total workers in the cluster

Parameters:

client (dask.client) – Dask client for the cluster

Returns:

Number of workers

Return type:

int

paircars.utils.proc_manage_utils.save_main_process_info(pid, jobid, scheduler_address, msdir, workdir, outdir, cpu_frac, mem_frac)[source]

Save main processes info

Parameters:
  • pid (int) – Main job process id for local cluster or scheduler job id

  • jobid (int) – Job ID

  • scheduler_address (str) – Dask scheduler address

  • msdir (str) – Measurement set directory

  • workdir (str) – Work directory

  • outdir (str) – Output directory

  • cpu_frac (float) – CPU fraction of the job

  • mem_frac (float) – Memory fraction of the job

Returns:

Job info file name

Return type:

str

paircars.utils.proc_manage_utils.scale_worker_and_wait(dask_cluster, dask_client, nworker, timeout=60)[source]

Scale worker and wait until it is done

Parameters:
  • dask_cluster (dask.cluster) – Dask cluster

  • dask_client (dask.client) – Dask client for the same cluster

  • nworker (int) – Number of worker

  • timeout (float, optional) – Timeout, show a warning and move

paircars.utils.proc_manage_utils.submit_local_master_flow(args, jobid)[source]

Submit P-AIRCARS master flow to a local cluster

Parameters:
  • args (dict) – Arparser dictionary

  • jobid (int) – P-AIRCARS jobid

Returns:

Success message

Return type:

int

paircars.utils.resource_utils module

paircars.utils.resource_utils.drop_cache(path, verbose=False)[source]

Drop file cache for a file or all files under a directory.

Parameters:

path (str) – File or directory path

paircars.utils.resource_utils.drop_file_cache(filepath, verbose=False)[source]

Advise the OS to drop the given file from the page cache. Safe, per-file, no sudo required.

paircars.utils.resource_utils.has_space(path, required_gb)[source]
paircars.utils.resource_utils.limit_threads(n_threads=-1)[source]

Limit number of threads usuage

Parameters:

n_threads (int, optional) – Number of threads

paircars.utils.resource_utils.shm_or_tmp(required_gb, workdir, prefix='solar_', verbose=False)[source]

Create a temporary working directory: 1. Try /dev/shm if it has required space 2. Else TMPDIR if set and has space 4. Else work directory Temporarily sets TMPDIR to the selected path during the context. Cleans up after use.

Parameters:
  • required_gb (float) – Required disk space in GB

  • workdir (str) – Fall back work directory

  • prefix (str, optional) – Temp directory prefix

  • verbose (bool, optional) – Verbose

paircars.utils.resource_utils.tmp_with_cache_rel(required_gb, workdir, prefix='solar_', verbose=False)[source]

Combined context manager: - Uses shm_or_tmp() for workspace - Drops kernel page cache for all files in that directory on exit

Parameters:
  • required_gb (float) – Required disk space in GB

  • workdir (str) – Fall back work directory

  • prefix (str, optional) – Temp directory prefix

  • verbose (bool, optional) – Verbose

paircars.utils.selfcal_utils module

paircars.utils.selfcal_utils.cal_crossphase(imagename)[source]

Function to calculate Stokes U, V leakage through correlation analysis

Parameters:

imagename (str) – FITS image

Returns:

Cross hand phase

Return type:

float

paircars.utils.selfcal_utils.calc_leakage(imagename, threshold=5, disc_size=50)[source]

Calculate Stokes I to Q, U, V leakages

Parameters:
  • imagename (str) – Image name

  • threshold (float) – Threshold to choose region with Stokes I detection

  • disc_size (float) – Solar disc area in arcminute to mask for calculating rms N.B.: Chosen slightly larger to avoid any off-coronal emission from CMEs

Returns:

  • float – Stokes I to Q leakage

  • float – Stokes I to U leakage

  • float – Stokes I to V leakage

  • float – Stokes I to Q leakage error

  • float – Stokes I to U leakage error

  • float – Stokes I to V leakage error

paircars.utils.selfcal_utils.check_valid_image(imagename)[source]

Check whether the image is valid or not

Parameters:

imagename (str) – Image name

Returns:

Whether valid image or not

Return type:

bool

paircars.utils.selfcal_utils.correct_image_leakage(imagename, modelname='', q_leakage=0.0, u_leakage=0.0, v_leakage=0.0, threshold=5, disc_size=50)[source]

Correct leakages in image plane

Parameters:
  • imagename (str) – Image name

  • modelname (str, optional) – Model name

  • q_leakage (float, optional) – Q leakage

  • u_leakage (float, optional) – U leakage

  • v_leakage (float, optional) – V leakage

  • threshold (float) – Threshold to choose region with Stokes I detection

  • disc_size (float) – Solar disc area in arcminute to mask for calculating rms N.B.: Chosen slightly larger to avoid any off-coronal emission from CMEs

Returns:

  • str – Leakage corrected imagename

  • str – Leakage corrected modelname

paircars.utils.selfcal_utils.correct_pbcor_leakage(imagename, modelname, metafits, pbcor=True, leakagecor=True, pbuncor=True, ncpu=1)[source]

Perform primary beam and leakage correction

Parameters:
  • imagename (str) – Image name

  • modelname (str) – Model image name

  • metafits (str) – Metafits file

  • pbcor (bool, optional) – Perform primary beam correction

  • leakagecor (bool, optional) – Perform image based residual leakage correction

  • pbuncor (bool, optional) – Undo primary beam correction

  • ncpu (int, optional) – Number of CPU threads

Returns:

  • str – Final image

  • str – Final model

  • list – Leakage and leakage error list

paircars.utils.selfcal_utils.correct_spectrosnap_pbleak(image_dic, model_dic, metafits, logger=None, pbcor=True, leakagecor=True, pbuncor=True, ncpu=-1)[source]

Correct spectrocopic snapshot images for leakage

Parameters:
  • image_dic (dict) – Image dictionary

  • model_dic (dict) – Model dictionary

  • metafits (str) – Metafits file

  • logger (logger, optional) – Python logger

  • pbcor (bool, optional) – Perform primary beam correction

  • leakagecor (bool, optional) – Leakage correction

  • pbuncor (bool, optional) – Undo primary beam correction

  • ncpu (int, optional) – Number of CPU threads to use

Returns:

Leakage information list

Return type:

list

paircars.utils.selfcal_utils.correct_spectrosnap_phaseshift(image_dic, model_dic, cellsize, imsize, stokes, logger)[source]

Correct spectrocopic snapshot images for phase shift

Parameters:
  • image_dic (dict) – Image dictionary

  • model_dic (dict) – Model dictionary

  • cellsize (float) – Pixel size in arcsecond

  • imsize (int) – Image size

  • stokes (str) – Stokes planes of image list

  • logger (logger, optional) – Python logger

Returns:

  • int – Success message

  • bool – If shift needed for any image

  • int – Maximum pixel offset

paircars.utils.selfcal_utils.determine_disk_visibility(msname)[source]

Determine whether solar disk is visible or not

Parameters:

msname (str) – Measurement set

Returns:

  • numpy.array – Channel list where disk may not be detected

  • numpy.array – Timestamp list where disk may not be detected

  • numpy.array – Timestamps where disk is detected at least in one channel

paircars.utils.selfcal_utils.do_uvsub_flag(msname, threshold_list=[10, 7, 5], ncpu=1)[source]

Perform uv-sub flags

Parameters:
  • msname (str) – Measurement set

  • threshold_list (list, optional) – Threshold list

  • ncpu (int, optional) – Number of CPU threads to use

paircars.utils.selfcal_utils.flag_non_disk(msname)[source]

Flag spectro-temporal blocks when solar disk is not visible

Parameters:

msname (str) – Measurement set

paircars.utils.selfcal_utils.get_quiet_sun_flux(freq)[source]

Get quiet Sun flux density in Jy.

Parameters:

freq (float) – Frequency in MHz

Returns:

Flux density in Jy

Return type:

float

paircars.utils.selfcal_utils.make_qs_model(msname, clname='quiet_sun.cl')[source]

Make CASA component list of quiet Sun model

Parameters:
  • msname (str) – Name of the measurement set

  • clname (str, optional) – Name of the component list

Returns:

Name of the component list file

Return type:

str

paircars.utils.selfcal_utils.quiet_sun_selfcal(msname, logger, selfcaldir, refant='1', solint='60s')[source]

Perform quiet Sun Gaussian model based self-calibration

Parameters:
  • msname (str) – Measurement set

  • logger (str) – Python logger

  • selfcaldir (str) – Self-calibration directory

  • refant (str, optional) – Reference antenna

  • solint (str, optional) – Solution interval

Returns:

  • int – Success message

  • str – Caltable name

paircars.utils.selfcal_utils.selfcal_round(msname, metafits, logger, selfcaldir, cellsize, imsize, round_number=0, uvrange='', minuv=0, calmode='ap', solint='60s', solnorm=True, refant='1', do_bandpass=True, applymode='calonly', threshold=3, weight='briggs', robust=0.0, use_previous_model=False, use_solar_mask=True, mask_radius=40, min_tol_factor=-1, calc_chunks=True, fluxscale_mwa=False, solar_attn=10, pbcor=True, leakagecor=True, pbuncor=True, do_intensity_cal=False, do_polcal=False, solve_array_leakage=False, pol_solnorm=False, do_flag=False, restore_flag=True, ncpu=-1, mem=-1)[source]

A single self-calibration round

Parameters:
  • msname (str) – Name of the measurement set

  • metafits (str) – Metafits file

  • logger (logger) – Python logger

  • selfcaldir (str) – Self-calibration directory

  • cellsize (float) – Cellsize in arcsec

  • imsize (int) – Image pixel size

  • round_number (int, optional) – Selfcal iteration number

  • uvrange (float, optional) – UV range for calibration

  • minuv (float, optional) – Minimum uv in lambda

  • calmode (str, optional) – Calibration mode (‘p’ or ‘ap’)

  • solint (str, optional) – Solution intervals

  • solnorm (bool, optional) – Solution normalisation

  • refant (str, optional) – Reference antenna

  • do_bandpass (bool, optional) – Perform bandpass calibration

  • applymode (str, optional) – Solution apply mode (calonly or calflag)

  • threshold (float, optional) – Imaging and auto-masking threshold

  • weight (str, optional) – Image weighting

  • robust (float, optional) – Robust parameter for briggs weighting

  • use_previous_model (bool, optional) – Use previous model

  • use_solar_mask (bool, optional) – Use solar disk mask or not

  • mask_radius (float, optional) – Mask radius in arcminute

  • min_tol_factor (float, optional) – Minimum tolerance factor

  • calc_chunks (bool, optional) – Whether calculate spectro-temporal chunks or not

  • fluxscale_mwa (bool, optional) – Fluxscale caltable using reference bandpass

  • solar_attn (float, optional) – Solar attenuation in dB (only used if fluxscale_mwa is True)

  • pbcor (bool, optional) – Primary beam correction

  • leakagecor (bool, optional) – Leakage correction

  • pbuncor (bool, optional) – Undo primary beam correction

  • do_intensity_cal (bool, optional) – Perform intensity self-calibration

  • do_polcal (bool, optional) – Perform polarisation calibration or not

  • solve_array_leakage (bool, optional) – Perform a single leakage correction over the entire array

  • pol_solnorm (bool, optional) – Normalise quartical solutions or not

  • do_flag (bool, optional) – Perform UVsub flagging

  • restore_flag (bool, optional) – Restore last round flags or not

  • ncpu (int, optional) – Number of CPUs to use in WSClean

  • mem (float, optional) – Memory usage limit in WSClean

Returns:

  • int – Success message

  • list – Caltable name list

  • float – RMS based dynamic range

  • float – RMS of the image

  • str – Image name

  • str – Model image name

  • str – Residual image name

  • list – Leakage informations [Q_leakage, U_leakage, V_leakage, Q_leakage_error, U_leakage_error, V_leakage_error]

  • int – Maximum pixel offset

paircars.utils.selfcal_utils.single_image_update_leakage(wsclean_images, wsclean_models, image_cube, model_cube, metafits, pbcor=True, leakagecor=True, pbuncor=True, ncpu=-1)[source]

Update leakage of a single set pf polarisation image

Parameters:
  • wsclean_images (list) – List of wsclean Stokes images

  • wsclean_models (list) – List of wsclean Stokes models

  • image_cube (str) – Stokes image cube name

  • model_cube (str) – Stokes model cube name

  • metafits (str) – Metafits file

  • pbcor (bool, optional) – Perform primary beam correction or not

  • leakagecor (bool, optional) – Perform leakage correction or not

  • pbuncor (bool, optional) – Undo primary beam correction or not

  • ncpu (int, optional) – NUmber of CPU threads to use

Returns:

Leakage informations

Return type:

list

paircars.utils.selfcal_utils.single_image_update_phasecenter(wsclean_images, wsclean_models, image_cube, model_cube, cellsize, imsize, stokes, logger)[source]

Update phase center of a single set of polarisation image

Parameters:
  • wsclean_images (list) – List of wsclean Stokes images

  • wsclean_models (list) – List of wsclean Stokes models

  • image_cube (str) – Stokes image cube name

  • model_cube (str) – Stokes model cube name

  • cellsize (float) – Pixel size in arcseconds

  • imsize (int) – Image size

  • stokes (str) – Stokes planes of image cube

Returns:

  • int – Success message

  • bool – Whether phase shift needed or not

  • float – Maximum offset in pixel

paircars.utils.sunpos_utils module

paircars.utils.sunpos_utils.cal_solar_phaseshift(imagename, sigma=10)[source]

Calculate the difference between solar center and phase center of the image

Parameters:
  • imagename (str) – Name of the image

  • sigma (float) – If Gaussian fitting is not used, threshold for estimating center of mass as solar center (default =10)

Returns:

  • int – Success message

  • float – RA of the apparent solar center in degree

  • float – DEC of the apparent solarcenter in degree

  • float – RA of true solarcenter in degree

  • float – DEC of true solarcenter in degree

  • int – Apparent RA pixel of solarcenter

  • int – Apparent DEC pixel of solarcenter

  • float – Shift size in arcseconds

paircars.utils.sunpos_utils.correct_solar_sidereal_motion(msname='', ncpu=1, verbose=False)[source]

Correct sodereal motion of the Sun

Parameters:
  • msname (str) – Name of the measurement set

  • ncpu (int, optional) – Number of CPU threads to use

Returns:

Success message

Return type:

int

paircars.utils.sunpos_utils.get_solar_elevation(lat, lon, elev, date_time)[source]

Get solar elevation

Parameters:
  • lat (float) – Latitude in degrees

  • lon (float) – Longitude in degrees

  • elev (float) – Elevation in degrees

  • date_time (str) – Date time in YYYY-MM-DDThh:mm:ss (ISOT) format, default : present time

Returns:

Solar elevation in degree

Return type:

float

paircars.utils.sunpos_utils.move_to_sun(msname, ncpu=1, only_uvw=False)[source]

Move the phasecenter of the measurement set at the center of the Sun (Assuming ms has one scan)

Parameters:
  • msname (str) – Name of the measurement set

  • ncpu (int, optional) – Number of CPU threads to use

  • only_uvw (bool, optional) – Note: This is required when visibilities are properly phase rotated in correlator to track the Sun, but while creating the MS, UVW values are estimated using a wrong phase center at the start of solar center at the start.

Returns:

Success message

Return type:

int

paircars.utils.sunpos_utils.radec_sun(msname)[source]

RA DEC of the Sun at the midpoint of scan (offline version)

Parameters:

msname (str) – Name of the measurement set

Returns:

  • str – RA DEC of the Sun in J2000

  • str – RA string

  • str – DEC string

  • float – RA in degree

  • float – DEC in degree

paircars.utils.sunpos_utils.radec_sun_at_time(timestamp)[source]

RA DEC of the Sun a given time

Parameters:

timestamp (str) – Time in format dd-mm-yyyyThh:mm:ss

Returns:

  • str – RA DEC of the Sun in J2000

  • str – RA string

  • str – DEC string

  • float – RA in degree

  • float – DEC in degree

paircars.utils.sunpos_utils.shift_solarcenter(imagename, sigma=10, sun_radeg=None, sun_decdeg=None, apparent_pix_ra=None, apparent_pix_dec=None, overwrite=True)[source]

Function to shift solar center to image phase center

Parameters:
  • imagename (str) – Name of the image

  • sigma (float, optional) – Sigma threshold for masking solar disk

  • sun_radeg (float, optional) – Sun RA in degree

  • sun_decdeg (float, optional) – Sun DEC in degree

  • apparent_pix_ra (int, optional) – Apparent solar center pixel in RA

  • apparent_pix_dec (int, optional) – Apparent solar center pixel in DEC

  • overwrite (bool, optional) – Overwrite existing image or not

Returns:

  • int – Success code 0: Successfully shifted, 1: Shifting is not required, 2: Error in shifting

  • str – Output image name

  • bool – Shifted or not

  • int – Maximum pixel offset

paircars.utils.udocker_utils module

paircars.utils.udocker_utils.check_udocker_container(name)[source]

Check whether a docker container is present or not

Parameters:

name (str) – Container name

Returns:

Whether present or not

Return type:

bool

paircars.utils.udocker_utils.init_udocker()[source]
paircars.utils.udocker_utils.initialize_container(image_name, name, update=False, verbose=False)[source]

Initialize container

Parameters:
  • image_name (str) – Docker image name

  • name (str) – Container name

  • update (bool, optional) – Update or not

  • verbose (bool, optional) – Verbose output

Returns:

Whether initialized successfully or not

Return type:

bool

paircars.utils.udocker_utils.initialize_hyperbeam_container(name='paircarshyperbeam', update=False, verbose=False)[source]

Initialize hyperbeam container

Parameters:
  • name (str, optional) – Name of the container

  • update (bool, optional) – Update container

  • verbose (bool, optional) – Verbose output

Returns:

Whether initialized successfully or not

Return type:

bool

paircars.utils.udocker_utils.initialize_hyperdrive_container(name='paircarshyperdrive', update=False, verbose=False)[source]

Initialize hyperdrive container

Parameters:
  • name (str, optional) – Name of the container

  • update (bool, optional) – Update container

  • verbose (bool, optional) – Verbose output

Returns:

Whether initialized successfully or not

Return type:

bool

paircars.utils.udocker_utils.initialize_postgres_container(name='paircarspostgres', update=False, verbose=False)[source]

Initialize postgres container

Parameters:
  • name (str, optional) – Name of the container

  • update (bool, optional) – Update container

  • verbose (bool, optional) – Verbose output

Returns:

Whether initialized successfully or not

Return type:

bool

paircars.utils.udocker_utils.initialize_quartical_container(name='paircarsquartical', update=False, verbose=True)[source]

Initialize quartical container

Parameters:
  • name (str, optional) – Name of the container

  • update (bool, optional) – Update container

  • verbose (bool, optional) – Verbose output

Returns:

Whether initialized successfully or not

Return type:

bool

paircars.utils.udocker_utils.initialize_shadems_container(name='paircarsshadems', update=False, verbose=False)[source]

Initialize shadems container

Parameters:
  • name (str, optional) – Name of the container

  • update (bool, optional) – Update container

  • verbose (bool, optional) – Verbose output

Returns:

Whether initialized successfully or not

Return type:

bool

paircars.utils.udocker_utils.initialize_wsclean_container(name='paircarswsclean', update=False, verbose=False)[source]

Initialize WSClean container

Parameters:
  • name (str, optional) – Name of the container

  • update (bool, optional) – Update container

Returns:

Whether initialized successfully or not

Return type:

bool

paircars.utils.udocker_utils.kill_postgres(postgres_port=5432, container_name='paircarspostgres', verbose=False)[source]

Kill postgres server

Parameters:
  • postgres_port (int, optional) – Postgres server

  • container_name (str, optional) – Container name

Returns:

Whether closed or not

Return type:

int

paircars.utils.udocker_utils.run_chgcenter(msname, ra, dec, only_uvw=False, ncpu=1, container_name='paircarswsclean', check_container=False, verbose=False)[source]

Run chgcenter inside a udocker container (no root permission required).

Parameters:
  • msname (str) – Name of the measurement set

  • ra (str) – RA can either be 00h00m00.0s or 00:00:00.0

  • dec (str) – Dec can either be 00d00m00.0s or 00.00.00.0

  • ncpu (bool, optional) – Number of CPU threads to use

  • only_uvw (bool, optional) – Update only UVW values Note: This is required when visibilities are properly phase rotated in correlator, but while creating the MS, UVW values are estimated using a wrong phase center.

  • check_container (bool, optional) – Check container

  • container_name (str, optional) – Container name

  • verbose (bool, optional) – Verbose output

Returns:

Success message

Return type:

int

paircars.utils.udocker_utils.run_hyperdrive(hyperdrive_cmd, ncpu=1, container_name='paircarshyperdrive', check_container=False, verbose=False)[source]

Run chgcenter inside a udocker container (no root permission required).

Parameters:
  • msname (str) – Name of the measurement set

  • ra (str) – RA can either be 00h00m00.0s or 00:00:00.0

  • dec (str) – Dec can either be 00d00m00.0s or 00.00.00.0

  • only_uvw (bool, optional) – Update only UVW values Note: This is required when visibilities are properly phase rotated in correlator, but while creating the MS, UVW values are estimated using a wrong phase center.

  • check_container (bool, optional) – Check container

  • container_name (str, optional) – Container name

  • verbose (bool, optional) – Verbose output

Returns:

Success message

Return type:

int

paircars.utils.udocker_utils.run_postgres(postgres_port=5432, container_name='paircarspostgres', verbose=False)[source]

Start postgres server

Parameters:
  • postgres_port (int, optional) – Postgres port

  • container_name (str, optional) – container name

  • verbose (bool, optional) – Verbose output or not

Returns:

Whether postgres server started or not

Return type:

int

paircars.utils.udocker_utils.run_quartical(cmd, container_name='paircarsquartical', check_container=False, verbose=False)[source]

Run quartical inside a udocker container (no root permission required).

Parameters:
  • cmd (str) – Quartical command

  • container_name (str, optional) – Container name

  • check_container (bool, optional) – Check container

  • verbose (bool, optional) – Verbose output

Returns:

Success message

Return type:

int

paircars.utils.udocker_utils.run_shadems(cmd, container_name='paircarsshadems', check_container=False, verbose=False)[source]

Run shadems inside a udocker container (no root permission required).

Parameters:
  • cmd (str) – Shadems command

  • container_name (str, optional) – Container name

  • check_container (bool, optional) – Check container

  • verbose (bool, optional) – Verbose output

Returns:

Success message

Return type:

int

paircars.utils.udocker_utils.run_solar_sidereal_cor(msname='', only_uvw=False, ncpu=1, container_name='paircarswsclean', check_container=False, verbose=False)[source]

Run chgcenter inside a udocker container to correct solar sidereal motion (no root permission required).

Parameters:
  • msname (str) – Name of the measurement set

  • only_uvw (bool, optional) – Update only UVW values Note: This is required when visibilities are properly phase rotated in correlator to track the Sun, but while creating the MS, UVW values are estimated using the first phasecenter of the Sun.

  • ncpu (int, optional) – Number of CPU threads to use

  • check_container (bool, optional) – Check container

  • container_name (str, optional) – Container name

  • verbose (bool, optional) – Verbose output or not

Returns:

Success message

Return type:

int

paircars.utils.udocker_utils.run_wsclean(wsclean_cmd, container_name='paircarswsclean', check_container=False, verbose=False)[source]

Run WSClean inside a udocker container (no root permission required).

Parameters:
  • wsclean_cmd (str) – Full WSClean command as a string.

  • container_name (str, optional) – Container name

  • check_container (bool, optional) – Check container presence or not

  • verbose (bool, optional) – Verbose output or not

Returns:

Success message

Return type:

int

paircars.utils.udocker_utils.set_udocker_env()[source]