orca.utils.modelutils

Source model generation and manipulation utilities.

Provides functions for generating solar and sky source models, computing source positions, creating CASA component lists, and performing model visibility calculations for calibration and imaging.

Functions

get_sun_pos(msfile[, str_output])

Return J2000 coordinates of the solar disk center.

get_solar_altaz_multiple_times(times)

get_solar_azel(msfile)

Returns az ,el of sun in degrees.

get_msinfo(msfile)

Return some basic information of an OVRO-LWA measurement set

get_image_data(imagename)

get_image_maxmin(imagename[, local])

check_image_quality(imagename, max1, min1[, reorder])

restore_flag(msfile)

get_flagged_solution_num(caltable)

get_strong_source_list()

get_time_from_name(msname)

get_timestr_from_name(msname)

get_freqstr_from_name(msname)

get_selfcal_time_to_apply(msname, caltables)

get_keyword(caltable, keyword[, return_status])

put_keyword(caltable, keyword, val[, return_status])

get_obs_time_interval(msfile)

convert_to_heliocentric_coords(msname, imagename[, ...])

The imagename, helio_imagename and reftime all can be a list.

make_wsclean_compatible(msname)

get_total_fields(msname)

collect_fast_fits(imagename[, pol])

collect the fits file names of fast img

rename_images(imagename[, pol, img_prefix, ...])

This will create the list of [present name, future name]

check_corrected_data_present(msname)

correct_primary_beam(msfile, imagename[, pol, fast_vis])

Can handle multiple images in a list. However if providing multiple images

get_solar_loc_pix(msfile[, image])

Get the x, y pixel location of the Sun from an all-sky image

get_rms(data[, thresh])

This function returns the rms of the data. As a first cut, it calculates

blank_all_pixels(imagename)

get_uvlambda_from_uvdist(u, v[, msname, freqs])

swap_fastms_pols(msname)

This function corrects for the polarisation swap present in the fast MS data

correct_fastms_amplitude_scale(msname)

This function corrects for the amplitude correction present in the fast MS data

compress_fits_to_h5(fits_file, hdf5_file[, ...])

Compress an OVRO-LWA fits file to a h5 files

recover_fits_from_h5(hdf5_file[, fits_out, ...])

Recover a fits file from a compressed hdf5 file

check_h5_fits_consistency(fits_file[, hdf5_file, ...])

Check the consistency between a fits file and a hdf5 file,

check_for_file_presence(imagename, pol[, suffix])

manual_split_corrected_ms(vis, outputvis[, datacolumn])

get_primary_beam_single_source(alt, az, freq[, ...])

This is a utility function which returns the normalised beam factors for a single source.

get_caltable_freq(caltable)

Module Contents

orca.utils.modelutils.get_sun_pos(msfile: str, str_output: bool = True)[source]

Return J2000 coordinates of the solar disk center.

Parameters:
  • msfile – Input CASA measurement set.

  • str_output – If True, return coordinate as CASA-compatible string. If False, return a CASA measures dictionary.

Returns:

Solar disk center coordinate in string or dictionary format.

orca.utils.modelutils.get_solar_altaz_multiple_times(times)[source]
Parameters:

times – A astropy Time object. Can have multiple times

returns az,el in degrees for OVRO

orca.utils.modelutils.get_solar_azel(msfile)[source]

Returns az ,el of sun in degrees.

Parameters:

msfile (str) – Name of MS

Returns:

az,el in degrees

orca.utils.modelutils.get_msinfo(msfile)[source]

Return some basic information of an OVRO-LWA measurement set

Parameters:

msfile – path to CASA measurement set

Returns:

number of antennas, number of spectral windows, number of channels

orca.utils.modelutils.get_image_data(imagename)[source]
orca.utils.modelutils.get_image_maxmin(imagename, local=True)[source]
orca.utils.modelutils.check_image_quality(imagename, max1, min1, reorder=True)[source]
orca.utils.modelutils.restore_flag(msfile)[source]
orca.utils.modelutils.get_flagged_solution_num(caltable)[source]
orca.utils.modelutils.get_strong_source_list()[source]
orca.utils.modelutils.get_time_from_name(msname)[source]
orca.utils.modelutils.get_timestr_from_name(msname)[source]
orca.utils.modelutils.get_freqstr_from_name(msname)[source]
orca.utils.modelutils.get_selfcal_time_to_apply(msname, caltables)[source]
orca.utils.modelutils.get_keyword(caltable, keyword, return_status=False)[source]
orca.utils.modelutils.put_keyword(caltable, keyword, val, return_status=False)[source]
orca.utils.modelutils.get_obs_time_interval(msfile)[source]
orca.utils.modelutils.convert_to_heliocentric_coords(msname, imagename, helio_imagename=None, reftime='')[source]

The imagename, helio_imagename and reftime all can be a list. If reftime is not provided, it is assumed to the the center of the observation time given in the MS

orca.utils.modelutils.make_wsclean_compatible(msname)[source]
orca.utils.modelutils.get_total_fields(msname)[source]
orca.utils.modelutils.collect_fast_fits(imagename, pol='I')[source]

collect the fits file names of fast img

Parameters:
  • imagename – the image name from previous step of imaging, (e.g., ‘sun_only’)

  • pol – the polarization of the image, default is ‘I’

orca.utils.modelutils.rename_images(imagename, pol='I', img_prefix=None, intervals_out=1, channels_out=1)[source]

