本文整理汇总了Python中ichnaea.geocode.GEOCODER.region方法的典型用法代码示例。如果您正苦于以下问题:Python GEOCODER.region方法的具体用法?Python GEOCODER.region怎么用?Python GEOCODER.region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ichnaea.geocode.GEOCODER
的用法示例。
在下文中一共展示了GEOCODER.region方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: aggregate_obs
# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import region [as 别名]
def aggregate_obs(self):
positions = numpy.array(
[(obs.lat, obs.lon) for obs in self.observations],
dtype=numpy.double)
max_lat, max_lon = positions.max(axis=0)
min_lat, min_lon = positions.min(axis=0)
box_distance = distance(min_lat, min_lon, max_lat, max_lon)
if box_distance > self.MAX_DIST_METERS:
return None
weights = numpy.array(
[obs.weight for obs in self.observations],
dtype=numpy.double)
lat, lon = numpy.average(positions, axis=0, weights=weights)
lat = float(lat)
lon = float(lon)
radius = circle_radius(lat, lon, max_lat, max_lon, min_lat, min_lon)
region = GEOCODER.region(lat, lon)
samples, weight = self.bounded_samples_weight(
len(self.observations), float(weights.sum()))
return {
'positions': positions, 'weights': weights,
'lat': lat, 'lon': lon,
'max_lat': float(max_lat), 'min_lat': float(min_lat),
'max_lon': float(max_lon), 'min_lon': float(min_lon),
'radius': radius, 'region': region,
'samples': samples, 'weight': weight,
}
示例2: aggregate_station_obs
# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import region [as 别名]
def aggregate_station_obs(self):
station = self.station
obs_data = self.obs_data
def get_nan(name):
value = getattr(station, name, None)
return numpy.nan if value is None else value
positions = numpy.append(obs_data['positions'], [
(get_nan('lat'), get_nan('lon')),
(get_nan('max_lat'), get_nan('max_lon')),
(get_nan('min_lat'), get_nan('min_lon')),
], axis=0)
max_lat, max_lon = numpy.nanmax(positions, axis=0)
min_lat, min_lon = numpy.nanmin(positions, axis=0)
if station.lat is None or station.lon is None:
old_weight = 0.0
else:
old_weight = min((station.weight or 0.0), self.MAX_OLD_WEIGHT)
lat = ((obs_data['lat'] * obs_data['weight'] +
(station.lat or 0.0) * old_weight) /
(obs_data['weight'] + old_weight))
lon = ((obs_data['lon'] * obs_data['weight'] +
(station.lon or 0.0) * old_weight) /
(obs_data['weight'] + old_weight))
radius = circle_radius(lat, lon, max_lat, max_lon, min_lat, min_lon)
region = station.region
if (region and not GEOCODER.in_region(lat, lon, region)):
# reset region if it no longer matches
region = None
if not region:
region = GEOCODER.region(lat, lon)
samples, weight = self.bounded_samples_weight(
(station.samples or 0) + obs_data['samples'],
(station.weight or 0.0) + obs_data['weight'])
return {
'lat': lat, 'lon': lon,
'max_lat': float(max_lat), 'min_lat': float(min_lat),
'max_lon': float(max_lon), 'min_lon': float(min_lon),
'radius': radius, 'region': region,
'samples': samples, 'weight': weight,
}
示例3: station_values
# 需要导入模块: from ichnaea.geocode import GEOCODER [as 别名]
# 或者: from ichnaea.geocode.GEOCODER import region [as 别名]
def station_values(self, station_key, shard_station, observations):
"""
Return two-tuple of status, value dict where status is one of:
`new`, `new_moving`, `moving`, `changed`.
"""
# cases:
# we always get a station key and observations
# 0. observations disagree
# 0.a. no shard station, return new_moving
# 0.b. shard station, return moving
# 1. no shard station
# 1.a. obs agree -> return new
# 2. shard station
# 2.a. obs disagree -> return moving
# 2.b. obs agree -> return changed
created = self.utcnow
values = self._base_station_values(station_key, observations)
obs_positions = numpy.array(
[(obs.lat, obs.lon) for obs in observations],
dtype=numpy.double)
obs_length = len(observations)
obs_weights = numpy.array(
[obs.weight for obs in observations],
dtype=numpy.double)
obs_weight = float(obs_weights.sum())
obs_new_lat, obs_new_lon = numpy.average(
obs_positions, axis=0, weights=obs_weights)
obs_new_lat = float(obs_new_lat)
obs_new_lon = float(obs_new_lon)
obs_max_lat, obs_max_lon = obs_positions.max(axis=0)
obs_min_lat, obs_min_lon = obs_positions.min(axis=0)
obs_box_dist = distance(obs_min_lat, obs_min_lon,
obs_max_lat, obs_max_lon)
if obs_box_dist > self.max_dist_meters:
# the new observations are already too far apart
if not shard_station:
values.update({
'created': created,
'block_first': self.today,
'block_last': self.today,
'block_count': 1,
})
return ('new_moving', values)
else:
block_count = shard_station.block_count or 0
values.update({
'lat': None,
'lon': None,
'max_lat': None,
'min_lat': None,
'max_lon': None,
'min_lon': None,
'radius': None,
'region': shard_station.region,
'samples': None,
'source': None,
'weight': None,
'block_first': shard_station.block_first or self.today,
'block_last': self.today,
'block_count': block_count + 1,
})
return ('moving', values)
if shard_station is None:
# totally new station, only agreeing observations
radius = circle_radius(
obs_new_lat, obs_new_lon,
obs_max_lat, obs_max_lon, obs_min_lat, obs_min_lon)
values.update({
'created': created,
'lat': obs_new_lat,
'lon': obs_new_lon,
'max_lat': float(obs_max_lat),
'min_lat': float(obs_min_lat),
'max_lon': float(obs_max_lon),
'min_lon': float(obs_min_lon),
'radius': radius,
'region': GEOCODER.region(obs_new_lat, obs_new_lon),
'samples': obs_length,
'source': None,
'weight': obs_weight,
})
return ('new', values)
else:
# shard_station + new observations
positions = numpy.append(obs_positions, [
(numpy.nan if shard_station.lat is None
else shard_station.lat,
numpy.nan if shard_station.lon is None
else shard_station.lon),
(numpy.nan if shard_station.max_lat is None
else shard_station.max_lat,
numpy.nan if shard_station.max_lon is None
else shard_station.max_lon),
(numpy.nan if shard_station.min_lat is None
#.........这里部分代码省略.........