Пример #1
0
    def setup(self):
        data = mss_wms_settings.data["ecmwf_EUR_LL015"]
        data.setup()

        self.bbox = [-22.5, 27.5, 55, 62.5]

        self.init_time = datetime(2012, 10, 17, 12)
        self.valid_time = datetime(2012, 10, 17, 12)
        self.hsec = HorizontalSectionDriver(data)
Пример #2
0
class Test_HSec(object):
    def setup(self):
        data = mss_wms_settings.data["ecmwf_EUR_LL015"]
        data.setup()

        self.bbox = [-22.5, 27.5, 55, 62.5]

        self.init_time = datetime(2012, 10, 17, 12)
        self.valid_time = datetime(2012, 10, 17, 12)
        self.hsec = HorizontalSectionDriver(data)

    def plot(self,
             plot_object,
             style="default",
             level=None,
             crs="EPSG:4326",
             bbox=None):
        if bbox is None:
            bbox = self.bbox
        self.hsec.set_plot_parameters(plot_object=plot_object,
                                      bbox=bbox,
                                      level=level,
                                      crs=crs,
                                      init_time=self.init_time,
                                      valid_time=self.valid_time,
                                      style=style,
                                      noframe=False,
                                      show=False)
        return self.hsec.plot()

    @pytest.mark.parametrize("crs", [
        "EPSG:4326", "EPSG:77890010", "EPSG:77790010", "MSS:stere,20,40,40",
        "MSS:lcc,20,0,40,20", "MSS:cass,20,40", "MSS:merc,40"
    ])
    def test_degree_crs_codes(self, crs):
        img = self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec),
                        crs=crs)
        assert img is not None

    @pytest.mark.parametrize(
        "crs", ["EPSG:3031", "EPSG:3857", "EPSG:3413", "EPSG:3995"])
    def test_meter_crs_codes(self, crs):
        bbox_meter = [-1e7, -1e7, 1e7, 1e7]
        img = self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec),
                        crs=crs,
                        bbox=bbox_meter)
        assert img is not None

    @pytest.mark.parametrize("crs", ["EPSG:12345678", "FNORD", "MSS:lagranto"])
    def test_invalid_crs_codes(self, crs):
        with pytest.raises(ValueError):
            self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec),
                      crs=crs)

    def test_repeated_locations(self):
        p1 = [45.00, 8.]
        p2 = [50.00, 12.]
        self.path = [p1, p1]
        img = self.plot(
            mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec),
            level=10)
        assert img is not None
        self.path = [p1, p1, p2]
        img = self.plot(
            mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec),
            level=10)
        assert img is not None
        self.path = [p1, p2, p2]
        img = self.plot(
            mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec),
            level=10)
        assert img is not None

    def test_HS_CloudsStyle_01(self):
        for style in ["TOT", "HIGH", "MED", "LOW"]:
            img = self.plot(
                mpl_hsec_styles.HS_CloudsStyle_01(driver=self.hsec),
                style=style)
        assert img is not None

    def test_HS_MSLPStyle_01(self):
        img = self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec))
        assert img is not None

    def test_HS_SEAStyle_01(self):
        img = self.plot(mpl_hsec_styles.HS_SEAStyle_01(driver=self.hsec))
        assert img is not None

    @pytest.mark.parametrize("style", ["PCOL", "CONT"])
    def test_HS_SeaIceStyle_01(self, style):
        img = self.plot(mpl_hsec_styles.HS_SeaIceStyle_01(driver=self.hsec),
                        style=style)
        assert img is not None

    def test_HS_TemperatureStyle_ML_01(self):
        img = self.plot(
            mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec),
            level=10)
        assert img is not None

    def test_HS_TemperatureStyle_PL_01(self):
        img = self.plot(
            mpl_hsec_styles.HS_TemperatureStyle_PL_01(driver=self.hsec),
            level=800)
        assert img is not None

    def test_HS_GeopotentialWindStyle_PL(self):
        img = self.plot(
            mpl_hsec_styles.HS_GeopotentialWindStyle_PL(driver=self.hsec),
            level=300)
        assert img is not None

    @pytest.mark.parametrize(
        "style", ["default", "nonlinear", "auto", "log", "autolog"])
    def test_HS_GenericStyle_styles(self, style):
        img = self.plot(
            mpl_hsec_styles.HS_GenericStyle_PL_mole_fraction_of_ozone_in_air(
                driver=self.hsec),
            level=300,
            style=style)
        assert img is not None

    def test_HS_GenericStyle_other(self):
        img = self.plot(
            mpl_hsec_styles.HS_GenericStyle_TL_mole_fraction_of_ozone_in_air(
                driver=self.hsec),
            level=300)
        assert img is not None

        img = self.plot(
            mpl_hsec_styles.HS_GenericStyle_PL_ertel_potential_vorticity(
                driver=self.hsec),
            style="ertel_potential_vorticity",
            level=300)
        assert img is not None

        img = self.plot(mpl_hsec_styles.HS_GenericStyle_PL_equivalent_latitude(
            driver=self.hsec),
                        style="equivalent_latitude",
                        level=300)
        assert img is not None

    def test_HS_RelativeHumidityStyle_PL_01(self):
        img = self.plot(
            mpl_hsec_styles.HS_RelativeHumidityStyle_PL_01(driver=self.hsec),
            level=300)
        assert img is not None

    def test_HS_EQPTStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_EQPTStyle_PL_01(driver=self.hsec),
                        level=300)
        assert img is not None

    def test_HS_WStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_WStyle_PL_01(driver=self.hsec),
                        level=300)
        assert img is not None

    def test_HS_DivStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_DivStyle_PL_01(driver=self.hsec),
                        level=300)
        assert img is not None

    def test_HS_EMAC_TracerStyle_ML_01(self):
        img = self.plot(
            mpl_hsec_styles.HS_EMAC_TracerStyle_ML_01(driver=self.hsec),
            level=10)
        assert img is not None

    def test_HS_EMAC_TracerStyle_SFC_01(self):
        img = self.plot(
            mpl_hsec_styles.HS_EMAC_TracerStyle_SFC_01(driver=self.hsec))
        assert img is not None

    def test_HS_PVTropoStyle_PV_01(self):
        # test fractional levels and non-existing levels
        img = self.plot(
            mpl_hsec_styles.HS_PVTropoStyle_PV_01(driver=self.hsec), level=2.5)
        assert img is not None
        with pytest.raises(ValueError):
            self.plot(mpl_hsec_styles.HS_PVTropoStyle_PV_01(driver=self.hsec),
                      level=2.75)

    def test_HS_VIProbWCB_Style_01(self):
        img = self.plot(
            mpl_hsec_styles.HS_VIProbWCB_Style_01(driver=self.hsec))
        assert img is not None

    def test_HS_LagrantoTrajStyle_PL_01(self):
        img = self.plot(
            mpl_hsec_styles.HS_LagrantoTrajStyle_PL_01(driver=self.hsec),
            level=300)
        assert img is not None

    def test_HS_BLH_MSLP_Style_01(self):
        img = self.plot(mpl_hsec_styles.HS_BLH_MSLP_Style_01(driver=self.hsec))
        assert img is not None

    def test_HS_Meteosat_BT108_01(self):
        img = self.plot(mpl_hsec_styles.HS_Meteosat_BT108_01(driver=self.hsec))
        assert img is not None
