pyadps 0.2.1b0__py3-none-any.whl → 0.3.0b0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,122 +1,63 @@
1
- import matplotlib.pyplot as plt
2
1
  import numpy as np
3
- import streamlit as st
4
- from matplotlib.widgets import Button, Slider, TextBox
5
- from pyadps.utils import readrdi as rd
6
-
7
- from .plotgen import plotmask, plotvar
8
-
9
-
10
- class PlotEnds:
11
- def __init__(self, pressure, delta=10):
12
- self.dep = pressure / 980
13
-
14
- self.n = np.size(self.dep)
15
- self.delta = delta
16
- self.nmin = 0
17
- self.nmax = self.nmin + self.delta
18
- self.mmax = 0
19
- self.mmin = self.mmax - self.delta
20
-
21
- self.x = np.arange(0, self.n)
22
-
23
- self.start_ens = 0
24
- self.end_ens = 0
25
-
26
- self.fig, self.axs = plt.subplots(1, 2, figsize=(12, 8))
27
- self.fig.set_facecolor("darkgrey")
28
- plt.subplots_adjust(bottom=0.28, right=0.72)
29
-
30
- self.ax_end = self.fig.add_axes(rect=(0.25, 0.08, 0.47, 0.03))
31
- self.ax_start = self.fig.add_axes(rect=(0.25, 0.15, 0.47, 0.03))
32
- self.ax_button = self.fig.add_axes(rect=(0.81, 0.05, 0.15, 0.075))
33
- # self.ax_depmaxbutton = self.fig.add_axes(rect=(0.68, 0.13, 0.04, 0.02))
34
- # self.ax_depminbutton = self.fig.add_axes(rect=(0.25, 0.13, 0.04, 0.02))
35
- # self.ax_recmaxbutton = self.fig.add_axes(rect=(0.68, 0.06, 0.04, 0.02))
36
- # self.ax_recminbutton = self.fig.add_axes(rect=(0.25, 0.06, 0.04, 0.02))
37
-
38
- # Plot
39
- self.axs[0].scatter(self.x, self.dep, color="k")
40
- self.axs[1].scatter(self.x, self.dep, color="k")
41
-
42
- # Figure Labels
43
- for i in range(2):
44
- self.axs[i].set_xlabel("Ensemble")
45
- self.axs[0].set_xlim([self.nmin - 1, self.nmax])
46
- self.axs[1].set_xlim([self.n - self.delta, self.n])
47
- self.axs[0].set_ylabel("Depth (m)")
48
- self.fig.suptitle("Trim Ends")
49
-
50
- # Display statistics
51
- self.axs[0].text(0.82, 0.60, "Statistics", transform=plt.gcf().transFigure)
52
- self.max = np.round(np.max(self.dep), decimals=2)
53
- self.min = np.round(np.min(self.dep), decimals=2)
54
- self.median = np.round(np.median(self.dep), decimals=2)
55
- self.mean = np.round(np.mean(self.dep), decimals=2)
56
- self.t1 = self.axs[0].text(
57
- 0.75,
58
- 0.50,
59
- f"Dep. Max = {self.max} \nDep. Min = {self.min} \nDep. Median = {self.median}",
60
- transform=plt.gcf().transFigure,
61
- )
2
+ import scipy as sp
3
+ from pyadps.utils.readrdi import ReadFile
4
+ from .plotgen import PlotEnds
62
5
 
63
- self.sl_start = Slider(
64
- ax=self.ax_start,
65
- label="Dep. Ensemble",
66
- valmin=self.nmin,
67
- valmax=self.nmax,
68
- valinit=0,
69
- valfmt="%i",
70
- valstep=1,
71
- )
72
6
 
