コード例 #1
0
    def get(self, name):
        sCounts = {"US-AL" : 0, "US-AK" : 0, "US-AZ" : 0, "US-AR" : 0, "US-CA" : 0, "US-CO" :0, "US-CT" : 0, "US-DE" : 0, "US-FL" : 0, "US-GA" : 0, "US-HI" : 0, "US-ID" : 0, "US-IL" : 0, "US-IN" : 0, "US-IA" : 0, "US-KS" : 0, "US-KY" : 0, "US-LA" : 0, "US-ME" : 0, "US-MD" : 0, "US-MA" : 0, "US-MI" : 0, "US-MN" : 0, "US-MS" : 0, "US-MO" : 0, "US-MT" : 0, "US-NE" : 0, "US-NV" : 0, "US-NH" : 0, "US-NJ" : 0, "US-NM" : 0, "US-NY" : 0, "US-NC" : 0, "US-ND" : 0, "US-OH" : 0, "US-OK" : 0, "US-OR" : 0, "US-PA" : 0, "US-RI" : 0, "US-SC" : 0, "US-SD" : 0, "US-TN" : 0, "US-TX" : 0, "US-UT" : 0, "US-VT" : 0, "US-VA" : 0, "US-WA" : 0, "US-WV" : 0, "US-WI" : 0, "US-WY" : 0}
        consumer_key = ""
        consumer_secret = ""
        access_token = ""
        access_token_secret = ""

        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        api = tweepy.API(auth,wait_on_rate_limit=True)

        if name == '':
            name = 'eminem'

        retJ = []

        count = 0
        for tweet in tweepy.Cursor(api.search,q=name, count=100, lang="en", since="2014-04-03").items(6000):

            # Push to producer
            self.producer.send(KAFKA_TOPIC, value=tweet.text.encode('utf-16be'))

            if tweet.place is not None:
                if tweet.place.country_code == u'US':
                    count = count + 1
                    #print (tweet.created_at, tweet.coordinates, tweet.place, tweet.user.derived.locations.region)
                    cood = tweet.place.bounding_box.coordinates[0][0]
                    # print (cood)
                    tweetState = 'US-'+stateplane.identify(cood[0], cood[1], fmt='short')[:2]
                    if tweetState in sCounts.keys():
                        sCounts[tweetState] += 1

        for k, v in zip(sCounts.keys(), sCounts.values()):
            retJ.append({"id" : k, "value" : v})
        return (retJ)
コード例 #2
0
ファイル: test_stateplane.py プロジェクト: fitnr/stateplane
 def test_inverting(self):
     for _ in range(500):
         lon, lat = rand()
         epsg = stateplane.identify(lon, lat)
         e, n = stateplane.from_lonlat(lon, lat)
         x, y = stateplane.to_lonlat(e, n, epsg=epsg)
         self.assertAlmostEqual(lon, x)
         self.assertAlmostEqual(lat, y)
コード例 #3
0
 def test_inverting(self):
     for _ in range(500):
         lon, lat = rand()
         epsg = stateplane.identify(lon, lat)
         e, n = stateplane.from_lonlat(lon, lat)
         x, y = stateplane.to_lonlat(e, n, epsg=epsg)
         self.assertAlmostEqual(lon, x)
         self.assertAlmostEqual(lat, y)
コード例 #4
0
    def test_identify(self):
        assert 'NY_LI' == stateplane.identify(-73.604107, 40.750638, fmt='short')
        assert 'NC' == stateplane.identify(-80.1, 36.2, fmt='short')
        assert '3200' == stateplane.identify(-80.1, 36.2, fmt='fips')
        assert stateplane.identify(-75.2, 40.2, fmt='short') == 'PA_S'
        assert stateplane.identify(-75.2, 40.2) == '32129'

        assert stateplane.identify(-80.1, 36.2, fmt='proj4') == "+proj=lcc +lat_1=36.16666666666666 +lat_2=34.33333333333334 +lat_0=33.75 +lon_0=-79 +x_0=609601.22 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"

        self.assertEqual(stateplane.identify(-80.1, 36.2, fmt='FOOBAR'), '32119')
コード例 #5
0
ファイル: test_stateplane.py プロジェクト: fitnr/stateplane
    def test_identify(self):
        assert 'NY_LI' == stateplane.identify(-73.604107, 40.750638, fmt='short')
        assert 'NC' == stateplane.identify(-80.1, 36.2, fmt='short')
        assert '3200' == stateplane.identify(-80.1, 36.2, fmt='fips')
        assert stateplane.identify(-75.2, 40.2, fmt='short') == 'PA_S'
        assert stateplane.identify(-75.2, 40.2) == '32129'

        fixture = (
            "+proj=lcc +lat_1=36.16666666666666 +lat_2=34.33333333333334 "
            "+lat_0=33.75 +lon_0=-79 +x_0=609601.22 +y_0=0 +ellps=GRS80 "
            "+towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
        )
        self.assertEqual(stateplane.identify(-80.1, 36.2, fmt='proj4').strip(), fixture)

        self.assertEqual(stateplane.identify(-80.1, 36.2, fmt='FOOBAR'), '32119')
