Пример #1
0
def test_collapse_multiscene():
    """Test collapsing a multiscene."""
    from sattools.scutil import collapse_abi_glm_multiscene
    cont_part = {"flash_extent_density": numpy.arange(6 * 6).reshape(6, 6)}
    cont_full = cont_part.copy()
    cont_full["strawberry"] = numpy.arange(6 * 6).reshape(6, 6)
    in_ = satpy.MultiScene([
        satpy.tests.utils.make_fake_scene(cont_full if i %
                                          3 == 0 else cont_part)
        for i in range(6)
    ])
    for sc in in_.scenes:
        sc["flash_extent_density"].attrs["sensor"] = "glm"
        if "strawberry" in sc:
            sc["strawberry"].attrs["sensor"] = "abi"
    ref = satpy.MultiScene([
        satpy.tests.utils.make_fake_scene({
            "flash_extent_density":
            cont_part["flash_extent_density"],
            "strawberry":
            3 * cont_full["strawberry"]
        }) for i in range(2)
    ])
    out = collapse_abi_glm_multiscene(in_)
    # cannot directly compare multiscene or scene, see
    # https://github.com/pytroll/satpy/issues/1583
    assert len(out.scenes) == len(ref.scenes)
    for (outscene, refscene) in zip(out.scenes, ref.scenes):
        assert (outscene.to_xarray_dataset() == refscene.to_xarray_dataset()
                ).all()
Пример #2
0
def fake_multiscene2():
    """Like fake_multiscene, but with real areas (one stacked)."""
    from satpy.dataset.dataid import WavelengthRange
    from satpy.tests.utils import make_dataid
    common_attrs = {
        "start_time": datetime.datetime(1900, 1, 1, 0, 0),
        "end_time": datetime.datetime(1900, 1, 1, 0, 1)
    }
    wl = {
        "C08": WavelengthRange(5.7, 6.2, 6.7),
        "C10": WavelengthRange(6.8, 7.3, 7.8),
        "C14": WavelengthRange(10, 11, 12)
    }
    content = {
        make_dataid(name=x, wavelength=wl.get(x)):
        numpy.arange(5 * 5).reshape(5, 5)
        for x in ("C08", "C10", "C14", "C14_flash_extent_density")
    }
    sc1 = satpy.tests.utils.make_fake_scene(content.copy(),
                                            common_attrs=common_attrs)
    sc2 = satpy.tests.utils.make_fake_scene(content.copy(),
                                            common_attrs=common_attrs)
    sc3 = satpy.tests.utils.make_fake_scene(
        {k: numpy.concatenate([v, v], 0)
         for (k, v) in content.items()},
        area=pyresample.geometry.StackedAreaDefinition(
            sc1["C14"].attrs["area"], sc2["C14"].attrs["area"]),
        common_attrs=common_attrs)
    return satpy.MultiScene([sc1, sc2, sc3])
Пример #3
0
def fake_multiscene3(fake_multiscene2):
    """Like fake_multiscene2, but with real areas (none stacked)."""
    fms = satpy.MultiScene(copy.deepcopy(fake_multiscene2.scenes))
    for k in fms.scenes[2].keys():
        fms.scenes[2][k].attrs["area"] = fake_multiscene2.scenes[0][k].\
                attrs["area"]
    return fms
Пример #4
0
def fake_multiscene4():
    """Like fake_multiscene2, but with varying areas (none stacked)."""
    from satpy.dataset.dataid import WavelengthRange
    from satpy.tests.utils import make_dataid
    common_attrs = {}
    wl = {
        "C08": WavelengthRange(5.7, 6.2, 6.7),
        "C10": WavelengthRange(6.8, 7.3, 7.8),
        "C14": WavelengthRange(10, 11, 12)
    }
    content = {
        make_dataid(name=x, wavelength=wl.get(x)):
        numpy.arange(5 * 5).reshape(5, 5)
        for x in ("C08", "C10", "C14")
    }
    content[make_dataid(
        name="flash_extent_density")] = numpy.arange(5 * 5).reshape(5, 5) + 1
    areas = [
        pyresample.create_area_def("test-area", {
            "proj": "eqc",
            "lat_ts": 0,
            "lat_0": 0,
            "lon_0": 0,
            "x_0": 0,
            "y_0": 0,
            "ellps": "sphere",
            "units": "m",
            "no_defs": None,
            "type": "crs"
        },
                                   units="m",
                                   shape=(5, 5),
                                   resolution=1000,
                                   center=(10 * i, 20 * i)) for i in range(3)
    ]

    aids = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
    scenes = [
        satpy.tests.utils.make_fake_scene(content.copy(),
                                          common_attrs=common_attrs,
                                          area=areas[i]) for i in aids
    ]
    for (i, sc) in enumerate(scenes):
        for da in sc.values():
            da.attrs["start_time"] = datetime.datetime(1900, 1, 1, 0, i)
            da.attrs["end_time"] = datetime.datetime(1900, 1, 1, 0, i + 1)
    return satpy.MultiScene(scenes)
