示例#1
0
class TestRadarServer(object):
    @recorder.use_cassette('thredds_radarserver_metadata')
    def setup(self):
        self.server = 'http://thredds.ucar.edu/thredds/radarServer/'
        self.client = RadarServer(self.server + 'nexrad/level2/IDD')

    def test_stations(self):
        assert 'KFTG' in self.client.stations

    def test_float_attrs(self):
        stn = self.client.stations['KFTG']
        eq_(stn.elevation, 1675.0)
        eq_(stn.latitude, 39.78)
        eq_(stn.longitude, -104.53)

    def test_metadata(self):
        assert 'Reflectivity' in self.client.variables

    def test_valid_stations(self):
        q = self.client.query()
        q.stations('KFTG', 'KTLX')
        assert self.client.validate_query(q), 'Bad validation check'

    def test_invalid_stations(self):
        q = self.client.query()
        q.stations('KFOO', 'KTLX')
        assert not self.client.validate_query(q), 'Bad validation check'

    @recorder.use_cassette('thredds_radarserver_level2_single')
    def test_raw_catalog(self):
        dt = datetime(2015, 6, 15, 12, 0, 0)
        q = self.client.query().stations('KFTG').time(dt)
        cat = self.client.get_catalog_raw(q).strip()
        eq_(cat[-10:], b'</catalog>')

    @recorder.use_cassette('thredds_radarserver_level2_single')
    def test_good_query(self):
        dt = datetime(2015, 6, 15, 12, 0, 0)
        q = self.client.query().stations('KFTG').time(dt)
        cat = self.client.get_catalog(q)
        eq_(len(cat.datasets), 1)

    @recorder.use_cassette('thredds_radarserver_level3_bad')
    @raises(BadQueryError)
    def test_bad_query_raises(self):
        dt = datetime(2015, 6, 15, 12, 0, 0)
        client = RadarServer(self.server + '/nexrad/level3/IDD')
        q = client.query().stations('FTG').time(dt)
        client.get_catalog(q)

    @recorder.use_cassette('thredds_radarserver_level3_good')
    def test_good_level3_query(self):
        dt = datetime(2015, 6, 15, 12, 0, 0)
        client = RadarServer(self.server + '/nexrad/level3/IDD/')
        q = client.query().stations('FTG').time(dt).variables('N0Q')
        cat = client.get_catalog(q)
        eq_(len(cat.datasets), 1)
示例#2
0
class TestRadarServer(object):
    @recorder.use_cassette('thredds_radarserver_metadata')
    def setup(self):
        self.server = 'http://thredds.ucar.edu/thredds/radarServer/'
        self.client = RadarServer(self.server + 'nexrad/level2/IDD')

    def test_stations(self):
        assert 'KFTG' in self.client.stations

    def test_float_attrs(self):
        stn = self.client.stations['KFTG']
        assert stn.elevation == 1675.0
        assert stn.latitude == 39.78
        assert stn.longitude == -104.53

    def test_metadata(self):
        assert 'Reflectivity' in self.client.variables

    def test_valid_stations(self):
        q = self.client.query()
        q.stations('KFTG', 'KTLX')
        assert self.client.validate_query(q), 'Bad validation check'

    def test_invalid_stations(self):
        q = self.client.query()
        q.stations('KFOO', 'KTLX')
        assert not self.client.validate_query(q), 'Bad validation check'

    @recorder.use_cassette('thredds_radarserver_level2_single')
    def test_raw_catalog(self):
        dt = datetime(2015, 6, 15, 12, 0, 0)
        q = self.client.query().stations('KFTG').time(dt)
        cat = self.client.get_catalog_raw(q).strip()
        assert cat[-10:] == b'</catalog>'

    @recorder.use_cassette('thredds_radarserver_level2_single')
    def test_good_query(self):
        dt = datetime(2015, 6, 15, 12, 0, 0)
        q = self.client.query().stations('KFTG').time(dt)
        cat = self.client.get_catalog(q)
        assert len(cat.datasets) == 1

    @recorder.use_cassette('thredds_radarserver_level3_bad')
    def test_bad_query_raises(self):
        dt = datetime(2015, 6, 15, 12, 0, 0)
        client = RadarServer(self.server + '/nexrad/level3/IDD')
        q = client.query().stations('FTG').time(dt)
        with pytest.raises(BadQueryError):
            client.get_catalog(q)

    @recorder.use_cassette('thredds_radarserver_level3_good')
    def test_good_level3_query(self):
        dt = datetime(2015, 6, 15, 12, 0, 0)
        client = RadarServer(self.server + '/nexrad/level3/IDD/')
        q = client.query().stations('FTG').time(dt).variables('N0Q')
        cat = client.get_catalog(q)
        assert len(cat.datasets) == 1
