Reading a telescope configuration with read_OSKAR_tm_file() can raise an exception. This is true if the layout files layout.txt of a station has 6 columns and there is a space at the end of each row, e.g. here:
1.0, 1.0, 0.0, 0.0, 0.0, 0.0 (there is a space at the end of the line)
Steps to reproduce
Create a telescope, save the configuration to disk, and read it back in:
from karabo.simulation.telescope import Telescope
from karabo.simulator_backend import SimulatorBackend
SIMULATOR_BACKEND = SimulatorBackend.OSKAR
telescope = Telescope.constructor("MeerKAT", backend=SIMULATOR_BACKEND)
telescope.write_to_file("mytelescope.tm")
my_tel = Telescope.read_OSKAR_tm_file("mytelescope.tm")
Result
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[18], [line 1](vscode-notebook-cell:?execution_count=18&line=1)
----> [1](vscode-notebook-cell:?execution_count=18&line=1) my_tel = Telescope.read_OSKAR_tm_file("mytelescope.tm")
File ~/miniconda3/envs/karabo/lib/python3.9/site-packages/karabo/simulation/telescope.py:561, in Telescope.read_OSKAR_tm_file(cls, path)
[554] raise karabo.error.KaraboError(
[555] "Could not create Telescope from position.txt file_or_dir. "
[556] + "It must contain one line with two or three numbers."
[557] )
[559] position_file.close()
--> [561] station_positions = cls.__read_layout_txt(station_layout_file)
[562] for station_position in station_positions:
[563] telescope.add_station(
[564] station_position[0],
[565] station_position[1],
(...)
[569] station_position[5],
[570] )
File ~/miniconda3/envs/karabo/lib/python3.9/site-packages/karabo/simulation/telescope.py:609, in Telescope.__read_layout_txt(cls, path)
[607] i = 0
[608] for pos in station_position:
--> [609] values[i] = cls.__float_try_parse(pos)
[610] i += 1
[611] positions.append(
[612] [values[0], values[1], values[2], values[3], values[4], values[5]]
[613] )
IndexError: index 6 is out of bounds for axis 0 with size 6
Expected result
The telescope configuration can be read in without an exception being raised.
Summary
Reading a telescope configuration with
read_OSKAR_tm_file()
can raise an exception. This is true if the layout fileslayout.txt
of a station has 6 columns and there is a space at the end of each row, e.g. here:1.0, 1.0, 0.0, 0.0, 0.0, 0.0
(there is a space at the end of the line)Steps to reproduce
Create a telescope, save the configuration to disk, and read it back in:
Result
Expected result
The telescope configuration can be read in without an exception being raised.
Version
Latest version 0.25.1