-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdist.pyx
More file actions
78 lines (66 loc) · 2.49 KB
/
Copy pathdist.pyx
File metadata and controls
78 lines (66 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""
===================
Distance Calculator
===================
Implemented by Juan Chacon @ UNESCO-IHE
Integrated Water Systems and Governance Department
Hydroinformatics Laboratory
This library contains utilities to calculate euclidean distances between \
stations, and with respect to a pre-defined target.
* Pre requisites
you will need the following libraries, not coming alongside with the \
Anaconda ditribution (recommended)
* Functions
*between: Calculates the geometric distance between a series of points.
*target: Calculate the geometric distance to a target, from different \
points.
* Use policy
* You should include the respective citation to the authors
* If you find this tool usefull, you will give the main author a beer next\
time you see him :)
* References
"""
f = 'initialise'
import numpy
def between(stations):
'''
Calculates the distance between stations.
Parameters
----------
stations : array_like, shape ``(n,2)``
Vector with `x,y` coordinates of measurement stations
Returns
-------
result_distance : array_like ``(n,n)``
Matrix of size "[n,n]" with distance between stations
'''
# Calculate distances between stations
result_distance = numpy.zeros((len(stations),len(stations)))
for i in xrange(0,len(stations)):
for j in xrange(0,len(stations)):
result_distance[i][j] = numpy.sqrt((stations[i][0]-stations[j][0])**2 +
(stations[i][1]-stations[j][1])**2 )
return result_distance
def target(stations, targets):
'''
Calculates the distance between stations and targets
Parameters
----------
stations : array_like, shape ``(n,2)``
Vector with `x,y` coordinates of measurement stations.
targets : array_like, shape ``(m,2)``
Vector with `x,y` coordinates of targets.
Returns
-------
result_distance : ndarray, shape ``(n,m)``
Matrix with distance between stations to targets.
'''
# Calculate distances between stations and targetsgets
result_distance = numpy.zeros((len(targets),len(stations)))
for i in xrange(0,len(targets)):
for j in xrange(0,len(stations)):
# Calculate distance from target to stations
result_distance[i][j] = numpy.sqrt((targets[i][0]-stations[j][0])**2 +
(targets[i][1]-stations[j][1])**2 )
return result_distance