Create an example dataset. Parameters ---------- seed : int, optional Seed for the random number generation.
(*, seed: int | None = None)
| 217 | |
| 218 | |
| 219 | def scatter_example_dataset(*, seed: int | None = None) -> Dataset: |
| 220 | """ |
| 221 | Create an example dataset. |
| 222 | |
| 223 | Parameters |
| 224 | ---------- |
| 225 | seed : int, optional |
| 226 | Seed for the random number generation. |
| 227 | """ |
| 228 | rng = np.random.default_rng(seed) |
| 229 | A = DataArray( |
| 230 | np.zeros([3, 11, 4, 4]), |
| 231 | dims=["x", "y", "z", "w"], |
| 232 | coords={ |
| 233 | "x": np.arange(3), |
| 234 | "y": np.linspace(0, 1, 11), |
| 235 | "z": np.arange(4), |
| 236 | "w": 0.1 * rng.standard_normal(4), |
| 237 | }, |
| 238 | ) |
| 239 | B = 0.1 * A.x**2 + A.y**2.5 + 0.1 * A.z * A.w |
| 240 | A = -0.1 * A.x + A.y / (5 + A.z) + A.w |
| 241 | ds = Dataset({"A": A, "B": B}) |
| 242 | ds["w"] = ["one", "two", "three", "five"] |
| 243 | |
| 244 | ds.x.attrs["units"] = "xunits" |
| 245 | ds.y.attrs["units"] = "yunits" |
| 246 | ds.z.attrs["units"] = "zunits" |
| 247 | ds.w.attrs["units"] = "wunits" |
| 248 | |
| 249 | ds.A.attrs["units"] = "Aunits" |
| 250 | ds.B.attrs["units"] = "Bunits" |
| 251 | |
| 252 | return ds |
| 253 | |
| 254 | |
| 255 | def open_datatree( |