Пример #1
0
	def test01_radar_coverage(self):

		pattern = os.path.join(os.path.dirname(__file__), 'data/private', '*')

		for path in glob.glob(pattern):

			name = os.path.join("private", os.path.basename(path))

			img_data = open(datafile(name)).read()
			r = RadarPadavin(picdata=img_data.encode('base64'),
					last_modified=datetime.datetime.now())
			r.save()
			r.process()

			gr = GeocodedRadar()
			gr.load_from_model(r)

			for lat in xrange(45210, 47050+1, 10):
				for lon in xrange(12920, 16710+1, 10):
					lat_f = lat * 1e-3
					lon_f = lon * 1e-3
					pos, rain_mmph = gr.get_rain_at_coords(lat_f, lon_f)

					self.assertTrue(rain_mmph is not None,
							msg="get_rain_at_coords(%f, %f) is None "
								"(%s, pos = %r)" % (
								lat_f, lon_f, name, pos))

			del gr
			r.delete()
Пример #2
0
	def test01_radar(self):
		img_data = open(datafile('test_sirad_si1_si2.gif')).read()
		r = RadarPadavin(picdata=img_data.encode('base64'), last_modified=datetime.datetime.now())
		r.save()
		r.process()

		gr = GeocodedRadar()
		gr.load_from_model(r)

		# koper
		pos, rain_mmph = gr.get_rain_at_coords(45.547356,13.729792)
		self.assertEqual(pos, (294, 357))
		self.assertEqual(rain_mmph, 0)

		# ljubljana
		pos, rain_mmph = gr.get_rain_at_coords(46.054173,14.507332)
		self.assertEqual(pos, (428, 270))
		self.assertEqual(rain_mmph, 0)

		# maribor
		pos, rain_mmph = gr.get_rain_at_coords(46.554611,15.646534)
		self.assertEqual(pos, (624, 184))
		self.assertEqual(rain_mmph, 0)

		pos, rain_level = gr.get_rain_at_coords(45.545763, 14.106696)
		self.assertEqual(pos, (359, 357)) # 'Pixel coords are off?')
		self.assertEqual(rain_level, .5)
		
		del gr
		r.delete()
Пример #3
0
    def test01_radar(self):
        img_data = open(datafile('test_sirad_si1_si2.gif')).read()
        r = RadarPadavin(picdata=img_data.encode('base64'),
                         last_modified=datetime.datetime.now())
        r.save()
        r.process()

        gr = GeocodedRadar()
        gr.load_from_model(r)

        # koper
        pos, rain_mmph = gr.get_rain_at_coords(45.547356, 13.729792)
        self.assertEqual(pos, (294, 357))
        self.assertEqual(rain_mmph, 0)

        # ljubljana
        pos, rain_mmph = gr.get_rain_at_coords(46.054173, 14.507332)
        self.assertEqual(pos, (428, 270))
        self.assertEqual(rain_mmph, 0)

        # maribor
        pos, rain_mmph = gr.get_rain_at_coords(46.554611, 15.646534)
        self.assertEqual(pos, (624, 184))
        self.assertEqual(rain_mmph, 0)

        pos, rain_level = gr.get_rain_at_coords(45.545763, 14.106696)
        self.assertEqual(pos, (359, 357))  # 'Pixel coords are off?')
        self.assertEqual(rain_level, .5)

        del gr
        r.delete()
Пример #4
0
    def test01_radar_coverage(self):

        pattern = os.path.join(os.path.dirname(__file__), 'data/private', '*')

        for path in glob.glob(pattern):

            name = os.path.join("private", os.path.basename(path))

            img_data = open(datafile(name)).read()
            r = RadarPadavin(picdata=img_data.encode('base64'),
                             last_modified=datetime.datetime.now())
            r.save()
            r.process()

            gr = GeocodedRadar()
            gr.load_from_model(r)

            for lat in xrange(45210, 47050 + 1, 10):
                for lon in xrange(12920, 16710 + 1, 10):
                    lat_f = lat * 1e-3
                    lon_f = lon * 1e-3
                    pos, rain_mmph = gr.get_rain_at_coords(lat_f, lon_f)

                    self.assertTrue(rain_mmph is not None,
                                    msg="get_rain_at_coords(%f, %f) is None "
                                    "(%s, pos = %r)" %
                                    (lat_f, lon_f, name, pos))

            del gr
            r.delete()
Пример #5
0
	def test01_radar_unknown_format(self):
		img_data = open(datafile('test_invalid.gif')).read()
		r = RadarPadavin(picdata=img_data.encode('base64'), last_modified=datetime.datetime.now())
		r.save()
		r.process()

		gr = GeocodedRadar()
		gr.load_from_model(r)

		pos, rain_mmph = gr.get_rain_at_coords(45.545763, 14.106696)
		self.assertTrue(rain_mmph is None)

		del gr
		r.delete()
Пример #6
0
	def handle(self, *args, **options):
		from arsoapi.models import RadarPadavin, fetch_radar
		from StringIO import StringIO
		import Image
		
		imgdata, last_modified = fetch_radar()
		image = Image.open(StringIO(imgdata))
		try:
			r = RadarPadavin.objects.get(last_modified=last_modified)
		except RadarPadavin.DoesNotExist:
			r = RadarPadavin(picdata=imgdata.encode('base64'), last_modified=last_modified)
			r.save()
			assert image.size == (819, 658)
			r.process()
Пример #7
0
    def test01_radar_unknown_format(self):
        img_data = open(datafile('test_invalid.gif')).read()
        r = RadarPadavin(picdata=img_data.encode('base64'),
                         last_modified=datetime.datetime.now())
        r.save()
        r.process()

        gr = GeocodedRadar()
        gr.load_from_model(r)

        pos, rain_mmph = gr.get_rain_at_coords(45.545763, 14.106696)
        self.assertTrue(rain_mmph is None)

        del gr
        r.delete()
Пример #8
0
    def handle(self, *args, **options):
        from arsoapi.models import RadarPadavin, fetch_radar
        from StringIO import StringIO
        from PIL import Image

        imgdata, last_modified = fetch_radar()
        image = Image.open(StringIO(imgdata))
        try:
            r = RadarPadavin.objects.get(last_modified=last_modified)
        except RadarPadavin.DoesNotExist:
            r = RadarPadavin(picdata=imgdata.encode('base64'),
                             last_modified=last_modified)
            r.save()
            assert image.size == (821, 660)
            r.process()