Pipeline library

Contents

Pipeline library#

Pipeline orchestration, configuration, step implementations, and result reporting.

Pipeline entry point#

class avica.pipe.main.AvicaPipeline(pipe_params=None, steps=None)#

Bases: AvicaPipelineCore

Parameters:
LEGACY_MPI_PARAMS = {'mpi_cores_avgms': 'avica_avg.mpi_cores', 'mpi_cores_importfitsidi': 'fits_to_ms.mpi_cores', 'mpi_cores_rpicard': 'rpicard.mpi_cores', 'mpi_cores_snrating': 'avica_snr.mpi_cores', 'mpi_cores_splitms': 'avica_split_ms.mpi_cores'}#
DEFAULT_STEPS = [<class 'avica.pipe.steps.PreProcessFitsIdi'>, <class 'avica.pipe.steps.FitsIdiToMS'>, <class 'avica.pipe.steps.Phaseshift'>, <class 'avica.pipe.steps.AverageMS'>, <class 'avica.pipe.steps.AvicaMetaMS'>, <class 'avica.pipe.steps.SnRating'>, <class 'avica.pipe.steps.FillInputMs'>, <class 'avica.pipe.steps.FinalSplitMs'>, <class 'avica.pipe.steps.Calibration'>]#
step_names()#
steps_from(step_name)#
config_report(*step_names)#

Configuration#

class avica.pipe.config.LogFramework(primary_colname='', primary_value='', csv_file='pipeline_out.csv', working_col='', polars=False, gsc=None, verbose=False)#

Bases: object

A DataFrame based utility for tracking pipeline step results against rows identified by a primary key column.

Supports pandas and polars backends, CSV persistence, and optional google sheet support.

Parameters#

primary_colnamestr

Column name used as the unique row identifier.

primary_valuestr

The value in primary_colname that identifies the current row.

working_colstr

Default column to read/write when no colname is explicitly given.

csv_filestr

Path to the CSV file used as the data source and persistence target.

polarsbool

If True, use polars as the internal backend. Falls back to pandas if unavailable.

gscoptional

A gspread-backed connection object. Pass None to work in CSV-only mode.

property is_googlesheet#
property df_sheet#

mutable sheet obj.

property df_sheet0#

shet df for diffs

get_pandas()#
Return type:

pandas.DataFrame

get_polars()#
Return type:

polars.DataFrame

get_value(colname='', where=None)#

Returns the cell value for colname (or working_col) at the current primary_value row. Returns empty string when not found.

Parameters:
Return type:

str

isvalue(value, colname='')#

Returns True if the cell value matches value.

Parameters:
Return type:

bool

get_working_cols()#
Return type:

List[str]

get_previous_working_col()#
Return type:

str | None

put_value(value, colname='', count=0, where=None, force=False)#

Writes value into colname (or working_col) for the current primary_value row. Skips the write if the cell is already populated and force=False. Returns count + 1 on a successful write.

Parameters:
Return type:

int

update_csv(count, failed, csvfile=None)#

Persists the current frame to CSV if anything changed since last save.

Parameters:
  • count (int)

  • failed (int)

  • csvfile (str | None)

Return type:

None

update_sheet(count, failed, by_cell=True, comment_col='Comment', csvfile=None)#
  • syncs changes to Google Sheets if a gsc instance was provided.

  • falls back to CSV on failure. Rate-limited to stay under 60 req/min.

  • no-ops cleanly when gsc is None.

Parameters:
  • count (int)

  • failed (int)

  • by_cell (bool)

  • comment_col (str)

  • csvfile (str | None)

Return type:

None

Parameters:
  • primary_colname (str)

  • primary_value (str)

  • csv_file (Union[str, Path, io.IOBase, None])

  • working_col (str)

  • polars (bool)

  • gsc (Optional[Any])

  • verbose (bool)

avica.pipe.config.get_added_casa_paths()#
Return type:

list

avica.pipe.config.get_added_casa_lib_dirs()#
Return type:

list

avica.pipe.config.setup_casa_path(casadir)#

Inject CASA’s site-packages (and lib dirs) into the current interpreter so that CASA modules can be imported in-process.

Also records what was added so that run_subprocess can propagate the same paths into child processes via PYTHONPATH / LD_LIBRARY_PATH.

Parameters:

casadir (str)

Return type:

None

avica.pipe.config.populate_default_csv()#
class avica.pipe.config.PipeConfig(configfile)#

Bases: object

to_dict()#
defaults(all=False)#

Core types and task wrappers#

avica.pipe.core.catalog_search_from_fits(fitsfile, df_catalog, seplimit, thres_sep, source_name_col='Obsname', frame='icrs', include_not_found=False, verbose=False, outdir='')#
avica.pipe.core.df_search_brightcalib_fromascii_catalogfile(fitsfile, rfc_filepath, class_filepath, scanlist_arr, targets=[], seplimit=5000.0, thres_sep=10000.0, crossmatch_sep=600, outfile='', nfilter_sources=20)#

TODO: Increase seplimit for sources which were not found by the seplimit class_filepath e.g ‘/data/avi/d/smile/smile_complete_table.txt’

uses scanlist information to check if sources, dont have any data in UV_DATA. searches for source information by coordinate from fits in the calibrator fille,

if provided uses true coordinates from coordinate file to make separation limits to calibrators, also saves output file containing separation (in mas) between provided and observed file coordinate

