-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_radiance.py
78 lines (65 loc) · 1.93 KB
/
search_radiance.py
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
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from pymongo import WriteConcern
import json
import time
import dotenv
import os
import argparse
dotenv.load_dotenv()
uri = os.getenv("MONGODB_URI")
# Create a new client and connect to the server
client = MongoClient(uri, server_api=ServerApi('1'))
def main():
parser = argparse.ArgumentParser(description="Searches radiance data into the radiance collection.")
parser.add_argument('--lat', help="The Point latitude", type=float, required=True)
parser.add_argument('--lon', help="The Point longitude", type=float, required=True)
parser.add_argument('--dist', help="Maximum distance in meters", type=int, default=1000)
args = parser.parse_args()
# Get the database and collection
db = client.astroshoots
collection = db.radiance
filter = [
{
'$geoNear': {
'near': {
'type': 'Point',
'coordinates': [args.lat, args.lon]
},
'distanceField': 'distance',
'spherical': True,
'maxDistance': args.dist
}
},
{
'$match': {
'properties.Bortle': {
'$exists': True
}
}
},
{
'$sort': {
'distance': 1
}
},
{
'$group': {
'_id': None,
'meanBortle': {
'$avg': '$properties.Bortle'
},
'nearestDistance': {
'$first': '$distance'
},
'furthestDistance': {
'$last': '$distance'
},
}
}
]
result = client['astroshoots']['radiance'].aggregate(filter)
for doc in result:
print(doc)
if __name__ == '__main__':
main()