Пример #5
0
def split_meso(ms):
    """Split a meso-multiscene into smaller multiscenes.

    Split a multiscene where the scenes have MESO areas that vary into smaller
    subset multiscenes where the MESO area is constant.

    Assumes this happens at the same scene for all channels.
    """
    # NB: https://github.com/pytroll/satpy/issues/1419
    ch = next(iter(ms.first_scene.keys()))
    ref = ms.first_scene[ch].attrs["area"]
    prev = 0
    for (i, sc) in enumerate(ms.scenes):
        if (newref := sc[ch].attrs["area"]) != ref:
            yield satpy.MultiScene(ms.scenes[prev:i])
            ref = newref
            prev = i
Пример #6
0
def fake_multiscene():
    """Get a fake satpy MultiScene."""
    sc1 = satpy.tests.utils.make_fake_scene({
        "rasberry":
        numpy.arange(5 * 5).reshape(5, 5),
        "straberry":
        numpy.arange(5 * 5).reshape(5, 5)
    })
    sc2 = satpy.tests.utils.make_fake_scene({
        "rasberry":
        numpy.arange(6 * 6).reshape(6, 6),
        "straberry":
        numpy.arange(6 * 6).reshape(6, 6)
    })
    sc3 = satpy.tests.utils.make_fake_scene(
        {
            "rasberry": numpy.arange(5 * 5).reshape(5, 5),
            "straberry": numpy.arange(5 * 5).reshape(5, 5)
        },
        area=pyresample.geometry.StackedAreaDefinition(
            sc1["rasberry"].attrs["area"], sc2["rasberry"].attrs["area"]))
    sc2["no-area"] = xarray.DataArray(numpy.arange(5))
    return satpy.MultiScene([sc1, sc2, sc3])
Пример #7
0
def fake_multiscene_empty():
    """Fake multiscene with empty scenes."""
    return satpy.MultiScene([satpy.Scene() for _ in range(3)])
Пример #8
0
        path=f"noaa-goes16/ABI-L1b-Rad{sector[0]:s}/"
        "{year}/{doy}/{hour}/"
        f"OR_ABI-L1b-Rad{sector:s}-M6C*_G16_"
        "s{year}{doy}{hour}{minute}{second}*_e{end_year}{end_doy}"
        "{end_hour}{end_minute}{end_second}*_c*.nc",
        name="abi",
        fs=fs_s3)
    files = list(fi for fi in abi_fileset.find(start_date, end_date)
                 if any(f"C{c:>02d}_" in fi.path for c in chans))
    return [satpy.readers.FSFile(fi.path, fs=fs_block) for fi in files]


def split_meso(ms):
    """Split a meso-multiscene into smaller multiscenes.

    Split a multiscene where the scenes have MESO areas that vary into smaller
    subset multiscenes where the MESO area is constant.

    Assumes this happens at the same scene for all channels.
    """
    # NB: https://github.com/pytroll/satpy/issues/1419
    ch = next(iter(ms.first_scene.keys()))
    ref = ms.first_scene[ch].attrs["area"]
    prev = 0
    for (i, sc) in enumerate(ms.scenes):
        if (newref := sc[ch].attrs["area"]) != ref:
            yield satpy.MultiScene(ms.scenes[prev:i])
            ref = newref
            prev = i
    yield satpy.MultiScene(ms.scenes[prev:])
Пример #9
0
    scenes = []
    glm = {}
    abi_cont = {}
    for old in ms.scenes:
        for did in sorted(old.keys()):
            if (sens := old[did].attrs["sensor"]) == "glm":
                if did["name"] == "flash_extent_density":
                    if did not in glm:
                        glm[did] = []
                    glm[did].append(old[did])
                else:
                    raise ValueError("For GLM I can only handle "
                                     f"flash_extent_density, not {did!s}")
            elif sens == "abi":
                abi_cont[did] = old[did]
            else:
                raise ValueError("I can only handle GLM and ABI, but I got "
                                 f"{sens!s}")
        # gone through all in the scene now...
        # if I had new ABI, then make new scene collecting GLM...
        if abi_cont:
            sc = satpy.Scene()
            for (did, val) in abi_cont.items():
                sc[did] = val
            for (did, vals) in glm.items():
                sc[did] = xarray.concat(vals, "dummy").mean("dummy")
            scenes.append(sc)
            glm.clear()
            abi_cont.clear()
    return satpy.MultiScene(scenes)