Skip to content

Commit b5cdff4

Browse files
committed
some debug stuff
1 parent 75cfe84 commit b5cdff4

File tree

8 files changed

+58
-19
lines changed

8 files changed

+58
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,4 @@ _build/
186186
?.*
187187
~*
188188
*.sync
189+
*.dot

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ anemoi-datasets = "anemoi.datasets.__main__:main"
9696

9797
[tool.setuptools_scm]
9898
version_file = "src/anemoi/datasets/_version.py"
99+
100+
[tool.setuptools.package-data]
101+
"anemoi.datasets.data" = ["*.css"]

src/anemoi/datasets/data/dataset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,7 @@ def _check(ds):
222222

223223
def _repr_html_(self):
224224
return self.tree().html()
225+
226+
@property
227+
def label(self):
228+
return self.__class__.__name__.lower()

src/anemoi/datasets/data/debug.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
table.dataset td {
2+
vertical-align: top;
3+
text-align: left !important;
4+
}
5+
6+
table.dataset span.dataset {
7+
font-weight: bold !important;
8+
}
9+
10+
table.dataset span.values {
11+
font-style: italic !important;
12+
}

src/anemoi/datasets/data/debug.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
# a.flags.writeable = False
2222

2323

24+
def css(name):
25+
path = os.path.join(os.path.dirname(__file__), f"{name}.css")
26+
with open(path) as f:
27+
return f"<style>{f.read()}</style>"
28+
29+
2430
class Node:
2531
def __init__(self, dataset, kids, **kwargs):
2632
self.dataset = dataset
@@ -46,7 +52,7 @@ def __repr__(self):
4652
return "\n".join(result)
4753

4854
def graph(self, digraph, nodes):
49-
label = self.dataset.__class__.__name__.lower()
55+
label = self.dataset.label # dataset.__class__.__name__.lower()
5056
if self.kwargs:
5157
param = []
5258
for k, v in self.kwargs.items():
@@ -107,7 +113,7 @@ def _html(self, indent, rows):
107113
if k == "path":
108114
v = v[::-1]
109115
kwargs[k] = v
110-
label = self.dataset.__class__.__name__.lower()
116+
label = self.dataset.label
111117
label = f'<span class="dataset">{label}</span>'
112118
if len(kwargs) == 1:
113119
k, v = list(kwargs.items())[0]
@@ -116,25 +122,14 @@ def _html(self, indent, rows):
116122
rows.append([indent] + [label])
117123

118124
for k, v in kwargs.items():
119-
rows.append([indent] + [k, v])
125+
rows.append([indent] + [f"<span class='param'>{k}</span>", f"<span class='param'>{v}</span>"])
120126

121127
for kid in self.kids:
122128
kid._html(indent + "&nbsp;&nbsp;&nbsp;", rows)
123129

124130
def html(self):
125-
result = [
126-
"""
127-
<style>
128-
table.dataset td {
129-
vertical-align: top;
130-
text-align: left !important;
131-
}
132-
span.dataset {
133-
font-weight: bold !important;
134-
}
135-
</style>
136-
"""
137-
]
131+
result = [css("debug")]
132+
138133
result.append('<table class="dataset">')
139134
rows = []
140135

@@ -147,6 +142,26 @@ def html(self):
147142
result.append("</table>")
148143
return "\n".join(result)
149144

145+
def _as_tree(self, tree):
146+
147+
for kid in self.kids:
148+
n = tree.node(kid)
149+
kid._as_tree(n)
150+
151+
def as_tree(self):
152+
from anemoi.utils.text import Tree
153+
154+
tree = Tree(self)
155+
self._as_tree(tree)
156+
return tree
157+
158+
@property
159+
def summary(self):
160+
return self.dataset.label
161+
162+
def as_dict(self):
163+
return {}
164+
150165

151166
class Source:
152167
"""Class used to follow the provenance of a data point."""

src/anemoi/datasets/data/grids.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def tree(self):
127127
return Node(self, [d.tree() for d in self.datasets], mode="concat")
128128

129129

130-
class CutoutGrids(Grids):
130+
class Cutout(Grids):
131131
def __init__(self, datasets, axis):
132132
from anemoi.datasets.grids import cutout_mask
133133

@@ -236,4 +236,4 @@ def cutout_factory(args, kwargs):
236236
datasets = [_open(e) for e in cutout]
237237
datasets, kwargs = _auto_adjust(datasets, kwargs)
238238

239-
return CutoutGrids(datasets, axis=axis)._subset(**kwargs)
239+
return Cutout(datasets, axis=axis)._subset(**kwargs)

src/anemoi/datasets/data/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _open(a):
237237
if isinstance(a, (list, tuple)):
238238
return _open_dataset(*a)
239239

240-
raise NotImplementedError("Unsupported argument: " + type(a))
240+
raise NotImplementedError(f"Unsupported argument: {type(a)}")
241241

242242

243243
def _auto_adjust(datasets, kwargs):

src/anemoi/datasets/data/stores.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ def _report_missing(self, n):
328328
def tree(self):
329329
return Node(self, [], path=self.path, missing=sorted(self.missing))
330330

331+
@property
332+
def label(self):
333+
return "zarr*"
334+
331335

332336
def zarr_lookup(name):
333337

0 commit comments

Comments
 (0)