How To Map An Animal's Path From Locations Time In Python
One fascinating area of research uses GPS to track the movements of animals. It is at present possible to manufacture a small GPS device that is solar charged, then you don't need to change batteries and employ it to rail flying patterns of birds.
The data for this case written report comes from the LifeWatch INBO projection. Several information sets take been released every bit part of this project. Nosotros will use a small information set that consists of migration data for iii gulls named Eric, Nico, and Sanne. The official_datasets; used dataset – CSV">csv file contains eight columns and includes variables like latitude, longitude, distance, and time stamps. In this instance written report, we will commencement load the data, visualize some simple flight trajectories, track flight speed, learn nearly daytime, and much, much more.
Aim: Track the movement of three gulls namely – Eric, Nico & Sanne
Dataset: official_datasets; used dataset – csv
Dependencies: Matplotlib, Pandas, Numpy, Cartopy, Shapely
Repository(Github): source code
(check the repository for the documentation of source lawmaking.)
Writeup: explanation(.pdf)
We will split up our example study into five parts:
1. Visualizing longitude and latitude information of the gulls.
2. Visualize the variation of the speed of the gulls.
3. Visualize the time required past the gulls to comprehend equal distances over the journeying.
4. Visualize the daily mean speed of the gulls.
5. Cartographic view of the journey of the gulls.
Role (ane/5): Breadth and Longitude
In this role, we are going to visualize the location of the birds. We are going to plot breadth and longitude along the y and 10-axis respectively and visualize the location information present in the csv file.
Python
import
pandas as pd
import
matplotlib.pyplot as plt
import
numpy as np
birddata
=
pd.read_csv(
"bird_tracking.csv"
)
bird_names
=
pd.unique(birddata.bird_name)
9
=
birddata.bird_name
=
=
"Eric"
x,y
=
birddata.longitude[ix], birddata.latitude[ix]
plt.effigy(figsize
=
(
seven
,
7
))
plt.plot(ten,y,
"b."
)
plt.figure(figsize
=
(
seven
,
7
))
for
bird_name
in
bird_names:
ix
=
birddata.bird_name
=
=
bird_name
x,y
=
birddata.longitude[ix], birddata.latitude[ix]
plt.plot(10,y,
"."
, label
=
bird_name)
plt.xlabel(
"Longitude"
)
plt.ylabel(
"Breadth"
)
plt.legend(loc
=
"lower right"
)
plt.show()
plt.figure(figsize = (7,vii)) plt.plot(x,y,"b.")
We use the matplotlib part, figure() to initialize size of the figure as 7 x 7 and plot it using the plot() part.The parameters within the role plot() i.e 10, y and "b." are specifying to use longitude information along x axis(for x), breadth along y(for y) and b=blue, . = circles in the visualization.
Output : You must have all the dependencies.Install them using "pip install dependency_name"
Office (ii/five): 2D Speed Vs Frequency
In this 2d role of the case study, we are going to visualize 2d speed vs Frequency for the gull named "Eric".
Python
import
pandas as pd
import
matplotlib.pyplot as plt
import
numpy as np
birddata
=
pd.read_csv(
"bird_tracking.csv"
)
bird_names
=
pd.unique(birddata.bird_name)
9
=
birddata.bird_name
=
=
"Eric"
speed
=
birddata.speed_2d[nine]
plt.figure(figsize
=
(
8
,
4
))
ind
=
np.isnan(speed)
plt.hist(speed[~ind], bins
=
np.linspace(
0
,
30
,
20
), normed
=
True
)
plt.xlabel(
" 2D speed (m/s) "
)
plt.ylabel(
" Frequency "
)
plt.show()
ind = np.isnan(speed) plt.hist(speed[~ind], bins = np.linspace(0,30,20), normed=True) plt.xlabel(" 2d speed (m/southward) ") plt.ylabel(" Frequency ") plt.show()
The parameters speed[~ind] indicates that we will include simply those entries for which ind != True, bins=np.linspace(0,30,twenty) indicates the bins along the x-axis will vary from 0 to 30 with twenty bins inside them, linearly spaced. Lastly, we plot 2D speed in m/due south along the ten-axis and Frequency along the y-axis using the xlabel() and ylabel() functions respectively and plot the data using plt.bear witness().
Output :
PART (3/5): Fourth dimension and Appointment
The tertiary part is associated with date and time. We are going to visualize the time(in days) required by Eric to embrace abiding distances through his journey. If he covers equal distances in an equal corporeality of fourth dimension, and so the Elapsed time vs Observation curve will be linear.
Python
import
pandas every bit pd
import
matplotlib.pyplot as plt
import
datetime
import
numpy as np
birddata
=
pd.read_csv(
"bird_tracking.csv"
)
bird_names
=
pd.unique(birddata.bird_name)
timestamps
=
[]
for
chiliad
in
range
(
len
(birddata)):
timestamps.append(datetime.datetime.strptime(birddata.date_time.iloc[k][:
-
three
],
"%Y-%m-%d %H:%M:%S"
))
birddata[
"timestamp"
]
=
pd.Series(timestamps, index
=
birddata.alphabetize)
times
=
birddata.timestamp[birddata.bird_name
=
=
"Eric"
]
elapsed_time
=
[time
-
times[
0
]
for
time
in
times]
plt.plot(np.assortment(elapsed_time)
/
datetime.timedelta(days
=
1
))
plt.xlabel(
" Observation "
)
plt.ylabel(
" Elapsed time (days) "
)
plt.prove()
for k in range(len(birddata)): timestamps.suspend(datetime.datetime.strptime(birddata.date_time.iloc[thou][:-3], "%Y-%m-%d %H:%M:%S"))
">>>datetime.datetime.today()", returns the current Date (yy-mm-dd) & time (h:m:southward).
">>>date_str[:-3]", slices/removes the UTC +00 coordinated time stamps.
">>>datetime.datetime.strptime(date_str[:-3], "%Y-%grand-%d %H:%K:%S")" ,the time-postage stamp strings from date_str are converted to datetime object to exist worked upon. "%Y-%m-%d %H:%Yard:%S" is the Year-Calendar month-Date and Hour-Minute-Second format.
Output:
PART (iv/five): Daily Mean Speed
Nosotros are going to visualize the daily hateful speed of the gull named "Eric" for the total number of days of recorded flight.
Python
import
pandas as pd
import
matplotlib.pyplot every bit plt
import
datetime
import
numpy every bit np
birddata
=
pd.read_csv(
"bird_tracking.csv"
)
bird_names
=
pd.unique(birddata.bird_name)
timestamps
=
[]
for
m
in
range
(
len
(birddata)):
timestamps.suspend(datetime.datetime.strptime(birddata.date_time.iloc[k][:
-
3
],
"%Y-%grand-%d %H:%G:%Southward"
))
birddata[
"timestamp"
]
=
pd.Series(timestamps, alphabetize
=
birddata.index)
data
=
birddata[birddata.bird_name
=
=
"Eric"
]
times
=
information.timestamp
elapsed_time
=
[time
-
times[
0
]
for
time
in
times]
elapsed_days
=
np.array(elapsed_time)
/
datetime.timedelta(days
=
one
)
next_day
=
1
inds
=
[]
daily_mean_speed
=
[]
for
(i,t)
in
enumerate
(elapsed_days):
if
t < next_day:
inds.append(i)
else
:
daily_mean_speed.append(np.mean(information.speed_2d[inds]))
next_day
+
=
1
inds
=
[]
plt.figure(figsize
=
(
8
,
6
))
plt.plot(daily_mean_speed,
"rs-"
)
plt.xlabel(
" Day "
)
plt.ylabel(
" Mean Speed (m/s) "
);
plt.show()
enumerate() - is one of the built-in Python functions. It returns an enumerated object. In our case, that object is a list of tuples (immutable lists), each containing a pair of count/alphabetize and value.
Output:
Function (v/5): Cartographic View
In this last part, we are going to track the Birds over a map.
Python
import
pandas as pd
import
cartopy.crs as ccrs
import
cartopy.feature as cfeature
import
matplotlib.pyplot as plt
birddata
=
pd.read_csv(
"bird_tracking.csv"
)
bird_names
=
pd.unique(birddata.bird_name)
proj
=
ccrs.Mercator()
plt.figure(figsize
=
(
ten
,
10
))
ax
=
plt.axes(projection
=
proj)
ax.set_extent((
-
25.0
,
20.0
,
52.0
,
x.0
))
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.Ocean)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS, linestyle
=
':'
)
for
proper noun
in
bird_names:
nine
=
birddata[
'bird_name'
]
=
=
proper noun
x,y
=
birddata.longitude[nine], birddata.breadth[ix]
ax.plot(10,y,
'.'
, transform
=
ccrs.Geodetic(), label
=
name)
plt.legend(loc
=
"upper left"
)
plt.show()
import cartopy.crs as ccrs import cartopy.feature as cfeature
These modules are of import for mapping information.
ax.add_feature(cfeature.Country) ax.add_feature(cfeature.Ocean) ax.add_feature(cfeature.COASTLINE) ax.add_feature(cfeature.BORDERS, linestyle=':')
We add the salient physical features of a map.
Output:
Resources :
i. edX – HarvardX – Using Python for Enquiry
2. Python functions doc_I
3. Python functions doc_II
This article is contributed by Amartya Ranjan Saikia. If you like GeeksforGeeks and would like to contribute, y'all can also write an article using write.geeksforgeeks.org or mail your article to review-squad@geeksforgeeks.org. See your article appearing on the GeeksforGeeks primary page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more than information about the topic discussed above.
Source: https://www.geeksforgeeks.org/tracking-bird-migration-using-python-3/
Posted by: szaboswely1945.blogspot.com
0 Response to "How To Map An Animal's Path From Locations Time In Python"
Post a Comment