avica.pipe.core.split_in_freqid(fitsfiles, verbose=False)#
avica.pipe.core.python_type_to_str(value)#
Parameters:

value (Any)

Return type:

str

avica.pipe.core.dic_from_inpfile(wd_ifolder, *args)#
Return type:

List | None

avica.pipe.core.update_ifolderdata_from_new_ifolder(old_ifolder, new_ifolder, *inpfilenames)#
Return type:

List[dict] | None

avica.pipe.core.merge_obs_data(base_dict, *new_dicts)#

provide time sorted dicts to create a merged dicts of listobs.

Parameters:

base_dict (_type_) – _description_

Returns:

_description_

Return type:

_type_

class avica.pipe.core.StepResult(name: str, success_count: int, failed_count: int, start_stamp: datetime.datetime, detail: Dict, desc: List[str] = <factory>, success: List[bool] = <factory>, end_stamp: datetime.datetime = <factory>)#

Bases: object

Parameters:
name: str#
success_count: int#
failed_count: int#
start_stamp: datetime#
detail: Dict#
desc: List[str]#
success: List[bool]#
end_stamp: datetime#
class avica.pipe.core.ColName(working_col, comment_col, timestamp_col)#

Bases: NamedTuple

Parameters:
  • working_col (str)

  • comment_col (str)

  • timestamp_col (str)

working_col: str#

Alias for field number 0

comment_col: str#

Alias for field number 1

timestamp_col: str#

Alias for field number 2

class avica.pipe.core.RemoveRemovables(wd, removables)#

Bases: object

Parameters:

removables (List[str])

rm()#
class avica.pipe.core.AvicaResult(initlist=None)#

Bases: UserList[StepResult]

to_polars()#
Return type:

polars.DataFrame

summary()#
Return type:

polars.DataFrame

avica.pipe.core.append_step_result_csv(result, csvfile)#
Parameters:
Return type:

bool

avica.pipe.core.step_stage(name, **context)#

Wraps a stage inside run(), logs entry and enriches any exception with context.

Parameters:

name (str)

class avica.pipe.core.PipelineContext#

Bases: object

params: Dict = {}#
step_name: str = ''#
validation_success: bool | None = None#
result: StepResult | None = None#
result_persisted: bool = False#
colnames: ColName | None = None#
logfolder: str = 'avica.logs/'#
casalogfolder: str = 'casa.logs/'#
classmethod init_params(params)#
Parameters:

params (dict)

classmethod read_paramfile(filepath)#
Parameters:

filepath (str)

classmethod reset_params()#
avica.pipe.core.pipeline_context(params)#
Parameters:

params (dict)

avica.pipe.core.casa_logfiles(wd, step_name, start_stamp)#

(logfile, errfile) for CASA tasks of a step. Inside a pipeline run this is the single run-level pair in casa.logs/ (issue #58); outside a run (e.g. a step called directly) it falls back to per-step files in wd.

class avica.pipe.core.WorkDirMeta(wd_ifolder)#

Bases: object

to_new_WD(band, target, create=True)#
Return type:

tuple[Path, Path]

get_inp(band='', target='', inpfile='observation.inp')#

Returns (obs_dic, arr_dic, flag_dic, arr_finetune_dic, constants_dic)

Return type:

dict

get_diclistobs()#
to_dict()#
class avica.pipe.core.PipelineStepValidatorResult(success: List[bool], msg: str)#

Bases: object

Parameters:
success: List[bool]#
msg: str#
class avica.pipe.core.PipelineStepValidatorBase#

Bases: ABC

name: str = 'default'#
run_after: bool = False#
run_once: bool = False#
desc: str = ''#
result: PipelineStepValidatorResult = PipelineStepValidatorResult(success=[False], msg='')#
abstract run(**kwargs)#
Return type:

PipelineStepValidatorResult

class avica.pipe.core.PipelineStepBase#

Bases: ABC


  • All the intialized arguments outside the step should be passed in initialized_config.
    • this makes easy checking for missing requirements when .run() is called.

  • Everything else goes as function arguments.


name: str#
validate_by: List#
description: str#
colnames: ColName#
metadata: Dict#
output_printable: str#
result: StepResult#
initialized_config: Dict#
abstract run(step_name, wd_ifolder, pipe_params)#
Parameters:
  • step_name (str)

  • wd_ifolder (str)

  • pipe_params (Dict)

Return type:

StepResult

class avica.pipe.core.InitVariables#

Bases: PipelineStepValidatorBase

name: str = 'init_variables'#
run_after: bool = False#
run_once: bool = False#
desc: str = 'Uses the provided parameters to initialize the variables'#
run(lf, target, targets, init_params)#
class avica.pipe.core.CasaSetup#

Bases: PipelineStepValidatorBase

name: str = 'casadir_setup'#
run_after: bool = False#
desc: str = 'If use_casadir_pythonpath is True, adds the casadir to PATH'#
check_casa_import()#
Return type:

bool

run(lf, casadir, use_casadir_pythonpath)#
class avica.pipe.core.ColValidation#

Bases: PipelineStepValidatorBase

name: str = 'col_validations'#
run_after: bool = False#
desc: str = 'Executes the step column-wise validation'#
run(lf, working_col, first_col, skip_cols=True)#
class avica.pipe.core.RowValidation#

Bases: PipelineStepValidatorBase

name: str = 'row_validations'#
run_after: bool = False#
desc: str = 'Uses parameters derived by iterating each row in a given sheet'#
run(fitsfile)#
class avica.pipe.core.RunValidation#

Bases: PipelineStepValidatorBase

name: str = 'run_validations'#
run_after: bool = False#
run(working_col, first_col, skip_cols=True)#
class avica.pipe.core.UpdateResults#

Bases: PipelineStepValidatorBase

name: str = 'update_results'#
run_after: bool = True#
run(lf, count, failed, fitsfile_name, result_csv_file=None)#
class avica.pipe.core.UpdateSheet#

Bases: PipelineStepValidatorBase

name: str = 'update_sheet'#
run_after: bool = True#
run_once: bool = False#
run(lf, count, failed, fitsfile_name, csv_file=None)#
class avica.pipe.core.AvicaPipelineCore(pipe_params, steps, provided_pipe_params=None)#

Bases: object

register_steps()#
get_kwargs(step)#
get_config_requirements(*steps_to_check)#
check_config_requirements(step)#
filter_steps(*keys)#
execute(loglevel='INFO')#
Return type:

AvicaResult

class avica.pipe.core.PicardCMD(picard_input_template: str, input_template: str, logfile: str, errfile: str, args: Dict[str, Any], args_type: Dict[str, str], mpi_cores: int = 10, verbose: bool = False)#

Bases: object

Parameters:
picard_input_template: str#
input_template: str#
logfile: str#
errfile: str#
args: Dict[str, Any]#
args_type: Dict[str, str]#
mpi_cores: int = 10#
verbose: bool = False#
class avica.pipe.core.CasaTaskCMD(casadir: str, task_casa: str, logfile: str, errf: str, args: Dict[str, Any], args_type: Dict[str, str], mpi_cores: int = 0)#

Bases: object

Parameters:
casadir: str#
task_casa: str#
logfile: str#
errf: str#
args: Dict[str, Any]#
args_type: Dict[str, str]#
mpi_cores: int = 0#
class avica.pipe.core.CasaStep(meta: Dict[str, Any], cmd: avica.pipe.core.CasaTaskCMD)#

Bases: object

Parameters:
meta: Dict[str, Any]#
cmd: CasaTaskCMD#
class avica.pipe.core.CasaConfigGen(tasks_list: List[avica.pipe.core.CasaStep] = <factory>)#

Bases: object

Parameters:

tasks_list (List[CasaStep])

tasks_list: List[CasaStep]#
to_dict()#
classmethod from_dict(data)#
Parameters:

data (Dict[str, Any])

class avica.pipe.core.CasaTask#

Bases: object

to_args()#
task_meta()#
Return type:

str

parse_to_step(task_name, logfile, errf, casadir, mpi_cores=5)#
Parameters:
Return type:

CasaStep

avica.pipe.core.antab_spws(values)#

Zero-based spectral windows in INDEX/INDEX2 (cf. update_map).

avica.pipe.core.antab_spw_count(values)#
class avica.pipe.core.GenerateAndAppendAntab(fitsfiles, metafolder, verbose, wd, valid_perc=5, artifact_dirs=None, use_local_antab=True, local_antab_require_full_array=False)#

Bases: object

find_and_attach_antab(fitsfile, fitsfiles, antabfile, attach_all, verbose=False)#
attach_antab(only_first=True, attach_all=False)#
attach_partial_antab(fitsfile)#

TSYS exists but not for every antenna, or gain curves are missing: use a local ANTAB that calibrates at least one of those antennas. Never downloads (the archive fallback is only for files without any TSYS).

sort_by_time(reverse=False)#
sort_by_tsys()#
validate()#

tsys_exists_in_fitsfiles(fitsfile, self.fitsfiles) gc_exists_in_fitsfiles(fitsfile, self.fitsfiles) other things are already checked

class avica.pipe.core.ImportFITSIdi(vis: str = '', fitsidifile: List[str] = <factory>, constobsid: bool = True, scanreindexgap_s: float = 15.0)#

Bases: CasaTask

Parameters:
vis: str = ''#
fitsidifile: List[str]#
constobsid: bool = True#
scanreindexgap_s: float = 15.0#
to_step(logfile, errf, casadir, mpi_cores=5)#
Parameters:
class avica.pipe.core.FringeFit(vis: str = '', caltable: str = '', field: str = '', spw: str = '', selectdata: bool = True, timerange: str = '', antenna: str = '', scan: str = '', observation: str = '', msselect: str = '', solint: str = 'inf', combine: str = 'spw', refant: str = '', minsnr: str = '', zerorates: bool = False, globalsolve: bool = False, append: bool = False, docallib: bool = False, callib: str = '', gaintable: List | str = '', gainfield: List | str = '', interp: str = '', corrdepflags: bool = True, concatspws: bool = True, corrcomb: str = 'none', parang: bool = True)#

Bases: CasaTask

Parameters:
vis: str = ''#
caltable: str = ''#
field: str = ''#
spw: str = ''#
selectdata: bool = True#
timerange: str = ''#
antenna: str = ''#
scan: str = ''#
observation: str = ''#
msselect: str = ''#
solint: str = 'inf'#
combine: str = 'spw'#
refant: str = ''#
minsnr: str = ''#
zerorates: bool = False#
globalsolve: bool = False#
append: bool = False#
docallib: bool = False#
callib: str = ''#
gaintable: List | str = ''#
gainfield: List | str = ''#
interp: str = ''#
corrdepflags: bool = True#
concatspws: bool = True#
corrcomb: str = 'none'#
parang: bool = True#
to_step(logfile, casadir, errf, mpi_cores=5)#
Parameters:
class avica.pipe.core.MsTransform(vis: str = '', outputvis: str = '', datacolumn: str = 'data', field: str = '', spw: str = '', antenna: str = '', scan: str = '', correlation: str = '', chanaverage: bool = False, chanbin: int | List[int] = 1, timeaverage: bool = False, timebin: str = '0s', hanning: bool = False, reindex: bool = True, keepflags: bool = True, createmms: bool = True)#

Bases: CasaTask

Parameters:
vis: str = ''#
outputvis: str = ''#
datacolumn: str = 'data'#
field: str = ''#
spw: str = ''#
antenna: str = ''#
scan: str = ''#
correlation: str = ''#
chanaverage: bool = False#
chanbin: int | List[int] = 1#
timeaverage: bool = False#
timebin: str = '0s'#
hanning: bool = False#
reindex: bool = True#
keepflags: bool = True#
createmms: bool = True#
to_step(logfile, casadir, errf, mpi_cores=5)#
Parameters:
class avica.pipe.core.FlagData(vis: str = '', mode: str = 'manual', inpfile: str = '', action: str = 'apply', flagbackup: bool = True, savepars: bool = False, datacolumn: str = 'data', field: str = '', spw: str = '', antenna: str = '', scan: str = '', reason: str = 'any')#

Bases: CasaTask

Parameters:
vis: str = ''#
mode: str = 'manual'#
inpfile: str = ''#
action: str = 'apply'#
flagbackup: bool = True#
savepars: bool = False#
datacolumn: str = 'data'#
field: str = ''#
spw: str = ''#
antenna: str = ''#
scan: str = ''#
reason: str = 'any'#
to_step(logfile, casadir, errf, mpi_cores=5)#
Parameters:
class avica.pipe.core.FlagManager(vis: str = '', mode: str = 'save', versionname: str = '', comment: str = '', merge: str = 'replace')#

Bases: CasaTask

Parameters:
vis: str = ''#
mode: str = 'save'#
versionname: str = ''#
comment: str = ''#
merge: str = 'replace'#
to_step(logfile, casadir, errf, mpi_cores=5)#
Parameters:
class avica.pipe.core.IterativeSubprocess(cmd_list, clean_env=True, verbose=True)#

Bases: object

get_stderr()#
send_and_receive(inp_data)#
Parameters:

inp_data (dict)

Return type:

dict

close()#
class avica.pipe.core.PersistentMpiCasaRunner(casadir, mpi_cores=10, verbose=False, logfile=None, errfile=None)#

Bases: object

Parameters:
  • casadir (str)

  • mpi_cores (int)

  • verbose (bool)

  • logfile (str | None)

  • errfile (str | None)

run_task(task_name, args, args_type, block=False, target_server=None, logfile='', run_on_master=False, label='')#
Parameters:
get_response(command_ids, block=True)#
Parameters:
close()#
avica.pipe.core.run_subprocess(cmd_list, inp_data, mode='stdin', clean_env=True, verbose=True)#
Parameters:
Return type:

dict

class avica.pipe.core.SubprocessPayload(inp_data, cmd_list=None, host='localhost', port=5030)#

Bases: object

Parameters:
mode: str = 'stdin'#
clean_env: bool = True#
cmd_list: List[str] = []#
run()#
Return type:

dict

class avica.pipe.core.PicardTask(input: str, n: int = 10)#

Bases: object

Parameters:
input: str#
n: int = 10#
to_args()#
Return type:

List[str]

class avica.pipe.core.PicardStepParser(casadir: str, logfile: str, errf: str)#

Bases: object

Parameters:
casadir: str#
logfile: str#
errf: str#
parse(task)#
Parameters:

task (PicardTask)

Return type:

CasaStep

class avica.pipe.core.PicardPayload(task)#

Bases: SubprocessPayload

Parameters:

task (PicardTask)

mode: str = 'args'#

Pipeline steps#

class avica.pipe.steps.PreProcessFitsIdi#

Bases: PipelineStepBase


  1. Fix minor problems in the fits.

  2. Check scanlist, print listobs if scanlist output file not found in metadata.

  3. Split sources to contain only desired sources.

  4. Fix remaining problems.

  5. Split in frequency id and attach missing tsys, gain curve table.

  6. Fill optional metadata in the pipeline input files.


name: str = 'preprocess_fitsidi'#
colnames: ColName = ('preprocess_fitsidi', 'Comment_prepfits', 'timestamp_prepfits')#
py_env = ''#
description: str = 'Fixes FITS-IDI data and headers, selects sources, splits by frequency ID, and attaches local ANTAB calibration or falls back to downloading and converting VLBA calibration.'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='preprocess_fitsidi', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772207), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772212))#
output_printable: str = ''#
run(lf, fitsfiles, target, wd_ifolder, source_extract_multi_fitsfiles=False, removables=[], rm_only=False, rm_pre=False, delete_removables=False, artifact_dirs=[], use_local_antab=True, local_antab_require_full_array=False, force_reset=False, verbose=False)#
class avica.pipe.steps.FitsIdiToMS#

