示例#1
0
def test_tracking_tdating_dating(source, dry_input):
    pytest.importorskip("skimage")
    pandas = pytest.importorskip("pandas")

    if not dry_input:
        input, metadata = get_precipitation_fields(0, 2, True, True, 4000, source)
        input, __ = to_reflectivity(input, metadata)
    else:
        input = np.zeros((3, 50, 50))
        metadata = {"timestamps": ["00", "01", "02"]}

    timelist = metadata["timestamps"]

    output = dating(input, timelist, mintrack=1)

    # Check output format
    assert isinstance(output, tuple)
    assert len(output) == 3
    assert isinstance(output[0], list)
    assert isinstance(output[1], list)
    assert isinstance(output[2], list)
    assert len(output[1]) == input.shape[0]
    assert len(output[2]) == input.shape[0]
    assert isinstance(output[1][0], pandas.DataFrame)
    assert isinstance(output[2][0], np.ndarray)
    assert output[1][0].shape[1] == 8
    assert output[2][0].shape == input.shape[1:]
    if not dry_input:
        assert len(output[0]) > 0
        assert isinstance(output[0][0], pandas.DataFrame)
        assert output[0][0].shape[1] == 8
    else:
        assert len(output[0]) == 0
        assert output[1][0].shape[0] == 0
        assert output[2][0].sum() == 0
示例#2
0
def test_feature_tstorm_detection(source, output_feat, dry_input,
                                  max_num_features):

    pytest.importorskip("skimage")
    pytest.importorskip("pandas")

    if not dry_input:
        input, metadata = get_precipitation_fields(0, 0, True, True, None,
                                                   source)
        input = input.squeeze()
        input, __ = to_reflectivity(input, metadata)
    else:
        input = np.zeros((50, 50))

    time = "000"
    output = detection(input,
                       time=time,
                       output_feat=output_feat,
                       max_num_features=max_num_features)

    if output_feat:
        assert isinstance(output, np.ndarray)
        assert output.ndim == 2
        assert output.shape[1] == 2
        if max_num_features is not None:
            assert output.shape[0] <= max_num_features
    else:
        assert isinstance(output, tuple)
        assert len(output) == 2
        assert isinstance(output[0], DataFrame)
        assert isinstance(output[1], np.ndarray)
        if max_num_features is not None:
            assert output[0].shape[0] <= max_num_features
        assert output[0].shape[1] == 9
        assert list(output[0].columns) == [
            "ID",
            "time",
            "x",
            "y",
            "cen_x",
            "cen_y",
            "max_ref",
            "cont",
            "area",
        ]
        assert (output[0].time == time).all()
        assert output[1].ndim == 2
        assert output[1].shape == input.shape
        if not dry_input:
            assert output[0].shape[0] > 0
            assert sorted(list(output[0].ID)) == sorted(
                list(np.unique(output[1]))[1:])
        else:
            assert output[0].shape[0] == 0
            assert output[1].sum() == 0
示例#3
0
timestep = data_source["timestep"]

# Load the data from the archive
fns = io.archive.find_by_date(date,
                              root_path,
                              path_fmt,
                              fn_pattern,
                              fn_ext,
                              timestep,
                              num_next_files=20)
importer = io.get_method(importer_name, "importer")
R, _, metadata = io.read_timeseries(fns, importer, **importer_kwargs)

# Convert to reflectivity (it is possible to give the a- and b- parameters of the
# Marshall-Palmer relationship here: zr_a = and zr_b =).
Z, metadata = to_reflectivity(R, metadata)

# Extract the list of timestamps
timelist = metadata["timestamps"]

pprint(metadata)

###############################################################################
# Example of thunderstorm identification in a single timestep.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# The function tstorm_detect.detection requires a 2-D input image, all further inputs are
# optional.

input_image = Z[2, :, :].copy()
time = timelist[2]
cells_id, labels = tstorm_detect.detection(