Skip to content

Commit 719a780

Browse files
committed
Update: Gaussian filter (FWHM)
1 parent 27f8f30 commit 719a780

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ will print a detailed usage message to the screen:
9191
specify the engine used to write the target product
9292
file. (default: None)
9393
--gaussian-filter {0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0}
94-
specify the standard deviation (pixels) of a lateral
95-
Gaussian filter applied to the forecast. If not
96-
specified no filter is applied. (default: None)
94+
specify the full width at half maximum (pixels) of
95+
a lateral Gaussian filter applied to the forecast.
96+
If not specified no filter is applied. (default:
97+
None)
9798
--horizon {1,2,3,4,5,6,7}
9899
specify the forecast horizon (days). (default: None)
99100
--log-level {debug,info,warning,error,off}

wqf/algorithms/gaussian.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ class Gaussian(Algorithm):
2222
"""
2323

2424
@override
25-
def apply_to(self, cube: da.Array, *, sigma: Number = 1.0) -> da.Array:
25+
def apply_to(self, cube: da.Array, *, fwhm: Number = 1.0) -> da.Array:
2626
"""
2727
Applies a lateral Gaussian filter to a data cube.
2828
2929
:param cube: The data cube.
30-
:param sigma: The standard deviation of the Gaussian kernel (pixels).
30+
:param fwhm: The full width at half maximum of the Gaussian
31+
kernel (pixels).
3132
:return: The filtered data cube.
3233
"""
34+
# noinspection PyTypeChecker
35+
sigma = fwhm / 2.35482
3336
m = da.isnan(cube)
3437
v = da.where(m, 0.0, cube)
3538
w = da.where(m, 0.0, 1.0)

wqf/operators/forecastop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(self, source: Dataset) -> Dataset: # noqa: D102
6767
array = f.apply_to(*feats, names=names)
6868
if self._args.gaussian_filter is not None:
6969
g = Gaussian(array.dtype)
70-
array = g.apply_to(array, sigma=self._args.gaussian_filter)
70+
array = g.apply_to(array, fwhm=self._args.gaussian_filter)
7171

7272
builder = DatasetBuilder()
7373
for name, value in sorted(

wqf/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def _add_options(parser):
115115
)
116116
parser.add_argument(
117117
"--gaussian-filter",
118-
help="specify the standard deviation (pixels) of a lateral "
119-
"Gaussian filter applied to the forecast. If not specified "
120-
"no filter is applied.",
118+
help="specify the full width at half maximum (pixels) of "
119+
"a lateral Gaussian filter applied to the forecast. "
120+
"If not specified no filter is applied.",
121121
choices=[0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0],
122122
type=float,
123123
required=False,

wqf/val/mov.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def plot_analysis(chl: DataArray, period: Period):
3838
continue
3939
ScenePlot().plot(
4040
chl[t],
41-
title=f"Analysis {time}",
41+
title=f"(Re)analysis {time}",
4242
fn=file,
4343
cbar_label=r"chlorophyll concentration (mg m$^{-3}$)",
4444
norm=plc.SymLogNorm(1.0, linscale=0.1, vmin=0.0, vmax=100.0),
@@ -49,14 +49,14 @@ def plot_analysis(chl: DataArray, period: Period):
4949

5050

5151
def plot_forecast(
52-
chl: DataArray, period: Period, sigma: Number | None, h: int
52+
chl: DataArray, period: Period, fwhm: Number | None, h: int
5353
):
5454
chl = period.slice(chl)
5555

56-
if sigma is not None:
56+
if fwhm is not None:
5757
g = Gaussian(chl.dtype)
5858
chl = DataArray(
59-
data=g.apply_to(chl.data, sigma=sigma),
59+
data=g.apply_to(chl.data, fwhm=fwhm),
6060
coords=chl.coords,
6161
dims=chl.dims,
6262
attrs=chl.attrs,
@@ -79,13 +79,13 @@ def plot_forecast(
7979
)
8080

8181

82-
def plot_observed(chl: DataArray, period: Period, sigma: Number | None):
82+
def plot_observed(chl: DataArray, period: Period, fwhm: Number | None):
8383
chl = period.slice(chl)
8484

85-
if sigma is not None:
85+
if fwhm is not None:
8686
g = Gaussian(chl.dtype)
8787
chl = DataArray(
88-
data=g.apply_to(chl.data, sigma=sigma),
88+
data=g.apply_to(chl.data, fwhm=fwhm),
8989
coords=chl.coords,
9090
dims=chl.dims,
9191
attrs=chl.attrs,
@@ -114,7 +114,7 @@ def generate_figures(args):
114114

115115
obs = reader.read(args.cube_id, depth_level=3.0)
116116
ref, pre = XGB(args).predict(obs)
117-
plot_observed(ref, period=period, sigma=args.sigma)
117+
plot_observed(ref, period=period, fwhm=args.fwhm)
118118
pre.close()
119119
ref.close()
120120
obs.close()
@@ -130,7 +130,7 @@ def generate_figures(args):
130130
for h in [1, 2, 3, 4, 5, 6, 7]:
131131
obs = reader.read(args.cube_id, depth_level=3.0)
132132
ref, pre = XGB(args).predict(obs, h=h)
133-
plot_forecast(pre, period=period, sigma=args.sigma, h=h)
133+
plot_forecast(pre, period=period, fwhm=args.fwhm, h=h)
134134
pre.close()
135135
ref.close()
136136
obs.close()
@@ -157,29 +157,29 @@ def generate_figures(args):
157157
)
158158
parser.add_argument(
159159
"--analysis",
160-
help="plot BGCM analysis",
160+
help="plot BGCM (re)analysis",
161161
action="store_true",
162162
default=True,
163163
required=False,
164164
dest="analysis",
165165
)
166166
parser.add_argument(
167167
"--no-analysis",
168-
help="do not plot BGCM analysis",
168+
help="do not plot BGCM (re)analysis",
169169
action="store_false",
170170
default=False,
171171
required=False,
172172
dest="analysis",
173173
)
174174
parser.add_argument(
175175
"--gaussian-filter",
176-
help="specify the standard deviation (pixels) of a lateral "
177-
"Gaussian filter applied to the forecast. If not specified "
178-
"no filter is applied.",
176+
help="specify the full width at half maximum (pixels) of "
177+
"a lateral Gaussian filter applied to the forecast. "
178+
"If not specified no filter is applied.",
179179
choices=[0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0],
180180
type=float,
181181
required=False,
182-
dest="sigma",
182+
dest="fwhm",
183183
)
184184
parser.add_argument(
185185
"--period-start",

0 commit comments

Comments
 (0)