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 Nov 6, 2023
1 parent 8aff3b3 commit 5ca0937
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 48 deletions.
119 changes: 73 additions & 46 deletions pyuvdata/uvbeam/feko_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ class FEKOBeam(UVBeam):
read_feko_beam method on the UVBeam class.
"""

def nametopol(self, fname):

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
"""
Get name of the y file from the main filename.
Parameters
----------
fname : str
Expand All @@ -37,10 +38,9 @@ def nametopol(self, fname):
str
New file name.
"""
fnew = fname.replace("x","y")

return fnew
fnew = fname.replace("x", "y")

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L41

Added line #L41 was not covered by tests

return fnew

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L43

Added line #L43 was not covered by tests

def read_feko_beam(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L45

Added line #L45 was not covered by tests
self,
Expand Down Expand Up @@ -156,13 +156,12 @@ def read_feko_beam(
else:
self.Naxes_vec = 2
self.Ncomponents_vec = 2

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L157-L158

Added lines #L157 - L158 were not covered by tests



if feed_pol == "x":
self.feed_array = np.array(["x" , "y"])
self.feed_array = np.array(["x", "y"])
elif feed_pol == "y":
self.feed_array = np.array(["y" , "x"])
self.feed_array = np.array(["y", "x"])

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L160-L163

Added lines #L160 - L163 were not covered by tests

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#L165-L166

Added lines #L165 - L166 were not covered by tests

Expand Down Expand Up @@ -193,46 +192,65 @@ def read_feko_beam(

if beam_type == "efield":
filename2 = self.nametopol(filename)
with open(filename2, '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_all2 = [i.splitlines()[9:] for i in data_chunks] ## skips the 9 lines of text in each chunk

frequency = [float(i.split('Frequency')[1].split()[1]) for i in data_chunks[:-1]]
with open(filename2, "r") as fh:
data_chunks = fh.read()[1:].split(

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#L193-L196

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

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
i.splitlines()[9:] for i in data_chunks
] ## skips the 9 lines of text in each chunk

frequency = [

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#L203

Added line #L203 was not covered by tests
float(i.split("Frequency")[1].split()[1]) for i in data_chunks[:-1]
]
self.Nfreqs = len(frequency)
self.freq_array = np.zeros((1, self.Nfreqs))
self.freq_array[0] = frequency
self.bandpass_array = np.zeros((1, self.Nfreqs))

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L206-L209

Added lines #L206 - L209 were not covered by tests

data_each=np.zeros((len(self.freq_array[0]),np.shape(data_all[0])[0],9))
data_each = np.zeros((len(self.freq_array[0]), np.shape(data_all[0])[0], 9))
if beam_type == "efield":
data_each2=np.zeros((len(self.freq_array[0]),np.shape(data_all2[0])[0],9))

data_each2 = np.zeros(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L211-L213

Added lines #L211 - L213 were not covered by tests
(len(self.freq_array[0]), np.shape(data_all2[0])[0], 9)
)

for i in range(len(self.freq_array[0])):

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

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L217-L218

Added lines #L217 - L218 were not covered by tests
[list(map(float, data.split())) for data in data_all[i]]
)
if beam_type == "efield":
data_each2[i,:,:] = np.array([list(map(float,data.split())) for data in data_all2[i]])
if i ==0 :

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
data_each2[i, :, :] = np.array(

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
[list(map(float, data.split())) for data in data_all2[i]]
)
if i == 0:
theta_data = np.radians(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L225-L226

Added lines #L225 - L226 were not covered by tests
data_each[i, :, theta_col]
) ## theta is always exported in degs
phi_data = np.radians(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L229

Added line #L229 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 234 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L233-L234

Added lines #L233 - L234 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 237 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L236-L237

Added lines #L236 - L237 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L239

Added line #L239 was not covered by tests
(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 242 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L242

Added line #L242 was 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 244 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L244

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

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L247

Added line #L247 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 251 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L251

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

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L254

Added line #L254 was not covered by tests
"Data does not appear to be regularly gridded in azimuth angle"
)
Expand All @@ -241,8 +259,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 261 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L257-L261

Added lines #L257 - L261 were not covered by tests



if self.beam_type == "power":

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L263

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

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#L274

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


# 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 283 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L279-L283

Added lines #L279 - L283 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 286 in pyuvdata/uvbeam/feko_beam.py

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L286

Added line #L286 was not covered by tests

else:
self.basis_vector_array = np.zeros(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L289

Added line #L289 was not covered by tests
(self.Naxes_vec, self.Ncomponents_vec, self.Naxes2, self.Naxes1)
Expand All @@ -293,8 +311,13 @@ def read_feko_beam(
phi_phase = np.angle(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L311

Added line #L311 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_each[i,:, theta_imag_col])
phi_phase = np.angle(data_each[i,:, phi_real_col] +1j *data_each[i,:, phi_imag_col])
theta_phase = np.angle(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L314

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

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L318

Added line #L318 was not covered by tests
data_each[i, :, phi_real_col] + 1j * data_each[i, :, phi_imag_col]
)

theta_phase = theta_phase.reshape(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L322

Added line #L322 was not covered by tests
(theta_axis.size, phi_axis.size), order="F"
Expand All @@ -309,29 +332,33 @@ def read_feko_beam(
self.data_array[0, 0, 0, i, :, :] = phi_beam
self.data_array[1, 0, 0, i, :, :] = theta_beam

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#L332-L333

Added lines #L332 - L333 were not covered by tests


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

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
10 ** (data_each2[i, :, theta_mag_col] / 10)
).reshape((theta_axis.size, phi_axis.size), order="F")
phi_mag2 = np.sqrt(10 ** (data_each2[i, :, phi_mag_col] / 10)).reshape(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L338

Added line #L338 was not covered by tests
(theta_axis.size, phi_axis.size), order="F"
)
phi_mag2 = np.sqrt(10**(data_each2[i,:, phi_mag_col]/10)).reshape(
(theta_axis.size, phi_axis.size), order="F"
theta_phase2 = np.angle(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L341

Added line #L341 was not covered by tests
data_each2[i, :, theta_real_col]
+ 1j * data_each2[i, :, theta_imag_col]
)
phi_phase2 = np.angle(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L345

Added line #L345 was not covered by tests
data_each2[i, :, phi_real_col] + 1j * data_each2[i, :, phi_imag_col]
)
theta_phase2 = np.angle(data_each2[i,:, theta_real_col] + 1j * data_each2[i,:, theta_imag_col])
phi_phase2 = np.angle(data_each2[i,:, phi_real_col] +1j *data_each2[i,:, phi_imag_col])

theta_phase2 = theta_phase2.reshape(

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L349

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

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L352

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

theta_beam2 = theta_mag2 * np.exp(1j * theta_phase2)
phi_beam2 = phi_mag2 * np.exp(1j * phi_phase2)

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L356-L357

Added lines #L356 - L357 were not covered by tests


self.data_array[0, 0, 1, i, :, :] = phi_beam2
self.data_array[1, 0, 1, i, :, :] = theta_beam2

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L359-L360

Added lines #L359 - L360 were not covered by tests



self.bandpass_array[0] = 1

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/feko_beam.py#L362

Added line #L362 was not covered by tests

if frequency is None:
Expand Down
4 changes: 2 additions & 2 deletions pyuvdata/uvbeam/uvbeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -4583,10 +4583,10 @@ def read_feko_beam(
"lists they need to be the same length"
)
pol = feed_pol[0]

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/uvbeam.py#L4585

Added line #L4585 was not covered by tests

else:
pol = feed_pol

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

View check run for this annotation

Codecov / codecov/patch

pyuvdata/uvbeam/uvbeam.py#L4588

Added line #L4588 was not covered by tests

if isinstance(freq, (list, tuple)):
raise ValueError("frequency can not be a nested list")
if isinstance(pol, (list, tuple)):
Expand Down

0 comments on commit 5ca0937

Please sign in to comment.