Bases: PipelineStepBase


  • uses the last used fitsfiled to run importfitsidi

  • runs iteratively for files requiring different vis output.

  • casa tasks is triggered with the correct python environment using payload service

  • logs “vis exists!” when the visiblity file is already present.


name: str = 'fits_to_ms'#
colnames: ColName = ('fits_to_ms', 'Comment_fits2ms', 'timestamp_fits2ms')#
py_env = ''#
description: str = 'load fits to ms'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='fits_to_ms', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772240), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772242))#
run(lf, casadir, wd_ifolder, target='', apply_flag_from_idi=True, mpi_cores=5, flag_source='ms', removables=[], rm_only=False, rm_pre=False, delete_removables=False, apply_flag_to_existing_vis=False, apply_flag_from_artifacts=True, artifact_dirs=None, artifact_flag_extensions='.fg;.uvflag;.uvflg;.uvfg;.flag;.flg;.uvflags;.uvflgs;.uvfgs;.flags;.flgs', artifact_flagfiles=None)#
class avica.pipe.steps.Phaseshift#

Bases: PipelineStepBase


  • works if coordinate file was provided e.g class_search_coord.ascii

  • match sources by coordinate and phaseshift if not coordinates within 1 arcsecond

  • casa tasks is triggered with the correct python environment using payload service


