ebird-api 3.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ebird/api/__init__.py +51 -0
- ebird/api/checklists.py +97 -0
- ebird/api/client.py +338 -0
- ebird/api/constants.py +93 -0
- ebird/api/hotspots.py +143 -0
- ebird/api/observations.py +629 -0
- ebird/api/regions.py +109 -0
- ebird/api/statistics.py +86 -0
- ebird/api/taxonomy.py +181 -0
- ebird/api/utils.py +165 -0
- ebird/api/validation.py +329 -0
- ebird_api-3.0.6.dist-info/LICENSE.txt +21 -0
- ebird_api-3.0.6.dist-info/METADATA +321 -0
- ebird_api-3.0.6.dist-info/RECORD +16 -0
- ebird_api-3.0.6.dist-info/WHEEL +6 -0
- ebird_api-3.0.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
# pylint: disable=R0913,R0914
|
|
2
|
+
|
|
3
|
+
"""Functions for fetching information about what species have been seen."""
|
|
4
|
+
|
|
5
|
+
from ebird.api.utils import call
|
|
6
|
+
from ebird.api.validation import clean_areas, clean_locale, clean_back, clean_provisional, \
|
|
7
|
+
clean_hotspot, clean_detail, clean_categories, clean_max_observations, clean_lat, clean_lng, \
|
|
8
|
+
clean_dist, clean_sort
|
|
9
|
+
|
|
10
|
+
OBSERVATIONS_URL = 'https://ebird.org/ws2.0/data/obs/%s/recent'
|
|
11
|
+
NOTABLE_OBSERVATIONS_URL = 'https://ebird.org/ws2.0/data/obs/%s/recent/notable'
|
|
12
|
+
SPECIES_OBSERVATIONS_URL = 'https://ebird.org/ws2.0/data/obs/%s/recent/%s'
|
|
13
|
+
|
|
14
|
+
NEARBY_OBSERVATIONS_URL = 'https://ebird.org/ws2.0/data/obs/geo/recent'
|
|
15
|
+
NEARBY_NOTABLE_URL = 'https://ebird.org/ws2.0/data/obs/geo/recent/notable'
|
|
16
|
+
NEARBY_SPECIES_URL = 'https://ebird.org/ws2.0/data/obs/geo/recent/%s'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
NEAREST_SPECIES_URL = 'https://ebird.org/ws2.0/data/nearest/geo/recent/%s'
|
|
20
|
+
|
|
21
|
+
HISTORIC_OBSERVATIONS_URL = 'https://ebird.org/ws2.0/data/obs/%s/historic/%s'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_observations(token, area, back=14, max_results=None, locale='en',
|
|
25
|
+
provisional=False, hotspot=False, detail='simple',
|
|
26
|
+
category=None):
|
|
27
|
+
"""Get recent observations (up to 30 days ago) for a region or location.
|
|
28
|
+
|
|
29
|
+
The maps to the end point in the eBird API 2.0,
|
|
30
|
+
https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#3d2a17c1-2129-475c-b4c8-7d362d6000cd
|
|
31
|
+
|
|
32
|
+
:param token: the token needed to access the API.
|
|
33
|
+
|
|
34
|
+
:param area: a country, subnational1, subnational2 or location code
|
|
35
|
+
or a list of up to 10 codes. All codes must be same type.
|
|
36
|
+
|
|
37
|
+
:param back: the number of days in the past to include. Ranges from
|
|
38
|
+
1 to 30 with a default of 14 days.
|
|
39
|
+
|
|
40
|
+
:param max_results: the maximum number of observations to return from
|
|
41
|
+
1 to 10000. The default value is None which means all observations will
|
|
42
|
+
be returned.
|
|
43
|
+
|
|
44
|
+
:param locale: the language (to use) for the species common names. The
|
|
45
|
+
default of 'en' will use species names from the eBird/Clements checklist.
|
|
46
|
+
This can be any locale for which eBird has translations available. For a
|
|
47
|
+
complete list see, http://help.ebird.org/customer/portal/articles/1596582.
|
|
48
|
+
|
|
49
|
+
:param provisional: include records which have not yet been reviewed.
|
|
50
|
+
Either True or False, the default is False.
|
|
51
|
+
|
|
52
|
+
:param hotspot: return records only from hotspots, True or include both
|
|
53
|
+
hotspots and private locations, False (the default).
|
|
54
|
+
|
|
55
|
+
:param detail: return records in 'simple' or 'full' format. See the eBird
|
|
56
|
+
API documentation for a description of the fields.
|
|
57
|
+
|
|
58
|
+
:param category: one or more categories of species to return: 'domestic',
|
|
59
|
+
'form', 'hybrid', 'intergrade', 'issf', 'slash', 'species' or 'spuh'.
|
|
60
|
+
More than one value can be given in a comma-separated string. The default
|
|
61
|
+
value is None and records from all categories will be returned.
|
|
62
|
+
|
|
63
|
+
:return: the list of observations in simple format.
|
|
64
|
+
|
|
65
|
+
:raises ValueError: if any of the arguments fail the validation checks.
|
|
66
|
+
|
|
67
|
+
:raises URLError if there is an error with the connection to the
|
|
68
|
+
eBird site.
|
|
69
|
+
|
|
70
|
+
:raises HTTPError if the eBird API returns an error.
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
cleaned = clean_areas(area)
|
|
75
|
+
|
|
76
|
+
url = OBSERVATIONS_URL % cleaned[0]
|
|
77
|
+
|
|
78
|
+
params = {
|
|
79
|
+
'back': clean_back(back),
|
|
80
|
+
'maxObservations': clean_max_observations(max_results),
|
|
81
|
+
'sppLocale': clean_locale(locale),
|
|
82
|
+
'includeProvisional': clean_provisional(provisional),
|
|
83
|
+
'hotspot': clean_hotspot(hotspot),
|
|
84
|
+
'detail': clean_detail(detail),
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if category is not None:
|
|
88
|
+
params['cat'] = ','.join(clean_categories(category))
|
|
89
|
+
|
|
90
|
+
if len(cleaned) > 1:
|
|
91
|
+
params['r'] = ','.join(cleaned)
|
|
92
|
+
|
|
93
|
+
headers = {
|
|
94
|
+
'X-eBirdApiToken': token,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return call(url, params, headers)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def get_notable_observations(token, area, back=14, max_results=None, locale='en',
|
|
101
|
+
hotspot=False, detail='simple'):
|
|
102
|
+
"""Get recent observations of a rare species for a region or location
|
|
103
|
+
|
|
104
|
+
Get all the recent observations (up to 30 days ago) of species classes
|
|
105
|
+
as rare (locally or nationally) for a country, subnational1 region,
|
|
106
|
+
subnational2 region or location.
|
|
107
|
+
|
|
108
|
+
The maps to the end point in the eBird API 2.0,
|
|
109
|
+
https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#397b9b8c-4ab9-4136-baae-3ffa4e5b26e4
|
|
110
|
+
|
|
111
|
+
:param token: the token needed to access the API.
|
|
112
|
+
|
|
113
|
+
:param area: a country, subnational1, subnational2 or location code
|
|
114
|
+
or a list of up to 10 codes. All codes must be same type.
|
|
115
|
+
|
|
116
|
+
:param back: the number of days in the past to include. Ranges from
|
|
117
|
+
1 to 30 with a default of 14 days.
|
|
118
|
+
|
|
119
|
+
:param max_results: the maximum number of observations to return from
|
|
120
|
+
1 to 10000. The default value is None which means all observations will
|
|
121
|
+
be returned.
|
|
122
|
+
|
|
123
|
+
:param locale: the language (to use) for the species common names. The
|
|
124
|
+
default of 'en' will use species names from the eBird/Clements checklist.
|
|
125
|
+
This can be any locale for which eBird has translations available. For a
|
|
126
|
+
complete list see, http://help.ebird.org/customer/portal/articles/1596582.
|
|
127
|
+
|
|
128
|
+
:param hotspot: return records only from hotspots, True or include both
|
|
129
|
+
hotspots and private locations, False (the default).
|
|
130
|
+
|
|
131
|
+
:param detail: return records in 'simple' or 'full' format. See the eBird
|
|
132
|
+
API documentation for a description of the fields.
|
|
133
|
+
|
|
134
|
+
:return: the list of observations.
|
|
135
|
+
|
|
136
|
+
:raises ValueError: if any of the arguments fail the validation checks.
|
|
137
|
+
|
|
138
|
+
:raises URLError if there is an error with the connection to the
|
|
139
|
+
eBird site.
|
|
140
|
+
|
|
141
|
+
:raises HTTPError if the eBird API returns an error.
|
|
142
|
+
|
|
143
|
+
"""
|
|
144
|
+
cleaned = clean_areas(area)
|
|
145
|
+
|
|
146
|
+
url = NOTABLE_OBSERVATIONS_URL % cleaned[0]
|
|
147
|
+
|
|
148
|
+
params = {
|
|
149
|
+
'back': clean_back(back),
|
|
150
|
+
'maxObservations': clean_max_observations(max_results),
|
|
151
|
+
'sppLocale': clean_locale(locale),
|
|
152
|
+
'hotspot': clean_hotspot(hotspot),
|
|
153
|
+
'detail': clean_detail(detail),
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if len(cleaned) > 1:
|
|
157
|
+
params['r'] = ','.join(cleaned)
|
|
158
|
+
|
|
159
|
+
headers = {
|
|
160
|
+
'X-eBirdApiToken': token,
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return call(url, params, headers)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def get_species_observations(token, species, area, back=14, max_results=None, locale='en',
|
|
167
|
+
provisional=False, hotspot=False, detail='simple', category=None):
|
|
168
|
+
"""Get recent observations for a given species in a region.
|
|
169
|
+
|
|
170
|
+
Get all the recent observations (up to 30 days ago) for a species
|
|
171
|
+
in a given region.
|
|
172
|
+
|
|
173
|
+
The maps to the end point in the eBird API 2.0,
|
|
174
|
+
https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#755ce9ab-dc27-4cfc-953f-c69fb0f282d9
|
|
175
|
+
|
|
176
|
+
:param token: the token needed to access the API.
|
|
177
|
+
|
|
178
|
+
:param species: the scientific name of the species.
|
|
179
|
+
|
|
180
|
+
:param area: a country, subnational1, subnational2 or location code
|
|
181
|
+
or a list of up to 10 codes. All codes must be same type.
|
|
182
|
+
|
|
183
|
+
:param back: the number of days in the past to include. Ranges from
|
|
184
|
+
1 to 30 with a default of 14 days.
|
|
185
|
+
|
|
186
|
+
:param max_results: the maximum number of observations to return from
|
|
187
|
+
1 to 10000. The default value is None which means all observations will
|
|
188
|
+
be returned.
|
|
189
|
+
|
|
190
|
+
:param locale: the language (to use) for the species common names. The
|
|
191
|
+
default of 'en' will use species names from the eBird/Clements checklist.
|
|
192
|
+
This can be any locale for which eBird has translations available. For a
|
|
193
|
+
complete list see, http://help.ebird.org/customer/portal/articles/1596582.
|
|
194
|
+
|
|
195
|
+
:param provisional: include records which have not yet been reviewed.
|
|
196
|
+
Either True or False, the default is False.
|
|
197
|
+
|
|
198
|
+
:param hotspot: return records only from hotspots, True or include both
|
|
199
|
+
hotspots and private locations, False (the default).
|
|
200
|
+
|
|
201
|
+
:param detail: return records in 'simple' or 'full' format. See the eBird
|
|
202
|
+
API documentation for a description of the fields.
|
|
203
|
+
|
|
204
|
+
:param category: one or more categories of species to return: 'domestic',
|
|
205
|
+
'form', 'hybrid', 'intergrade', 'issf', 'slash', 'species' or 'spuh'.
|
|
206
|
+
More than one value can be given in a comma-separated string. The default
|
|
207
|
+
value is None and records from all categories will be returned. It's not clear
|
|
208
|
+
what the purpose of this parameter is given the species is being specified.
|
|
209
|
+
It is not documented on the eBird API page but it is supported by the code.
|
|
210
|
+
|
|
211
|
+
:return: the list of observations in simple format.
|
|
212
|
+
|
|
213
|
+
:raises ValueError: if any of the arguments fail the validation checks.
|
|
214
|
+
|
|
215
|
+
:raises URLError if there is an error with the connection to the
|
|
216
|
+
eBird site.
|
|
217
|
+
|
|
218
|
+
:raises HTTPError if the eBird API returns an error.
|
|
219
|
+
|
|
220
|
+
"""
|
|
221
|
+
cleaned = clean_areas(area)
|
|
222
|
+
|
|
223
|
+
url = SPECIES_OBSERVATIONS_URL % (cleaned[0], species)
|
|
224
|
+
|
|
225
|
+
params = {
|
|
226
|
+
'back': clean_back(back),
|
|
227
|
+
'maxObservations': clean_max_observations(max_results),
|
|
228
|
+
'sppLocale': clean_locale(locale),
|
|
229
|
+
'includeProvisional': clean_provisional(provisional),
|
|
230
|
+
'hotspot': clean_hotspot(hotspot),
|
|
231
|
+
'detail': clean_detail(detail),
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if category is not None:
|
|
235
|
+
params['cat'] = ','.join(clean_categories(category))
|
|
236
|
+
|
|
237
|
+
if len(cleaned) > 1:
|
|
238
|
+
params['r'] = ','.join(cleaned)
|
|
239
|
+
|
|
240
|
+
headers = {
|
|
241
|
+
'X-eBirdApiToken': token,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return call(url, params, headers)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def get_nearby_observations(token, lat, lng, dist=25, back=14, max_results=None,
|
|
248
|
+
locale='en', provisional=False, hotspot=False, category=None,
|
|
249
|
+
sort='date'):
|
|
250
|
+
"""Get nearby recent observations of each species.
|
|
251
|
+
|
|
252
|
+
Get recent observations (up to 30 days ago) of each species from all
|
|
253
|
+
locations in an area centered on a set of coordinates (latitude,
|
|
254
|
+
longitude) and optional distance (up to 50km away, with a default
|
|
255
|
+
distance of 25km).
|
|
256
|
+
|
|
257
|
+
NOTE: Only the most recent record of each species is returned.
|
|
258
|
+
|
|
259
|
+
The maps to the end point in the eBird API 1.1,
|
|
260
|
+
https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#62b5ffb3-006e-4e8a-8e50-21d90d036edc
|
|
261
|
+
|
|
262
|
+
:param token: the token needed to access the API.
|
|
263
|
+
|
|
264
|
+
:param lat: the latitude, which will be rounded to 2 decimal places.
|
|
265
|
+
|
|
266
|
+
:param lng: the longitude, which will be rounded to 2 decimal places.
|
|
267
|
+
|
|
268
|
+
:param dist: include all sites within this distance, from 0 to 50km
|
|
269
|
+
with a default of 25km.
|
|
270
|
+
|
|
271
|
+
:param back: the number of days in the past to include. Ranges from
|
|
272
|
+
1 to 30 with a default of 14 days.
|
|
273
|
+
|
|
274
|
+
:param max_results: the maximum number of observations to return from
|
|
275
|
+
1 to 10000. The default value is None which means all observations will
|
|
276
|
+
be returned.
|
|
277
|
+
|
|
278
|
+
:param locale: the language (to use) for the species common names. The
|
|
279
|
+
default of 'en_US' will use species names from the eBird/Clements checklist.
|
|
280
|
+
This can be any locale for which eBird has translations available. For a
|
|
281
|
+
complete list see, http://help.ebird.org/customer/portal/articles/1596582.
|
|
282
|
+
|
|
283
|
+
:param provisional: include records which have not yet been reviewed.
|
|
284
|
+
Either True or False, the default is False.
|
|
285
|
+
|
|
286
|
+
:param hotspot: get only observations from hotspots, in other words
|
|
287
|
+
exclude private locations. The default is False so observations will
|
|
288
|
+
be returned from all locations.
|
|
289
|
+
|
|
290
|
+
:param category: one or more categories of species to return: 'domestic',
|
|
291
|
+
'form', 'hybrid', 'intergrade', 'issf', 'slash', 'species' or 'spuh'.
|
|
292
|
+
More than one value can be given in a comma-separated string. The default
|
|
293
|
+
value is None and records from all categories will be returned.
|
|
294
|
+
|
|
295
|
+
:param sort: return the records sorted by date, 'date' or taxonomy, 'species'.
|
|
296
|
+
|
|
297
|
+
:return: the list of observations in simple format.
|
|
298
|
+
|
|
299
|
+
:raises ValueError: if any of the arguments fail the validation checks.
|
|
300
|
+
|
|
301
|
+
:raises URLError if there is an error with the connection to the
|
|
302
|
+
eBird site.
|
|
303
|
+
|
|
304
|
+
:raises HTTPError if the eBird API returns an error.
|
|
305
|
+
|
|
306
|
+
"""
|
|
307
|
+
params = {
|
|
308
|
+
'lat': clean_lat(lat),
|
|
309
|
+
'lng': clean_lng(lng),
|
|
310
|
+
'dist': clean_dist(dist),
|
|
311
|
+
'back': clean_back(back),
|
|
312
|
+
'maxObservations': clean_max_observations(max_results),
|
|
313
|
+
'sppLocale': clean_locale(locale),
|
|
314
|
+
'includeProvisional': clean_provisional(provisional),
|
|
315
|
+
'hotspot': clean_hotspot(hotspot),
|
|
316
|
+
'sort': clean_sort(sort),
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if category is not None:
|
|
320
|
+
params['cat'] = ','.join(clean_categories(category))
|
|
321
|
+
|
|
322
|
+
headers = {
|
|
323
|
+
'X-eBirdApiToken': token,
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return call(NEARBY_OBSERVATIONS_URL, params, headers)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def get_nearby_species(token, species, lat, lng, dist=25, back=14, max_results=None,
|
|
330
|
+
locale='en', provisional=False, hotspot=False, category=None):
|
|
331
|
+
"""Get most recent observation of a species nearby.
|
|
332
|
+
|
|
333
|
+
Get the most recent observation (up to 30 days ago) for a species seen at
|
|
334
|
+
any locations in an area centered on a set of coordinates (latitude,
|
|
335
|
+
longitude) and optional distance (up to 50km away).
|
|
336
|
+
|
|
337
|
+
The maps to the end point in the eBird API 1.1,
|
|
338
|
+
https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#20fb2c3b-ee7f-49ae-a912-9c3f16a40397
|
|
339
|
+
|
|
340
|
+
:param token: the token needed to access the API.
|
|
341
|
+
|
|
342
|
+
:param species: the scientific name of the species.
|
|
343
|
+
|
|
344
|
+
:param lat: the latitude, which will be rounded to 2 decimal places.
|
|
345
|
+
|
|
346
|
+
:param lng: the longitude, which will be rounded to 2 decimal places.
|
|
347
|
+
|
|
348
|
+
:param dist: include all sites within this distance, from 0 to 50km
|
|
349
|
+
with a default of 25km.
|
|
350
|
+
|
|
351
|
+
:param back: the number of days in the past to include. Ranges from
|
|
352
|
+
1 to 30 with a default of 14 days.
|
|
353
|
+
|
|
354
|
+
:param max_results: the maximum number of observations to return from
|
|
355
|
+
1 to 10000. The default value is None which means all observations will
|
|
356
|
+
be returned.
|
|
357
|
+
|
|
358
|
+
:param locale: the language (to use) for the species common names. The
|
|
359
|
+
default of 'en_US' will use species names from the eBird/Clements checklist.
|
|
360
|
+
This can be any locale for which eBird has translations available. For a
|
|
361
|
+
complete list see, http://help.ebird.org/customer/portal/articles/1596582.
|
|
362
|
+
|
|
363
|
+
:param provisional: include records which have not yet been reviewed.
|
|
364
|
+
Either True or False, the default is False.
|
|
365
|
+
|
|
366
|
+
:param hotspot: get only observations from hotspots, in other words exclude
|
|
367
|
+
private locations. The default is False so observations will be returned from
|
|
368
|
+
all locations.
|
|
369
|
+
|
|
370
|
+
:param category: one or more categories of species to return: 'domestic',
|
|
371
|
+
'form', 'hybrid', 'intergrade', 'issf', 'slash', 'species' or 'spuh'.
|
|
372
|
+
More than one value can be given in a comma-separated string. The default
|
|
373
|
+
value is None and records from all categories will be returned. It's not
|
|
374
|
+
clear what the purpose of this parameter is given the species is being
|
|
375
|
+
specified. It is not documented on the eBird API page but it is supported
|
|
376
|
+
by the code.
|
|
377
|
+
|
|
378
|
+
:return: the list of observations in 'simple' form. See the eBird API
|
|
379
|
+
documentation for a description of the fields.
|
|
380
|
+
|
|
381
|
+
:raises ValueError: if any of the arguments fail the validation checks.
|
|
382
|
+
|
|
383
|
+
:raises URLError if there is an error with the connection to the
|
|
384
|
+
eBird site.
|
|
385
|
+
|
|
386
|
+
:raises HTTPError if the eBird API returns an error.
|
|
387
|
+
|
|
388
|
+
"""
|
|
389
|
+
url = NEARBY_SPECIES_URL % species
|
|
390
|
+
|
|
391
|
+
params = {
|
|
392
|
+
'lat': clean_lat(lat),
|
|
393
|
+
'lng': clean_lng(lng),
|
|
394
|
+
'dist': clean_dist(dist),
|
|
395
|
+
'back': clean_back(back),
|
|
396
|
+
'maxObservations': clean_max_observations(max_results),
|
|
397
|
+
'sppLocale': clean_locale(locale),
|
|
398
|
+
'includeProvisional': clean_provisional(provisional),
|
|
399
|
+
'hotspot': clean_hotspot(hotspot),
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if category is not None:
|
|
403
|
+
params['cat'] = ','.join(clean_categories(category))
|
|
404
|
+
|
|
405
|
+
headers = {
|
|
406
|
+
'X-eBirdApiToken': token,
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return call(url, params, headers)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def get_nearby_notable(token, lat, lng, dist=25, back=14, max_results=None, locale='en',
|
|
413
|
+
hotspot=False, detail='simple'):
|
|
414
|
+
"""Get the nearby, recent observations of rare species.
|
|
415
|
+
|
|
416
|
+
Get all the recent observations (up to 30 days ago) for a species seen at
|
|
417
|
+
locations in an area centered on a set of coordinates (latitude, longitude)
|
|
418
|
+
and optional distance (up to 50km away) which are locally or nationally
|
|
419
|
+
rare.
|
|
420
|
+
|
|
421
|
+
The maps to the end point in the eBird API 2.0,
|
|
422
|
+
https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#caa348bb-71f6-471c-b203-9e1643377cbc
|
|
423
|
+
|
|
424
|
+
:param token: the token needed to access the API.
|
|
425
|
+
|
|
426
|
+
:param lat: the latitude, which will be rounded to 2 decimal places.
|
|
427
|
+
|
|
428
|
+
:param lng: the longitude, which will be rounded to 2 decimal places.
|
|
429
|
+
|
|
430
|
+
:param dist: include all sites within this distance, from 0 to 50km
|
|
431
|
+
with a default of 25km.
|
|
432
|
+
|
|
433
|
+
:param back: the number of days in the past to include. Ranges from
|
|
434
|
+
1 to 30 with a default of 14 days.
|
|
435
|
+
|
|
436
|
+
:param max_results: the maximum number of observations to return from
|
|
437
|
+
1 to 10000. The default value is None which means all observations will
|
|
438
|
+
be returned.
|
|
439
|
+
|
|
440
|
+
:param locale: the language (to use) for the species common names. The
|
|
441
|
+
default of 'en_US' will use species names from the eBird/Clements checklist.
|
|
442
|
+
This can be any locale for which eBird has translations available. For a
|
|
443
|
+
complete list see, http://help.ebird.org/customer/portal/articles/1596582.
|
|
444
|
+
|
|
445
|
+
:param hotspot: get only observations from hotspots, in other words
|
|
446
|
+
exclude private locations. The default is False so observations will be
|
|
447
|
+
returned from all locations.
|
|
448
|
+
|
|
449
|
+
:param detail: return records in 'simple' or 'full' format. See the eBird
|
|
450
|
+
API documentation for a description of the fields.
|
|
451
|
+
|
|
452
|
+
:return: the list of observations.
|
|
453
|
+
|
|
454
|
+
:raises ValueError: if any of the arguments fail the validation checks.
|
|
455
|
+
|
|
456
|
+
:raises URLError if there is an error with the connection to the
|
|
457
|
+
eBird site.
|
|
458
|
+
|
|
459
|
+
:raises HTTPError if the eBird API returns an error.
|
|
460
|
+
|
|
461
|
+
"""
|
|
462
|
+
params = {
|
|
463
|
+
'lat': clean_lat(lat),
|
|
464
|
+
'lng': clean_lng(lng),
|
|
465
|
+
'dist': clean_dist(dist),
|
|
466
|
+
'back': clean_back(back),
|
|
467
|
+
'maxObservations': clean_max_observations(max_results),
|
|
468
|
+
'sppLocale': clean_locale(locale),
|
|
469
|
+
'hotspot': clean_hotspot(hotspot),
|
|
470
|
+
'detail': clean_detail(detail),
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
headers = {
|
|
474
|
+
'X-eBirdApiToken': token,
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return call(NEARBY_NOTABLE_URL, params, headers)
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def get_nearest_species(token, species, lat, lng, dist=25, back=14, max_results=None,
|
|
481
|
+
locale='en', provisional=False, hotspot=False):
|
|
482
|
+
"""Get the nearest, recent, observations of a species.
|
|
483
|
+
|
|
484
|
+
Get the recent observations (up to 30 days ago) for a species seen at
|
|
485
|
+
locations closest to a set of coordinates (latitude, longitude).
|
|
486
|
+
|
|
487
|
+
IMPORTANT: As of 2019-05-27 the dist parameter does not appear to be
|
|
488
|
+
respected and so this call will return records from anywhere the
|
|
489
|
+
specified species are reported. Also the English common name for the
|
|
490
|
+
species is always returned regardless of which locale is specified.
|
|
491
|
+
|
|
492
|
+
The maps to the end point in the eBird API 1.1,
|
|
493
|
+
https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#6bded97f-9997-477f-ab2f-94f254954ccb
|
|
494
|
+
|
|
495
|
+
:param token: the token needed to access the API.
|
|
496
|
+
|
|
497
|
+
:param species: the scientific name of the species.
|
|
498
|
+
|
|
499
|
+
:param lat: the latitude, which will be rounded to 2 decimal places.
|
|
500
|
+
|
|
501
|
+
:param lng: the longitude, which will be rounded to 2 decimal places.
|
|
502
|
+
|
|
503
|
+
:param dist: include all sites within this distance, from 0 to 50km
|
|
504
|
+
with a default of 25km.
|
|
505
|
+
|
|
506
|
+
:param back: the number of days in the past to include. Ranges from
|
|
507
|
+
1 to 30 with a default of 14 days.
|
|
508
|
+
|
|
509
|
+
:param max_results: the maximum number of observations to return from
|
|
510
|
+
1 to 1000. The default value is None which means all observations will
|
|
511
|
+
be returned.
|
|
512
|
+
|
|
513
|
+
:param locale: the language (to use) for the species common names. The
|
|
514
|
+
default of 'en_US' will use species names from the eBird/Clements checklist.
|
|
515
|
+
This can be any locale for which eBird has translations available. For a
|
|
516
|
+
complete list see, http://help.ebird.org/customer/portal/articles/1596582.
|
|
517
|
+
|
|
518
|
+
:param provisional: include records which have not yet been reviewed.
|
|
519
|
+
Either True or False, the default is False.
|
|
520
|
+
|
|
521
|
+
:param hotspot: get only observations from hotspots, in other words
|
|
522
|
+
exclude private locations. The default is False so observations will
|
|
523
|
+
be returned from all locations.
|
|
524
|
+
|
|
525
|
+
:return: the list of observations in 'simple' form. See the eBird API
|
|
526
|
+
documentation for a description of the fields.
|
|
527
|
+
|
|
528
|
+
:raises ValueError: if any of the arguments fail the validation checks.
|
|
529
|
+
|
|
530
|
+
:raises URLError if there is an error with the connection to the
|
|
531
|
+
eBird site.
|
|
532
|
+
|
|
533
|
+
:raises HTTPError if the eBird API returns an error.
|
|
534
|
+
|
|
535
|
+
"""
|
|
536
|
+
url = NEAREST_SPECIES_URL % species
|
|
537
|
+
|
|
538
|
+
params = {
|
|
539
|
+
'lat': clean_lat(lat),
|
|
540
|
+
'lng': clean_lng(lng),
|
|
541
|
+
'back': clean_back(back),
|
|
542
|
+
'dist': clean_dist(dist),
|
|
543
|
+
'maxObservations': clean_max_observations(max_results),
|
|
544
|
+
'sppLocale': clean_locale(locale),
|
|
545
|
+
'includeProvisional': clean_provisional(provisional),
|
|
546
|
+
'hotspot': clean_hotspot(hotspot),
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
headers = {
|
|
550
|
+
'X-eBirdApiToken': token,
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
return call(url, params, headers)
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
def get_historic_observations(token, area, date, max_results=None, locale='en',
|
|
557
|
+
provisional=False, hotspot=False, detail='simple',
|
|
558
|
+
category=None):
|
|
559
|
+
"""Get recent observations for a region.
|
|
560
|
+
|
|
561
|
+
Get all the recent observations (up to 30 days ago) for a region.
|
|
562
|
+
|
|
563
|
+
The maps to the end point in the eBird API 2.0,
|
|
564
|
+
https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#2d8c6ee8-c435-4e91-9f66-6d3eeb09edd2
|
|
565
|
+
|
|
566
|
+
:param token: the token needed to access the API.
|
|
567
|
+
|
|
568
|
+
:param area: a country, subnational1, subnational2 or location code
|
|
569
|
+
or a list of up to 10 codes. All codes must be same type.
|
|
570
|
+
|
|
571
|
+
:param date: the date, since Jan 1st 1800.
|
|
572
|
+
|
|
573
|
+
:param max_results: the maximum number of observations to return from
|
|
574
|
+
1 to 10000. The default value is None which means all observations will
|
|
575
|
+
be returned.
|
|
576
|
+
|
|
577
|
+
:param locale: the language (to use) for the species common names. The
|
|
578
|
+
default of 'en_US' will use species names from the eBird/Clements checklist.
|
|
579
|
+
This can be any locale for which eBird has translations available. For a
|
|
580
|
+
complete list see, http://help.ebird.org/customer/portal/articles/1596582.
|
|
581
|
+
|
|
582
|
+
:param provisional: include records which have not yet been reviewed.
|
|
583
|
+
Either True or False, the default is False.
|
|
584
|
+
|
|
585
|
+
:param hotspot: return records only from hotspots, True or include both
|
|
586
|
+
hotspots and private locations, False (the default).
|
|
587
|
+
|
|
588
|
+
:param detail: return records in 'simple' or 'full' format. See the
|
|
589
|
+
eBird API documentation for a description of the fields.
|
|
590
|
+
|
|
591
|
+
:param category: one or more categories of species to return: 'domestic',
|
|
592
|
+
'form', 'hybrid', 'intergrade', 'issf', 'slash', 'species' or 'spuh'.
|
|
593
|
+
More than one value can be given in a comma-separated string. The default
|
|
594
|
+
value is None and records from all categories will be returned.
|
|
595
|
+
|
|
596
|
+
:return: the list of observations in simple format.
|
|
597
|
+
|
|
598
|
+
:raises ValueError: if any of the arguments fail the validation checks.
|
|
599
|
+
|
|
600
|
+
:raises URLError if there is an error with the connection to the
|
|
601
|
+
eBird site.
|
|
602
|
+
|
|
603
|
+
:raises HTTPError if the eBird API returns an error.
|
|
604
|
+
|
|
605
|
+
"""
|
|
606
|
+
cleaned = clean_areas(area)
|
|
607
|
+
|
|
608
|
+
url = HISTORIC_OBSERVATIONS_URL % (cleaned[0], date.strftime('%Y/%m/%d'))
|
|
609
|
+
|
|
610
|
+
params = {
|
|
611
|
+
'rank': 'mrec',
|
|
612
|
+
'detail': clean_detail(detail),
|
|
613
|
+
'sppLocale': clean_locale(locale),
|
|
614
|
+
'includeProvisional': clean_provisional(provisional),
|
|
615
|
+
'hotspot': clean_hotspot(hotspot),
|
|
616
|
+
'maxObservations': clean_max_observations(max_results),
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if len(cleaned) > 1:
|
|
620
|
+
params['r'] = ','.join(cleaned)
|
|
621
|
+
|
|
622
|
+
if category is not None:
|
|
623
|
+
params['cat'] = ','.join(clean_categories(category))
|
|
624
|
+
|
|
625
|
+
headers = {
|
|
626
|
+
'X-eBirdApiToken': token,
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
return call(url, params, headers)
|