cubevis 0.5.14__py3-none-any.whl → 0.5.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cubevis might be problematic. Click here for more details.

@@ -1,116 +0,0 @@
1
- '''
2
- Check inputs to MsRaster plot() or its GUI
3
- '''
4
-
5
- from cubevis.plot.ms_plot._ms_plot_constants import VIS_AXIS_OPTIONS, AGGREGATOR_OPTIONS
6
-
7
- def check_inputs(inputs):
8
- ''' Check plot input types, and axis input values. '''
9
- _set_baseline_antenna_axis(inputs)
10
- _check_axis_inputs(inputs)
11
- _check_selection_input(inputs)
12
- _check_agg_inputs(inputs)
13
- _check_color_inputs(inputs)
14
- _check_other_inputs(inputs)
15
-
16
- def _set_baseline_antenna_axis(inputs):
17
- ''' Set baseline axis to dimension in data_dims '''
18
- if 'data_dims' not in inputs:
19
- return
20
-
21
- data_dims = inputs['data_dims']
22
- baseline_dim = 'antenna_name' if 'antenna_name' in data_dims else 'baseline'
23
-
24
- # Convert baseline axis to existing baseline dimension
25
- baseline_dims = ['baseline', 'antenna_name']
26
- for axis in ['x_axis', 'y_axis', 'iter_axis', 'agg_axis']:
27
- if inputs[axis] in baseline_dims:
28
- inputs[axis] = baseline_dim
29
-
30
- def _check_axis_inputs(inputs):
31
- ''' Check x_axis, y_axis, vis_axis, and iter_axis inputs. '''
32
- x_axis = inputs['x_axis']
33
- y_axis = inputs['y_axis']
34
- if x_axis == y_axis:
35
- raise ValueError(f"Invalid parameter values: x_axis {x_axis} cannot be same as y_axis {y_axis}.")
36
-
37
- iter_axis = inputs['iter_axis']
38
- if iter_axis and iter_axis in (x_axis, y_axis):
39
- raise ValueError(f"Invalid parameter value: iter_axis {iter_axis} cannot be x_axis ({x_axis}) or y_axis ({y_axis}).")
40
-
41
- data_dims = inputs['data_dims'] if 'data_dims' in inputs else None
42
- if data_dims:
43
- if x_axis not in data_dims or y_axis not in data_dims:
44
- raise ValueError(f"Invalid parameter value: x and y axis must be a data dimension in {data_dims}.")
45
- if iter_axis and iter_axis not in data_dims:
46
- raise ValueError(f"Invalid parameter value: iter_axis {iter_axis} must be a data dimension in {data_dims}.")
47
-
48
- vis_axis = inputs['vis_axis']
49
- if vis_axis not in VIS_AXIS_OPTIONS:
50
- raise ValueError(f"Invalid parameter value: vis_axis {vis_axis} must be one of {VIS_AXIS_OPTIONS}")
51
-
52
- def _check_selection_input(inputs):
53
- ''' Check selection type and data_group selection. Make copy of user selection. '''
54
- if 'selection' in inputs:
55
- user_selection = inputs['selection']
56
- if user_selection:
57
- if not isinstance(user_selection, dict):
58
- raise TypeError("Invalid parameter type: selection must be dictionary.")
59
-
60
- def _check_agg_inputs(inputs):
61
- ''' Check aggregator and agg_axis. Set agg_axis if not set. '''
62
- aggregator = inputs['aggregator']
63
- agg_axis = inputs['agg_axis']
64
-
65
- x_axis = inputs['x_axis']
66
- y_axis = inputs['y_axis']
67
- data_dims = inputs['data_dims'] if 'data_dims' in inputs else None
68
-
69
- if aggregator and aggregator not in AGGREGATOR_OPTIONS:
70
- raise ValueError(f"Invalid parameter value: aggregator {aggregator} must be None or one of {AGGREGATOR_OPTIONS}.")
71
-
72
- if agg_axis:
73
- if not isinstance(agg_axis, str) and not isinstance(agg_axis, list):
74
- raise TypeError(f"Invalid parameter type: agg_axis {agg_axis} must be str or list.")
75
-
76
- # Make agg_axis a list
77
- if isinstance(agg_axis, str):
78
- agg_axis = [agg_axis]
79
-
80
- for axis in agg_axis:
81
- if axis in (x_axis, y_axis):
82
- raise ValueError(f"Invalid parameter value: agg_axis {agg_axis} cannot be x_axis ({x_axis}) or y_axis ({y_axis}).")
83
- if data_dims and axis not in data_dims:
84
- raise ValueError(f"Invalid parameter value: agg_axis {axis} must be a data dimension in {data_dims}.")
85
- elif aggregator and data_dims:
86
- # Set agg_axis to non-plotted dim axes
87
- agg_axis = data_dims.copy()
88
- agg_axis.remove(x_axis)
89
- agg_axis.remove(y_axis)
90
- if 'iter_axis' in inputs and inputs['iter_axis']:
91
- agg_axis.remove(inputs['iter_axis'])
92
- inputs['agg_axis'] = agg_axis
93
-
94
- def _check_color_inputs(inputs):
95
- if inputs['color_mode']:
96
- color_mode = inputs['color_mode'].lower()
97
- valid_color_modes = ['auto', 'manual']
98
- if color_mode not in valid_color_modes:
99
- raise ValueError(f"Invalid parameter value: color_mode {color_mode} must be None or one of {valid_color_modes}.")
100
- inputs['color_mode'] = color_mode
101
-
102
- if inputs['color_range']:
103
- if not (isinstance(inputs['color_range'], tuple) and len(inputs['color_range']) == 2):
104
- raise ValueError("Invalid parameter type: color_range must be None or a tuple of (min, max).")
105
-
106
- def _check_other_inputs(inputs):
107
- if inputs['iter_range']:
108
- if not (isinstance(inputs['iter_range'], tuple) and len(inputs['iter_range']) == 2):
109
- raise ValueError("Invalid parameter type: iter_range must be None or a tuple of (start, end).")
110
-
111
- if inputs['subplots']:
112
- if not (isinstance(inputs['subplots'], tuple) and len(inputs['subplots']) == 2):
113
- raise ValueError("Invalid parameter type: subplots must be None or a tuple of (rows, columns).")
114
-
115
- if inputs['title'] and not isinstance(inputs['title'], str):
116
- raise TypeError("Invalid parameter type: title must be None or a string.")
@@ -1,110 +0,0 @@
1
- '''
2
- Functions for plot axes labels
3
- '''
4
-
5
- # pylint: disable=inconsistent-return-statements
6
- def get_coordinate_labels(xds, coordinate):
7
- ''' Return coordinate values as string or list of strings, or None if numeric '''
8
- if coordinate == 'time':
9
- return _get_time_labels(xds.time)
10
- if coordinate == 'baseline':
11
- return _get_baseline_antenna_labels(xds.baseline)
12
- if coordinate == 'antenna_name':
13
- return _get_baseline_antenna_labels(xds.antenna_name)
14
- if coordinate == 'frequency':
15
- return _get_frequency_labels(xds.frequency)
16
- if coordinate == 'polarization':
17
- return _get_polarization_labels(xds.polarization)
18
- # pylint: enable=inconsistent-return-statements
19
-
20
- def get_axis_labels(xds, axis):
21
- ''' Return axis name, label and ticks, reindex for regular axis '''
22
- labels = get_coordinate_labels(xds, axis)
23
- ticks = list(enumerate(labels)) if labels is not None and isinstance(labels, list) else None
24
-
25
- if axis == "time":
26
- start_date, _ = _get_date_range(xds.time)
27
- label = f"Time {xds.time.attrs['scale'].upper()} ({start_date})"
28
- elif axis == "baseline":
29
- label = "Baseline Antenna1"
30
- ticks = _get_baseline_ant1_ticks(ticks)
31
- elif axis == "antenna_name":
32
- label = "Antenna"
33
- elif axis == "frequency":
34
- label = f"Frequency ({xds.frequency.attrs['units']}) {xds.frequency.attrs['observer'].upper()}"
35
- elif axis == "polarization":
36
- label = "Polarization"
37
- else:
38
- label = None
39
- return (axis, label, ticks)
40
-
41
- def get_vis_axis_labels(xds, data_group, correlated_data, vis_axis, include_unit=True):
42
- ''' Get vis axis label for colorbar. Returns (axis, label, ticks) '''
43
- label = vis_axis.capitalize()
44
- if data_group != 'base':
45
- label += f":{data_group.capitalize()}"
46
-
47
- if include_unit:
48
- units = None
49
- if vis_axis in xds.data_vars and 'units' in xds[vis_axis].attrs:
50
- units = xds[vis_axis].units
51
- else:
52
- if 'units' in xds[correlated_data].attrs:
53
- units = xds[correlated_data].units
54
- if units:
55
- label += f" ({units})"
56
-
57
- return (vis_axis, label)
58
-
59
- def _get_time_labels(time_xda):
60
- ''' Return time as formatted string, or None to autogenerate ticks '''
61
- if time_xda.size == 1:
62
- time = time_xda.values.astype('datetime64[s]').item().strftime("%d-%b-%Y %H:%M:%S")
63
- time += " " + time_xda.attrs['scale'].upper()
64
- return time
65
- return None # auto ticks from time values
66
-
67
- def _get_baseline_antenna_labels(baseline_antenna_xda):
68
- ''' Return baseline pairs as string or list of strings '''
69
- if baseline_antenna_xda.size == 1:
70
- return baseline_antenna_xda.values
71
- return baseline_antenna_xda.values.ravel().tolist()
72
-
73
- def _get_polarization_labels(polarization_xda):
74
- ''' Return polarization as single string or list of strings '''
75
- if polarization_xda.size == 1: # string
76
- return polarization_xda.values
77
- return list(polarization_xda.values) # array of strings
78
-
79
- def _get_frequency_labels(frequency_xda):
80
- ''' Return frequency as formatted string, or None to autogenerate ticks '''
81
- if frequency_xda.size == 1:
82
- return f"{frequency_xda.item():.4f} {frequency_xda.attrs['units']} {frequency_xda.attrs['observer'].upper()}"
83
- return None # auto ticks from frequency values
84
-
85
- def _get_date_range(time_xda):
86
- ''' Return date as dd-Mon-yyyy e.g. 23-Aug-2010 '''
87
- if time_xda.size == 1:
88
- date = time_xda.values.astype('datetime64[s]').item().strftime("%d-%b-%Y")
89
- return (date, date)
90
- start_date = time_xda.values[0].astype('datetime64[s]').item().strftime("%d-%b-%Y")
91
- end_date = time_xda.values[time_xda.size - 1].astype('datetime64[s]').item().strftime("%d-%b-%Y")
92
- return (start_date, end_date)
93
-
94
- def _get_baseline_ant1_ticks(baseline_ticks):
95
- ''' Return labels for each new ant1 name in baselines '''
96
- ant1_ticks = []
97
- last_ant1 = None
98
- last_idx = None
99
-
100
- # space by minimum increment to avoid overlapping tick labels
101
- min_increment = max(int(len(baseline_ticks) / 50), 1)
102
-
103
- for idx, tick in baseline_ticks:
104
- ant1_name = tick.split(' & ')[0]
105
- if ant1_name != last_ant1:
106
- last_ant1 = ant1_name
107
- if last_idx is None or ((idx - last_idx) >= min_increment):
108
- ant1_ticks.append((idx, ant1_name))
109
- last_idx = idx
110
- return ant1_ticks