Skip to content

Commit

Permalink
address reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Feb 14, 2024
1 parent 5bb6acd commit eef859d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docs/parameter_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Telescope Configuration
- 2 is a Gaussian beam with sigma 0.03 radians (for the E-Field beam)
- 3 is another Airy beam with diameter 12 m
- 4 is a Gaussian with diameter 14 m
- 5 is a Gaussian with with diameter 12 m.
- 5 is a Gaussian with diameter 12 m.
- 6 is a UVBeam (for the MWA) with some keywords specified to pass to UVBeam.read

When specifying a shape parameter for a specific beam_id, the beam type
Expand Down
19 changes: 11 additions & 8 deletions pyuvsim/simsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,9 +1013,11 @@ def _construct_beam_list(beam_ids, telconfig, freq_range=None, force_check=False
beam_file = _check_uvbeam_file(beam_model)

beam_list.append(beam_file)
elif "filename" in beam_model:
elif isinstance(beam_model, dict) and "filename" in beam_model:
# this a UVBeam readable file with (possibly) some read kwargs
beam_file = beam_model["filename"]
beam_file = beam_model.pop("filename")
read_kwargs = beam_model
read_kwargs = {}
for key, value in beam_model.items():
if key != "filename":
Expand All @@ -1038,7 +1040,7 @@ def _construct_beam_list(beam_ids, telconfig, freq_range=None, force_check=False
)

if beam_type not in AnalyticBeam.supported_types:
raise ValueError("Undefined beam model type: {}".format(beam_type))
raise ValueError(f"Undefined beam model type: {beam_type}")

this_beam_opts = {}
if isinstance(beam_model, dict):
Expand Down Expand Up @@ -1160,7 +1162,7 @@ def parse_telescope_params(tele_params, config_path='', freq_range=None, force_b
if not os.path.isdir(config_path):
config_path = os.path.dirname(config_path)
if not os.path.isdir(config_path):
raise ValueError('config_path {} is not a directory'.format(config_path))
raise ValueError(f'config_path {config_path} is not a directory')
telescope_config_name = tele_params['telescope_config_name']
if not os.path.exists(telescope_config_name):
telescope_config_name = os.path.join(config_path, telescope_config_name)
Expand Down Expand Up @@ -1207,7 +1209,8 @@ def parse_telescope_params(tele_params, config_path='', freq_range=None, force_b
layout_csv = os.path.join(config_path, layout_csv)
if not os.path.exists(layout_csv):
raise ValueError(
'layout_csv file {} from yaml does not exist'.format(layout_csv))
f'layout_csv file {layout_csv} from yaml does not exist'
)
ant_layout = _parse_layout_csv(layout_csv)
E, N, U = ant_layout['e'], ant_layout['n'], ant_layout['u']
antnames = ant_layout['name']
Expand Down Expand Up @@ -1478,7 +1481,7 @@ def parse_time_params(time_params):
atol=dayspersec): # To nearest second
raise ValueError(
"Calculated time array is not consistent with set integration_time."
"\nInput parameters are: {}".format(str(init_time_params)))
f"\nInput parameters are: {init_time_params}")

return_dict['integration_time'] = time_params['integration_time']
return_dict['time_array'] = time_arr
Expand Down Expand Up @@ -2157,7 +2160,7 @@ def uvdata_to_telescope_config(
telescope_config_path = \
check_file_exists_and_increment(
os.path.join(
path_out, 'telescope_config_{}.yaml'.format(uvdata_in.telescope_name)
path_out, 'telescope_config_{uvdata_in.telescope_name}.yaml'
)
)
telescope_config_name = os.path.basename(telescope_config_path)
Expand Down Expand Up @@ -2185,8 +2188,8 @@ def uvdata_to_telescope_config(
with open(os.path.join(path_out, telescope_config_name), 'w+') as yfile:
yaml.dump(yaml_dict, yfile, default_flow_style=False)

logger.info('Path: {}, telescope_config: {}, layout: {}'.format(
path_out, telescope_config_name, layout_csv_name)
logger.info(
f'Path: {path_out}, telescope_config: {telescope_config_name}, layout: {layout_csv_name}'
)

if return_names:
Expand Down
54 changes: 19 additions & 35 deletions pyuvsim/telescope.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def __init__(
self,
beam_list=None,
uvb_params=None,
uvb_read_kwargs: dict[str: tuple[float, float]] = None,
select_params: dict[str: tuple[float, float]] = None,
uvb_read_kwargs: dict[str: tuple[float, float]] | None = None,
select_params: dict[str: tuple[float, float]] | None = None,
spline_interp_opts: dict[str: int] | None = None,
freq_interp_kind: str = "cubic",
check: bool = True,
Expand Down Expand Up @@ -507,43 +507,16 @@ def _str_to_obj(self, beam_id, beam_model, use_shared_mem=False):

path = beam_model # beam_model = path to UVBeam readable file
uvb = UVBeam()
read_kwargs = {}
if len(self.select_params) > 0:
read_kwargs = self.select_params
if len(self.uvb_read_kwargs) > 0 and beam_id in self.uvb_read_kwargs:
# do this after select_params to ensure these overwrite select_params
read_kwargs.update(self.uvb_read_kwargs[beam_id])
read_kwargs = {**self.select_params, **self.uvb_read_kwargs.get(beam_id, {})}

# always use future shapes
read_kwargs["use_future_array_shapes"] = True

if self.select_params is not None:
for key, value in self.select_params.items():
if key not in read_kwargs:
read_kwargs[key] = value

if use_shared_mem and (mpi.world_comm is not None):
if mpi.rank == 0:
try:
uvb.read(path, **read_kwargs)
except ValueError:
# If file type is not recognized, assume beamfits,
# which was originally the only option.
uvb.read_beamfits(path, **read_kwargs)
warnings.warn(
weird_beamfits_extension_warning,
DeprecationWarning,
)
uvb.peak_normalize()
for key, attr in uvb.__dict__.items():
if not isinstance(attr, parameter.UVParameter):
continue
if key == '_data_array':
uvb.__dict__[key].value = mpi.shared_mem_bcast(attr.value, root=0)
else:
uvb.__dict__[key].value = mpi.world_comm.bcast(attr.value, root=0)
mpi.world_comm.Barrier()
else:
if (
(mpi.world_comm is not None and use_shared_mem and mpi.rank == 0)
or not use_shared_mem
or mpi.world_comm is None
):
try:
uvb.read(path, **read_kwargs)
except ValueError:
Expand All @@ -554,6 +527,17 @@ def _str_to_obj(self, beam_id, beam_model, use_shared_mem=False):
weird_beamfits_extension_warning,
DeprecationWarning,
)
uvb.peak_normalize()

if use_shared_mem and (mpi.world_comm is not None):
for key, attr in uvb.__dict__.items():
if not isinstance(attr, parameter.UVParameter):
continue
if key == '_data_array':
uvb.__dict__[key].value = mpi.shared_mem_bcast(attr.value, root=0)
else:
uvb.__dict__[key].value = mpi.world_comm.bcast(attr.value, root=0)
mpi.world_comm.Barrier()
for key, val in self.uvb_params.items():
setattr(uvb, key, val)
uvb.extra_keywords['beam_path'] = path
Expand Down
3 changes: 3 additions & 0 deletions pyuvsim/tests/test_telescope.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def beam_objs_main():
uvb.use_future_array_shapes()
uvb.extra_keywords['beam_path'] = herabeam_default

# beams are always peak normalized inside BeamList
uvb.peak_normalize()

uvb2 = uvb.copy()

beams = [uvb, uvb2]
Expand Down

0 comments on commit eef859d

Please sign in to comment.