73
- self.sl_end = Slider(
74
- ax=self.ax_end,
75
- label="Rec. Ensemble",
76
- valmin=self.mmin,
77
- valmax=self.mmax,
78
- valinit=0,
79
- valfmt="%i",
80
- valstep=1,
81
- )
7
+ def trim_ends(ds, mask, transducer_depth=None, delta=20, method="Manual"):
8
+ """
9
+ Trim the ends of the data based on the provided method (e.g., manual selection)
10
+ to remove invalid or irrelevant data points during deployment and recovery
11
+ of moorings. This function modifies the mask to reflect the valid data range by marking
12
+ invalid data points as `1` at the ends.
13
+
14
+ Parameters
15
+ ----------
16
+ ds : pyadps.dataset
17
+ The pyadps dataframe is loaded to obtain the data from the variable leader.
18
+ This includes the depth of the transducer and other relevant information
19
+ for trimming the data.
20
+ mask : numpy.ndarray
21
+ A mask array of the same shape as the data, where `1` indicates invalid data
22
+ and `0` indicates valid data. The function modifies the mask based on the trimming
23
+ process.
24
+ method : str, optional
25
+ The method used for trimming the data. Default is "Manual", which allows the user
26
+ to manually select the start and end indices for trimming. Other methods can be
27
+ added if required in the future.
28
+
29
+ Returns
30
+ -------
31
+ numpy.ndarray
32
+ The updated mask array with the ends trimmed. Data points at the beginning and end
33
+ of the array marked as invalid (`1`) based on the trimming results.
34
+
35
+ Notes
36
+ -----
37
+ - The function uses the transducer depth from the `vlobj` to determine the trimming boundaries.
38
+ - When using the "Manual" method, the user is prompted with a plot that allows them to select
39
+ the start and end indices for trimming. These indices are then used to adjust the mask.
40
+ - The mask array is updated in-place to mark the trimmed areas as invalid.
41
+ - The trimming process is based on the variable leader data and the selected method.
42
+
43
+ Example
44
+ -------
45
+ >>> import pyadps
46
+ >>> ds = pyadps.ReadFile("demo.000")
47
+ >>> mask = pyadps.default_mask(ds)
48
+ >>> updated_mask = trim_ends(ds, mask, method="Manual")
49
+ """
50
+
51
+ if isinstance(ds, ReadFile):
52
+ vlobj = ds.variableleader
53
+ transducer_depth = vlobj.vleader["Depth of Transducer"]
54
+ elif isinstance(ds, np.ndarray) and ds.ndim == 1:
55
+ transducer_depth = ds
56
+ else:
57
+ raise ValueError("Input must be a 1-D numpy array or a PyADPS instance")
82
58
 
83
- self.sl_start.on_changed(self.update1)
84
- self.sl_end.on_changed(self.update2)
85
- self.button = Button(self.ax_button, "Save & Exit")
86
- # self.depminbutton = Button(self.ax_depminbutton, "<<")
87
- # self.depmaxbutton = Button(self.ax_depmaxbutton, ">>")
88
- # self.recminbutton = Button(self.ax_recminbutton, "<<")
89
- # self.recmaxbutton = Button(self.ax_recmaxbutton, ">>")
90
-
91
- self.button.on_clicked(self.exitwin)
92
-
93
- def update1(self, value):
94
- self.axs[0].scatter(self.x, self.dep, color="k")
95
- self.axs[0].scatter(self.x[0:value], self.dep[0:value], color="r")
96
- self.start_ens = value
97
-
98
- def update2(self, value):
99
- self.axs[1].scatter(self.x, self.dep, color="k")
100
- if value < 0:
101
- self.axs[1].scatter(
102
- self.x[self.n + value : self.n],
103
- self.dep[self.n + value : self.n],
104
- color="r",
105
- )
106
- self.end_ens = value
107
-
108
- def show(self):
109
- plt.show()
110
-
111
- def exitwin(self, event):
112
- plt.close()
113
-
114
-
115
- def trim_ends(vlobj, mask, method="Manual"):
116
- transducer_depth = vlobj.vleader["Depth of Transducer"]
117
- # pressure = vlobj.vleader["Pressure"]
118
59
  if method == "Manual":
119
- out = PlotEnds(transducer_depth, delta=20)
60
+ out = PlotEnds(transducer_depth, delta=delta)
120
61
  out.show()
