Skip to content

Commit a24c782

Browse files
committed
Update: filter configuration
1 parent 54a8ad2 commit a24c782

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

kaleidoscope/config/config.collect.json

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,65 @@
77
"dic": {
88
"attrs": {
99
"long_name": "standard uncertainty of Dissolved Inorganic Carbon in seawater"
10+
},
11+
"filter": {
12+
"kind": "Gaussian",
13+
"fwhm": 1.0
1014
}
1115
},
1216
"DOC": {
1317
"attrs": {
1418
"long_name": "standard uncertainty of estimated DOC"
1519
},
16-
"filter": true
20+
"filter": {
21+
"kind": "Gaussian",
22+
"fwhm": 4.0
23+
}
1724
},
1825
"PIC": {
1926
"attrs": {
2027
"long_name": "standard uncertainty of PIC"
2128
},
22-
"filter": true
29+
"filter": {
30+
"kind": "Gaussian",
31+
"fwhm": 4.0
32+
}
2333
},
2434
"POC": {
2535
"attrs": {
2636
"long_name": "standard uncertainty of POC"
2737
},
28-
"filter": true
38+
"filter": {
39+
"kind": "Gaussian",
40+
"fwhm": 4.0
41+
}
2942
},
3043
"pc": {
3144
"attrs": {
3245
"long_name": "standard uncertainty of Phytoplankton Carbon concentration in seawater"
3346
},
34-
"filter": true
47+
"filter": {
48+
"kind": "Gaussian",
49+
"fwhm": 4.0
50+
}
3551
},
3652
"pp": {
3753
"attrs": {
3854
"long_name": "standard uncertainty of Phytoplankton Primary Production"
3955
},
40-
"filter": true
56+
"filter": {
57+
"kind": "Gaussian",
58+
"fwhm": 4.0
59+
}
4160
},
4261
"Predicted_DOC": {
4362
"attrs": {
4463
"long_name": "standard uncertainty of Predicted Dissolved Organic Carbon",
4564
"description": "standard uncertainty of Predicted DOC values"
4665
},
47-
"filter": true
66+
"filter": {
67+
"kind": "Gaussian",
68+
"fwhm": 4.0
69+
}
4870
}
4971
}

kaleidoscope/config/config.writer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"time": 12,
2020
"latitude": 0,
2121
"longitude": 0,
22-
"depth": 0
22+
"depth": 13
2323
},
2424
"esa-scope-doc": {
2525
"lat": 720,

kaleidoscope/operators/collectop.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@
2222
from ..logger import get_logger
2323

2424

25-
def _filter(x: da.Array, dims: tuple) -> da.Array:
25+
def _filter(x: da.Array, dims: tuple, filter_config: dict) -> da.Array:
2626
"""
2727
Applies a lateral low pass filter to suppress statistical
2828
fluctuations caused by finite sampling of error probability
2929
density functions.
3030
"""
3131
return Gaussian(dtype=x.dtype, m=x.ndim, n=x.ndim).apply_to(
32-
x, dims=dims, fwhm=4.0
32+
x, dims=dims, fwhm=filter_config.get("fwhm", 1.0)
3333
)
3434

3535

36-
def _std(x: da.Array, dims: tuple, filtered: bool = False) -> da.Array:
36+
def _std(
37+
x: da.Array,
38+
dims: tuple,
39+
filtered: bool = False,
40+
filter_config: dict | None = None,
41+
) -> da.Array:
3742
"""
3843
Returns the standard deviation of simulated errors.
3944
@@ -44,7 +49,7 @@ def _std(x: da.Array, dims: tuple, filtered: bool = False) -> da.Array:
4449
Monte Carlo method.
4550
"""
4651
return da.sqrt(
47-
_filter(_mse(x[1:] - x[:1]), dims)
52+
_filter(_mse(x[1:] - x[:1]), dims, filter_config)
4853
if filtered
4954
else _mse(x[1:] - x[:1])
5055
)
@@ -110,7 +115,7 @@ def run(self, source: Dataset) -> Dataset: # noqa: D102
110115
if v not in config:
111116
continue
112117
self.add_uncertainty(target, source, v, x)
113-
if config[v].get("filter", False):
118+
if config[v].get("filter", {}):
114119
self.add_uncertainty(target, source, v, x, filtered=True)
115120
return target
116121

@@ -131,7 +136,12 @@ def add_uncertainty(self, target, source, v, x, filtered: bool = False):
131136
if v_unc in target:
132137
return
133138
get_logger().info(f"starting graph for variable: {v_unc}")
134-
x_unc = _std(decode(source[v].data, x.attrs), x.dims, filtered)
139+
x_unc = _std(
140+
decode(source[v].data, x.attrs),
141+
x.dims,
142+
filtered,
143+
config[v].get("filter", {}),
144+
)
135145
get_logger().info(f"finished graph for variable: {v_unc}")
136146
target[v_unc] = DataArray(
137147
data=encode(x_unc, x.attrs, x.dtype),

0 commit comments

Comments
 (0)