|
2 | 2 | Contains functions necessary to compute the split-beam (alongship/athwartship) |
3 | 3 | angles and add them to a Dataset. |
4 | 4 | """ |
5 | | - |
6 | 5 | from typing import List, Tuple |
7 | 6 |
|
| 7 | +import dask.array as da |
8 | 8 | import numpy as np |
9 | 9 | import xarray as xr |
10 | 10 |
|
@@ -111,8 +111,12 @@ def _compute_angle_from_complex( |
111 | 111 | else: |
112 | 112 | raise ValueError("beam_type not recognized!") |
113 | 113 |
|
114 | | - theta = theta / sens[0] - offset[0] |
115 | | - phi = phi / sens[1] - offset[1] |
| 114 | + if isinstance(sens[0].data, da.Array): |
| 115 | + theta = theta / float(sens[0].values) - float(offset[0].values) |
| 116 | + phi = phi / float(sens[1].values) - float(offset[1].values) |
| 117 | + else: |
| 118 | + theta = theta / sens[0] - offset[0] |
| 119 | + phi = phi / sens[1] - offset[1] |
116 | 120 |
|
117 | 121 | return theta, phi |
118 | 122 |
|
@@ -234,39 +238,46 @@ def get_angle_complex_samples( |
234 | 238 | else: |
235 | 239 | # beam_type different for some channels, process each channel separately |
236 | 240 | theta_list, phi_list, valid_channels = [], [], [] |
237 | | - beam_types = ds_beam["beam_type"].values |
238 | | - |
239 | | - for idx, ch_id in enumerate(bs["channel"].data): |
240 | | - beam_type_ch = beam_types[idx] |
241 | | - |
242 | | - if beam_type_ch not in SUPPORTED_BEAM_TYPES: |
243 | | - logger.warning(f"Skipping channel {ch_id}: unsupported beam_type {beam_type_ch}") |
| 241 | + for ch_id in bs["channel"].data: |
| 242 | + beam_type = ds_beam["beam_type"].sel(channel=ch_id) |
| 243 | + beam_type = int(beam_type) |
| 244 | + if beam_type not in SUPPORTED_BEAM_TYPES: |
| 245 | + logger.warning(f"Skipping channel {ch_id}: unsupported beam_type {beam_type}") |
244 | 246 | continue |
245 | 247 |
|
246 | 248 | theta_ch, phi_ch = _compute_angle_from_complex( |
247 | | - bs=bs.isel(channel=idx), |
248 | | - beam_type=beam_type_ch, |
| 249 | + bs=bs.sel(channel=ch_id), |
| 250 | + # beam_type is not time-varying |
| 251 | + beam_type=beam_type, |
249 | 252 | sens=[ |
250 | | - float(angle_params["angle_sensitivity_alongship"].isel(channel=idx).values), |
251 | | - float(angle_params["angle_sensitivity_athwartship"].isel(channel=idx).values), |
| 253 | + angle_params["angle_sensitivity_alongship"].sel(channel=ch_id), |
| 254 | + angle_params["angle_sensitivity_athwartship"].sel(channel=ch_id), |
252 | 255 | ], |
253 | 256 | offset=[ |
254 | | - float(angle_params["angle_offset_alongship"].isel(channel=idx).values), |
255 | | - float(angle_params["angle_offset_athwartship"].isel(channel=idx).values), |
| 257 | + angle_params["angle_offset_alongship"].sel(channel=ch_id), |
| 258 | + angle_params["angle_offset_athwartship"].sel(channel=ch_id), |
256 | 259 | ], |
257 | 260 | ) |
258 | 261 | theta_list.append(theta_ch) |
259 | 262 | phi_list.append(phi_ch) |
260 | 263 | valid_channels.append(ch_id) |
261 | 264 |
|
262 | | - if not theta_list: |
263 | | - raise ValueError("No valid channels found for angle computation.") |
264 | | - |
265 | 265 | # Combine angles from all channels |
266 | | - theta = xr.concat(theta_list, dim="channel") |
267 | | - theta = theta.assign_coords(channel=("channel", valid_channels)) |
268 | | - |
269 | | - phi = xr.concat(phi_list, dim="channel") |
270 | | - phi = phi.assign_coords(channel=("channel", valid_channels)) |
| 266 | + theta = xr.DataArray( |
| 267 | + data=theta_list, |
| 268 | + coords={ |
| 269 | + "channel": valid_channels, |
| 270 | + "ping_time": bs["ping_time"], |
| 271 | + "range_sample": bs["range_sample"], |
| 272 | + }, |
| 273 | + ) |
| 274 | + phi = xr.DataArray( |
| 275 | + data=phi_list, |
| 276 | + coords={ |
| 277 | + "channel": valid_channels, |
| 278 | + "ping_time": bs["ping_time"], |
| 279 | + "range_sample": bs["range_sample"], |
| 280 | + }, |
| 281 | + ) |
271 | 282 |
|
272 | 283 | return theta, phi |
0 commit comments