src.common package

Submodules

src.common.calibrate module

src.common.contextManagers module

src.common.contextManagers.change_dir(destination: str)[source]

Context manager to change working directory

Parameters:

destination (str) – path to directory

src.common.contextManagers.open_database(dbName: str)[source]

Context manager for opening and closing a database file

Parameters:

file_name (str) – filename of database

Yields:

cursor – cursor object to run database operations.

src.common.contextManagers.open_file(filePath: str)[source]

Context manager to open fits file for processing

The open_file function returns an object called an HDULIST which is a list-like collection of HDU objects. An HDU (Header Data Unit) is the highest level component of the FITS file structure, consisting of a header and (typically) a data array or table. see https://docs.astropy.org/en/stable/io/fits/

Parameters:

file (str) – path to file or filename

src.common.dataProcessingFlowManager module

src.common.dialog_app module

class src.common.dialog_app.App(log)[source]

Bases: QWidget

Dialog box application to get file/folder path. Had to use this because tkinter was crashing on my mac.

get_file_path()[source]

Get file path using the file open dialog.

Returns:

Path to the requested file.

Return type:

file_path (str)

get_folder_path()[source]

Get directory path using the directory open dialog.

Returns:

The path to the directory requested.

Return type:

folder_path (str)

src.common.driftScanAttributes module

src.common.driftScanData module

src.common.driftScans module

src.common.enums module

