Esempio n. 1
0
 def test_haversine_na(self):
     km_dist_na = compareLatLong((0.0, 0.0), (1.0, 2.0))
     assert numpy.isnan(km_dist_na)
     km_dist_na = compareLatLong((1.0, 2.0), (0.0, 0.0))
     assert numpy.isnan(km_dist_na)
     km_dist_n_na = compareLatLong((0.0, 1.0), (1.0, 2.0))
     self.assertAlmostEqual(km_dist_n_na, 157, -1)
Esempio n. 2
0
 def test_haversine_na(self):
     km_dist_na = compareLatLong((0.0, 0.0), (1.0, 2.0))
     assert numpy.isnan(km_dist_na)
     km_dist_na = compareLatLong((1.0, 2.0), (0.0, 0.0))
     assert numpy.isnan(km_dist_na)
     km_dist_n_na = compareLatLong((0.0, 1.0), (1.0, 2.0))
     self.assertAlmostEqual(km_dist_n_na, 157, -1)
Esempio n. 3
0
    df_patstat = pd.read_csv(patstat_file, sep='\t', usecols = ['person_id', 'lat', 'lng'])
    df_patstat = df_patstat[pd.notnull(df_patstat['lat'])]
    
    geodist = df_out[['patstat_id','company_id']].set_index('patstat_id').join(df_patstat.set_index('person_id'))
    geodist = geodist.rename(columns = {'lat':'plat', 'lng': 'plng'})
    geodist = geodist.reset_index().set_index('company_id').join(df_amadeus.set_index('company_id')).reset_index()
    geodist = geodist.rename(columns = {'index':'patstat_id','lat':'alat', 'lng': 'alng'})
    
    geodist = geodist[pd.notnull(geodist['plat']*geodist['alat'])]
    
    # geocode matches
    print 'computing geo-distances of selected matches'
    geo_dist = []
    for i,v in geodist.iterrows():
        geo_dist.append(haversine.compareLatLong((v['plat'],v['plng']),(v['alat'],v['alng'])))

    geodist['geo_dist'] = geo_dist
    geodist = geodist[['patstat_id','company_id','geo_dist']].set_index(['patstat_id','company_id'])
    df_out = df_out.set_index(['patstat_id','company_id']).join(geodist)
    
    print 'done with geo-distances'
    
    df_out['country'] = country
    
    # save
    print 'saving to file', output_file
    df_out.to_csv(output_file, sep='\t')
    print 'done!'
    
Esempio n. 4
0
 def test_haversine_zero(self):
     km_dist_zero = compareLatLong(self.ord, self.ord)
     self.assertAlmostEqual(km_dist_zero, 0.0, 0)
Esempio n. 5
0
    def test_haversine_equal(self):
        km_dist_val = compareLatLong(self.sfo, self.ord)

        self.assertAlmostEqual(km_dist_val, 2964, -1)
Esempio n. 6
0
    def test_haversine_equal(self):
        km_dist_val = compareLatLong(self.sfo, self.ord)

        self.assertAlmostEqual(km_dist_val, 2964, -1)
Esempio n. 7
0
 def test_haversine_zero(self):
     km_dist_zero = compareLatLong(self.ord, self.ord)
     self.assertAlmostEqual(km_dist_zero, 0.0, 0)