示例#3
0
class TestRadarServerLevel3(object):
    @recorder.use_cassette('thredds_radarserver_level3_metadata')
    def setup(self):
        self.server = 'http://thredds.ucar.edu/thredds/radarServer/'
        self.client = RadarServer(self.server + 'nexrad/level3/IDD')

    def test_valid_variables(self):
        q = self.client.query()
        q.variables('N0Q', 'N0C')
        assert self.client.validate_query(q)

    def test_invalid_variables(self):
        q = self.client.query()
        q.variables('FOO', 'BAR')
        assert not self.client.validate_query(q)
示例#4
0
class TestRadarServerLevel3(object):
    @recorder.use_cassette('thredds_radarserver_level3_metadata')
    def setup(self):
        self.server = 'http://thredds.ucar.edu/thredds/radarServer/'
        self.client = RadarServer(self.server + 'nexrad/level3/IDD')

    def test_valid_variables(self):
        q = self.client.query()
        q.variables('N0Q', 'N0C')
        assert self.client.validate_query(q)

    def test_invalid_variables(self):
        q = self.client.query()
        q.variables('FOO', 'BAR')
        assert not self.client.validate_query(q)
示例#5
0
class TestRadarServerLevel3(object):
    """Test radar server functionality for requesting level 3 data."""
    @recorder.use_cassette('thredds_radarserver_level3_metadata')
    def setup(self):
        """Set up server and client for level 3 tests."""
        self.server = 'http://thredds.ucar.edu/thredds/radarServer/'
        self.client = RadarServer(self.server + 'nexrad/level3/IDD')

    def test_valid_variables(self):
        """Test that validating a query respects correct variables."""
        q = self.client.query()
        q.variables('N0Q', 'N0C')
        assert self.client.validate_query(q)

    def test_invalid_variables(self):
        """Test that validating a query catches incorrect variables."""
        q = self.client.query()
        q.variables('FOO', 'BAR')
        assert not self.client.validate_query(q)
示例#6
0
class TestRadarServerLevel3(object):
    """Test radar server functionality for requesting level 3 data."""

    @recorder.use_cassette('thredds_radarserver_level3_metadata')
    def setup(self):
        """Set up server and client for level 3 tests."""
        self.server = 'http://thredds.ucar.edu/thredds/radarServer/'
        self.client = RadarServer(self.server + 'nexrad/level3/IDD')

    def test_valid_variables(self):
        """Test that validating a query respects correct variables."""
        q = self.client.query()
        q.variables('N0Q', 'N0C')
        assert self.client.validate_query(q)

    def test_invalid_variables(self):
        """Test that validating a query catches incorrect variables."""
        q = self.client.query()
        q.variables('FOO', 'BAR')
        assert not self.client.validate_query(q)
示例#7
0
    def get_radar(station, product):
        rs = RadarServer('http://thredds.ucar.edu/thredds/radarServer/nexrad/level3/IDD/')
        query = rs.query()
        query.stations(station).time(datetime.utcnow()).variables(product)
        validator = rs.validate_query(query)
        if validator is not True:
            ed = ErrorDialog('This query is not valid')
            ed.show()
        catalog = rs.get_catalog(query)
        ds = list(catalog.datasets.values())[0]
        data = Dataset(ds.access_urls['CdmRemote'])
        rng = data.variables['gate'][:] / 1000.
        az = data.variables['azimuth'][:]
        ref = data.variables['BaseReflectivityDR'][:]
        x = rng * np.sin(np.deg2rad(az))[:, None]
        y = rng * np.cos(np.deg2rad(az))[:, None]
        ref = np.ma.array(ref, mask=np.isnan(ref))

        return x, y, ref
示例#8
0
# Next, we'll create a new query object to help request the data. Using the chaining methods, let's ask for the latest data at the radar KLVX (Louisville, KY). We see that when the query is represented as a string, it shows the encoded URL.

# In[3]:

from datetime import datetime, timedelta
query = rs.query()
query.stations('KLVX').time(datetime.utcnow())


# We can use the RadarServer instance to check our query, to make sure we have required parameters and that we have chosen valid station(s) and variable(s)
# 

# In[4]:

rs.validate_query(query)


# Make the request, which returns an instance of TDSCatalog; this handles parsing the returned XML information.

# In[5]:

catalog = rs.get_catalog(query)


