Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 18, 2023
1 parent f4b09df commit a185d93
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 57 deletions.
90 changes: 55 additions & 35 deletions pyuvdata/uvbeam/feko_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

__all__ = ["FEKOBeam"]

Check warning on line 14 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L14

Added line #L14 was not covered by tests


class FEKOBeam(UVBeam):

Check warning on line 17 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L17

Added line #L17 was not covered by tests
"""
Defines a FEKO-specific subclass of UVBeam for reading FEKO ffe files.
Expand All @@ -21,6 +22,7 @@ class FEKOBeam(UVBeam):
read_feko_beam method on the UVBeam class.
"""

def read_feko_beam(

Check warning on line 26 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L26

Added line #L26 was not covered by tests
self,
filename,
Expand Down Expand Up @@ -112,7 +114,6 @@ def read_feko_beam(
self.filename = [basename]
self._filename.form = (1,)

Check warning on line 115 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L113-L115

Added lines #L113 - L115 were not covered by tests


self.telescope_name = telescope_name
self.feed_name = feed_name
self.feed_version = feed_version
Expand Down Expand Up @@ -164,64 +165,75 @@ def read_feko_beam(
self.Nfeeds = self.feed_array.size
self._set_efield()

Check warning on line 166 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L164-L166

Added lines #L164 - L166 were not covered by tests


self.data_normalization = "physical"
self.antenna_type = "simple"

Check warning on line 169 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L168-L169

Added lines #L168 - L169 were not covered by tests



if not use_future_array_shapes:
self.Nspws = 1
self.spw_array = np.array([0])
self.pixel_coordinate_system = "az_za"
self._set_cs_params()

Check warning on line 175 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L171-L175

Added lines #L171 - L175 were not covered by tests


out_file = open(filename,"r")
line = out_file.readlines()[9].strip() # Get the line with column names
out_file = open(filename, "r")
line = out_file.readlines()[9].strip() # Get the line with column names
out_file.close()
column_names = line.split("\"")[1::2]
column_names = line.split('"')[1::2]

Check warning on line 180 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L177-L180

Added lines #L177 - L180 were not covered by tests

theta_col = np.where(np.array(column_names) == "Theta")[0][0]
phi_col = np.where(np.array(column_names) == "Phi")[0][0]

Check warning on line 183 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L182-L183

Added lines #L182 - L183 were not covered by tests

with open(filename, 'r') as fh:
data_chunks = fh.read()[1:].split('\n\n') ## avoiding the first row since there is a blank row at the start of every file
data_all = [i.splitlines()[9:] for i in data_chunks] ## skips the 9 lines of text in each chunk
with open(filename, "r") as fh:
data_chunks = fh.read()[1:].split(

Check warning on line 186 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L185-L186

Added lines #L185 - L186 were not covered by tests
"\n\n"
) ## avoiding the first row since there is a blank row at the start of every file
data_all = [

Check warning on line 189 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L189

Added line #L189 was not covered by tests
i.splitlines()[9:] for i in data_chunks
] ## skips the 9 lines of text in each chunk

if frequency is not None:
self.freq_array = frequency

Check warning on line 194 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L193-L194

Added lines #L193 - L194 were not covered by tests
else:
frequency = [float(i.split('Frequency')[1].split()[1]) for i in data_chunks[:-1]]
frequency = [

Check warning on line 196 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L196

Added line #L196 was not covered by tests
float(i.split("Frequency")[1].split()[1]) for i in data_chunks[:-1]
]
self.freq_array = frequency

Check warning on line 199 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L199

Added line #L199 was not covered by tests

self.Nfreqs = len(frequency)
self.freq_array = np.zeros((1, self.Nfreqs))
self.bandpass_array = np.zeros((1, self.Nfreqs))

Check warning on line 203 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L201-L203

Added lines #L201 - L203 were not covered by tests

data_each=np.zeros((len(self.freq_array),np.shape(data_all[0])[0],9))
data_each = np.zeros((len(self.freq_array), np.shape(data_all[0])[0], 9))
for i in range(len(self.freq_array)):
data_each[i, :, :] = np.array(

Check warning on line 207 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L205-L207

Added lines #L205 - L207 were not covered by tests
[list(map(float, data.split())) for data in data_all[i]]
)

data_each[i,:,:] = np.array([list(map(float,data.split())) for data in data_all[i]])

theta_data = np.radians(data_each[i,:, theta_col]) ## theta is always exported in degs
phi_data = np.radians(data_each[i, :, phi_col]) ## phi is always exported in degs
theta_data = np.radians(

Check warning on line 211 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L211

Added line #L211 was not covered by tests
data_each[i, :, theta_col]
) ## theta is always exported in degs
phi_data = np.radians(

Check warning on line 214 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L214

Added line #L214 was not covered by tests
data_each[i, :, phi_col]
) ## phi is always exported in degs

theta_axis = np.sort(np.unique(theta_data))
phi_axis = np.sort(np.unique(phi_data))

Check warning on line 219 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L218-L219

Added lines #L218 - L219 were not covered by tests

if not theta_axis.size * phi_axis.size == theta_data.size:
raise ValueError("Data does not appear to be on a grid")

Check warning on line 222 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L221-L222

Added lines #L221 - L222 were not covered by tests

theta_data = theta_data.reshape((theta_axis.size, phi_axis.size), order="F")
phi_data = phi_data.reshape((theta_axis.size, phi_axis.size), order="F")

Check warning on line 225 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L224-L225

Added lines #L224 - L225 were not covered by tests

if not uvutils._test_array_constant_spacing(theta_axis, self._axis2_array.tols):
if not uvutils._test_array_constant_spacing(

Check warning on line 227 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L227

Added line #L227 was not covered by tests
theta_axis, self._axis2_array.tols
):
raise ValueError(

Check warning on line 230 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L230

Added line #L230 was not covered by tests
"Data does not appear to be regularly gridded in zenith angle"
)

if not uvutils._test_array_constant_spacing(phi_axis, self._axis1_array.tols):
if not uvutils._test_array_constant_spacing(

Check warning on line 234 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L234

Added line #L234 was not covered by tests
phi_axis, self._axis1_array.tols
):
raise ValueError(

Check warning on line 237 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L237

Added line #L237 was not covered by tests
"Data does not appear to be regularly gridded in azimuth angle"
)
Expand All @@ -230,7 +242,7 @@ def read_feko_beam(
self.Naxes1 = self.axis1_array.size
self.axis2_array = theta_axis
self.Naxes2 = self.axis2_array.size

Check warning on line 244 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L240-L244

Added lines #L240 - L244 were not covered by tests

if self.beam_type == "power":

Check warning on line 246 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L246

Added line #L246 was not covered by tests
# type depends on whether cross pols are present
# (if so, complex, else float)
Expand All @@ -243,9 +255,8 @@ def read_feko_beam(
)
else:
self.data_array = np.zeros(

Check warning on line 257 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L257

Added line #L257 was not covered by tests
self._data_array.expected_shape(self), dtype=np.complex128
self._data_array.expected_shape(self), dtype=np.complex128
)


if rotate_pol:

Check warning on line 261 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L261

Added line #L261 was not covered by tests
# for second polarization, rotate by pi/2
Expand All @@ -255,19 +266,22 @@ def read_feko_beam(
if not np.allclose(roll_rot_phi, phi_data):
raise ValueError("Rotating by pi/2 failed")

Check warning on line 267 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L263-L267

Added lines #L263 - L267 were not covered by tests


# get beam
if self.beam_type == "power":
name = "Gain(Total)"
this_col = np.where(np.array(column_names) == name)[0]
data_col = this_col.tolist()
power_beam1 = 10**(data_each[i,:,data_col]/10).reshape((theta_axis.size, phi_axis.size), order="F")
power_beam1 = 10 ** (data_each[i, :, data_col] / 10).reshape(

Check warning on line 274 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L270-L274

Added lines #L270 - L274 were not covered by tests
(theta_axis.size, phi_axis.size), order="F"
)

self.data_array[0, 0, 0, i, :, :] = power_beam1

Check warning on line 278 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L278

Added line #L278 was not covered by tests

if rotate_pol:

Check warning on line 280 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L280

Added line #L280 was not covered by tests
# rotate by pi/2 for second polarization
power_beam2 = np.roll(power_beam1, int((np.pi / 2) / delta_phi), axis=1)
power_beam2 = np.roll(

Check warning on line 282 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L282

Added line #L282 was not covered by tests
power_beam1, int((np.pi / 2) / delta_phi), axis=1
)
self.data_array[0, 0, 1, i, :, :] = power_beam2

Check warning on line 285 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L285

Added line #L285 was not covered by tests
else:
self.basis_vector_array = np.zeros(

Check warning on line 287 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L287

Added line #L287 was not covered by tests
Expand All @@ -283,19 +297,25 @@ def read_feko_beam(
phi_real_col = np.where(np.array(column_names) == "Re(Ephi)")[0][0]
phi_imag_col = np.where(np.array(column_names) == "Im(Ephi)")[0][0]

Check warning on line 298 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L293-L298

Added lines #L293 - L298 were not covered by tests

theta_mag = np.sqrt(10**(data_each[i,:, theta_mag_col]/10)).reshape(
theta_mag = np.sqrt(

Check warning on line 300 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L300

Added line #L300 was not covered by tests
10 ** (data_each[i, :, theta_mag_col] / 10)
).reshape((theta_axis.size, phi_axis.size), order="F")
phi_mag = np.sqrt(10 ** (data_each[i, :, phi_mag_col] / 10)).reshape(

Check warning on line 303 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L303

Added line #L303 was not covered by tests
(theta_axis.size, phi_axis.size), order="F"
)
phi_mag = np.sqrt(10**(data_each[i,:, phi_mag_col]/10)).reshape(
(theta_axis.size, phi_axis.size), order="F"
theta_phase = np.angle(

Check warning on line 306 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L306

Added line #L306 was not covered by tests
data_each[i, :, theta_real_col] + 1j * data_c1[:, theta_imag_col]
)
phi_phase = np.angle(

Check warning on line 309 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L309

Added line #L309 was not covered by tests
data_each[i, :, phi_real_col] + 1j * data_c1[:, phi_imag_col]
)
theta_phase = np.angle(data_each[i,:, theta_real_col] + 1j * data_c1[:, theta_imag_col])
phi_phase = np.angle(data_each[i,:, phi_real_col] +1j *data_c1[:, phi_imag_col])

theta_phase = theta_phase.reshape(

Check warning on line 313 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L313

Added line #L313 was not covered by tests
(theta_axis.size, phi_axis.size), order="F"
)
phi_phase = phi_phase.reshape((theta_axis.size, phi_axis.size), order="F")
phi_phase = phi_phase.reshape(

Check warning on line 316 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L316

Added line #L316 was not covered by tests
(theta_axis.size, phi_axis.size), order="F"
)

theta_beam = theta_mag * np.exp(1j * theta_phase)
phi_beam = phi_mag * np.exp(1j * phi_phase)

Check warning on line 321 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L320-L321

Added lines #L320 - L321 were not covered by tests
Expand All @@ -305,12 +325,12 @@ def read_feko_beam(

if rotate_pol:

Check warning on line 326 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L326

Added line #L326 was not covered by tests
# rotate by pi/2 for second polarization
theta_beam2 = np.roll(theta_beam, int((np.pi / 2) / delta_phi), axis=1)
theta_beam2 = np.roll(

Check warning on line 328 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L328

Added line #L328 was not covered by tests
theta_beam, int((np.pi / 2) / delta_phi), axis=1
)
phi_beam2 = np.roll(phi_beam, int((np.pi / 2) / delta_phi), axis=1)
self.data_array[0, 0, 1, i, :, :] = phi_beam2
self.data_array[1, 0, 1, i, :, :] = theta_beam2

Check warning on line 333 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L331-L333

Added lines #L331 - L333 were not covered by tests



self.bandpass_array[0] = 1

Check warning on line 335 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L335

Added line #L335 was not covered by tests

Expand Down
44 changes: 22 additions & 22 deletions pyuvdata/uvbeam/uvbeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -4430,7 +4430,6 @@ def read_feko_beam(
"""
from . import feko_beam

Check warning on line 4431 in pyuvdata/uvbeam/uvbeam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/uvbeam.py#L4431

Added line #L4431 was not covered by tests


if not isinstance(filename, (list, tuple)) and filename.endswith("yaml"):
settings_dict = self._read_feko_beam_yaml(filename)
if not isinstance(settings_dict["frequencies"], list):
Expand Down Expand Up @@ -4782,6 +4781,7 @@ def read_mwa_beam(
)
self._convert_from_filetype(mwabeam_obj)
del mwabeam_obj

def read(
self,
filename,
Expand Down Expand Up @@ -5199,28 +5199,28 @@ def read(
elif file_type == "feko":
self.read_feko_beam(

Check warning on line 5200 in pyuvdata/uvbeam/uvbeam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/uvbeam.py#L5199-L5200

Added lines #L5199 - L5200 were not covered by tests
filename,
use_future_array_shapes=use_future_array_shapes,
beam_type=beam_type,
feed_pol=feed_pol,
rotate_pol=rotate_pol,
frequency=frequency,
telescope_name=telescope_name,
feed_name=feed_name,
feed_version=feed_version,
model_name=model_name,
model_version=model_version,
history=history,
x_orientation=x_orientation,
reference_impedance=reference_impedance,
extra_keywords=extra_keywords,
frequency_select=frequency_select,
run_check=run_check,
check_extra=check_extra,
run_check_acceptability=run_check_acceptability,
check_auto_power=check_auto_power,
fix_auto_power=fix_auto_power,

use_future_array_shapes=use_future_array_shapes,
beam_type=beam_type,
feed_pol=feed_pol,
rotate_pol=rotate_pol,
frequency=frequency,
telescope_name=telescope_name,
feed_name=feed_name,
feed_version=feed_version,
model_name=model_name,
model_version=model_version,
history=history,
x_orientation=x_orientation,
reference_impedance=reference_impedance,
extra_keywords=extra_keywords,
frequency_select=frequency_select,
run_check=run_check,
check_extra=check_extra,
run_check_acceptability=run_check_acceptability,
check_auto_power=check_auto_power,
fix_auto_power=fix_auto_power,
)

@classmethod
def from_file(
cls,
Expand Down

0 comments on commit a185d93

Please sign in to comment.