コード例 #6
0
ファイル: inun3.py プロジェクト: larryyin/barrier_interp
x_ul = geotransform[0]
y_ul = geotransform[3]
x_size = geotransform[1]
y_size = geotransform[5]

data_raw = BandReadAsArray(band1)
(y_cell, x_cell) = data_raw.shape
#xv, yv = meshgrid(range(x_cell), range(y_cell), indexing='xy')
#x_coor = xv * x_size + x_ul + (x_size*.5)
#y_coor = yv * y_size + y_ul + (y_size*.5)
#x_cent = (x_coor[0][0]+x_coor[-1][-1])*.5
#y_cent = (y_coor[0][0]+y_coor[-1][-1])*.5
x_cent = int(x_cell * .5) * x_size + x_ul + (x_size * .5)
y_cent = int(y_cell * .5) * y_size + y_ul + (y_size * .5)

sp_code = stateplane.identify(x_cent, y_cent)
sp_str = stateplane.identify(x_cent, y_cent, 'short')

nodata = np.nanmin(data_raw)
mask_domain = ~(data_raw == nodata)

#%% Domain
print('Generating Domain...')

data1 = np.copy(data_raw)
data1[~mask_domain] = 0
data1[mask_domain] = 1
data1 = data1.astype(int)

dsOut = driver.Create(file_bool1, DEM.RasterXSize, DEM.RasterYSize, bandNum1,
                      band1.DataType)
コード例 #7
0
    logger.debug('%s : %d :: %s' %
                 (column_name, len(train_uniques), train_uniques))

for column_name in list(train):
    logger.debug('%s : train unique: %d properties unique: %d' %
                 (column_name, len(train[column_name].unique()),
                  (len(properties[column_name].unique()))
                  if column_name in list(properties) else -1))

if False:
    import stateplane
    logger.debug(train['fips'].head(20))

    logger.debug(train[['latitude', 'longitude']].head(20))

    train['t0'] = train.apply(lambda row: stateplane.identify(
        row['longitude'] / 1000000.0, row['latitude'] / 1000000.0, fmt='fips'),
                              axis=1)
    logger.debug(train['t0'].head(20))

logger.debug('training data shape: %s' % (train.shape, ))

# make a scatterplot of the training data
if False:
    column_names = ['latitude', 'longitude', 'fips']
    logger.debug(train.fips.unique())
    train.plot(kind='scatter', x='latitude', y='longitude', c='fips')

colors = {6037: 'red', 6059: 'blue', 6111: 'green'}

column_name = 'logerror'
# visualize the error
コード例 #8
0
import stateplane
import csv
import sys

misses = 0

with open(sys.argv[1], 'r') as coords:
    coord_reader = csv.reader(coords)

    for i, coord in enumerate(coord_reader):
        if i % 5000 is 0:
            print("Processing " + str(i))

        try:
            #Get state and first two chars (bc that is state code)
            state = stateplane.identify(float(coord[1]), float(coord[0]),
                                        'short')[:2]
        except:
            misses += 1
            continue

        state_file = open(
            "substations_states/" + str(state) + "_substations.csv", 'a')
        w = csv.writer(state_file)
        w.writerow(coord)
        state_file.close()
コード例 #9
0
 def test_statefp(self):
     assert '26943' == stateplane.identify(-121.986361, 37.524384999999995, statefp='06')
     self.assertEqual('26957', stateplane.identify(0, 0, statefp='10'))
     self.assertRaises(ValueError, stateplane.identify, -121, 35.7, statefp='KK')
コード例 #10
0
 def test_identify_with_countyfp(self):
     assert 'NY_LI' == stateplane.identify(None, None, fmt='short', statefp='36', countyfp='005')
     assert 'NY_LI' == stateplane.identify(None, None, fmt='short', countyfp='36005')
コード例 #11
0
ファイル: test_stateplane.py プロジェクト: fitnr/stateplane
 def test_statefp(self):
     assert '26943' == stateplane.identify(-121.986361, 37.524384999999995, statefp='06')
     self.assertEqual('26957', stateplane.identify(0, 0, statefp='10'))
     self.assertRaises(ValueError, stateplane.identify, -121, 35.7, statefp='KK')
コード例 #12
0
ファイル: test_stateplane.py プロジェクト: fitnr/stateplane
 def test_identify_with_countyfp(self):
     assert 'NY_LI' == stateplane.identify(None, None, fmt='short', statefp='36', countyfp='005')
     assert 'NY_LI' == stateplane.identify(None, None, fmt='short', countyfp='36005')