1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
|
Data class
==========
.. default-domain:: lua
.. class:: Data
The Data class contains the visibility data, flag masks and meta data.
It may hold information for multiple polarizations, channels and timesteps,
such that it contains the data for a particular observing field,
spectral window (band) and antenna-pair (or single dish).
The data object thus holds a dynamic spectrum for each polarization.
The visibility data can consist of complex values, or single-float
values representing the real, imaginary, amplitude or phase of the
visibilities (see :meth:`get_complex_state`).
The Data class is a Lua ``userdata`` object.
Assigning one Data variable to another will therefore cause both variables
to point to the same object, and changing one will also change the other.
To create an independent object, :meth:`copy` can be used.
Internally, AOFlagger uses a copy-on-write-like mechanism for the
visibility sets, flag masks and meta data. It is not required for users
of the class to know about these implementation details, but the
relevant thing to know is that copy or assignment operations are generally
fast and don't increase memory usage.
Method summary
^^^^^^^^^^^^^^
* Copy & Modification
- :meth:`~Data.clear_mask`
- :meth:`~Data.copy`
- :meth:`~Data.flag_nans`
- :meth:`~Data.flag_zeros`
- :meth:`~Data.invert_mask`
- :meth:`~Data.join_mask`
- :meth:`~Data.set_mask`
- :meth:`~Data.set_mask_for_channel_range`
- :meth:`~Data.set_masked_visibilities`
- :meth:`~Data.set_polarization_data`
- :meth:`~Data.set_visibilities`
- :meth:`~Data.__div`
- :meth:`~Data.__sub`
* Conversion
- :meth:`~Data.convert_to_complex`
- :meth:`~Data.convert_to_polarization`
* Meta-data
- :meth:`~Data.get_antenna1_index`
- :meth:`~Data.get_antenna1_name`
- :meth:`~Data.get_antenna2_index`
- :meth:`~Data.get_antenna2_name`
- :meth:`~Data.get_baseline_angle`
- :meth:`~Data.get_baseline_distance`
- :meth:`~Data.get_baseline_vector`
- :meth:`~Data.get_complex_state`
- :meth:`~Data.get_frequencies`
- :meth:`~Data.get_polarizations`
- :meth:`~Data.get_times`
- :meth:`~Data.has_metadata`
- :meth:`~Data.is_auto_correlation`
- :meth:`~Data.is_complex`
Detailed descriptions
^^^^^^^^^^^^^^^^^^^^^
.. method:: Data.clear_mask(data)
Clear the flag mask. Unflags all visibilities (sets all flags to
false).
:param data: Data for which the mask is cleared.
:type data: :class:`Data`
.. method:: Data.convert_to_complex(data, new_state)
Make a new :class:`Data` object with a different complex-value state.
Complex input data (data with :meth:`get_complex_state` ==
``"complex"``) can be converted to real, imaginary, amplitude or
phase values.
Amplitude data (:meth:`get_complex_state` == ``"amplitude"``)
can also be converted back to complex.
In that case the phases become zero. Other conversions are not
implemented and will cause an error.
The complex state of an :class:`Data` object is stored internally and
can be acquired by calling :meth:`get_complex_state`.
:param data: Input data (unchanged).
:type data: :class:`Data`
:param new_state: ``"complex"``, ``"real"``, ``"imaginary"``,
``"amplitude"`` or ``"phase"``.
:type new_state: string
:return: New object with :meth:`get_complex_state` == ``new_state``
:rtype: :class:`Data`
.. method:: Data.convert_to_polarization(data, new_polarization)
Make a new :class:`Data` object by converting the polarization.
If the input data does not hold the polarimetric data to convert
to the requested polarization, an error is thrown. For example,
converting to ``"i"`` from data for which
:meth:`get_polarizations` == ``{"xx","yy"}`` is possible, but
converting to ``"q"`` from data with
:meth:`get_polarizations` == ``{"ll"}`` is not.
This method can also be used to extract a single polarization
from the set of available polarizations, e.g.
.. code-block:: lua
xxdata = data:convert_to_polarization("xx")
for data with :meth:`get_polarizations`
== ``{"xx", "xy", "yx", "yy"}``.
:param data: input data (unchanged).
:type data: :class:`Data`
:param new_polarization: ``"i"``, ``"q"``, ``"u"``, ``"v"``,
``"xx"``, ``"xy"``, ``"yx"``, ``"yy"``, ``"rr"``, ``"rl"``,
``"lr"`` or ``"ll"``.
:type new_polarization: string
.. method:: Data.copy(data)
Make a value copy of the data.
:param data: Source data.
:type data: :class:`Data`
:return: Value copy of input data.
:rtype: :class:`Data`
.. method:: Data.flag_nans(data)
Flag visibilities that are 'not a number' (nan) or hold overflow.
Each polarization is independently searched for nans, and its
mask is updated for that polarization (this is different from
:meth:`Data.flag_zeros`).
:since: AOFlagger 3.1.
.. method:: Data.flag_zeros(data)
Flag visibilities that are exactly zero. This corrects for
correlators that output zeros during faults, such as network problems.
It flags samples when the sum of visibilities over polarizations is
zero. When it is necessary to flag the polarizations independently, the
statement should be placed inside a loop, e.g.:
.. code-block:: lua
for _,polarization in ipairs(data.get_polarizations()) do
pol_data = data:convert_to_polarization(polarization)
flag_zeros(pol_data)
data:set_polarization_data(polarization, pol_data)
end
:param data: Data (modified inplace).
:type data: :class:`Data`
.. method:: Data.get_antenna1_index(data)
Get first antenna index of the two correlated antennas.
Throws an error of the antenna metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: Index of first antenna
:rtype: integer
.. method:: Data.get_antenna1_name(data)
Get name of first antenna of the two correlated antennas.
Throws an error of the antenna metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: Name of first antenna
:rtype: string
.. method:: Data.get_antenna2_index(data)
Get second antenna index of the two correlated antennas.
Throws an error of the antenna metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: Index of second antenna
:rtype: integer
.. method:: Data.get_antenna2_name(data)
Get name of second antenna of the two correlated antennas.
Throws an error of the antenna metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: Name of second antenna
:rtype: string
.. method:: Data.get_baseline_angle(data)
Get angle of this baseline. This is that angle between
the line from antenna2 to antenna1 and North.
Throws an error of the antenna metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged)
:type data: :class:`Data`
:return: Baseline angle in radians
:rtype: number
.. method:: Data.get_baseline_distance(data)
Get distance of the antenna1-antenna2 baseline in meters.
Throws an error of the antenna metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: Baseline distance in meters
:rtype: number
.. method:: Data.get_baseline_vector(data)
Get a table with items ``x``, ``y`` and ``z`` that form the three-
dimensional vector between antennas 1 and 2.
Throws an error of the antenna metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: Baseline vector in meters
:rtype: table
.. method:: Data.get_complex_state(data)
Get the state that the visibilities represent. This can be ``"phase"``,
``"amplitude"``, ``"real"``, ``"imaginary"`` or ``"complex"``. When the
data is complex, each visibility consists of two number. Conversions
can be performed with :meth:`convert_to_complex`.
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: Complex state of data.
:rtype: string
.. method:: Data.get_frequencies(data)
Get the frequencies of the channels.
Throws an error of the spectral window metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: List that maps channel nr to frequency in Hz.
:rtype: table
.. method:: Data.get_polarizations(data)
Get the list of polarizations provided by the data.
See :meth:`convert_to_polarization` for the list of possible
polarization names.
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: List that maps polarization nr to a string.
:rtype: table
.. method:: Data.get_times(data)
Get the time of each timestep in these data.
Throws an error of the time metadata is not available
(see :meth:`has_metadata`).
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: List that maps timestep nr to MJD time in s.
:rtype: table
.. method:: Data.has_metadata(data)
Returns whether metadata is completely present.
Not all data formats (or simulations) provide all metadata
items and some of the other methods (e.g. :meth:`get_times`) may throw
an error because of this. If this function returns ``true``, all these
functions will succeed.
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: ``true`` in case all metadata is available, ``false`` otherwise.
:rtype: boolean
.. method:: Data.invert_mask(data)
Changes masked values to be unmasked and vice versa.
:param data: Destination data (modified in place)
:type data: :class:`Data`
.. method:: Data.is_auto_correlation(data)
Determine whether this baseline is an auto-correlation.
This is the case if :meth:`get_antenna1_index` ==
:meth:`get_antenna2_index`. Unlike the ``get_antenna*``
functions, this method won't throw an error when no meta-data is
available. ``false`` is returned in that case.
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: ``true`` when this is an auto-correlation.
:type: boolean
.. method:: Data.is_complex(data)
:param data: Input data (unchanged).
:type data: :class:`Data`
:return: ``true`` when :meth:`get_complex_state` == ``"complex"``
:type: boolean
.. method:: Data.join_mask(first_data, second_data)
Join two masks together. A flag will be set when it is set in either or
both of the input data sets.
:param first_data: First mask and destination of operation.
:type first_data: :class:`Data`
:param second_data: Second mask (unchanged).
:type second_data: :class:`Data`
.. method:: Data.set_mask(destination_data, mask_data)
Assign the mask of one :class:`Data` object to another.
:param first_data: Destination data (changed inplace).
:type first_data: :class:`Data`
:param second_data: Source data (unchanged).
:type second_data: :class:`Data`
.. method:: Data.set_mask_for_channel_range(destination_data, mask_data, freq_start, freq_end)
Partially assign the mask of one :class:`Data` object to another.
The flag mask of channels within the given frequency range are copied
from ``mask_data`` to ``destination_data``.
This can for example be useful when a certain channel range should not
be flagged, by partially copying the initial flags to the mask
produced by the RFI detection.
:param first_data: Destination data (changed inplace).
:type first_data: :class:`Data`
:param second_data: Source data (unchanged).
:type second_data: :class:`Data`
:param freq_start: Frequency range start in MHz
:type freq_start: number
:param freq_end: Frequency range end in MHz
:type freq_end: number
.. method:: Data.set_polarization_data(destination_data, polarization, source_data)
Replace one polarization of a :class:`Data` object with some other data.
The ``source_data`` should have only one polarization. The typical
use-case for this method is to loop over polarizations and modify
them one by one, e.g.:
.. code-block:: lua
for _,polarization in ipairs(data:get_polarizations()) do
pol_data = input:convert_to_polarization(polarization)
-- Change pol_data here...
data:set_polarization_data(polarization, pol_data)
end
Note that the two data sets should have the same complex state
(see :meth:`get_complex_state()`). This method copies both the
mask and the visibilities. The meta-data is unchanged.
:param destination_data: Destination data (changed inplace).
:type destination_data: :class:`Data`
:param polarization: Name of polarization to change
:type polarization: string
:param source_data: Source data (unchanged).
:type source_data: :class:`Data`
.. method:: Data.set_visibilities(destination_data, visibility_data)
Assign the visibility data from one :class:`Data` object to another.
The flagmask and meta-data are unchanged. The two sets should have
the same number of polarizations and the same complex state.
:param destination_data: Destination data (changed inplace).
:type destination_data: :class:`Data`
:param visibility_data: Source data (unmodified).
:type visibility_data: :class:`Data`
.. method:: Data.set_masked_visibilities(destination_data, visibility_data)
Conditionally assign the visibility data from one :class:`Data` object
to another. Only visibilities that are set to `true` in the destination mask
are altered. The flagmask and meta-data are unchanged. The two sets should have
the same number of polarizations and the same complex state.
:param destination_data: Destination data (changed inplace).
:type destination_data: :class:`Data`
:param visibility_data: Source data (unmodified).
:type visibility_data: :class:`Data`
.. method:: Data.__gc(data)
Internal method for garbage collection function of the Data class.
This will free the allocated data when those data are no longer
used by other Data objects. Note that AOFlagger will immediately
clear data when the :meth:`execute` function is finished, even when
the class hasn't been garbage collected yet.
TODO add a method ``set_persistent`` to disable this.
:param destination_data: Garbage collected data.
:type destination_data: :class:`Data`
.. method:: Data.__div(lhs_data, rhs_data)
Special Lua method for the division operator. Performs
element-wise division of :class:`Data`
objects. For example, with ``data`` and ``rms`` both of
type ``Data``, this would assign ``corrected`` to the element-wise
divided data:
.. code-block:: lua
corrected = data / rms
The parameters ``lhs_data`` and ``rhs_data`` are required to have the same number
of polarizations and are required to have the same complex state.
The output data will have the same meta-data and masks as ``lhs_data``.
:param lhs_data: Left-hand side data (not modified)
:type lhs_data: :class:`Data`
:param rhs_data: Right-hand side data (not modified)
:type rhs_data: :class:`Data`
:returns: Left / right
:rtype: :class:`Data`
.. method:: Data.__sub(lhs_data, rhs_data)
Lua-special method for element-wise subtraction of :class:`Data`
objects, e.g.:
.. code-block:: lua
data = data - filtered_data
For information about the requirements and produced meta data, see :meth:`__div`.
:param lhs_data: Left-hand side data (not modified)
:type lhs_data: :class:`Data`
:param rhs_data: Right-hand side data (not modified)
:type rhs_data: :class:`Data`
:returns: Left - right
:rtype: :class:`Data`
|