name: str = 'phaseshift'#
colnames: ColName = ('phaseshift', 'Comment_phaseshift', 'timestamp_phaseshift')#
py_env = 'casa-6.7'#
description: str = 'uses the coodinate search file result from previous step, performs phaseshift when source is off by 1 arcsecond'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='phaseshift', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772262), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772263))#
run(lf, wd_ifolder, fitsfile, target, separation_thres, class_search_asciifile, removables=[], rm_only=False, rm_pre=False, delete_removables=False, verbose=False)#
class avica.pipe.steps.AverageMS#

Bases: PipelineStepBase


  • When required average data to 2s and 500KHz in time and frequency resolution.

  • split the averaged data by removing filtered anenna.


name: str = 'avica_avg'#
colnames: ColName = ('avica_avg', 'Comment_avg', 'timestamp_avg')#
py_env = 'casa-6.7'#
description: str = 'Average the Measurement Set to have INTTIM=2sec, CHWIDTH=500KHz | uses CASA task mstransform'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.CasaSetup'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='avica_avg', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772278), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772278))#
run(lf, wd_ifolder, casadir, targets, target, mpi_cores=5, drop_dead_pol='auto', removables=[], rm_only=False, rm_pre=False, delete_removables=False, verbose=True)#
class avica.pipe.steps.AvicaMetaMS#

Bases: PipelineStepBase


  • Creates metadata by identifying sources from MS file per band.

  • Saves msmeta and sources avica files per band.


name: str = 'avicameta_ms'#
colnames: ColName = ('avicameta_ms', 'Comment_metams', 'timestamp_metams')#
py_env = 'casa-6.7'#
description: str = 'Creates MS metadata by identifying sources per band'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.CasaSetup'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='avicameta_ms', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772291), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772291))#
run(lf, wd_ifolder, init_params, rfc_catalogfile, target, flux_threshold_phref=0.15, removables=[], rm_only=False, rm_pre=False, delete_removables=False, verbose=True)#
class avica.pipe.steps.SnRating#

Bases: PipelineStepBase


  • iteratively run s/n rating through each workdir


name: str = 'avica_snr'#
colnames: ColName = ('avica_snr', 'Comment_avica_snr', 'timestamp_avica_snr')#
py_env = 'casa-6.7'#
description: str = 'To do a short fringefit to get the signal-to-noise rating'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.CasaSetup'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='avica_snr', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772305), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772307))#
run(lf, wd_ifolder, init_params, casadir, target, n_refant=5, n_calib=6, removables=[], rm_only=False, rm_pre=False, delete_removables=False, multiband_snrating=True, mpi_cores=5, n_scan_snrting=7, verbose=True)#
class avica.pipe.steps.FillInputMs#

Bases: PipelineStepBase


  • Fills input folder using metadata from the s/n rating if exists.


name: str = 'avica_fill_input'#
colnames: ColName = ('avica_fill_input', 'Comment fill_input', 'timestamp_fill_input')#
py_env = 'casa-6.7'#
description: str = 'fill the rPicard input using the metadata from the previous step'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.CasaSetup'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='avica_fill_input', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772319), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772320))#
run(lf, wd_ifolder, rfc_catalogfile, target, n_calib=6, snr_threshold_phref=7, hi_freq_ref=11, removables=[], rm_only=False, rm_pre=False, delete_removables=False, min_channel_flagging=32, sci_solints='auto', solint_max_scan_partitions=8, verbose=True)#
class avica.pipe.steps.FinalSplitMs#

Bases: PipelineStepBase


  • Uses mstransform to split the input visibility to contain only the final selected sources.


name: str = 'avica_split_ms'#
colnames: ColName = ('avica_split_ms', 'Comment split ms', 'timestamp_split_ms')#
py_env = 'casa-6.7'#
description: str = 'Split the MS file to only contain selected sources.'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.CasaSetup'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='avica_split_ms', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772332), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772333))#
run(lf, wd_ifolder, casadir, target, removables=[], rm_only=False, rm_pre=False, delete_removables=False, verbose=True, mpi_cores=10)#
class avica.pipe.steps.Calibration#

Bases: PipelineStepBase


  • Runs the complete rPicard calibrtion framework.