121
62
  if out.start_ens > 0:
122
63
  mask[:, 0 : out.start_ens] = 1
@@ -127,26 +68,110 @@ def trim_ends(vlobj, mask, method="Manual"):
127
68
  return mask
128
69
 
129
70
 
130
- def side_lobe_beam_angle(flobj, vlobj, mask, orientation='default', water_column_depth=0, extra_cells=2):
131
- beam_angle = int(flobj.system_configuration()["Beam Angle"])
132
- cell_size = flobj.field()["Depth Cell Len"]
133
- bin1dist = flobj.field()["Bin 1 Dist"]
134
- cells = flobj.field()["Cells"]
135
- ensembles = flobj.ensembles
136
- transducer_depth = vlobj.vleader["Depth of Transducer"]
137
-
138
- if orientation.lower() == "default":
139
- orientation = flobj.system_configuration()['Beam Direction']
71
+ def side_lobe_beam_angle(
72
+ ds,
73
+ mask,
74
+ orientation='default',
75
+ water_column_depth=0,
76
+ extra_cells=2,
77
+ cells=None,
78
+ cell_size=None,
79
+ bin1dist=None,
80
+ beam_angle=None
81
+ ):
82
+ """
83
+ Mask the data contaminated due to surface/bottom backscatter based on the
84
+ side lobe beam angle. This function can correct the orientation of the beam
85
+ (upward or downward looking) and can account for deletion of additional cells.
86
+ Water column depth is applicable for downward-looking ADCP.
87
+
88
+ Parameters
89
+ ----------
90
+ ds : pyadps.dataset or np.ndarray
91
+ The pyadps dataframe is loaded to obtain the data from the fixed and variable leader.
92
+ This includes the depth of the transducer and other relevant information
93
+ for trimming the data.
94
+
95
+ If numpy.ndarray is loaded, the value should contain the transducer_depth.
96
+ In such cases provide cells, cell_size, and bin 1 distance.
97
+ Orientiation should be either 'up' or 'down' and not 'default'.
98
+
99
+ mask : numpy.ndarray
100
+ A mask array where invalid or false data points are marked. The mask is updated
101
+ based on the calculated side lobe beam angles.
102
+ orientation : str, optional
103
+ The orientation of the beam. It can be 'default', 'up', or 'down'.
104
+ Default orientation, set before deployment, is obtained from the file.
105
+ If 'up' or 'down' is selected, the function will correct the orientation accordingly.
106
+ water_column_depth : int, optional
107
+ The depth of the water column. This value is used to adjust the beam angle
108
+ calculations. Default is 0.
109
+ extra_cells : int, optional
110
+ The number of extra cells to consider when calculating the beam angle. Default is 2.
111
+ cells: int, optional
112
+ Number of cells
113
+ cell_size: int, optional
114
+ Cell size or depth cell length in cm
115
+ beam_angle: int, optional
116
+ Beam angle in degrees
117
+
118
+ Returns
119
+ -------
120
+ numpy.ndarray
121
+ The updated mask array with side lobe beam angle adjustments. The mask will
122
+ reflect valid and invalid data points based on the calculated beam angles.
123
+
124
+ Notes
125
+ -----
126
+ - The function uses the fixedleader and variableleader to retrieve the necessary information
127
+ for the beam angle calculation. The `mask` array is updated based on these calculations.
128
+ - The `orientation` parameter allows for adjustments to account for upward or downward
129
+ looking ADCPs.
130
+ - The `water_column_depth` permits detecting the bottom of the ocean for downward looking
131
+ ADCP.
132
+ - The `extra_cells` parameter adds additional cells in addition to those masked by beam angle
133
+ calculation.
134
+
135
+ Example
136
+ -------
137
+ >>> import pyadps
138
+ >>> ds = pyadps.ReadFile("demo.000")
139
+ >>> mask = pyadps.default_mask(ds)
140
+ >>> updated_mask = side_lobe_beam_angle(ds, mask, orientation='down', water_column_depth=50, extra_cells=3)
141
+
142
+ >>> transducer_depth = ds.variableleader.transducer_depth
143
+ >>> cells = ds.fixedleader.cells
144
+ >>> cell_size = ds.fixedleader.depth_cell_length
145
+ >>> new_mask = side_lobe_beam_angle(transducer_depth, orientation='up', cells=cells, cell_size=cell_size, bin1dist=bindist)
146
+ """
147
+ if isinstance(ds, ReadFile) or ds.__class__.__name__ == "ReadFile":
148
+ flobj = ds.fixedleader
149
+ vlobj = ds.variableleader
150
+ beam_angle = int(flobj.system_configuration()["Beam Angle"])
151
+ cell_size = flobj.field()["Depth Cell Len"]
152
+ bin1dist = flobj.field()["Bin 1 Dist"]
153
+ cells = flobj.field()["Cells"]
154
+ ensembles = flobj.ensembles
155
+ transducer_depth = vlobj.vleader["Depth of Transducer"]
156
+ if orientation.lower() == "default":
157
+ orientation = flobj.system_configuration()['Beam Direction']
158
+ elif isinstance(ds, np.ndarray) and np.squeeze(ds).ndim == 1:
159
+ transducer_depth = ds
160
+ ensembles = np.size(ds)
161
+ else:
162
+ raise ValueError("Input must be a 1-D numpy array or a PyADPS instance")
140
163
 
