Skip to content

Commit d72e27e

Browse files
committed
Update: seeding
1 parent a6f6904 commit d72e27e

File tree

6 files changed

+83
-14
lines changed

6 files changed

+83
-14
lines changed

bin/kaleidoscope-esa-cci-oc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) Brockmann Consult GmbH, 2025
4+
# License: MIT
5+
#
6+
set -e
7+
## Produces Monte Carlo variants of the ESA CCI Ocean Colour product.
8+
#
9+
# ./kaleidoscope-esa-cci-oc <file>
10+
#
11+
for selector in 001 002 003 004 005 006 007 008 009 010; do
12+
echo "$(tput setaf 2)$(date -u "+%Y-%m-%dT%H:%M:%S") [INFO] Selector ${selector} ...$(tput sgr0)"
13+
kaleidoscope \
14+
--selector ${selector} \
15+
--product-type esa-cci-oc \
16+
--log-level warning \
17+
--progress \
18+
"${1}" \
19+
"${1%.nc}"."${selector}".nc
20+
done

bin/kaleidoscope-esa-scope-ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ set -e
88
#
99
# ./kaleidoscope-esa-scope-ex
1010
#
11-
for selector in 003 005 007 011 013 017 019 023 029 031; do
11+
for selector in 001 002 003 004 005 006 007 008 009 010; do
1212
echo "$(tput setaf 2)$(date -u "+%Y-%m-%dT%H:%M:%S") [INFO] Selector ${selector} ...$(tput sgr0)"
1313
kaleidoscope \
1414
--selector ${selector} \
1515
--product-type esa-scope-exchange \
16-
--log-level off \
16+
--log-level warning \
1717
--progress \
1818
Ford_et_al_UExP-FNN-U_physics_carbonatesystem_ESASCOPE_v5.nc \
1919
Ford_et_al_UExP-FNN-U_physics_carbonatesystem_ESASCOPE_v5.${selector}.nc

bin/kaleidoscope-ghrsst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) Brockmann Consult GmbH, 2025
4+
# License: MIT
5+
#
6+
set -e
7+
## Produces Monte Carlo variants of the GHRSST product.
8+
#
9+
# ./kaleidoscope-ghrsst <file>
10+
#
11+
for selector in 001 002 003 004 005 006 007 008 009 010; do
12+
echo "$(tput setaf 2)$(date -u "+%Y-%m-%dT%H:%M:%S") [INFO] Selector ${selector} ...$(tput sgr0)"
13+
kaleidoscope \
14+
--selector ${selector} \
15+
--product-type ghrsst \
16+
--log-level warning \
17+
--progress \
18+
"${1}" \
19+
"${1%.nc}"."${selector}".nc
20+
done

bin/kaleidoscope-glorys

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) Brockmann Consult GmbH, 2025
4+
# License: MIT
5+
#
6+
set -e
7+
## Produces Monte Carlo variants of the GLORYS product.
8+
#
9+
# ./kaleidoscope-glorys <file>
10+
#
11+
for selector in 001 002 003 004 005 006 007 008 009 010; do
12+
echo "$(tput setaf 2)$(date -u "+%Y-%m-%dT%H:%M:%S") [INFO] Selector ${selector} ...$(tput sgr0)"
13+
kaleidoscope \
14+
--selector ${selector} \
15+
--product-type esa-cci-oc \
16+
--log-level warning \
17+
--progress \
18+
"${1}" \
19+
"${1%.nc}"."${selector}".nc
20+
done

kaleidoscope/algorithms/randomize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class Randomize(InformedBlockAlgorithm):
7676

7777
def __init__(
7878
self,
79-
dtype: np.dtype,
80-
m: int,
79+
dtype: np.dtype = np.single,
80+
m: int = 2,
8181
dist: Literal["normal", "lognormal", "chlorophyll"] | str = "normal",
8282
entropy: int | list[int] | None = None,
8383
):

kaleidoscope/operators/randomizeop.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ..algorithms.codec import Decode
1919
from ..algorithms.codec import Encode
2020
from ..algorithms.randomize import Randomize
21+
from ..generators import DefaultGenerator
2122
from ..interface.logging import Logging
2223
from ..interface.operator import Operator
2324
from ..logger import get_logger
@@ -90,6 +91,10 @@ def run(self, source: Dataset) -> Dataset: # noqa: D102
9091
:param source: The source dataset.
9192
:return: The result dataset.
9293
"""
94+
source_id = source.attrs.get(
95+
"tracking_id",
96+
source.attrs.get("uuid", self._args.source_file.stem),
97+
)
9398
target = Dataset(
9499
data_vars=source.data_vars,
95100
coords=source.coords,
@@ -106,10 +111,9 @@ def run(self, source: Dataset) -> Dataset: # noqa: D102
106111

107112
a: dict[str:Any] = config[v]
108113
f = Randomize(
109-
np.single,
110-
x.ndim,
114+
m=x.ndim,
111115
dist=a["distribution"],
112-
entropy=self.entropy(v),
116+
entropy=self.entropy(v, source_id),
113117
)
114118
if "uncertainty" in a:
115119
u = (
@@ -179,15 +183,20 @@ def config(self) -> dict[str : dict[str:Any]]:
179183
config = json.load(r)
180184
return config
181185

182-
def entropy(self, v: str) -> list[int]:
186+
def entropy(self, vid: str, did: str, n: int = 8) -> list[int]:
183187
"""
184188
Returns the entropy of the seed sequence used for a given variable.
185189
186-
:param v: The name of the variable.
190+
Entropy is generated using the Philox bit generator, which produces
191+
truly independent sequences for different values of the seed.
192+
193+
:param vid: The variable ID.
194+
:param did: The dataset ID.
195+
:param n: The length of the seed sequence.
187196
:return: The entropy.
188197
"""
189-
return [
190-
self._args.selector,
191-
_hash(v),
192-
_hash(self._args.source_file.stem),
193-
]
198+
from numpy.random import Philox
199+
200+
seed = _hash(f"{vid}-{did}") + self._args.selector
201+
g = DefaultGenerator(Philox(seed))
202+
return [g.next() for _ in range(n)]

0 commit comments

Comments
 (0)