Convert chunks from Dask Array into an SVG Image Parameters ---------- chunks: tuple size: int Rough size of the image Returns ------- text: An svg string depicting the array as a grid of chunks
(chunks, size=200, **kwargs)
| 11 | |
| 12 | @lru_cache(maxsize=512) |
| 13 | def svg(chunks, size=200, **kwargs): |
| 14 | """Convert chunks from Dask Array into an SVG Image |
| 15 | |
| 16 | Parameters |
| 17 | ---------- |
| 18 | chunks: tuple |
| 19 | size: int |
| 20 | Rough size of the image |
| 21 | |
| 22 | Returns |
| 23 | ------- |
| 24 | text: An svg string depicting the array as a grid of chunks |
| 25 | """ |
| 26 | shape = tuple(map(sum, chunks)) |
| 27 | if np.isnan(shape).any(): # don't support unknown sizes |
| 28 | raise NotImplementedError( |
| 29 | "Can't generate SVG with unknown chunk sizes.\n\n" |
| 30 | " A possible solution is with x.compute_chunk_sizes()" |
| 31 | ) |
| 32 | if not all(shape): |
| 33 | raise NotImplementedError("Can't generate SVG with 0-length dimensions") |
| 34 | if len(chunks) == 0: |
| 35 | raise NotImplementedError("Can't generate SVG with 0 dimensions") |
| 36 | if len(chunks) == 1: |
| 37 | return svg_1d(chunks, size=size, **kwargs) |
| 38 | elif len(chunks) == 2: |
| 39 | return svg_2d(chunks, size=size, **kwargs) |
| 40 | elif len(chunks) == 3: |
| 41 | return svg_3d(chunks, size=size, **kwargs) |
| 42 | else: |
| 43 | return svg_nd(chunks, size=size, **kwargs) |
| 44 | |
| 45 | |
| 46 | text_style = 'font-size="1.0rem" font-weight="100" text-anchor="middle"' |