55
66from typing import List , Tuple
77
8+ import dask .array as da
89import numpy as np
910import xarray as xr
1011
@@ -111,8 +112,12 @@ def _compute_angle_from_complex(
111112 else :
112113 raise ValueError ("beam_type not recognized!" )
113114
114- theta = theta / sens [0 ] - offset [0 ]
115- phi = phi / sens [1 ] - offset [1 ]
115+ if isinstance (sens [0 ].data , da .Array ):
116+ theta = theta / float (sens [0 ].values ) - float (offset [0 ].values )
117+ phi = phi / float (sens [1 ].values ) - float (offset [1 ].values )
118+ else :
119+ theta = theta / sens [0 ] - offset [0 ]
120+ phi = phi / sens [1 ] - offset [1 ]
116121
117122 return theta , phi
118123
@@ -235,16 +240,16 @@ def get_angle_complex_samples(
235240 # beam_type different for some channels, process each channel separately
236241 theta_list , phi_list , valid_channels = [], [], []
237242 for ch_id in bs ["channel" ].data :
238- beam_type_ch = ds_beam ["beam_type" ].sel (channel = ch_id ). item ( )
239-
240- if beam_type_ch not in SUPPORTED_BEAM_TYPES :
241- logger .warning (f"Skipping channel { ch_id } : unsupported beam_type { beam_type_ch } " )
243+ beam_type = ds_beam ["beam_type" ].sel (channel = ch_id )
244+ beam_type = int ( beam_type )
245+ if beam_type not in SUPPORTED_BEAM_TYPES :
246+ logger .warning (f"Skipping channel { ch_id } : unsupported beam_type { beam_type } " )
242247 continue
243248
244249 theta_ch , phi_ch = _compute_angle_from_complex (
245250 bs = bs .sel (channel = ch_id ),
246251 # beam_type is not time-varying
247- beam_type = ( ds_beam [ " beam_type" ]. sel ( channel = ch_id )) ,
252+ beam_type = beam_type ,
248253 sens = [
249254 angle_params ["angle_sensitivity_alongship" ].sel (channel = ch_id ),
250255 angle_params ["angle_sensitivity_athwartship" ].sel (channel = ch_id ),
@@ -258,14 +263,22 @@ def get_angle_complex_samples(
258263 phi_list .append (phi_ch )
259264 valid_channels .append (ch_id )
260265
261- if not theta_list :
262- raise ValueError ("No valid channels found for angle computation." )
263-
264266 # Combine angles from all channels
265- theta = xr .concat (theta_list , dim = "channel" )
266- theta = theta .assign_coords (channel = ("channel" , valid_channels ))
267-
268- phi = xr .concat (phi_list , dim = "channel" )
269- phi = phi .assign_coords (channel = ("channel" , valid_channels ))
267+ theta = xr .DataArray (
268+ data = theta_list ,
269+ coords = {
270+ "channel" : valid_channels ,
271+ "ping_time" : bs ["ping_time" ],
272+ "range_sample" : bs ["range_sample" ],
273+ },
274+ )
275+ phi = xr .DataArray (
276+ data = phi_list ,
277+ coords = {
278+ "channel" : valid_channels ,
279+ "ping_time" : bs ["ping_time" ],
280+ "range_sample" : bs ["range_sample" ],
281+ },
282+ )
270283
271284 return theta , phi
0 commit comments