# We can look at the datasets on the catalog to see what data we found by the query. We find one volume in the return, since we asked for the volume nearest to a single time.

# In[6]:

catalog.datasets
示例#9
0
class TestRadarServer(object):
    """Test radar server functionality for accessing data."""
    @recorder.use_cassette('thredds_radarserver_metadata')
    def setup(self):
        """Set up server and client for tests."""
        self.server = 'http://thredds.ucar.edu/thredds/radarServer/'
        self.client = RadarServer(self.server + 'nexrad/level2/IDD')

    def test_stations(self):
        """Test parsing of the station information from the server."""
        assert 'KFTG' in self.client.stations

    def test_float_attrs(self):
        """Test parsing of values from the station information on the server."""
        stn = self.client.stations['KFTG']
        assert stn.elevation == 1675.0
        assert stn.latitude == 39.78
        assert stn.longitude == -104.53

    def test_metadata(self):
        """Test parsing of variable information from server."""
        assert 'Reflectivity' in self.client.variables

    def test_valid_stations(self):
        """Test validating a query with valid stations."""
        q = self.client.query()
        q.stations('KFTG', 'KTLX')
        assert self.client.validate_query(q), 'Bad validation check'

    def test_invalid_stations(self):
        """Test validating a query with invalid stations."""
        q = self.client.query()
        q.stations('KFOO', 'KTLX')
        assert not self.client.validate_query(q), 'Bad validation check'

    @recorder.use_cassette('thredds_radarserver_level2_single')
    def test_raw_catalog(self):
        """Test getting raw catalog bytes."""
        dt = datetime(2015, 6, 15, 12, 0, 0)
        q = self.client.query().stations('KFTG').time(dt)
        cat = self.client.get_catalog_raw(q).strip()
        assert cat[-10:] == b'</catalog>'

    @recorder.use_cassette('thredds_radarserver_level2_single')
    def test_good_query(self):
        """Test making a good request."""
        dt = datetime(2015, 6, 15, 12, 0, 0)
        q = self.client.query().stations('KFTG').time(dt)
        cat = self.client.get_catalog(q)
        assert len(cat.datasets) == 1

    @recorder.use_cassette('thredds_radarserver_level3_bad')
    def test_bad_query_raises(self):
        """Test that a bad query raises an error."""
        dt = datetime(2015, 6, 15, 12, 0, 0)
        client = RadarServer(self.server + '/nexrad/level3/IDD')
        q = client.query().stations('FTG').time(dt)
        with pytest.raises(BadQueryError):
            client.get_catalog(q)

    @recorder.use_cassette('thredds_radarserver_level3_good')
    def test_good_level3_query(self):
        """Test that a valid level 3 query succeeds."""
        dt = datetime(2015, 6, 15, 12, 0, 0)
        client = RadarServer(self.server + '/nexrad/level3/IDD/')
        q = client.query().stations('FTG').time(dt).variables('N0Q')
        cat = client.get_catalog(q)
        assert len(cat.datasets) == 1
示例#10
0
文件: level3.py 项目: WEP11/NEXpy
def update(frame):
	global SITE
	global PRODUCT
	
	print("Building Frame:",frame)
	#What is the age of this frame?
	frameIndex = frame % 9
	frameAge = frameIndex * 10 # minutes old

	# WHAT TIME WILL THE FRAME BE??
	date = datetime.utcnow() - timedelta(minutes=frameAge)
	year = date.year
	month = date.month
	day = date.day
	hour = date.hour
	minute = date.minute


	# What type of radar site is this?..
	
	siteType = validation.checkRadarType(SITE)
	ncfVar = validation.checkProduct(PRODUCT)
	colorTable = validation.checkColorTable(PRODUCT)

	if siteType=='88D':
		rs = RadarServer('http://thredds.ucar.edu/thredds/radarServer/nexrad/level3/IDD/')
	elif siteType=='TDWR':
		rs = RadarServer('http://thredds.ucar.edu/thredds/radarServer/terminal/level3/IDD/')
	else:
		print('INVALID SITE IDENTIFIER')
		sys.exit()


	# ACQUIRE DATA ----------------------------------------

	query = rs.query()
	query.stations(args.site).time(datetime(year,month,day,hour,minute)).variables(args.product)

	rs.validate_query(query)

	catalog = rs.get_catalog(query)

	catalog.datasets

	ds = list(catalog.datasets.values())[0]
	ds.access_urls

	# READ DATA ------------------------------------------
	data = Dataset(ds.access_urls['CdmRemote'])

	rng = data.variables['gate'][:]
	az = data.variables['azimuth'][:]
	ref = data.variables[ncfVar][:]

	x = (rng * np.sin(np.deg2rad(az))[:, None])
	y = (rng * np.cos(np.deg2rad(az))[:, None])
	ref = np.ma.array(ref, mask=np.isnan(ref))
	plot = ax.pcolormesh(x, y, ref, cmap=cmap, norm=norm, zorder=2)
	title_line1 = '%s %s - %i:%i' % (args.site,args.product,hour,minute)
	plt.title(title_line1,color='k',fontsize=18,fontweight='bold',style='italic')

	return plot