This will create the list of [present name, future name]

Parameters:
  • imagename (str) – Imagename supplied to WSClean call.

  • pol (str) – Pol supplied to WSClean. Should be ‘,’ separated list. Parsing is strict. Default is I

  • img_prefix (str) – Image prefix of the renamed images. The times and freq will be appened after this, separated by ‘_’. Default is None. If None, img_prefix is set to imagename

  • intervals_out (int) – Intervals_out passed to WSClean. If 1, time_str is not appended to img_prefix. Default: 1

  • channels_out – Channels_out passed to WSClean. If 1, channels_out is not appended to img_prefix. Default :1

Returns:

list of the renamed images. Blank list is returned if not present

Return type:

list

orca.utils.modelutils.check_corrected_data_present(msname)[source]
orca.utils.modelutils.correct_primary_beam(msfile, imagename, pol='I', fast_vis=False)[source]

Can handle multiple images in a list. However if providing multiple images provide full name of files. No addition to filename is done. If single file is provided, we can add ‘.image.fits’ to it.

orca.utils.modelutils.get_solar_loc_pix(msfile, image='allsky')[source]

Get the x, y pixel location of the Sun from an all-sky image

Parameters:
  • msfile – path to CASA measurement set

  • image – all sky image made from the measurement set

Returns:

pixel value in X and Y for solar disk center

orca.utils.modelutils.get_rms(data, thresh=7)[source]

This function returns the rms of the data. As a first cut, it calculates the std. Then it calculates the std again, by only considering pixels which are lower than the thresh*rms

Parameters:
  • data (numpy ndarray) – image data

  • thresh (float) – threshold above rms to remove true sources in rms caluclation. Default: 7

Returns:

rms

Return type:

float

orca.utils.modelutils.blank_all_pixels(imagename)[source]
orca.utils.modelutils.get_uvlambda_from_uvdist(u, v, msname=None, freqs=None)[source]
orca.utils.modelutils.swap_fastms_pols(msname)[source]
This function corrects for the polarisation swap present in the fast MS data

the date on which the swap was corrected in the

X engine itself. Details of this isse has been discussed in https://github.com/ovro-lwa/lwa-issues/issues/486

Parameters:

msname – Name of MS

: type msname: str :param correction_date: Datetime of correction in X-engine :type correction_date: Can be anything which is acceptable by Astropy Time

orca.utils.modelutils.correct_fastms_amplitude_scale(msname)[source]

This function corrects for the amplitude correction present in the fast MS data correction_dates provides the date on which the ampltiude correction was done in data recorder itself. The amplitude of fast vis data was initially off by a factor of 4. On December 18, when trying to correct for this, this factor became 16. As of February 7, 2024, this has not been corrected. Details of this issue has been discussed in https://github.com/ovro-lwa/lwa-issues/issues/501

Parameters:

msname – Name of MS

: type msname: str :param correction_date: Datetime of correction in X-engine :type correction_dates: Is a list of anything which is acceptable by Astropy Time

orca.utils.modelutils.compress_fits_to_h5(fits_file, hdf5_file, beam_ratio=3.0, smaller_than_src=True, theoretical_beam_thresh=True, longest_baseline=3000, purge_corrupted=False, purge_thresh=1.5)[source]

Compress an OVRO-LWA fits file to a h5 files

Parameters:
  • fits_file – the fits file to be compressed

  • hdf5_file – the h5 file to be saved. If not given, default to ‘{filename}.hdf’ in current directory

orca.utils.modelutils.recover_fits_from_h5(hdf5_file, fits_out=None, return_data=False, return_meta_only=False)[source]

Recover a fits file from a compressed hdf5 file

Parameters:
  • hdf5_file – the hdf5 file to be read

  • fits_out – the fits file to be recovered. If not given, default to ‘{filename}.fits’ in current directory

  • return_data – if True, return the fits data and header directly without creating the fits file

  • return_meta_only – if True, return only the metadata without creating the fits file

Returns:

If return_data is True, returns a tuple (header, data). If return_meta_only is True, returns the metadata. Otherwise, returns None.

orca.utils.modelutils.check_h5_fits_consistency(fits_file, hdf5_file=None, ignore_corrupted=False, work_dir='./', tolerance=0.001, ignore_ratio=2)[source]

Check the consistency between a fits file and a hdf5 file, if there is a hdf5 file, then compare the two files

Parameters:
  • fits_file – the fits file to be compared

  • hdf5_file – the hdf5 file to be compared, if None then the hdf will be fits file replacing “.fits”

  • ignore_corrupted – if True, ignore the check of the data in the fits file corrupted data has -np.min*ignore_ratio>np.max

orca.utils.modelutils.check_for_file_presence(imagename, pol, suffix='image')[source]
orca.utils.modelutils.manual_split_corrected_ms(vis, outputvis, datacolumn='CORRECTED_DATA')[source]
orca.utils.modelutils.get_primary_beam_single_source(alt, az, freq, model_beam_file='/lustre/msurajit/beam_model_nivedita/OVRO-LWA_soil_pt.h5')[source]

This is a utility function which returns the normalised beam factors for a single source. :param alt: altitude in degrees. float :param az: azimuth in degrees. float :param freq: Frequency in MHz :param model_beam_file: Location of the primary beam file

orca.utils.modelutils.get_caltable_freq(caltable)[source]