Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if len(ant_str[str_pos:].split(',')) > 1:
ant_pairs_nums = self.get_antpairs()
elif ant_str[str_pos:].upper().startswith('AUTO'):
for pair in ant_pairs_data:
if (pair[0] == pair[1]
and pair not in ant_pairs_nums):
ant_pairs_nums.append(pair)
elif ant_str[str_pos:].upper().startswith('CROSS'):
for pair in ant_pairs_data:
if not (pair[0] == pair[1]
or pair in ant_pairs_nums):
ant_pairs_nums.append(pair)
elif ant_str[str_pos:].upper().startswith('PI'):
polarizations.append(uvutils.polstr2num('pI'))
elif ant_str[str_pos:].upper().startswith('PQ'):
polarizations.append(uvutils.polstr2num('pQ'))
elif ant_str[str_pos:].upper().startswith('PU'):
polarizations.append(uvutils.polstr2num('pU'))
elif ant_str[str_pos:].upper().startswith('PV'):
polarizations.append(uvutils.polstr2num('pV'))
else:
raise ValueError('Unparsible argument {s}'.format(s=ant_str))
comma_cnt = ant_str[str_pos:].find(',')
if comma_cnt >= 0:
str_pos += comma_cnt + 1
else:
str_pos = len(ant_str)
else:
m = m.groups()
str_pos += len(m[0])
if m[2] is None:
if extra_keywords is not None:
self.extra_keywords = extra_keywords
if beam_type == "power":
self.Naxes_vec = 1
if feed_pol == "x":
feed_pol = "xx"
elif feed_pol == "y":
feed_pol = "yy"
if rotate_pol:
rot_pol_dict = {"xx": "yy", "yy": "xx", "xy": "yx", "yx": "xy"}
pol2 = rot_pol_dict[feed_pol]
self.polarization_array = np.array(
[uvutils.polstr2num(feed_pol), uvutils.polstr2num(pol2)]
)
else:
self.polarization_array = np.array([uvutils.polstr2num(feed_pol)])
self.Npols = len(self.polarization_array)
self._set_power()
else:
self.Naxes_vec = 2
self.Ncomponents_vec = 2
if rotate_pol:
if feed_pol == "x":
self.feed_array = np.array(["x", "y"])
else:
self.feed_array = np.array(["y", "x"])
else:
if feed_pol == "x":
def efield_to_power(self):
"""
Tell interp to return values corresponding with a power beam.
"""
self.beam_type = 'power'
pol_strings = ['XX', 'XY', 'YX', 'YY']
self.polarization_array = np.array([uvutils.polstr2num(ps.upper()) for ps in pol_strings])
if pols is not None:
for pol in pols:
if (pol.upper() in pols_data
and uvutils.polstr2num(pol) not in polarizations):
polarizations.append(uvutils.polstr2num(pol))
elif not (pol.upper() in pols_data
or pol in warned_pols):
warned_pols.append(pol)
else:
if pols is not None:
for pol in pols:
if pol.upper() in pols_data:
if (self.Npols == 1
and [pol.upper()] == pols_data):
ant_pairs_nums.remove(ant_tuple)
if uvutils.polstr2num(pol) in polarizations:
polarizations.remove(uvutils.polstr2num(pol))
elif not (pol.upper() in pols_data
or pol in warned_pols):
warned_pols.append(pol)
elif ant_tuple in ant_pairs_nums:
ant_pairs_nums.remove(ant_tuple)
if ant_str.upper() == 'ALL':
ant_pairs_nums = None
elif len(ant_pairs_nums) == 0:
if (not ant_str.upper() in ['AUTO', 'CROSS']):
ant_pairs_nums = None
if len(polarizations) == 0:
polarizations = None
else:
else: interpreted as a baseline number. Return all times and
polarizations for that baseline.
if len(key) == 2: interpreted as an antenna pair. Return all
times and pols for that baseline.
if len(key) == 3: interpreted as antenna pair and pol (ant1, ant2, pol).
Return all times for that baseline, pol. pol may be a string.
Returns:
blt_ind1: numpy array with blt indices for antenna pair.
blt_ind2: numpy array with blt indices for conjugate antenna pair.
pol_ind: numpy array with polarization indices
"""
key = uvutils.get_iterable(key)
if type(key) is str:
# Single string given, assume it is polarization
pol_ind = np.where(self.polarization_array == uvutils.polstr2num(key))[0]
if len(pol_ind) == 0:
raise KeyError('Polarization {pol} not found in data.'.format(pol=key))
blt_ind1 = np.arange(self.Nblts)
blt_ind2 = np.array([], dtype=np.int64)
elif len(key) == 1:
key = key[0] # For simplicity
if isinstance(key, collections.Iterable):
# Nested tuple. Call function again.
blt_ind1, blt_ind2, pol_ind = self._key2inds(key)
elif key < 5:
# Small number, assume it is a polarization number a la AIPS memo
pol_ind = np.where(self.polarization_array == key)[0]
if len(pol_ind) == 0:
raise KeyError('Polarization {pol} not found in data.'.format(pol=key))
blt_ind1 = np.arange(self.Nblts)
blt_ind2 = np.array([], dtype=np.int64)
feed_pol_order = [(0, 0)]
if beam_object.Nfeeds > 1:
feed_pol_order.append((1, 1))
if calc_cross_pols:
beam_object.Npols = beam_object.Nfeeds ** 2
if beam_object.Nfeeds > 1:
feed_pol_order.extend([(0, 1), (1, 0)])
else:
beam_object.Npols = beam_object.Nfeeds
pol_strings = []
for pair in feed_pol_order:
pol_strings.append(beam_object.feed_array[pair[0]] + beam_object.feed_array[pair[1]])
beam_object.polarization_array = np.array(
[uvutils.polstr2num(ps.upper(), x_orientation=self.x_orientation) for ps in pol_strings])
if not keep_basis_vector:
beam_object.Naxes_vec = 1
# adjust requirements, fix data_array form
beam_object.set_power()
power_data = np.zeros(beam_object._data_array.expected_shape(beam_object), dtype=np.complex)
if keep_basis_vector:
for pol_i, pair in enumerate(feed_pol_order):
power_data[:, :, pol_i] = (efield_data[:, :, pair[0]]
* np.conj(efield_data[:, :, pair[1]]))
else:
for pol_i, pair in enumerate(feed_pol_order):
if efield_naxes_vec == 2:
err_msg = (
"pols must be a list of polarization strings or ints, "
"Ex: ['xx', ...] or [-5, ...]"
)
assert isinstance(polarizations, (list, np.ndarray)), err_msg
assert np.array(
map(
lambda p: isinstance(p, (str, np.str, int, np.integer)),
polarizations,
)
).all(), err_msg
# convert to pol integer if string
polarizations = [
p
if isinstance(p, (int, np.integer))
else uvutils.polstr2num(p, x_orientation=self.x_orientation)
for p in polarizations
]
# iterate through all possible pols and reject if not in pols
pol_list = []
for p in np.arange(-8, 5):
if p not in polarizations:
uv.select("polarization", p, p, include=False)
else:
pol_list.append(p)
# assert not empty
assert len(pol_list) > 0, "No polarizations in data matched {}".format(
polarizations
)
if n_selects > 0:
history_update_string += ", polarizations"
else:
# Key is an antenna pair
blt_ind1 = self.antpair2ind(key[0], key[1])
blt_ind2 = self.antpair2ind(key[1], key[0])
if len(blt_ind1) + len(blt_ind2) == 0:
raise KeyError('Antenna pair {pair} not found in data'.format(pair=key))
pol_ind = np.arange(self.Npols)
elif len(key) == 3:
# Key is an antenna pair + pol
blt_ind1 = self.antpair2ind(key[0], key[1])
blt_ind2 = self.antpair2ind(key[1], key[0])
if len(blt_ind1) + len(blt_ind2) == 0:
raise KeyError('Antenna pair {pair} not found in '
'data'.format(pair=(key[0], key[1])))
if type(key[2]) is str:
# pol is str
pol_ind = np.where(self.polarization_array == uvutils.polstr2num(key[2]))[0]
else:
# polarization number a la AIPS memo
pol_ind = np.where(self.polarization_array == key[2])[0]
if len(pol_ind) == 0:
raise KeyError('Polarization {pol} not found in data.'.format(pol=key[2]))
# Catch autos
if np.array_equal(blt_ind1, blt_ind2):
blt_ind2 = np.array([])
return (blt_ind1, blt_ind2, pol_ind)
elif ant_str[str_pos:].upper().startswith('AUTO'):
for pair in ant_pairs_data:
if (pair[0] == pair[1]
and pair not in ant_pairs_nums):
ant_pairs_nums.append(pair)
elif ant_str[str_pos:].upper().startswith('CROSS'):
for pair in ant_pairs_data:
if not (pair[0] == pair[1]
or pair in ant_pairs_nums):
ant_pairs_nums.append(pair)
elif ant_str[str_pos:].upper().startswith('PI'):
polarizations.append(uvutils.polstr2num('pI'))
elif ant_str[str_pos:].upper().startswith('PQ'):
polarizations.append(uvutils.polstr2num('pQ'))
elif ant_str[str_pos:].upper().startswith('PU'):
polarizations.append(uvutils.polstr2num('pU'))
elif ant_str[str_pos:].upper().startswith('PV'):
polarizations.append(uvutils.polstr2num('pV'))
else:
raise ValueError('Unparsible argument {s}'.format(s=ant_str))
comma_cnt = ant_str[str_pos:].find(',')
if comma_cnt >= 0:
str_pos += comma_cnt + 1
else:
str_pos = len(ant_str)
else:
m = m.groups()
str_pos += len(m[0])
if m[2] is None:
ant_i_list = [m[8]]
ant_j_list = list(self.get_ants())
for pol in pols:
if (pol.upper() in pols_data
and uvutils.polstr2num(pol) not in polarizations):
polarizations.append(uvutils.polstr2num(pol))
elif not (pol.upper() in pols_data
or pol in warned_pols):
warned_pols.append(pol)
else:
if pols is not None:
for pol in pols:
if pol.upper() in pols_data:
if (self.Npols == 1
and [pol.upper()] == pols_data):
ant_pairs_nums.remove(ant_tuple)
if uvutils.polstr2num(pol) in polarizations:
polarizations.remove(uvutils.polstr2num(pol))
elif not (pol.upper() in pols_data
or pol in warned_pols):
warned_pols.append(pol)
elif ant_tuple in ant_pairs_nums:
ant_pairs_nums.remove(ant_tuple)
if ant_str.upper() == 'ALL':
ant_pairs_nums = None
elif len(ant_pairs_nums) == 0:
if (not ant_str.upper() in ['AUTO', 'CROSS']):
ant_pairs_nums = None
if len(polarizations) == 0:
polarizations = None
else:
polarizations.sort(reverse=True)