示例#11
0
class TestRadarServer(object):
    """Test radar server functionality for accessing data."""

    @recorder.use_cassette('thredds_radarserver_metadata')
    def setup(self):
        """Set up server and client for tests."""
        self.server = 'http://thredds.ucar.edu/thredds/radarServer/'
        self.client = RadarServer(self.server + 'nexrad/level2/IDD')

    def test_stations(self):
        """Test parsing of the station information from the server."""
        assert 'KFTG' in self.client.stations

    def test_float_attrs(self):
        """Test parsing of values from the station information on the server."""
        stn = self.client.stations['KFTG']
        assert stn.elevation == 1675.0
        assert stn.latitude == 39.78
        assert stn.longitude == -104.53

    def test_metadata(self):
        """Test parsing of variable information from server."""
        assert 'Reflectivity' in self.client.variables

    def test_valid_stations(self):
        """Test validating a query with valid stations."""
        q = self.client.query()
        q.stations('KFTG', 'KTLX')
        assert self.client.validate_query(q), 'Bad validation check'

    def test_invalid_stations(self):
        """Test validating a query with invalid stations."""
        q = self.client.query()
        q.stations('KFOO', 'KTLX')
        assert not self.client.validate_query(q), 'Bad validation check'

    @recorder.use_cassette('thredds_radarserver_level2_single')
    def test_raw_catalog(self):
        """Test getting raw catalog bytes."""
        dt = datetime(2015, 6, 15, 12, 0, 0)
        q = self.client.query().stations('KFTG').time(dt)
        cat = self.client.get_catalog_raw(q).strip()
        assert cat[-10:] == b'</catalog>'

    @recorder.use_cassette('thredds_radarserver_level2_single')
    def test_good_query(self):
        """Test making a good request."""
        dt = datetime(2015, 6, 15, 12, 0, 0)
        q = self.client.query().stations('KFTG').time(dt)
        cat = self.client.get_catalog(q)
        assert len(cat.datasets) == 1

    @recorder.use_cassette('thredds_radarserver_level3_bad')
    def test_bad_query_raises(self):
        """Test that a bad query raises an error."""
        dt = datetime(2015, 6, 15, 12, 0, 0)
        client = RadarServer(self.server + '/nexrad/level3/IDD')
        q = client.query().stations('FTG').time(dt)
        with pytest.raises(BadQueryError):
            client.get_catalog(q)

    @recorder.use_cassette('thredds_radarserver_level3_good')
    def test_good_level3_query(self):
        """Test that a valid level 3 query succeeds."""
        dt = datetime(2015, 6, 15, 12, 0, 0)
        client = RadarServer(self.server + '/nexrad/level3/IDD/')
        q = client.query().stations('FTG').time(dt).variables('N0Q')
        cat = client.get_catalog(q)
        assert len(cat.datasets) == 1
示例#12
0
sql_client.send("""CREATE TABLE IF NOT EXISTS nexrad_copy_example (
  the_geom geometry(Geometry,4326),
  reflectivity numeric
)""")
sql_client.send(
    "SELECT CDB_CartodbfyTable(current_schema, 'nexrad_copy_example')")
logger.info('Done')

logger.info('Trying to connect to the THREDDS radar query service')
rs = RadarServer(
    'http://thredds.ucar.edu/thredds/radarServer/nexrad/level2/IDD/')

logger.info('Quering data from the station')
query = rs.query()
query.stations('KLVX').time(datetime.utcnow())
assert rs.validate_query(query)

catalog = rs.get_catalog(query)
logger.info('Avaliable datasets: %s' % catalog.datasets)
logger.info('Using the first one')
ds = list(catalog.datasets.values())[0]
data = Dataset(ds.access_urls['CdmRemote'])
logger.info('Got the following data: %s' % data.Title)
logger.info(data.Summary)


# A helper method to clean up the data
def raw_to_masked_float(var, data):
    # Values come back signed. If the _Unsigned attribute is set, we
    # need to convert from the range [-127, 128] to [0, 255].
    if var._Unsigned: