orca.utils.modelutils ===================== .. py:module:: orca.utils.modelutils .. autoapi-nested-parse:: 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 --------- .. autoapisummary:: orca.utils.modelutils.get_sun_pos orca.utils.modelutils.get_solar_altaz_multiple_times orca.utils.modelutils.get_solar_azel orca.utils.modelutils.get_msinfo orca.utils.modelutils.get_image_data orca.utils.modelutils.get_image_maxmin orca.utils.modelutils.check_image_quality orca.utils.modelutils.restore_flag orca.utils.modelutils.get_flagged_solution_num orca.utils.modelutils.get_strong_source_list orca.utils.modelutils.get_time_from_name orca.utils.modelutils.get_timestr_from_name orca.utils.modelutils.get_freqstr_from_name orca.utils.modelutils.get_selfcal_time_to_apply orca.utils.modelutils.get_keyword orca.utils.modelutils.put_keyword orca.utils.modelutils.get_obs_time_interval orca.utils.modelutils.convert_to_heliocentric_coords orca.utils.modelutils.make_wsclean_compatible orca.utils.modelutils.get_total_fields orca.utils.modelutils.collect_fast_fits orca.utils.modelutils.rename_images orca.utils.modelutils.check_corrected_data_present orca.utils.modelutils.correct_primary_beam orca.utils.modelutils.get_solar_loc_pix orca.utils.modelutils.get_rms orca.utils.modelutils.blank_all_pixels orca.utils.modelutils.get_uvlambda_from_uvdist orca.utils.modelutils.swap_fastms_pols orca.utils.modelutils.correct_fastms_amplitude_scale orca.utils.modelutils.compress_fits_to_h5 orca.utils.modelutils.recover_fits_from_h5 orca.utils.modelutils.check_h5_fits_consistency orca.utils.modelutils.check_for_file_presence orca.utils.modelutils.manual_split_corrected_ms orca.utils.modelutils.get_primary_beam_single_source orca.utils.modelutils.get_caltable_freq Module Contents --------------- .. py:function:: get_sun_pos(msfile: str, str_output: bool = True) Return J2000 coordinates of the solar disk center. :param msfile: Input CASA measurement set. :param 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. .. py:function:: get_solar_altaz_multiple_times(times) :param times: A astropy Time object. Can have multiple times returns az,el in degrees for OVRO .. py:function:: get_solar_azel(msfile) Returns az ,el of sun in degrees. :param msfile: Name of MS :type msfile: str :return: az,el in degrees .. py:function:: get_msinfo(msfile) Return some basic information of an OVRO-LWA measurement set :param msfile: path to CASA measurement set :return: number of antennas, number of spectral windows, number of channels .. py:function:: get_image_data(imagename) .. py:function:: get_image_maxmin(imagename, local=True) .. py:function:: check_image_quality(imagename, max1, min1, reorder=True) .. py:function:: restore_flag(msfile) .. py:function:: get_flagged_solution_num(caltable) .. py:function:: get_strong_source_list() .. py:function:: get_time_from_name(msname) .. py:function:: get_timestr_from_name(msname) .. py:function:: get_freqstr_from_name(msname) .. py:function:: get_selfcal_time_to_apply(msname, caltables) .. py:function:: get_keyword(caltable, keyword, return_status=False) .. py:function:: put_keyword(caltable, keyword, val, return_status=False) .. py:function:: get_obs_time_interval(msfile) .. py:function:: convert_to_heliocentric_coords(msname, imagename, helio_imagename=None, reftime='') 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 .. py:function:: make_wsclean_compatible(msname) .. py:function:: get_total_fields(msname) .. py:function:: collect_fast_fits(imagename, pol='I') collect the fits file names of fast img :param imagename: the image name from previous step of imaging, (e.g., 'sun_only') :param pol: the polarization of the image, default is 'I' .. py:function:: rename_images(imagename, pol='I', img_prefix=None, intervals_out=1, channels_out=1) This will create the list of [present name, future name] :param imagename: Imagename supplied to WSClean call. :type imagename: str :param pol: Pol supplied to WSClean. Should be ',' separated list. Parsing is strict. Default is I :type pol: str :param img_prefix: 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 :type img_prefix: str :param intervals_out: Intervals_out passed to WSClean. If 1, time_str is not appended to img_prefix. Default: 1 :type intervals_out: int :param channels_out: Channels_out passed to WSClean. If 1, channels_out is not appended to img_prefix. Default :1 :return: list of the renamed images. Blank list is returned if not present :rtype: list .. py:function:: check_corrected_data_present(msname) .. py:function:: correct_primary_beam(msfile, imagename, pol='I', fast_vis=False) 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. .. py:function:: get_solar_loc_pix(msfile, image='allsky') Get the x, y pixel location of the Sun from an all-sky image :param msfile: path to CASA measurement set :param image: all sky image made from the measurement set :return: pixel value in X and Y for solar disk center .. py:function:: get_rms(data, thresh=7) 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 :param data: image data :type data: numpy ndarray :param thresh: threshold above rms to remove true sources in rms caluclation. Default: 7 :type thresh: float :return: rms :rtype: float .. py:function:: blank_all_pixels(imagename) .. py:function:: get_uvlambda_from_uvdist(u, v, msname=None, freqs=None) .. py:function:: swap_fastms_pols(msname) 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 :param 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 .. py:function:: correct_fastms_amplitude_scale(msname) 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 :param 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 .. py:function:: 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) Compress an OVRO-LWA fits file to a h5 files :param fits_file: the fits file to be compressed :param hdf5_file: the h5 file to be saved. If not given, default to '{filename}.hdf' in current directory .. py:function:: recover_fits_from_h5(hdf5_file, fits_out=None, return_data=False, return_meta_only=False) Recover a fits file from a compressed hdf5 file :param hdf5_file: the hdf5 file to be read :param fits_out: the fits file to be recovered. If not given, default to '{filename}.fits' in current directory :param return_data: if True, return the fits data and header directly without creating the fits file :param return_meta_only: if True, return only the metadata without creating the fits file :return: If return_data is True, returns a tuple (header, data). If return_meta_only is True, returns the metadata. Otherwise, returns None. .. py:function:: check_h5_fits_consistency(fits_file, hdf5_file=None, ignore_corrupted=False, work_dir='./', tolerance=0.001, ignore_ratio=2) Check the consistency between a fits file and a hdf5 file, if there is a hdf5 file, then compare the two files :param fits_file: the fits file to be compared :param hdf5_file: the hdf5 file to be compared, if None then the hdf will be fits file replacing ".fits" :param ignore_corrupted: if True, ignore the check of the data in the fits file corrupted data has -np.min*ignore_ratio>np.max .. py:function:: check_for_file_presence(imagename, pol, suffix='image') .. py:function:: manual_split_corrected_ms(vis, outputvis, datacolumn='CORRECTED_DATA') .. py:function:: get_primary_beam_single_source(alt, az, freq, model_beam_file='/lustre/msurajit/beam_model_nivedita/OVRO-LWA_soil_pt.h5') 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 .. py:function:: get_caltable_freq(caltable)