Пример #3
0
class Test_HSec(object):
    def setup(self):
        data = mswms_settings.data["ecmwf_EUR_LL015"]
        data.setup()

        self.bbox = [-22.5, 27.5, 55, 62.5]

        self.init_time = datetime(2012, 10, 17, 12)
        self.valid_time = datetime(2012, 10, 17, 12)
        self.hsec = HorizontalSectionDriver(data)

    def plot(self, plot_object, style="default", level=None, crs="EPSG:4326", bbox=None, noframe=False,
             transparent=False):
        if bbox is None:
            bbox = self.bbox
        self.hsec.set_plot_parameters(plot_object=plot_object, bbox=bbox, level=level, crs=crs,
                                      init_time=self.init_time, valid_time=self.valid_time, style=style,
                                      noframe=noframe, show=False, transparent=transparent)
        return self.hsec.plot()

    @pytest.mark.parametrize("crs", [
        "EPSG:4326",
        "EPSG:77890010", "EPSG:77790010",
        "MSS:stere,20,40,40", "MSS:lcc,20,0,40,20", "MSS:cass,20,40", "MSS:merc,40"])
    def test_degree_crs_codes(self, crs):
        img = self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec), crs=crs)
        assert img is not None

    @pytest.mark.parametrize("crs", ["EPSG:3031", "EPSG:3857", "EPSG:3413", "EPSG:3995"])
    def test_meter_crs_codes(self, crs):
        bbox_meter = [-1e7, -1e7, 1e7, 1e7]
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")  # disable warnings as there is no data for the cutout
            img = self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec), crs=crs, bbox=bbox_meter)
        assert img is not None

    @pytest.mark.parametrize("crs", ["EPSG:12345678", "FNORD", "MSS:lagranto"])
    def test_invalid_crs_codes(self, crs):
        with pytest.raises(ValueError):
            self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec), crs=crs)

    def test_repeated_locations(self):
        p1 = [45.00, 8.]
        p2 = [50.00, 12.]
        self.path = [p1, p1]
        img = self.plot(mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec), level=10)
        assert img is not None
        self.path = [p1, p1, p2]
        img = self.plot(mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec), level=10)
        assert img is not None
        self.path = [p1, p2, p2]
        img = self.plot(mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec), level=10)
        assert img is not None

    def test_HS_CloudsStyle_01(self):
        for style in ["TOT", "HIGH", "MED", "LOW"]:
            img = self.plot(mpl_hsec_styles.HS_CloudsStyle_01(driver=self.hsec), style=style)
            assert img is not None
            noframe = self.plot(mpl_hsec_styles.HS_CloudsStyle_01(driver=self.hsec), style=style, noframe=True)
            assert noframe is not None
            assert noframe != img
            assert not is_image_transparent(img)

    def test_HS_transparent(self):
        img = self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec), transparent=True)
        assert img is not None
        assert is_image_transparent(img)

    def test_HS_MSLPStyle_01(self):
        img = self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec))
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_MSLPStyle_01(driver=self.hsec), noframe=True)
        assert noframe is not None
        assert noframe != img

    def test_HS_SEAStyle_01(self):
        img = self.plot(mpl_hsec_styles.HS_SEAStyle_01(driver=self.hsec))
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_SEAStyle_01(driver=self.hsec), noframe=True)
        assert noframe is not None
        assert noframe != img

    @pytest.mark.parametrize("style", ["PCOL", "CONT"])
    def test_HS_SeaIceStyle_01(self, style):
        img = self.plot(mpl_hsec_styles.HS_SeaIceStyle_01(driver=self.hsec), style=style)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_SeaIceStyle_01(driver=self.hsec), style=style, noframe=True)
        assert noframe is not None
        assert noframe != img

    def test_HS_TemperatureStyle_ML_01(self):
        img = self.plot(mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec), level=10)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_TemperatureStyle_ML_01(driver=self.hsec), level=10, noframe=True)
        assert noframe is not None
        assert noframe != img

    def test_HS_TemperatureStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_TemperatureStyle_PL_01(driver=self.hsec), level=800)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_TemperatureStyle_PL_01(driver=self.hsec), level=800, noframe=True)
        assert noframe is not None
        assert noframe != img

    def test_HS_GeopotentialWindStyle_PL(self):
        img = self.plot(mpl_hsec_styles.HS_GeopotentialWindStyle_PL(driver=self.hsec), level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_GeopotentialWindStyle_PL(driver=self.hsec), level=300, noframe=True)
        assert noframe is not None
        assert noframe != img

    @pytest.mark.parametrize("style", ["default", "nonlinear", "auto", "log", "autolog"])
    def test_HS_GenericStyle_styles(self, style):
        img = self.plot(
            mpl_hsec_styles.HS_GenericStyle_PL_mole_fraction_of_ozone_in_air(driver=self.hsec),
            level=300, style=style)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_GenericStyle_PL_mole_fraction_of_ozone_in_air(driver=self.hsec),
                            level=300, style=style, noframe=True)
        assert noframe is not None
        assert noframe != img

    def test_HS_GenericStyle_other(self):
        img = self.plot(mpl_hsec_styles.HS_GenericStyle_TL_mole_fraction_of_ozone_in_air(driver=self.hsec), level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_GenericStyle_TL_mole_fraction_of_ozone_in_air(driver=self.hsec),
                            level=300, noframe=True)
        assert noframe != img

        img = self.plot(
            mpl_hsec_styles.HS_GenericStyle_PL_ertel_potential_vorticity(driver=self.hsec),
            style="ertel_potential_vorticity", level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_GenericStyle_PL_ertel_potential_vorticity(driver=self.hsec),
                            level=300, style="ertel_potential_vorticity", noframe=True)
        assert noframe is not None
        assert noframe != img

        img = self.plot(
            mpl_hsec_styles.HS_GenericStyle_PL_equivalent_latitude(driver=self.hsec),
            style="equivalent_latitude", level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_GenericStyle_PL_equivalent_latitude(driver=self.hsec),
                            level=300, style="equivalent_latitude", noframe=True)
        assert noframe is not None
        assert noframe != img

    def test_HS_RelativeHumidityStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_RelativeHumidityStyle_PL_01(driver=self.hsec), level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_RelativeHumidityStyle_PL_01(driver=self.hsec), level=300, noframe=True)
        assert noframe is not None
        assert noframe != img

    def test_HS_EQPTStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_EQPTStyle_PL_01(driver=self.hsec), level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_EQPTStyle_PL_01(driver=self.hsec), level=300, noframe=True)
        assert noframe != img

    def test_HS_WStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_WStyle_PL_01(driver=self.hsec), level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_WStyle_PL_01(driver=self.hsec), level=300, noframe=True)
        assert noframe != img

    def test_HS_DivStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_DivStyle_PL_01(driver=self.hsec), level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_DivStyle_PL_01(driver=self.hsec), level=300, noframe=True)
        assert noframe != img

    def test_HS_EMAC_TracerStyle_ML_01(self):
        img = self.plot(mpl_hsec_styles.HS_EMAC_TracerStyle_ML_01(driver=self.hsec), level=10)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_EMAC_TracerStyle_ML_01(driver=self.hsec), level=10, noframe=True)
        assert noframe != img

    def test_HS_EMAC_TracerStyle_SFC_01(self):
        img = self.plot(mpl_hsec_styles.HS_EMAC_TracerStyle_SFC_01(driver=self.hsec))
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_EMAC_TracerStyle_SFC_01(driver=self.hsec), noframe=True)
        assert noframe != img

    def test_HS_PVTropoStyle_PV_01(self):
        # test fractional levels and non-existing levels
        for style in ["PRES", "PT", "GEOP"]:
            img = self.plot(mpl_hsec_styles.HS_PVTropoStyle_PV_01(driver=self.hsec), level=2.5, style=style)
            assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_PVTropoStyle_PV_01(driver=self.hsec), level=2.5, style=style,
                            noframe=True)
        assert noframe != img
        with pytest.raises(ValueError):
            self.plot(mpl_hsec_styles.HS_PVTropoStyle_PV_01(driver=self.hsec), level=2.75)

    def test_HS_VIProbWCB_Style_01(self):
        img = self.plot(mpl_hsec_styles.HS_VIProbWCB_Style_01(driver=self.hsec))
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_VIProbWCB_Style_01(driver=self.hsec), noframe=True)
        assert noframe != img

    def test_HS_LagrantoTrajStyle_PL_01(self):
        img = self.plot(mpl_hsec_styles.HS_LagrantoTrajStyle_PL_01(driver=self.hsec), level=300)
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_LagrantoTrajStyle_PL_01(driver=self.hsec), level=300, noframe=True)
        assert noframe != img

    def test_HS_BLH_MSLP_Style_01(self):
        img = self.plot(mpl_hsec_styles.HS_BLH_MSLP_Style_01(driver=self.hsec))
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_BLH_MSLP_Style_01(driver=self.hsec), noframe=True)
        assert noframe != img

    def test_HS_Meteosat_BT108_01(self):
        img = self.plot(mpl_hsec_styles.HS_Meteosat_BT108_01(driver=self.hsec))
        assert img is not None
        noframe = self.plot(mpl_hsec_styles.HS_Meteosat_BT108_01(driver=self.hsec), noframe=True)
        assert noframe != img

    def test_HS_gallery_template(self):
        pytest.skip('Test can be biased. In pytest-reverse when there is not a plot_examples it can''t import')
        # ToDo Test Data have to be written to a random tmp dir and that may become purged afterwards
        templates_location = os.path.join(mslib.mswms.gallery_builder.DOCS_LOCATION, "plot_examples")
        sys.path.append(templates_location)
        from HS_template import HS_Template

        img = self.plot(HS_Template(driver=self.hsec), level=300)
        assert img is not None