31 + | """ |
32 + | Computes the absolute phase difference between two complex numbers in degrees. |
33 + | |
34 + | This function calculates the difference in phase angles between two complex numbers |
35 + | and returns the result in degrees. If either input is a real number (i.e., has no |
36 + | imaginary component), it returns zero, as the phase difference of real numbers is always zero. |
37 + | |
38 + | Args: |
39 + | c1 (complex): The first complex number. |
40 + | c2 (complex): The second complex number. |
41 + | |
42 + | Returns: |
43 + | float: The absolute phase difference between `c1` and `c2` in degrees. Returns 0.0 |
44 + | if either input is a real number. |
45 + | |
46 + | Raises: |
47 + | ValueError: If the inputs are not complex numbers. |
48 + | """ |
48 - | compTables - compare two CASA tables |
49 - | |
50 - | referencetab - the table which is assumed to be correct |
51 - | |
52 - | testtab - the table which is to be compared to referencetab |
53 - | |
54 - | excludecols - list of column names which are to be ignored |
55 - | |
56 - | tolerance - permitted fractional difference (default 0.001 = 0.1 percent) |
57 - | |
58 - | mode - comparison is made as "percentage", "absolute", "phaseabsdeg" (for complex numbers = difference of the phases in degrees) |
65 + | Compares columns from two tables and verifies if they match within specified tolerances. |
66 + | |
67 + | This function compares corresponding columns in two tables (`referencetab` and `testtab`) while ignoring columns listed in `excludecols`. It evaluates the differences based on the specified `mode` (e.g., "percentage", "absolute", "phaseabsdeg") and tolerance. It checks data types like float, int, string, and list/array, and reports discrepancies. |
68 + | |
69 + | Args: |
70 + | referencetab (str): Path to the reference table file. |
71 + | testtab (str): Path to the test table file. |
72 + | excludecols (list of str): List of column names to exclude from comparison. |
73 + | tolerance (float, optional): Tolerance level for comparison. Default is 0.001. |
74 + | mode (str, optional): Comparison mode. Can be "percentage", "absolute", or "phaseabsdeg". Default is "percentage". |
75 + | startrow (int, optional): Starting row index for comparison. Default is 0. |
76 + | nrow (int, optional): Number of rows to compare. Default is -1, which means all rows. |
77 + | rowincr (int, optional): Row increment for comparison. Default is 1. |
78 + | |
79 + | Returns: |
80 + | bool: `True` if all compared columns match within the specified tolerance, `False` otherwise. |
81 + | |
82 + | Notes: |
83 + | - Handles comparison of columns with different data types including lists and numpy arrays. |
84 + | - For "phaseabsdeg" mode, ensure that `phasediffabsdeg` function is defined. |
200 - | '''Compare a variable column of two tables. |
201 - | referencetab --> a reference table |
202 - | testtab --> a table to verify |
203 - | varcol --> the name of a variable column (str) |
204 - | Returns True or False. |
205 - | ''' |
206 - | |
225 + | """ |
226 + | Compares a variable column from two tables to ensure they match within a specified tolerance. |
227 + | |
228 + | This function compares a specific variable column (`varcol`) from two tables (`referencetab` and `testtab`). It checks if the columns are variable columns and if the number of rows matches between the two tables. If a tolerance is provided, it verifies that the values in the column match within this tolerance. If no tolerance is specified, it checks for exact equality. |
229 + | |
230 + | Args: |
231 + | referencetab (str): Path to the reference table file. |
232 + | testtab (str): Path to the test table file. |
233 + | varcol (str): The name of the column to compare. |
234 + | tolerance (float, optional): Tolerance level for comparing numeric values. Default is 0.0, which implies exact equality. |
235 + | |
236 + | Returns: |
237 + | bool: `True` if the variable column matches within the specified tolerance, `False` otherwise. |
238 + | |
239 + | Example: |
240 + | >>> compVarColTables('ref_table.csv', 'test_table.csv', 'variable_column', tolerance=0.01) |
241 + | ERROR: Column variable_column of ref_table.csv and test_table.csv do not agree within tolerance 0.01 |
242 + | False |
243 + | |
244 + | Notes: |
245 + | - The function assumes that both tables have the same structure and are accessible via a method to open them, retrieve column data, and check if a column is a variable column. |
246 + | - For lists or arrays within the column, the comparison is performed element-wise. |
247 + | - If `tolerance` is set to 0, the function checks for exact equality. |
248 + | """ |
522 561 | def compmsmainnumcol(vis1, vis2, tolerance, colname1='DATA', colname2="DATA"): |
523 562 | print("Comparing column "+colname1+" of MS "+vis1) |
524 563 | print(" with column "+colname2+" of MS "+vis2) |
525 564 | print("Discrepant row search ...") |
526 565 | rval = False |
527 566 | try: |
528 567 | discrepantrows = checkwithtaql("select from [select from "+vis1+" orderby TIME, DATA_DESC_ID, ANTENNA1, ANTENNA2 ] t1, [select from "+vis2+" orderby TIME, DATA_DESC_ID, ANTENNA1, ANTENNA2 ] t2 where (not all(near(t1."+colname1+",t2."+colname2+", "+str(tolerance)+")))") |
529 568 | if discrepantrows==0: |
530 569 | print("The two columns agree.") |
531 570 | rval = True |