class src.common.enums.Month(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Apr = '04'
Aug = '08'
Dec = '12'
Feb = '02'
Jan = '01'
Jul = '07'
Jun = '06'
Mar = '03'
May = '05'
Nov = '11'
Oct = '10'
Sep = '09'
class src.common.enums.ScanType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Drift scan type

Parameters:

Enum (enum) – Enum of the different scan types

SBW - wide single beam
SBN - narrow single beam
DB - dual beam
DB = 3
SBN = 2
SBW = 1

src.common.exceptions module

exception src.common.exceptions.BeamTypeNotFoundError[source]

Bases: Error

Beam type not found error

exception src.common.exceptions.DB_READ_ERROR[source]

Bases: Error

Database read error

exception src.common.exceptions.DB_WRITE_ERROR[source]

Bases: Error

Databae write error

exception src.common.exceptions.EmptyFilePathError[source]

Bases: Error

Raised when an expected file path is empty.

exception src.common.exceptions.EmptyFolderError[source]

Bases: Error

Raised when a folder is empty

exception src.common.exceptions.EmptyTableError[source]

Bases: Error

Raised when a database table is empty.

exception src.common.exceptions.Error[source]

Bases: Exception

Base class for other exceptions.

exception src.common.exceptions.FileResourceNotFoundError[source]

Bases: Error

Raised when a file resource is not found or wasn’t included in the distribution files

exception src.common.exceptions.InvalidFileExtensionError[source]

Bases: Error

Raised when a file has an invalid file extension.

exception src.common.exceptions.InvalidFilePath[source]

Bases: Error

Raised when a file path is invalid.

exception src.common.exceptions.MissingChartHeaderError[source]

Bases: Error

Raised when a fits file is missing a chart header unit.

exception src.common.exceptions.MissingParameterException[source]

Bases: Error

Raised when a fits file is missing a chart header unit.

exception src.common.exceptions.ValueOutOfRangeException[source]

Bases: Error

Raised when a value is out of range.

src.common.file_handler module

class src.common.file_handler.FileHandler(log, path='')[source]

Bases: object

FileHandler manages the access and modification of files and their folders.

Parameters:
  • log (object) – logging object

  • path (str) – Path to a file

confirm_file_extension(extension)[source]

Confirm that the file has the correct extension. e.g. the program processes fits files so the extension should be .fits

Parameters:

extension (str) – The file’s extension

confirm_file_path_exists(filePath='')[source]

Confirm the file path / file exists.

Parameters:

filePath (str) – The absolute path to a file

Returns:

Boolean value representing whether the path exists or not.

confirm_file_path_exists_no_exit(filePath='')[source]

Confirm the file path / file exists.

Parameters:

filePath (str) – The absolute path to a file

Returns:

Boolean value representing whether the path exists or not.

create_folder(folderName)[source]

Create a folder.

Parameters:

folderName (str) – String of folder name

create_folder_overwrite_existing(folderName)[source]

Create a folder.

delete_file(fileName)[source]

Delete a file.

Parameters:

fileName (str) – The name of the file being deleted.

get_details_from_path(path='')[source]

Get file name and containing directory and their from path.

get_directory_name(filePath='')[source]

Get directory name from path. You can supply a file path or the full path to the directory.

Parameters:
  • dirPath (str) – path to directory

  • filePath (str) – Path to file

  • log (object) – logging object

Return type:

name of opened directory

get_file_extension(fileName='')[source]

Get file extension from file name.

Parameters:

fileName (str) – The name of the file.

get_file_name_and_containing_folder()[source]

Get the name of the file and its containing folder.

get_file_name_from_path()[source]

return the name of a file from the path.

get_file_path_from_dialog_box()[source]

Get a file using the file dialog box.

get_folder_name_from_path()[source]

Get the name of the containing folder from a path.

get_folder_path_from_dialog_box()[source]

Get a file using the file dialog box.

print_path_info()[source]

Print information on the file.

validate_file()[source]

Perform file validations. Check if the file exists and if it is in the correct format.

src.common.fitting module

src.common.fitting.calc_residual(model, data, log='')[source]

Calculate the residual and rms between the model and the data.

Parameters:
  • model (array) – 1D array containing the model data

  • data (array) – 1D array containing the raw data

  • log (object) – file logging object

Returns:

  • res (1d array) – the residual

  • rms (int) – the rms value

src.common.fitting.calc_residual_and_rms(x, y, log, order=1)[source]

Calculate the residual and rms from data

Parameters:
  • x (array) – 1d array

  • x-axis (data representing the) –

  • y (array) – 1d array data representing the y-axis

  • deg (int) – degree of the polynomial

Returns:

model of res (array): rms (float): coeff():

Return type:

model (array)

src.common.fitting.calc_residual_and_rms_fit(x, y, order=1)[source]

Calculate the residual and rms from data

Parameters:
  • x (array) – 1d array

  • x-axis (data representing the) –

  • y (array) – 1d array data representing the y-axis

  • deg (int) – degree of the polynomial

Returns:

model of res (array): rms (float): coeff():

Return type:

model (array)

src.common.fitting.clean_data(spl, x, y, scanLen, log='')[source]

Clean the data using iterative fitting.

Parameters:
  • spl – 1d array the splined data

  • x – 1d array data representing the x-axis

  • y – 1d array data representing the y-axis

  • scanLen – int length of the drift scan array

  • log – object file logging object

Returns:

1d array

the residual before the rfi has been removed

rmsBeforeClean: int

the rms before removing rfi data

rmsAfterClean: int

the rms after removal of rfi data

finX: 1d array

the data representing the x-axis after the removal of rfi data

finY: 1d array

the data representing the y-axis after the removal of rfi data

finRes: 1d array

the residual of the cleaned data after the rfi has been removed

finMaxSpl: int

the maximum of the spline of the cleaned data

finspl: 1d array

the spline of the cleaned data

pointsDeleted: int

number of points deleted when cleaning the data

Return type:

resRFI

src.common.fitting.clean_data_iterative_fitting(x, y, scanLen, res, rms, log='', x2='')[source]

Find the best fit to the data by iteratively eliminating data points that fall beyond an established cut-off limit.

x1d array

data representing the x-axis

y1d array

data representing the y-axis

scanLenint

length of the drift scan array

res: 1d array

the residual

rms: int

the rms value

logobject

file logging object

x21d array

filenames

finalX: 1d array

the data representing the x-axis after the removal of rfi data

finalY: 1d array

the data representing the y-axis after the removal of rfi data

finalRms: int

the rms after removal of rfi data

finRes: 1d array

the residual of the cleaned data after the rfi has been removed

finMaxSpl: int

the maximum of the spline of the cleaned data

finalSplinedData: 1d array

the spline of the cleaned data

pointsDeleted: int

number of points deleted when cleaning the data

src.common.fitting.clean_rfi(x, y, log='')[source]

Clean the RFI in the data using iterative rms cuts.

Parameters:
  • x (array) – Array of the independent variable

  • y (array) – Array of the dependent variable

  • log (object) – file logging object

Returns:

the data representing the x-axis after the removal of rfi data finY (array):the data representing the y-axis after the removal of rfi data rmsBeforeClean (int): the rms before removal of rfi data rmsAfterClean (int): the rms after removal of rfi data finspl (array): the spline of the cleaned data pointsDeleted (int): number of points deleted when cleaning the data

Return type:

finX (array)

src.common.fitting.correct_drift(xBase, yBase, x, log, order=1)[source]

Correct for a drifting baseline in the scan by fitting a first order polynomial to a region with no signal.

Parameters:
  • xBase (x data of the baseline) –

  • yBase (y data of the baseline) –

  • x (x data of the entire drift scan) –

src.common.fitting.filter_scans(x, window_len=10, window='flat')[source]

smooth the data using a window with requested size.

This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.

Parameters:
  • x – the input signal

  • window_len – the dimension of the smoothing window; should be an odd integer

  • window – the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’ flat window will produce a moving average smoothing.

Returns:

the smoothed signal

src.common.fitting.fit_beam(x, y, p, fnbw, force, log, saveTag, fitTheoretical, autoFit=None)[source]

Fit single beam data.

Parameters:
  • x (array) – 1D array of data representing the x-axis

  • y (array) – 1D array of data representing the y-axis

  • p (list) – list of initial fit parameters

  • fnbw (float) – source first null beam width from file

  • dec (float) – source declination

  • data (dict) – dictionary of source parameters

  • scanNum (int) – Value representing the current scan

  • force (str) – String to determine whether to force a fit or not

  • log (object) – loffing object

src.common.fitting.fit_dual_beam(x, y, hpbw, fnbw, factor, saveTo, log)[source]
src.common.fitting.fit_poly_peak(xp, yp, order, log)[source]

Fit the peak and estimate the errors.

src.common.fitting.gauss(x, *p)[source]

Gaussian for fitting the beam

src.common.fitting.gauss_lin(x, *p)[source]

Generate a gaussian plus first-order polynomial to fit the drift scan beam. Note that the width of the Gaussian is hard-coded to the half-power beamwidth.

Parameters:
  • x (1D array) – 1D array of data representing the x-axis

  • p (tuple) – tuple of gaussian parameters

Returns:

gaussFit – array of data representing the gaussian fit

Return type:

1d array

src.common.fitting.get_base(localMinPositions, block_width, scan_len)[source]

get the baseline block/s from data with large sidelobes.

src.common.fitting.get_base_pts(x, y, base_index_list)[source]

Get baseline points from a list of indexes.

src.common.fitting.locate_baseline_blocks_auto(x, y, peakCenterGuess, hfnbw, log, saveLoc)[source]

Find the locations to fit a baseline automatically.

These locations are found/determined by fitting a spline to the data and using the locations of the local minimum as baseline regions.

Parameters:
  • peakCenterGuess (float) – value of x at peak center in x array

  • hfnbw (float) – half the first null beam width

  • log (object) – loffing object

src.common.fitting.poly_coeff(x, y, deg)[source]

Calculate the polynomial coeffecients depending on the degree/order of the polynomial

Parameters:
  • x (array) – 1d array data representing the x-axis

  • y (array) – 1d array data representing the y-axis

  • deg (int) – degree of the polynomial

Returns:

array of polynomial fitted data

src.common.fitting.spline(x, y, anchor_points=9, order=3, log='')[source]

Given a set of data points (x,y) determine a smooth spline approximation of degree k on the interval x[0] <= x <= x[n]

Parameters:
  • x (array) – 1D array of data representing the x-axis

  • y (array) – 1D array of data representing the y-axis

  • anchor_points (int) – the number of anchor points in the data

  • order (int) – polynomial order to fit, preferrably a cubic spline

Returns:

Spline of the data

Return type:

spline_fit (array)

src.common.fitting.spline_fit(x, y, anchor_points=9, order=3)[source]

Given a set of data points (x,y) determine a smooth spline approximation of degree k on the interval x[0] <= x <= x[n]

Parameters:
  • x (array) – 1D array of data representing the x-axis

  • y (array) – 1D array of data representing the y-axis

  • anchor_points (int) – the number of anchor points in the data

  • order (int) – polynomial order to fit, preferrably a cubic spline

Returns:

Spline of the data

Return type:

spline_fit (array)

src.common.fitting.test_gauss_fit(x, y, p0, log='')[source]

Fit the data using a gaussian

Parameters:

p0 – initial fit guess

src.common.fitting.test_position_validity(localMaxPositions, localMinPositions, maxPoints)[source]

Test the position validity of the local min/max positions. The local minimum positions cannot fall within the range of the local maximum positions.

Parameters:
  • localMaxPositions (list) – list of local max positions

  • localMinPositions (list) – list of local min positions

  • p (int) – maximum number of permissable points.

Returns:

index list of positions to delete

Return type:

pointsToDelete

src.common.getResources module

src.common.getResources.get_cal_list() DataFrame[source]

Get list of calibrator names from file

src.common.getResources.get_jpl_results() DataFrame[source]

Get list of calibrator names from file The data used here is obtained from the NASA HORIZONS website https://ssd.jpl.nasa.gov/horizons/app.html#/

params: Ephemeris type: Observer Table, Target body: Jupiter, Observer Location: Geocentric [500] Time specification: 1950 to 2100, step=1 day

src.common.logConfiguration module

src.common.miscellaneousFunctions module

src.common.msgConfiguration module

src.common.msgConfiguration.disclaimer()[source]

Prints disclaimer.

src.common.msgConfiguration.load_prog(prog: str)[source]

Print message to load the selected program.

src.common.msgConfiguration.msg_wrapper(logName: str, log: object, msg: str)[source]

Wraps logging messages.

Parameters:
  • log_name (str) – The name of the logger e.g. info

  • log (object) – The logging object

  • msg (str) – The message to be wrapped.

src.common.msgConfiguration.print_start()[source]

Prints program banner.

src.common.observation module

src.common.plotting module

src.common.plotting.fit_plot()[source]
src.common.plotting.make_plot(plotlab)[source]

plot data from plotting ionary

src.common.plotting.make_qv_plots(lcp, rcp)[source]
src.common.plotting.plotBaselineEstimate(x, y, yspl, posLeft, posRight, lab1, lab2, title, saveTo, lb=[], rb=[], xlabel='', ylabel='')[source]

Plot the positions or locations of the baseline local minimum estimate.

Parameters:
  • x (list/array) – x-axis data

  • y (list/array) – y-axis data

  • yspl (list/array) – splined y-axis data

  • posLeft (int) – index of the local min to the left of the central peak

  • posRight (int) – index of the local min to the right of the central peak

  • lab1 (str) – label of posLeft

  • lab2 (str) – label of posRight

  • title (str) – title of plot

  • saveTo (str) – saving location

src.common.plotting.plotCorrectedData(x, ycorr, posLeft, posRight, lab1, lab2, title, saveTo, xlabel='', ylabel='')[source]

Plot corrected data.

Parameters:
  • x (list/array) – x-axis data

  • y (list/array) – y-axis data

  • ycorr (list/array) – corrected y-axis data

  • posLeft (int) – local mins to the left of the central peak

  • posRight (int) – local mins to the right of the central peak

  • lab1 (str) – label of raw data

  • lab2 (str) – label of corrected data

  • title (str) – title of plot

  • saveTo (str) – saving location

src.common.plotting.plotDualBeamFit(x1, y1, x2, y2, x3, y3, title, plotLab1, plotLab2, plotLab3, saveTo, xlabel='', ylabel='')[source]

Plot dual beam scan

src.common.plotting.plotPeakFit(title, x, ycorr, ypeak, err_peak, peak_beam, saveTo, xlabel='', ylabel='')[source]

_summary_

Parameters:
  • title (_type_) – _description_

  • x (_type_) – _description_

  • ycorr (_type_) – _description_

  • ypeak (_type_) – _description_

  • err_peak (_type_) – _description_

  • peak_beam (_type_) – _description_

  • saveTo (_type_) – _description_

  • xlabel (str, optional) – _description_. Defaults to “”.

  • ylabel (str, optional) – _description_. Defaults to “”.

src.common.plotting.plot_no_fit(x, y, title, subtitle, saveTo, label='', xlabel='', ylabel='')[source]

Plot corrupted data.

src.common.plotting.plot_overlap(x1, y1, x2, y2, title, plotLab1, plotLab2, saveTo, xlabel='', ylabel='')[source]

Overplot 2 scans

src.common.plotting.plot_scan(x, y, plotLab, title, saveTo, xlab='Scandist [deg]', ylab='T$_{A}$ [K]')[source]

Plot the drift scan

src.common.sqlite_db module

class src.common.sqlite_db.SQLiteDB(dbPath: str, log: object)[source]

Bases: object

close_db()[source]

Close the database connection.

commit_changes()[source]

Commit/save changes you have implemented to the database.

create_db()[source]

Create a new database.

create_table(data, tableName)[source]

Create an sql statement to create a table.

create_table_stmt(data, tableName)[source]

Create table from dictionary.

dbPath: str
get_all_table_coloumns(table_name)[source]

Get coloumns of table return index, coloumn name and coloumn type

get_rows(tbname)[source]

Get the rows in the database table.

Parameters:

tbname (str) – table name

Returns:

rows – table row list

Return type:

str

get_rows_of_cols(tbname, cols)[source]

Get the rows in the database table.

Parameters:

tbname (str) – table name

Returns:

rows – table row list

Return type:

str

get_table_names(db)[source]

Get table names from the database.

Parameters:

db (str) – The name of the database

Returns:

List of table names

Return type:

table_names (list)

insert_into_table_stmt_with_pk(data, tableName)[source]

Insert values into table and create a primary key.

log: object
populate_table(data, tableName, key='')[source]

populate a database table with values.

set_database_name(databaseName)[source]

Set the name of the database.

src.common.variables module

Module contents