示例#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_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()
示例#3
0
文件: tests.py 项目: dz0ny/arsoapi
	def test01_radar(self):
		img_data = open(datafile('test01_radar.gif')).read()
		r = RadarPadavin(picdata=img_data.encode('base64'), last_modified=datetime.datetime.now())
		r.save()
		gr = GeocodedRadar()
		gr.load_from_model(r)
		
		pos, rain_level = gr.get_rain_at_coords(45.545763, 14.106696)
		self.assertEqual(pos, (358, 361), 'Pixel coords are off?')
		self.assertEqual(rain_level, 100, 'Rain not a 100% where it should be')
		
		del gr
		r.delete()
示例#4
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()
示例#5
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()
示例#6
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()
示例#7
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()
示例#8
0
    GeocodedRadar,
    GeocodedToca,
    GeocodedAladin,
    RadarPadavin,
    Toca,
    Aladin,
    mmph_to_level,
    annotate_geo_radar,
)
from arsoapi.formats import radar_get_format

from osgeo import gdal
import osgeo.gdalconst as gdalc
import numpy

geocoded_radar = GeocodedRadar()
geocoded_toca = GeocodedToca()
geocoded_aladin = GeocodedAladin()


def _dumps(s):
    return simplejson.dumps(s, use_decimal=True, ensure_ascii=True)


def _datetime2timestamp(dt):
    return int(time.mktime(dt.timetuple()))


def datetime_encoder(obj):
    if isinstance(obj, datetime.datetime):
        return obj.isoformat()