141
164
  if orientation.lower() == "up":
142
165
  sgn = -1
143
166
  water_column_depth = 0
144
- else:
167
+ elif orientation.lower() == "down":
145
168
  sgn = 1
169
+ else:
170
+ raise ValueError("Orientation should be either `up` or `down`")
146
171
 
147
172
  beam_angle = np.deg2rad(beam_angle)
148
173
  depth = transducer_depth / 10
149
- valid_depth = (water_column_depth - sgn*depth) * np.cos(beam_angle) + sgn*bin1dist / 100
174
+ valid_depth = (water_column_depth - sgn*depth) * np.cos(beam_angle) + sgn * bin1dist / 100
150
175
  valid_cells = np.trunc(valid_depth * 100 / cell_size) - extra_cells
151
176
 
152
177
  for i in range(ensembles):
@@ -185,3 +210,343 @@ def manual_cut_bins(mask, min_cell, max_cell, min_ensemble, max_ensemble):
185
210
  mask[min_cell:max_cell, min_ensemble:max_ensemble] = 1
186
211
 
187
212
  return mask
213
+
214
+
215
+ def regrid2d(
216
+ ds,
217
+ data,
218
+ fill_value,
219
+ end_bin_option="cell",
220
+ trimends=None,
221
+ method="nearest",
222
+ orientation="default",
223
+ boundary_limit=0,
224
+ cells=None,
225
+ cell_size=None,
226
+ bin1dist=None
227
+ ):
228
+ """
229
+ Regrids 2D data onto a new grid based on specified parameters.
230
+
231
+ Parameters:
232
+ -----------
233
+ ds : pyadps.dataset or numpy.ndarray
234
+ If pyadps dataframe is loaded, the data from the fixed and variable leader
235
+ is automatically obtained. This includes the depth of the transducer and other relevant information
236
+ for trimming the data.
237
+
238
+ If numpy.ndarray is loaded, the value should contain the transducer_depth.
239
+ In such cases provide cells, cell_size, and bin 1 distance.
240
+ Orientiation should be either 'up' or 'down' and not 'default'.
241
+
242
+
243
+ data : array-like
244
+ The 2D data array to be regridded.
245
+
246
+ fill_value : scalar
247
+ The value used to fill missing or undefined grid points.
248
+
249
+ end_bin_option : str or float, optional, default="cell"
250
+ The depth of the last bin or boundary for the grid.
251
+ Options include:
252
+ - "cell" : Calculates the depth of the default last bin for the grid.
253
+ Truncates to surface for upward ADCP.
254
+ - "surface": The data is gridded till the surface
255
+ - "manual": User-defined depth for the grid.
256
+ Use boundary_limit option to provide the value.
257
+ otherwise, a specific numerical depth value can be provided.
258
+
259
+ trimends : tuple of floats, optional, default=None
260
+ If provided, defines the ensemble range (start, end) for
261
+ calculating the maximum/minimum transducer depth.
262
+ Helps avoiding the deployment or retrieval data.
263
+ E.g. (10, 3000)
264
+
265
+ method : str, optional, default="nearest"
266
+ The interpolation method to use for regridding based
267
+ on scipy.interpolate.interp1d.
268
+ Options include:
269
+ - "nearest" : Nearest neighbor interpolation.
270
+ - "linear" : Linear interpolation.
271
+ - "cubic" : Cubic interpolation.
272
+
273
+ orientation : str, optional, default="up"
274
+ Defines the direction of the regridding for an upward/downward looking ADCP. Options include:
275
+ - "up" : Regrid upwards (for upward-looking ADCP).
276
+ - "down" : Regrid downwards (for downward-looking ADCP).
277
+
278
+ boundary_limit : float, optional, default=0
279
+ The limit for the boundary depth. This restricts the grid regridding to depths beyond the specified limit.
280
+
281
+ cells: int, optional
282
+ Number of cells
283
+
284
+ cell_size: int, optional
285
+ Cell size or depth cell length in cm
286
+
287
+ bin1dist: int, optional
288
+ Distance from the first bin in cm
289
+
290
+
291
+ Returns:
292
+ --------
293
+ z: regridded depth
294
+ regridded_data : array-like
295
+ The regridded 2D data array, based on the specified method,
296
+ orientation, and other parameters.
297
+
298
+ Notes:
299
+ ------
300
+ - If `end_bin_option == boundary`, then `boundary_limit` is used to regrid the data.
301
+ - This function allows for flexible regridding of 2D data to fit a new grid, supporting different interpolation methods.
302
+ - The `boundary_limit` parameter helps restrict regridding to depths above or below a certain threshold.
303
+ """
304
+
305
+ if isinstance(ds, ReadFile) or ds.__class__.__name__ == "ReadFile":
306
+ flobj = ds.fixedleader
307
+ vlobj = ds.variableleader
308
+ # Get values and convert to 'm'
309
+ bin1dist = flobj.field()["Bin 1 Dist"] / 100
310
+ transdepth = vlobj.vleader["Depth of Transducer"] / 10
311
+ cell_size = flobj.field()["Depth Cell Len"] / 100
312
+ cells = flobj.field()["Cells"]
313
+ ensembles = flobj.ensembles
314
+ if orientation.lower() == "default":
315
+ orientation = flobj.system_configuration()['Beam Direction']
316
+
317
+ elif isinstance(ds, np.ndarray) and np.squeeze(ds).ndim == 1:
318
+ transdepth = ds/10
319
+ ensembles = np.size(ds)
320
+
321
+ if cells is None:
322
+ raise ValueError("Input must include number of cells.")
323
+
324
+ if cell_size is None:
325
+ raise ValueError("Input must include cell size.")
326
+ else:
327
+ cell_size = cell_size/100
328
+
329
+ if bin1dist is None:
330
+ raise ValueError("Input must include bin 1 distance.")
331
+ else:
332
+ bin1dist = bin1dist/100
333
+
334
+ if orientation.lower() != "up" and orientation.lower() != "down":
335
+ raise ValueError("Orientation must be `up` or `down`.")
336
+ else:
337
+ raise ValueError("Input must be a 1-D numpy array or a PyADPS instance")
338
+
339
+ if orientation.lower() == "up":
340
+ sgn = -1
341
+ else:
342
+ sgn = 1
343
+
344
+ # Create a regular grid
345
+
346
+ # Find depth of first cell
347
+ depth = transdepth + sgn * bin1dist
348
+
349
+ # Find the maximum and minimum depth for first cell for upward
350
+ # looking ADCP (minimum and maximum for downward looking)
351
+ if trimends is not None:
352
+ max_depth = abs(np.min(sgn*depth[trimends[0] : trimends[1]]))
353
+ min_depth = abs(np.max(sgn*depth[trimends[0] : trimends[1]]))
354
+ else:
355
+ max_depth = abs(np.min(sgn*depth))
356
+ min_depth = abs(np.max(sgn*depth))
357
+
358
+ # FIRST CELL
359
+ # Convert the first cell depth to the first regular grid depth
360
+ depthfirstcell = max_depth - max_depth % cell_size
361
+
362
+ # LAST CELL
363
+ # Convert the last cell depth to last regular grid depth
364
+ if end_bin_option.lower() == "surface":
365
+ # Added one additional negative cell to accomodate 0 m.
366
+ depthlastcell = sgn * cell_size
367
+ elif end_bin_option.lower() == "cell":
368
+ min_depth_regrid = min_depth - sgn*min_depth % cell_size
369
+ depthlastcell = min_depth_regrid + sgn* (cells+1) * cell_size
370
+ # Check if this is required. Use 'surface' option
371
+ if depthlastcell < 0:
372
+ depthlastcell = sgn*cell_size
373
+ elif end_bin_option.lower() == "manual":
374
+ if sgn < 0 and boundary_limit > depthfirstcell:
375
+ print("ERROR: For upward looking ADCP, boundary limit should be less than transducer depth")
376
+ return
377
+ if sgn > 0 and boundary_limit < depthfirstcell:
378
+ print("ERROR: For downward looking ADCP, boundary limit should be greater than transducer depth")
379
+ return
380
+ # Set the last grid cell depth
381
+ depthlastcell = boundary_limit
382
+ else:
383
+ print("ERROR: `end_bin_option` not recognized.")
384
+ return
385
+
386
+ # Negative used for upward and positive for downward.
387
+ print(depthfirstcell, depthlastcell, cell_size, sgn)
388
+ z = np.arange(sgn * depthfirstcell, sgn * depthlastcell, cell_size)
389
+ regbins = len(z)
390
+
391
+ regridded_data = np.zeros((regbins, ensembles))
392
+
393
+ # Create original depth array
394
+ for i, d in enumerate(depth):
395
+ n = d + sgn*cell_size * cells
396
+ # np.arange may include unexpected elements due to floating-point
397
+ # precision issues at the stopping point. Changed to np.linspace.
398
+ #
399
+ # depth_bins = np.arange(sgn*d, sgn*n, cell_size)
400
+ depth_bins = np.linspace(sgn*d, sgn*n, cells)
401
+ f = sp.interpolate.interp1d(
402
+ depth_bins,
403
+ data[:, i],
404
+ kind=method,
405
+ fill_value=fill_value,
406
+ bounds_error=False,
407
+ )
408
+ gridz = f(z)
409
+
410
+ regridded_data[:, i] = gridz
411
+
412
+ return abs(z), regridded_data
413
+
414
+
415
+ def regrid3d(
416
+ ds,
417
+ data,
418
+ fill_value,
419
+ end_bin_option="cell",
420
+ trimends=None,
421
+ method="nearest",
422
+ orientation="up",
423
+ boundary_limit=0,
424
+ cells=None,
425
+ cell_size=None,
426
+ bin1dist=None,
427
+ beams=None
428
+ ):
429
+ """
430
+ Regrids 3D data onto a new grid based on specified parameters.
431
+
432
+ Parameters:
433
+ -----------
434
+ ds : pyadps.dataset
435
+ The pyadps dataframe is loaded to obtain the data from the fixed and variable leader.
436
+ This includes the depth of the transducer and other relevant information
437
+ for trimming the data.
438
+
439
+ data : array-like
440
+ The 3D data array to be regridded, with dimensions
441
+ typically representing time, depth, and another axis (e.g., ensembles).
442
+
443
+ fill_value : scalar
444
+ The value used to fill missing or undefined grid points.
445
+
446
+ end_bin_option : str or float, optional, default="cell"
447
+ The depth of the last bin or boundary for the grid.
448
+ Options include:
449
+ - "cell" : Calculates the depth of the default last bin for the grid.
450
+ Truncates to surface for upward ADCP.
451
+ - "surface" : The data is gridded till the surface.
452
+ - "manual" : User-defined depth for the grid.
453
+ Use boundary_limit option to provide the value.
454
+ Otherwise, a specific numerical depth value can be provided.
455
+
456
+ trimends : tuple of integer, optional, default=None
457
+ If provided, defines the ensemble range (start, end) for
458
+ calculating the maximum/minimum transducer depth.
459
+ Helps avoiding the deployment or retrieval data.
460
+ E.g., (10, 3000)
461
+
462
+ method : str, optional, default="nearest"
463
+ The interpolation method to use for regridding based
464
+ on scipy.interpolate.interp1d.
465
+ Options include:
466
+ - "nearest" : Nearest neighbor interpolation.
467
+ - "linear" : Linear interpolation.
468
+ - "cubic" : Cubic interpolation.
469
+
470
+ orientation : str, optional, default="up"
471
+ Defines the direction of the regridding for an upward/downward looking ADCP. Options include:
472
+ - "up" : Regrid upwards (for upward-looking ADCP).
473
+ - "down" : Regrid downwards (for downward-looking ADCP).
474
+
475
+ boundary_limit : float, optional, default=0
476
+ The limit for the boundary depth. This restricts the grid regridding to depths beyond the specified limit.
477
+
478
+ cells: int, optional
479
+ Number of cells
480
+
481
+ cell_size: int, optional
482
+ Cell size or depth cell length in cm
483
+
484
+ bin1dist: int, optional
485
+ Distance from the first bin in cm
486
+
487
+ beams: int, optional
488
+ Number of beams
489
+
490
+
491
+
492
+ Returns:
493
+ --------
494
+ z : array-like
495
+ The regridded depth array.
496
+ regridded_data : array-like
497
+ The regridded 3D data array, based on the specified method,
498
+ orientation, and other parameters.
499
+
500
+ Notes:
501
+ ------
502
+ - If `end_bin_option == boundary`, then `boundary_limit` is used to regrid the data.
503
+ - This function allows for flexible regridding of 3D data to fit a new grid, supporting different interpolation methods.
504
+ - The `boundary_limit` parameter helps restrict regridding to depths above or below a certain threshold.
505
+ - This function is an extension of 2D regridding to handle the time dimension or other additional axes in the data.
506
+ """
507
+
508
+ if isinstance(ds, ReadFile):
509
+ flobj = ds.fixedleader
510
+ beams = flobj.field()["Beams"]
511
+ elif isinstance(ds, np.ndarray) and ds.ndim == 1:
512
+ if beams is None:
513
+ raise ValueError("Input must include number of beams.")
514
+ else:
515
+ raise ValueError("Input must be a 1-D numpy array or a PyADPS instance")
516
+
517
+ z, data_dummy = regrid2d(
518
+ ds,
519
+ data[0, :, :],
520
+ fill_value,
521
+ end_bin_option=end_bin_option,
522
+ trimends=trimends,
523
+ method=method,
524
+ orientation=orientation,
525
+ boundary_limit=boundary_limit,
526
+ cells=cells,
527
+ cell_size=cell_size,
528
+ bin1dist=bin1dist
529
+ )
530
+
531
+ newshape = np.shape(data_dummy)
532
+ regridded_data = np.zeros((beams, newshape[0], newshape[1]))
533
+ regridded_data[0, :, :] = data_dummy
534
+
535
+ for i in range(beams - 1):
536
+ z, data_dummy = regrid2d(
537
+ ds,
538
+ data[i + 1, :, :],
539
+ fill_value,
540
+ end_bin_option=end_bin_option,
541
+ trimends=trimends,
542
+ method=method,
543
+ orientation=orientation,
544
+ boundary_limit=boundary_limit,
545
+ cells=cells,
546
+ cell_size=cell_size,
547
+ bin1dist=bin1dist
548
+ )
549
+ regridded_data[i + 1, :, :] = data_dummy
550
+
551
+ return z, regridded_data
552
+