2@file antenna_attributes.py
3@brief `main()` shows how to use
4[read_MI_antenna_geometry()](#antenna_attributes.read_MI_antenna_geometry) and
5[read_MI_antenna_geometry()](#antenna_attributes.read_global_channel_mapping).
8from pathlib
import Path
68ANTENNA_POLARIZATION_TYPE = pl.Enum([
"H",
"V"])
73PUEO_ANTENNA_TYPE = pl.Enum([
"MI",
"LF"])
91ASSUMED_PHI_SECTOR_APERTURE_WIDTH = 50
94def read_global_channel_mapping(tag: str =
"jan26") -> pl.DataFrame:
97 @brief Generates a Polars DataFrame from
98 [map.dat](https://github.com/PUEOCollaboration/pueo-data/blob/main/geometry/jun25/map.dat)
99 in the pueo-data repository.
101 * `map.dat` contains the channel mapping between the indices `GlobalChan`, `AntNum` and `AntIdx`
103 * That is, the dataframe contains both polarizations (V and H) of both instruments (MI and LF).
104 * `GlobalChan` is the index used by the `pueoEvent` repository to access the waveforms,
105 see its [example script](https://github.com/PUEOCollaboration/pueoEvent/tree/main/examples).
106 * The relevant line is
108 chan = pueo.GeomTool.Instance().getChanIndexFromRingPhiPol(
109 pueo.ring.ring_t.kTopRing, 10, pueo.pol.pol_t.kVertical
112 * `chan` in the line above comes from the column `GlobalChan` in the DataFrame.
116┌────────────┬────────┬────────┬──────┬─────────┬─────────┬─────────────┬───────────┬──────┬─────────┐
117│ GlobalChan ┆ AntNum ┆ AntIdx ┆ Pol ┆ AntType ┆ SurfNum ┆ SurfChanNum ┆ PhiSector ┆ Ring ┆ Comment │
118│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
119│ u32 ┆ enum ┆ u32 ┆ enum ┆ enum ┆ u8 ┆ u8 ┆ u8 ┆ u8 ┆ str │
120╞════════════╪════════╪════════╪══════╪═════════╪═════════╪═════════════╪═══════════╪══════╪═════════╡
121│ 0 ┆ 101 ┆ 0 ┆ H ┆ MI ┆ 0 ┆ 0 ┆ 1 ┆ 1 ┆ null │
122│ 1 ┆ 201 ┆ 1 ┆ H ┆ MI ┆ 0 ┆ 1 ┆ 1 ┆ 2 ┆ null │
123│ 2 ┆ 301 ┆ 2 ┆ H ┆ MI ┆ 0 ┆ 2 ┆ 1 ┆ 3 ┆ null │
124│ 3 ┆ 401 ┆ 3 ┆ H ┆ MI ┆ 0 ┆ 3 ┆ 1 ┆ 4 ┆ null │
125│ 4 ┆ 102 ┆ 4 ┆ H ┆ MI ┆ 0 ┆ 4 ┆ 2 ┆ 1 ┆ null │
126│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
127│ 203 ┆ 609 ┆ 99 ┆ V ┆ LF ┆ 25 ┆ 3 ┆ 9 ┆ 6 ┆ null │
128│ 204 ┆ 713 ┆ 100 ┆ V ┆ LF ┆ 25 ┆ 4 ┆ 13 ┆ 7 ┆ null │
129│ 205 ┆ 813 ┆ 101 ┆ V ┆ LF ┆ 25 ┆ 5 ┆ 13 ┆ 8 ┆ null │
130│ 206 ┆ 817 ┆ 102 ┆ V ┆ LF ┆ 25 ┆ 6 ┆ 17 ┆ 8 ┆ null │
131│ 207 ┆ 821 ┆ 103 ┆ V ┆ LF ┆ 25 ┆ 7 ┆ 21 ┆ 8 ┆ null │
132└────────────┴────────┴────────┴──────┴─────────┴─────────┴─────────────┴───────────┴──────┴─────────┘
136 map_dot_dat_file = os.environ.get(
"PUEO_UTIL_INSTALL_DIR") / Path(f
"share/pueo/geometry/{tag}/map.dat")
137 all_channels: pl.DataFrame = (
142 "GlobalChan": pl.UInt32,
144 "Pol": ANTENNA_POLARIZATION_TYPE,
145 "AntType": PUEO_ANTENNA_TYPE,
147 "SurfChanNum": pl.UInt8,
148 "PhiSector": pl.UInt8,
154 pl.col(
"AntNum").cast(pl.String).cast(pl.UInt32)
161def read_antenna_geometry(qrh_dot_dat: Path, tag: str =
"jan26", offset_inSIM:Path |
None =
None, ant_type=
'MI') -> pl.DataFrame:
164 @brief Reads in antenna positions (Cartesian coordinates, meters) and attitudes (degrees) from
165 [qrh.dat](https://github.com/PUEOCollaboration/pueo-data/blob/main/geometry/jun25/qrh.dat)
166 in the pueo-data repository.
167 @param[in] qrh_dot_dat Path to `qrh.dat`
169 * Note that `qrh.dat` contains the **face centers** of all main-instrument (MI) antennas
170 (quad-ridged horn antennas) and NOT the **phase center**.
172 * The function will error out if, although unlikely, `qrh.dat` contains an
173 index that is not listed in #ALL_PUEO_ANTENNA_NAMES.
178┌────────┬──────┬───────────┬────────┬───────┬────────┬───────┬────────────┬──────────┬───────────┐
179│ AntNum ┆ Ring ┆ PhiSector ┆ AntIdx ┆ X[m] ┆ Y[m] ┆ Z[m] ┆ Pitch[deg] ┆ Yaw[deg] ┆ Roll[deg] │
180│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
181│ enum ┆ u8 ┆ u8 ┆ u32 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 │
182╞════════╪══════╪═══════════╪════════╪═══════╪════════╪═══════╪════════════╪══════════╪═══════════╡
183│ 101 ┆ 1 ┆ 1 ┆ 0 ┆ 1.488 ┆ 0.0 ┆ 5.114 ┆ -10.0 ┆ 0.0 ┆ 0.0 │
184│ 201 ┆ 2 ┆ 1 ┆ 1 ┆ 2.596 ┆ 0.0 ┆ 1.457 ┆ -10.0 ┆ 0.0 ┆ 0.0 │
185│ 301 ┆ 3 ┆ 1 ┆ 2 ┆ 2.596 ┆ 0.0 ┆ 0.728 ┆ -10.0 ┆ 0.0 ┆ 0.0 │
186│ 401 ┆ 4 ┆ 1 ┆ 3 ┆ 2.596 ┆ 0.0 ┆ 0.0 ┆ -10.0 ┆ 0.0 ┆ 0.0 │
187│ 102 ┆ 1 ┆ 2 ┆ 4 ┆ 1.33 ┆ 0.356 ┆ 4.476 ┆ -10.0 ┆ 15.0 ┆ 0.0 │
188│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
189│ 423 ┆ 4 ┆ 23 ┆ 91 ┆ 2.248 ┆ -1.298 ┆ 0.0 ┆ -10.0 ┆ -30.0 ┆ 0.0 │
190│ 124 ┆ 1 ┆ 24 ┆ 92 ┆ 1.33 ┆ -0.357 ┆ 4.476 ┆ -10.0 ┆ -15.0 ┆ 0.0 │
191│ 224 ┆ 2 ┆ 24 ┆ 93 ┆ 2.507 ┆ -0.672 ┆ 1.457 ┆ -10.0 ┆ -15.0 ┆ 0.0 │
192│ 324 ┆ 3 ┆ 24 ┆ 94 ┆ 2.507 ┆ -0.672 ┆ 0.728 ┆ -10.0 ┆ -15.0 ┆ 0.0 │
193│ 424 ┆ 4 ┆ 24 ┆ 95 ┆ 2.507 ┆ -0.672 ┆ 0.0 ┆ -10.0 ┆ -15.0 ┆ 0.0 │
194└────────┴──────┴───────────┴────────┴───────┴────────┴───────┴────────────┴──────────┴───────────┘
199 version = [int(i)
for i
in pl.__version__.split(
".")]
203 assert minor > 26
and minor != 31,
"Bad polars version"
209 if ant_type
in (
'MI',
'LF'):
210 antenna_phi_sector_mapping = (
211 read_global_channel_mapping(tag=tag)
213 .select(
"AntNum",
"AntIdx",
"PhiSector",
"Ring")
216 print(
"Ant type is not supported!")
219 ants: pl.DataFrame = (
226 "Pitch[deg]": pl.Float64,
227 "Yaw[deg]": pl.Float64,
228 "Roll[deg]": pl.Float64,
232 .join(antenna_phi_sector_mapping, on=
"AntNum")
234 pl.col(
"AntNum",
"Ring",
"PhiSector",
"AntIdx"),
235 pl.col(
"X[m]",
"Y[m]",
"Z[m]",
"Pitch[deg]",
"Yaw[deg]",
"Roll[deg]")
241 offset_df = pl.read_csv(
246 new_columns=[
"Pol",
"dx[m]",
"dy[m]",
"dz[m]"],
249 dx, dy, dz = offset_df.select([
"dx[m]",
"dy[m]",
"dz[m]"]).row(0)
252 ants = ants.with_columns(
253 (pl.col(
"X[m]") + dx).alias(
"X[m]"),
254 (pl.col(
"Y[m]") + dy).alias(
"Y[m]"),
255 (pl.col(
"Z[m]") + dz).alias(
"Z[m]"),
258 return ants.sort(
"AntNum")
261def get_nominal_phase_center(face_centers: pl.DataFrame, coordinates: str =
None, ant_type=
'MI') -> pl.DataFrame:
262 """!Takes the antenna **face centers** and returns the (nominal) antenna **phase centers**
264 @param[in] face_centers The output of #read_MI_antenna_geometry
265 @param[in] coordinates can be "cylindrical" or default (Cartesian)
266 @retval phase_centers Same as `face_centers` except `X[m]`, `Y[m]`, and `Z[m]` now represent
269* Essential columns: `face_centers` **must** contain `X[m]` and `Y[m]`
270* The nominal phase center is obtained by taking the face center and moving radially inward by 30 cm
271 (cylindrical coordinates).
272* If `coordinates` is not specified then Cartesian coordinates is used, and the output schema is
285* If `coordinates` is `cylindrical`, then the ouput schema is
304 rho = (x ** 2 + y ** 2).sqrt()
306 rho = (x ** 2 + y ** 2).sqrt()
308 phi = pl.arctan2(y, x)
310 new_x = rho * phi.cos()
311 new_y = rho * phi.sin()
313 if coordinates
is None:
314 phase_centers = face_centers.with_columns(new_x.alias(
"X[m]"), new_y.alias(
"Y[m]"))
316 elif coordinates ==
"cylindrical":
317 phase_centers = face_centers.select(
318 pl.all().exclude(
"X[m]",
"Y[m]"),
320 phi.alias(
"Phi[rad]")
323 print(f
"I can't handle this coordinate system: {coordinates}")
329if __name__ ==
"__main__":
330 pl.Config().set_tbl_cols(10)
332 print(read_global_channel_mapping())
338 ants = read_antenna_geometry(
339 os.environ.get(
"PUEO_UTIL_INSTALL_DIR") / Path(
"share/pueo/geometry/jan26/lf.dat"),
344 print(get_nominal_phase_center(ants, coordinates=
'cylindrical', ant_type=
'LF'))