name: str = 'rpicard'#
colnames: ColName = ('rpicard', 'Comment_rpicard', 'timestamp_rpicard')#
py_env = 'casa-6.7'#
description: str = 'run the complete rPicard calibrtion framework.'#
validate_by: List = [<class 'avica.pipe.core.InitVariables'>, <class 'avica.pipe.core.RunValidation'>, <class 'avica.pipe.core.UpdateResults'>, <class 'avica.pipe.core.UpdateSheet'>]#
result: StepResult = StepResult(name='rpicard', success_count=0, failed_count=0, start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772344), detail={}, desc=[], success=[], end_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 772345))#
run(lf, wd_ifolder, casadir, target, verbose=True, removables=[], rm_only=False, picard_input_template_update='', delete_previous_data=True, rm_pre=False, delete_removables=False, mpi_cores=10)#

Helpers#

avica.pipe.helpers.get_targets_filenames(lf, filename_col, targetname_col)#
avica.pipe.helpers.select_existing_wd(fitsfiles, target_dir, ifolder)#

Return the workdir that setup_workdir would reuse for fitsfiles, or None.

Never creates anything, so it is safe to call before the pipeline runs (e.g. to locate the result CSV for --resume).

avica.pipe.helpers.get_wd_ifolder_multiplefits(fitsfiles, target_dir, ifolder)#

Reuse a complete input set, preferring preprocessed, newer workdirs.

avica.pipe.helpers.safe_name_part(value)#

Make value usable as one __-separated field of a file name: path separators and whitespace become -, and runs of _ are squeezed so a field can never contain the __ separator.

Return type:

str

avica.pipe.helpers.result_csv_name(target, project_code, workdir)#
Return type:

str

avica.pipe.helpers.result_csv_path(target_dir, target, project_code, workdir)#
Return type:

Path

avica.pipe.helpers.parse_result_csv_name(name)#

Inverse of result_csv_name. Returns {'target', 'project_code', 'workdir'} or None for names that do not follow the pattern.

avica.pipe.helpers.legacy_result_csv_path(target_dir, target)#

Pre-#59 name: {target}_result.csv.

Return type:

Path

avica.pipe.helpers.find_result_csvs(target_dir, target, project_code=None, workdir=None)#

Result CSVs in target_dir for target, optionally narrowed by project code and/or workdir name. Newest (by modification time) first.

avica.pipe.helpers.resolve_result_csv(target_dir, target, fitsfilenames, folder_for_fits, picard_input_template)#

Work out, without creating anything, which result CSV a run with these inputs will write to. Returns None when the workdir does not exist yet.

avica.pipe.helpers.search_input_template(picard_input_template, ifolder, depth=4)#
avica.pipe.helpers.setup_workdir(lf, target_dir, fitsfilenames, allfitsfile, picard_input_template)#
avica.pipe.helpers.fits_has_target(fitsfiles, target)#
avica.pipe.helpers.add_O(src_name)#
avica.pipe.helpers.normalize_strlist(value)#

Coerce a config list to a list of strings.

read_inputfile has no list syntax, so a list-valued option arrives as the raw text – [], [a, b] or a, b – and has to be unpacked here.

avica.pipe.helpers.parse_params(lf, params)#
avica.pipe.helpers.get_logfilename(fnname='fitsidiutil', start_stamp=datetime.datetime(2026, 10, 10, 1, 49, 24, 750599), module_name='avica')#

Return

{fnname}_{module_name}_log-{start_stamp.strftime(“%Y%m%d_%H%M%S”)}.log

fnn

avica.pipe.helpers.read_avica_sources_msmeta(metafile)#
avica.pipe.helpers.alls_fromobs(obs_b)#
avica.pipe.helpers.read_avica_sources(avicametafile=None, s=None)#
avica.pipe.helpers.update_constants(wd_ifolder, filename=None, val_dict={}, new_wd=None)#
avica.pipe.helpers.read_avicameta(wd_ifolder=None, avicametafile=None)#
avica.pipe.helpers.update_from_avicameta(wd_ifolder, filename=None, inpfile='', val_dict=None, new_wd=None, reference_ifolder='')#
avica.pipe.helpers.array_finetune_read(p)#
Parameters:

p (dict)

Return type:

dict

avica.pipe.helpers.array_finetune_write(p)#
avica.pipe.helpers.update_array_finetune(wd_ifolder, new_wd=None, dic_p={})#
avica.pipe.helpers.update_array_finetune_values(p)#
avica.pipe.helpers.fillinp_fromiwd(iwd, iwd_b)#
avica.pipe.helpers.update_obsfrom_avicameta(wd_ifolder, sources_dict=None, new_wd=None, band=None)#
avica.pipe.helpers.fill_input_byvalues(wd_ifolder, iwd_b, vis, target, flux_thres, n_calib, caliblist_file, sourcesf, refantsf, sourcesf_snr, band=None, min_channel_flagging=32, sci_solints='auto', solint_max_scan_partitions=8, pipe_params=None, hi_freq_ref=11)#
avica.pipe.helpers.casa_quote(value)#

Single-quote a CASA flagcmd value.

Parameters:

value (str)

Return type:

str

avica.pipe.helpers.contiguous_ranges(values)#

Return inclusive contiguous ranges for sorted integer values.

Parameters:

values (list[int])

Return type:

list[tuple[int, int]]

avica.pipe.helpers.format_ranges(values)#
Parameters:

values (list[int])

Return type:

str

avica.pipe.helpers.format_timerange(base_time, timerang_days)#

Convert FITS-IDI TIMERANG day offsets to CASA timerange syntax.

Parameters:
Return type:

str

avica.pipe.helpers.format_casa_time(time)#
Parameters:

time (datetime)

Return type:

str

avica.pipe.helpers.casa_time_from_seconds(seconds)#
Parameters:

seconds (float)

Return type:

datetime

avica.pipe.helpers.parse_fits_date(value)#
Parameters:

value (str)

Return type:

datetime

avica.pipe.helpers.antenna_names(hdul)#
Parameters:

hdul (astropy.io.fits.HDUList)

Return type:

dict[int, str]

avica.pipe.helpers.source_names(hdul)#
Parameters:

hdul (astropy.io.fits.HDUList)

Return type:

dict[int, str]

avica.pipe.helpers.format_antenna(ants, ant_names)#
Parameters:
Return type:

str | None

avica.pipe.helpers.format_spw(bands, chans, nband, nchan)#

Convert FITS-IDI BANDS/CHANS to a CASA spw selector.

FITS-IDI BANDS and CHANS use one-based numbering. A zero channel range means all channels.

Parameters:
Return type:

str | None

avica.pipe.helpers.format_correlation(pflags)#
Parameters:

pflags (numpy.ndarray)

Return type:

str | None

avica.pipe.helpers.flag_row_to_command(row, *, base_time, nband, nchan, ant_names, src_names)#
Parameters:
Return type:

str

avica.pipe.helpers.convert_flag_table(idifits, output)#
Parameters:
Return type:

int

avica.pipe.helpers.convert_ms_flag_cmd_table(vis, output)#
Parameters:
Return type:

int

avica.pipe.helpers.get_allfitsfiles(folder_for_fits, depth=3, extensions=['*fits', '*FITS', '*.idifits', '*.IDIFITS', '*.idi*', '*.IDI*'])#
avica.pipe.helpers.build_path(filepath)#
class avica.pipe.helpers.FileSize(dest, u='GB')#

Bases: object

get_size(u)#
avica.pipe.helpers.get_project(fitsfile)#
avica.pipe.helpers.iwd_for_fitsfile(fitsfile, target_dir, ifolder=None, create=False, splitted=False, allwds=False)#

looks for wd using project name

avica.pipe.helpers.get_wd_ifolder(fitsfile, target_dir, ifolder)#
avica.pipe.helpers.single_ifcheck(nchan, chwidth, nchan_default=16, chwidth_bound=500.0)#
avica.pipe.helpers.latest_file(path, pattern='*')#
Parameters:
avica.pipe.helpers.split_band_and_data(x)#
avica.pipe.helpers.split_and_stack_multiple_cols(dfsheet, cols)#

Only for columns containing values = [f”{band}: float]

Splits and stacks multiple columns in a DataFrame.

Params:

dfsheet (pd.DataFrame): The input DataFrame. cols (list): List of column names to process.

Returns:

A DataFrame with split and stacked rows for all specified columns.

Return type:

pd.DataFrame

avica.pipe.helpers.calc_vis_perc(fitsfile, calibrated=False)#
avica.pipe.helpers.find_url_tsys(fitsfile, proj='')#

TODO: if it is EVLA observation you need ppppcal.y for VLA refer https://science.nrao.edu/facilities/vlba/calibration-and-tools/caliblogs

avica.pipe.helpers.del_fl(wd, count=0, fl='*ms*', rm=False)#

delete files from the input folder

Parameters:
  • wd (str) – where to look for the file

  • count (int, optional) – _description_. Defaults to 0.

  • fl (str, optional) – _description_. Defaults to ‘ms’.

  • rm (bool, optional) – _description_. Defaults to False.

Returns:

_description_

Return type:

_type_

avica.pipe.helpers.find_tsys(wd_ifolder, fitsfile, count, failed)#
avica.pipe.helpers.overlap_percentage(A_start, A_end, B_start, B_end)#
avica.pipe.helpers.tsys_exists(fitsfile, valid_perc=5, verbose=False)#
avica.pipe.helpers.tsys_exists_in_fitsfiles(fitsfile, fitsfiles, valid_perc=5, verbose=True)#
avica.pipe.helpers.read_calibration_tables(fitsfile)#

read_idi of only the antenna and calibration tables (headers of all HDUs).

read_idi reports errors instead of raising and can return a truncated HDU list (seen while a file was being rewritten); every FITS-IDI file has UV_DATA, so its absence is treated as a failed read.

avica.pipe.helpers.tsys_antenna_coverage(fitsfile, valid_perc=5, hdul=None)#

{ANNAME: percent of the UV_DATA time range covered by valid TSYS}.

A TSYS row is valid if any TSYS_* value is finite and > 0 (single-hand bands carry -999.9 in the other hand). Antennas without valid rows get 0.0. Time reference and overlap follow tsys_exists.

avica.pipe.helpers.gain_curve_antennas(fitsfile, hdul=None)#

Antenna names that have at least one GAIN_CURVE row.

avica.pipe.helpers.uncalibrated_antennas(fitsfile, valid_perc=5)#

{‘tsys’: […], ‘gain’: […]}: antennas lacking TSYS coverage or any gain curve.

