Exemple #1
0
def test_generate_coord():
    s = CoordinateSchema(
        name="zaxis_1",
        dims=["zaxis_1"],
        value=[1.0],
    )
    expected = xr.DataArray(name="zaxis_1", dims=["zaxis_1"], data=[1.0])
    xr.testing.assert_equal(generate(s), expected)
Exemple #2
0
def test_generate_and_pickle_integration():
    x = CoordinateSchema("x", ["x"], np.array([1, 2, 3]))
    a = VariableSchema(
        "a", ["x"],
        ChunkedArray(shape=[3], chunks=[1], dtype=np.dtype("float32")))

    ranges = {"a": Range(0, 10)}

    ds = DatasetSchema(coords={x.name: x}, variables={a.name: a})
    d = generate(ds, ranges)
    pickle.dumps(d)
Exemple #3
0
def data_path(tmpdir):
    schema_path = pathlib.Path(__file__).parent / "data.zarr.json"

    with open(schema_path) as f:
        schema = synth.load(f)

    ranges = {
        "pressure_thickness_of_atmospheric_layer": synth.Range(0.99, 1.01)
    }
    ds = synth.generate(schema, ranges)

    ds.to_zarr(str(tmpdir), consolidated=True)
    return str(tmpdir)
Exemple #4
0
def test_cftime_generate():
    julian_time_attrs = {
        "calendar": "julian",
        "calendar_type": "JULIAN",
        "cartesian_axis": "T",
        "long_name": "time",
        "units": "seconds since 2016-08-01T00:15:00.000026",
    }

    store = {}

    group = zarr.open_group(store, mode="w")
    arr = group.zeros("time", shape=[1], dtype=np.float64)
    arr.attrs.update(julian_time_attrs)
    arr.attrs["_ARRAY_DIMENSIONS"] = ["time"]

    schema = read_schema_from_zarr(group, coords=["time"])
    ds = generate(schema, {})

    assert dict(ds.time.attrs) == dict(julian_time_attrs)
Exemple #5
0
def test_generate_regression(regtest):
    """
    Note:

        regtest fixture provided by pytest-regtest plugin:
        https://pypi.org/project/pytest-regtest/

    """
    x = CoordinateSchema("x", ["x"], np.array([1, 2, 3]))
    a = VariableSchema(
        "a",
        ["x"],
        ChunkedArray(shape=[3], chunks=[1], dtype=np.dtype("float32")),
    )

    ranges = {"a": Range(0, 10)}

    ds = DatasetSchema(coords={x.name: x}, variables={a.name: a})
    d = generate(ds, ranges)
    arr = d.a.values
    print(arr, file=regtest)
Exemple #6
0
def _grid_spec(datadir, nx):
    scaling_factor = 384 / nx
    ranges = {
        "dx":
        synth.Range(20000 * scaling_factor, 28800 * scaling_factor),
        "dy":
        synth.Range(20000 * scaling_factor, 28800 * scaling_factor),
        "area":
        synth.Range(3.6205933e08 * scaling_factor**2,
                    8.3428736e08 * scaling_factor**2),
    }
    path = str(datadir.join("grid_spec.json"))
    with open(path) as f:
        schema = synth.load(f)

    ds = synth.generate(schema, ranges)
    subset = ds.isel(grid_xt=slice(nx),
                     grid_yt=slice(nx),
                     grid_x=slice(nx + 1),
                     grid_y=slice(nx + 1))

    return subset
Exemple #7
0
 def __getitem__(self, key: str) -> xr.Dataset:
     ds = synth.generate(self._schema).drop("initial_time")
     return ds
Exemple #8
0
def open_schema(path_relative_to_file: str) -> xr.Dataset:
    path = Path(__file__)
    abspath = path.parent / path_relative_to_file
    with open(abspath) as f:
        return synth.generate(synth.load(f), ranges)
Exemple #9
0
 def _generate_from_schema(schema: DatasetSchema):
     return {tile: synth.generate(schema, ranges) for tile in tiles}