Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jigyasa Watwani
/
growth-pattern-control
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a4b8cfc4
authored
Jan 08, 2024
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code to plot movies from the data, find perimeter and long axis
parent
089ebb16
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
0 deletions
convergence_extension/perimeter_long_axis.py
convergence_extension/perimeter_long_axis.py
0 → 100644
View file @
a4b8cfc4
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
from
matplotlib.widgets
import
Slider
def
perimeter
(
X
,
Y
,
n
):
# Initialize perimeter
perimeter
=
0
# Calculate distance between each pair of consecutive points
for
j
in
range
(
n
):
# Get current point
x1
,
y1
=
X
[
j
],
Y
[
j
]
# Get next point (if i is the last index, get the first point)
if
j
==
n
-
1
:
x2
,
y2
=
X
[
0
],
Y
[
0
]
else
:
x2
,
y2
=
X
[
j
+
1
],
Y
[
j
+
1
]
# Calculate distance between points and add to perimeter
perimeter
+=
np
.
sqrt
((
x2
-
x1
)
**
2
+
(
y2
-
y1
)
**
2
)
return
perimeter
def
long_axis
(
x
,
y
):
x_diff
=
x
[:,
None
]
-
x
y_diff
=
y
[:,
None
]
-
y
distances
=
np
.
sqrt
(
x_diff
**
2
+
y_diff
**
2
)
return
np
.
max
(
distances
)
# NOTE: check perimeter and long_axis functions on known shapes
# x = np.array([0, 1, 0, -1])
# y = np.array([2, 0, -2, 0])
# print(x, y)
# print(long_axis(x, y))
# raise SystemExit
file
=
np
.
loadtxt
(
'xy_coordinates_movie1.txt'
)
number_of_pixels
=
file
.
shape
[
0
]
time_points
=
file
.
shape
[
1
]
time_array
=
np
.
arange
(
0
,
5
*
int
(
time_points
/
2
),
5
)
# x, y coordinates from data
x
,
y
=
np
.
zeros
((
number_of_pixels
,
int
(
time_points
/
2
))),
np
.
zeros
((
number_of_pixels
,
int
(
time_points
/
2
)))
for
i
in
range
(
0
,
int
(
time_points
/
2
)):
x
[:,
i
]
=
file
[:,
2
*
i
]
y
[:,
i
]
=
file
[:,
2
*
i
+
1
]
# Interpolate a value to replace NaN based on its neighbors
x
=
pd
.
DataFrame
(
x
)
x
=
np
.
array
(
x
.
interpolate
(
method
=
'linear'
,
axis
=
0
,
limit_direction
=
'both'
))
y
=
pd
.
DataFrame
(
y
)
y
=
np
.
array
(
y
.
interpolate
(
method
=
'linear'
,
axis
=
0
,
limit_direction
=
'both'
))
# x, y = (time x pixels)
x
=
x
.
T
y
=
y
.
T
# make movie of the contours
fig
,
ax
=
plt
.
subplots
(
1
,
1
,
sharex
=
True
,
figsize
=
(
8
,
8
))
ax
.
set_xlabel
(
r'$x$'
)
ax
.
set_xlim
(
np
.
min
(
x
),
np
.
max
(
x
))
ax
.
set_ylim
(
np
.
min
(
y
),
np
.
max
(
y
))
ax
.
set_ylabel
(
r'$y$'
)
outlineplot
,
=
ax
.
plot
(
x
[
0
],
y
[
0
],
marker
=
'o'
,
ms
=
3
,
linestyle
=
'None'
)
def
update
(
value
):
ti
=
np
.
abs
(
time_array
-
value
)
.
argmin
()
outlineplot
.
set_ydata
(
y
[
ti
])
outlineplot
.
set_xdata
(
x
[
ti
])
plt
.
draw
()
sax
=
plt
.
axes
([
0.1
,
0.92
,
0.7
,
0.02
])
slider
=
Slider
(
sax
,
r'$t/\tau$'
,
min
(
time_array
),
max
(
time_array
),
valinit
=
min
(
time_array
),
valfmt
=
'
%3.1
f'
,
fc
=
'#999999'
)
slider
.
drawon
=
False
slider
.
on_changed
(
update
)
plt
.
show
()
# find the long axis
long_axis_array
=
np
.
zeros
(
int
(
time_points
/
2
))
for
k
in
range
(
0
,
int
(
time_points
/
2
)):
long_axis_array
[
k
]
=
long_axis
(
x
[
k
],
y
[
k
])
plt
.
plot
(
time_array
,
long_axis_array
,
marker
=
'o'
,
linestyle
=
'None'
)
plt
.
xlabel
(
'Time'
)
plt
.
ylabel
(
'Length of the long axis'
)
plt
.
show
()
# find the perimeter
perimeter_array
=
np
.
zeros
(
int
(
time_points
/
2
))
for
k
in
range
(
0
,
int
(
time_points
/
2
)):
perimeter_array
[
k
]
=
perimeter
(
x
[
k
],
y
[
k
],
number_of_pixels
)
plt
.
plot
(
time_array
,
perimeter_array
,
marker
=
'o'
,
linestyle
=
'None'
)
plt
.
xlabel
(
'Time'
)
plt
.
ylabel
(
'Perimeter'
)
plt
.
show
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment