diff --git a/docs/parameter_files.rst b/docs/parameter_files.rst index d4246c36..02aa12a4 100644 --- a/docs/parameter_files.rst +++ b/docs/parameter_files.rst @@ -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 diff --git a/pyuvsim/simsetup.py b/pyuvsim/simsetup.py index 4808562b..7a7ffb83 100644 --- a/pyuvsim/simsetup.py +++ b/pyuvsim/simsetup.py @@ -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": @@ -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): @@ -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) @@ -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'] @@ -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 @@ -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) @@ -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: diff --git a/pyuvsim/telescope.py b/pyuvsim/telescope.py index ba30b194..fd319d8e 100644 --- a/pyuvsim/telescope.py +++ b/pyuvsim/telescope.py @@ -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, @@ -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: @@ -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 diff --git a/pyuvsim/tests/test_telescope.py b/pyuvsim/tests/test_telescope.py index e618eb93..91fde52d 100644 --- a/pyuvsim/tests/test_telescope.py +++ b/pyuvsim/tests/test_telescope.py @@ -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]