Exemplo n.º 1
0
    def animation_datetimes(self):
        """For every date/time in the last 24 hours, we check if the
        data is available.  We need at least the "full" geotiff, and
        if the user is logged in, then possibly a geotiff for the
        user's region as well.

        Returned JSON is set as a variable in Javascript
        (wms_neerslagradar.html), and used in lizard_neerslagradar.js
        to load the whole animation."""

        data = []
        for dt in animation_datetimes(utc_now()):
            p = netcdf.time_2_path(dt)
            p = reproject.cache_path(p, "EPSG:3857", TIFF_BBOX.split(", "), 525, 497)
            logger.debug("Checking path: {0}".format(p))
            if os.path.exists(p):
                data.append(
                    {
                        # Translate the UTC datetime to the timezone
                        # in Settings
                        "datetime": (dt.astimezone(pytz.timezone(settings.TIME_ZONE)).strftime("%Y-%m-%dT%H:%M"))
                    }
                )
        logger.debug("Data: {0}".format(data))

        return json.dumps(data)
    def test_name_and_directory_creation(self):
        path = reproject.cache_path(geotiff_path="/tmp/some_geotiff.tiff",
                                    srs="4382",
                                    bbox=(11111, 22222, 33333, 44444),
                                    width=100,
                                    height=200)

        self.assertTrue("/tmp/some_geotiff.tiff" in path)
        self.assertTrue("4382" in path)
        self.assertTrue("11111" in path)
        self.assertTrue("22222" in path)
        self.assertTrue("33333" in path)
        self.assertTrue("44444" in path)
        self.assertTrue("100" in path)
        self.assertTrue("200" in path)
        self.assertTrue(path.endswith(".png"))

        d = os.path.dirname(path)
        self.assertTrue(os.path.exists(d))
        self.assertTrue(os.path.isdir(d))

        os.rmdir(d)
    def test_name_and_directory_creation(self):
        path = reproject.cache_path(
            geotiff_path="/tmp/some_geotiff.tiff",
            srs="4382",
            bbox=(11111, 22222, 33333, 44444),
            width=100,
            height=200)

        self.assertTrue("/tmp/some_geotiff.tiff" in path)
        self.assertTrue("4382" in path)
        self.assertTrue("11111" in path)
        self.assertTrue("22222" in path)
        self.assertTrue("33333" in path)
        self.assertTrue("44444" in path)
        self.assertTrue("100" in path)
        self.assertTrue("200" in path)
        self.assertTrue(path.endswith(".png"))

        d = os.path.dirname(path)
        self.assertTrue(os.path.exists(d))
        self.assertTrue(os.path.isdir(d))

        os.rmdir(d)