flint.selfcal.casa ================== .. py:module:: flint.selfcal.casa .. autoapi-nested-parse:: Utilities related to using casa tasks to perform self-calibration. This tooling is mostly centred on using gaincal from casatasks. Classes ------- .. autoapisummary:: flint.selfcal.casa.GainCalOptions Functions --------- .. autoapisummary:: flint.selfcal.casa.cli flint.selfcal.casa.copy_and_clean_ms_casagain flint.selfcal.casa.create_spws_in_ms flint.selfcal.casa.gaincal_applycal_ms flint.selfcal.casa.get_parser flint.selfcal.casa.merge_spws_in_ms Module Contents --------------- .. py:class:: GainCalOptions(/, **data: Any) Bases: :py:obj:`flint.options.BaseOptions` Options provided to the casatasks gaincal function. Most options correspond to those in gaincal. .. py:attribute:: calmode :type: str :value: 'p' Calibration mode. .. py:attribute:: gaintype :type: str :value: 'G' The gain type that would be solved for. .. py:attribute:: minsnr :type: float :value: 0.0 Minimum signal-to-noise of the solutions. Below this the solutions and data are flagged. .. py:attribute:: nspw :type: int :value: 1 The number of spectral windows to use during the self-calibration routine. This will be used to craft an appropriate ``select_spw=`` interval range. If larger than one, ``gaincal`` will be carried out against each interval and results will be appended to a common solutions file. .. py:attribute:: round :type: int :value: 0 Self-calibration round. Not a gaincal option. .. py:attribute:: selectdata :type: bool :value: True Whether data selection actions will be applied in gaincal. .. py:attribute:: solint :type: str :value: '60s' Solution length interval .. py:attribute:: uvrange :type: str :value: '>200m' Data selected to go through calibration procedure .. py:function:: cli() -> None .. py:function:: copy_and_clean_ms_casagain(ms: flint.options.MS, round: int = 1, verify: bool = True, rename_ms: bool = False) -> flint.options.MS Create a copy of a measurement set in preparation for selfcalibration using casa's gaincal and applycal. Applycal only works when calibrating DATA and creating a CORRECTED_DATA column. Columns are removed in the copied MS to allow this. If the MS is large the `move_ms` option will simply renamed the input MS, adjusting the columns appropriately. Note that this potentially involves deleting the `DATA` column if present and renaming `CORRECTED_DATA`. :param ms: Measurement set that would go through self-calibration. :type ms: MS :param round: The self-calibration round. Defaults to 1. :type round: int, optional :param verify: Verify that copying the measurementt set (done in preparation for gaincal) was successful. Uses a call to rsync. Defaults to True. :type verify: bool, optional :param move_ms: Rather than copying the MS, simple renamed the MS and modify columns appropriately. Defaults to False. :type move_ms: bool, optional :returns: Copy of input measurement set with columns removed as required. :rtype: MS .. py:function:: create_spws_in_ms(casa_container: pathlib.Path, ms_path: pathlib.Path, nspw: int) -> pathlib.Path Use the casa task mstransform to create `nspw` spectral windows in the input measurement set. This is necessary when attempting to use gaincal to solve for some frequency-dependent solution. :param casa_container: Path to the singularity container with CASA tooling :type casa_container: Path :param ms_path: The measurement set that should be reformed to have `nspw` spectral windows :type ms_path: Path :param nspw: The number of spectral windows to create :type nspw: int :returns: The path to the measurement set that was updated :rtype: Path .. py:function:: gaincal_applycal_ms(ms: flint.options.MS, casa_container: pathlib.Path, round: int = 1, gain_cal_options: GainCalOptions | None = None, update_gain_cal_options: dict[str, Any] | None = None, archive_input_ms: bool = False, raise_error_on_fail: bool = True, skip_selfcal: bool = False, rename_ms: bool = False, archive_cal_table: bool = False) -> flint.options.MS Perform self-calibration using casa's gaincal and applycal tasks against an input measurement set. :param ms: Measurement set that will be self-calibrated. :type ms: MS :param round: Round of self-calibration, which is used for unique names. Defaults to 1. :type round: int, optional :param casa_container: A path to a singularity container with CASA tooling. :type casa_container: Path :param gain_cal_options: Options provided to gaincal. Defaults to None. :type gain_cal_options: Optional[GainCalOptions], optional :param update_gain_cal_options: Update the gain_cal_options with these. Defaults to None. :type update_gain_cal_options: Optional[Dict[str, Any]], optional :param archive_input_ms: If True, the input measurement set will be compressed into a single file. Defaults to False. :type archive_input_ms: bool, optional :param raise_error_on_fail: If gaincal does not converge raise en error. If False and gain cal fails return the input ms. Defaults to True. :type raise_error_on_fail: bool, optional :param skip_selfcal: Should this self-cal be skipped. If `True`, the a new MS is created but not calibrated the appropriate new name and returned. :type skip_selfcal: bool, optional :param rename_ms: It `True` simply rename a MS and adjust columns appropriately (potentially deleting them) instead of copying the complete MS. If `True` `archive_input_ms` is ignored. Defaults to False. :type rename_ms: bool, optional :param archive_cal_table: Archive the output calibration table in a tarball. Defaults to False. :type archive_cal_table: bool, optional :raises GainCallError: Raised when raise_error_on_fail is True and gaincal does not converge. :returns: The self-calibrated measurement set. :rtype: MS .. py:function:: get_parser() -> argparse.ArgumentParser .. py:function:: merge_spws_in_ms(casa_container: pathlib.Path, ms_path: pathlib.Path) -> pathlib.Path Attempt to merge together all SPWs in the input measurement set using the `cvel` casa task. This can be a little fragile. The `cvel` task creates a new measurement set, so there would temporially be a secondary measurement set. :param ms_path: The measurement set that should have its SPWs merged together. :type ms_path: Path :returns: The measurement set with merged SPWs. It will have the same path as `ms_path`, but is a new measurement set. :rtype: Path