avica.pipe.helpers.attach_antab(self, only_first=True, attach_all=False)#
avica.pipe.helpers.meta_from_fitsfile(fitsfile, target, wd_ifolder, metafolder, reference_ifolder, do_manual_selection)#
avica.pipe.helpers.meta_from_fitsfile_freqid(fitsfiles, target, wd_ifolder, metafolder, reference_ifolder, do_manual_selection)#

assumes wd_ifolder exists

avica.pipe.helpers.count_freqids(fitsfile)#
avica.pipe.helpers.check_target_in_ms(vis, target)#

Artifact flags#

Discover station UVFLG artifacts and build additive CASA manual flags.

Uses the JIVE keyin parser also used by casavlbitools.convert_flags. TIMEOFF and DTIMRANG follow AIPS UVFLG INTEXT semantics (seconds, persistent nonzero values): https://www.aips.nrao.edu/cgi-bin/ZXHLP2.PL?UVFLG Unsupported selectors are rejected rather than silently broadening a flag.

avica.pipe.artifact_flags.discover_flagfiles(directories, extensions='.fg;.uvflag;.uvflg;.uvfg;.flag;.flg;.uvflags;.uvflgs;.uvfgs;.flags;.flgs', explicit=None)#

Explicit files override discovery; each resolved path is visited once.

avica.pipe.artifact_flags.read_uvflg(path)#
avica.pipe.artifact_flags.fits_flag_contexts(fitsfiles)#

Read antennas, IF dimensions and actual UV time ranges per input file.

avica.pipe.artifact_flags.row_commands(row, contexts)#
avica.pipe.artifact_flags.build_artifact_flagcmd(fitsfiles, output, directories, extensions='.fg;.uvflag;.uvflg;.uvfg;.flag;.flg;.uvflags;.uvflgs;.uvfgs;.flags;.flgs', explicit=None)#

Return command count and per-file provenance without modifying input data.

Reports#

Rendering of AVICA pipeline result CSVs.

A result CSV is written incrementally by avica.pipe.core.append_step_result_csv(), one row per step attempt, to <target_dir>/result__{target}__{project_code}__{workdir}.csv (see avica.pipe.helpers.result_csv_name()), with the column layout of avica.pipe.core.StepResult:

name, success_count, failed_count, start_stamp, detail, desc, success, end_stamp

The file is APPEND-ONLY: re-running a step appends a further row, so a step name may appear several times. latest_per_step() collapses to the most recent attempt; render_history() shows every attempt.

Four layouts are provided:

  • render_ladder(): one row per pipeline step in canonical order, with a status tally and the command needed to resume.

  • render_detail(): full desc text in panels for steps that did not fully succeed.

  • render_history(): every attempt of every step, grouped by step.

  • render_oneline(): a single compact status line for scripts and CI.

render_result() composes them according to the flags passed by avica pipe result.

Reading uses the standard-library csv module so that inspecting a result file never requires the heavier pipeline imports.

avica.pipe.report.read_result_csv(csvfile)#

Read every attempt recorded in a result CSV, oldest first.

Returns an empty list when the file is missing or has no usable rows, so callers can distinguish “nothing ran” from “something failed”.

Return type:

List[Dict]

avica.pipe.report.classify(row)#

Status of a single attempt.

‘ok’ is the same condition as cli_new._is_successful_result(); ‘partial’ additionally distinguishes a step that produced some output but also recorded failures, which a success/fail flag alone cannot express.

Parameters:

row (Dict | None)

Return type:

str

avica.pipe.report.latest_per_step(rows)#

Collapse the append-only log to the most recent attempt of each step.

Parameters:

rows (List[Dict])

Return type:

Dict[str, Dict]

avica.pipe.report.resume_step(rows)#

First pipeline step that has not completed successfully, i.e. the step avica pipe run –resume would start from. None when all steps are done.

Parameters:

rows (List[Dict])

Return type:

str | None

avica.pipe.report.render_result(rows, target='', history=False, oneline=False, detail=True, console=None)#

Render a result CSV according to the flags of avica pipe result.

oneline a single status line, and nothing else history every attempt, instead of the collapsed ladder detail append failure panels when a step did not fully succeed

Parameters:
Return type:

None

avica.pipe.report.render_ladder(console, rows, target='', note=None)#

One row per pipeline step, in canonical order rather than CSV order, so steps that never ran are shown as pending instead of being absent.

note defaults to showing the condensed failure note only when the terminal is wide enough to carry it.

Parameters:
  • console (rich.console.Console)

  • rows (List[Dict])

  • target (str)

  • note (bool | None)

Return type:

None

avica.pipe.report.render_detail(console, rows, target='')#

Full desc text for every step that did not fully succeed, one panel each.

desc holds complete exception traces; rendering it in a table cell would dictate the width of every other column, so it is given its own block.

Parameters:
  • console (rich.console.Console)

  • rows (List[Dict])

  • target (str)

Return type:

None

avica.pipe.report.render_history(console, rows, target='')#

Every recorded attempt, grouped by step. The step name is printed only on the first row of each group and groups are separated by a rule, following the grouping style of avica pipe config –summary.

Parameters:
  • console (rich.console.Console)

  • rows (List[Dict])

  • target (str)

Return type:

None

avica.pipe.report.render_oneline(console, rows, target='')#

A single line: per-step glyph strip, tally, and the next step to run.

Parameters:
  • console (rich.console.Console)

  • rows (List[Dict])

  • target (str)

Return type:

None