3
3
"""
4
4
5
5
import logging
6
- from typing import Literal
6
+ from typing import Literal , Union
7
7
8
8
import numpy as np
9
9
import pandas as pd
@@ -32,9 +32,11 @@ def compute_MVBS(
32
32
range_var : Literal ["echo_range" , "depth" ] = "echo_range" ,
33
33
range_bin : str = "20m" ,
34
34
ping_time_bin : str = "20s" ,
35
- method = "map-reduce" ,
36
- skipna = True ,
35
+ method : str = "map-reduce" ,
36
+ reindex : bool = False ,
37
+ skipna : bool = True ,
37
38
closed : Literal ["left" , "right" ] = "left" ,
39
+ range_var_max : Union [int , float ] = None ,
38
40
** flox_kwargs ,
39
41
):
40
42
"""
@@ -63,11 +65,21 @@ def compute_MVBS(
63
65
The flox strategy for reduction of dask arrays only.
64
66
See flox `documentation <https://flox.readthedocs.io/en/latest/implementation.html>`_
65
67
for more details.
68
+ reindex: bool, default False
69
+ If False, reindex after the blockwise stage. If True, reindex at the blockwise stage.
70
+ Generally, `reindex=False` results in less memory at the cost of computation speed.
71
+ Can only be used when method='map-reduce'.
72
+ See flox `documentation <https://flox.readthedocs.io/en/latest/implementation.html>`_
73
+ for more details.
66
74
skipna: bool, default True
67
75
If true, the mean operation skips NaN values.
68
76
Else, the mean operation includes NaN values.
69
77
closed: {'left', 'right'}, default 'left'
70
78
Which side of bin interval is closed.
79
+ range_var_max: Union[int, float], default None
80
+ Range variable maximum. Can be true range variable maximum or the maximum depth the
81
+ user wishes to regrid to. If known, users can pass in range variable maximum to
82
+ ensure that `compute_MVBS` can lazily run without any computation.
71
83
**flox_kwargs
72
84
Additional keyword arguments to be passed
73
85
to flox reduction function.
@@ -76,6 +88,8 @@ def compute_MVBS(
76
88
-------
77
89
A dataset containing bin-averaged Sv
78
90
"""
91
+ if method != "map-reduce" and reindex is not None :
92
+ raise ValueError (f"Passing in reindex={ reindex } is only allowed when method='map_reduce'." )
79
93
80
94
# Setup and validate
81
95
# * Sv dataset must contain specified range_var
@@ -86,10 +100,11 @@ def compute_MVBS(
86
100
if not isinstance (ping_time_bin , str ):
87
101
raise TypeError ("ping_time_bin must be a string" )
88
102
89
- # create bin information for echo_range
90
- # this computes the echo range max since there might NaNs in the data
91
- echo_range_max = ds_Sv [range_var ].max ()
92
- range_interval = np .arange (0 , echo_range_max + range_bin , range_bin )
103
+ # Create bin information for the range variable
104
+ if range_var_max is None :
105
+ # This computes the range variable max since there might NaNs in the data
106
+ range_var_max = ds_Sv [range_var ].max (skipna = True )
107
+ range_interval = np .arange (0 , range_var_max + range_bin , range_bin )
93
108
94
109
# create bin information needed for ping_time
95
110
d_index = (
@@ -109,6 +124,7 @@ def compute_MVBS(
109
124
ping_interval ,
110
125
range_var = range_var ,
111
126
method = method ,
127
+ reindex = reindex ,
112
128
skipna = skipna ,
113
129
** flox_kwargs ,
114
130
)
0 commit comments