Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nd2shrink
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrey ARISTOV
nd2shrink
Commits
41d7aa9d
Unverified
Commit
41d7aa9d
authored
1 year ago
by
Andrey Aristov
Browse files
Options
Downloads
Patches
Plain Diff
flip sumo
parent
81000023
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
flip_timelapse_SUMO.py
+92
-0
92 additions, 0 deletions
flip_timelapse_SUMO.py
with
92 additions
and
0 deletions
flip_timelapse_SUMO.py
0 → 100644
+
92
−
0
View file @
41d7aa9d
import
tifffile
as
tf
import
numpy
as
np
import
pandas
as
pd
import
os
import
logging
from
tqdm
import
tqdm
logging
.
basicConfig
(
level
=
"
DEBUG
"
)
logger
=
logging
.
getLogger
(
__name__
)
path
=
"
/home/aaristov/Multicell/Sebastien/mESC_aggregates/SUMO/SOX1-T_Movie/{well}/POINT 00001/aligned.tif
"
coords
=
{
"
H10
"
:
[
34
,
35
,
36
,
37
,
38
,
39
,
40
],
"
I12
"
:
[
15
,
18
,
20
],
"
J08
"
:
[
37
],
"
J12
"
:
[
27
,
28
,
29
,
30
,
31
,
32
,
33
,
34
,
35
,
36
,
37
,
38
,
39
,
40
],
"
J15
"
:
range
(
13
,
40
),
"
L13
"
:
[
14
,
17
,
36
,
37
,
38
,
39
,
40
],
"
N06
"
:
[
17
],
}
def
flip_gfp_rfp_values
(
csv_file_path
,
frames_to_flip
):
logger
.
info
(
csv_file_path
)
new_path
=
csv_file_path
.
replace
(
"
.csv
"
,
"
-realigned.csv
"
)
assert
new_path
!=
csv_file_path
try
:
assert
not
os
.
path
.
exists
(
new_path
)
except
AssertionError
:
logger
.
warning
(
"
csv exists
"
)
# Load the CSV file
df
=
pd
.
read_csv
(
csv_file_path
,
index_col
=
0
)
print
(
df
.
head
)
# Flip the values for specified frames
try
:
for
frame
in
frames_to_flip
:
df
.
loc
[
frame
,
[
'
GFP
'
,
'
RFP
'
]]
=
df
.
loc
[
frame
,
[
'
RFP
'
,
'
GFP
'
]].
values
except
KeyError
:
df
=
df
.
rename
(
columns
=
{
"
SOX1
"
:
"
GFP
"
,
"
BRA
"
:
"
RFP
"
})
for
frame
in
frames_to_flip
:
df
.
loc
[
frame
,
[
'
GFP
'
,
'
RFP
'
]]
=
df
.
loc
[
frame
,
[
'
RFP
'
,
'
GFP
'
]].
values
# Save the modified DataFrame back to the same CSV file
df
.
to_csv
(
new_path
)
logger
.
info
(
f
"
saved new table to
{
new_path
}
"
)
def
flip_frames
(
file_path
,
frames_to_flip
):
logger
.
debug
(
file_path
)
# Convert frames_to_flip from 1-based to 0-based indexing
frames_to_flip
=
[
frame
-
1
for
frame
in
frames_to_flip
]
new_file_path
=
file_path
.
replace
(
'
aligned.tif
'
,
'
realigned.tif
'
)
assert
new_file_path
!=
file_path
flip_gfp_rfp_values
(
file_path
.
replace
(
"
aligned.tif
"
,
"
peaks.csv
"
),
frames_to_flip
)
try
:
assert
not
os
.
path
.
exists
(
new_file_path
)
except
AssertionError
:
logger
.
warning
(
"
File exists
"
)
return
new_file_path
# Load the tiff file
with
tf
.
TiffFile
(
file_path
)
as
tif
:
data
=
tif
.
asarray
()
logger
.
debug
(
data
.
shape
)
# Check if data is TCYX and flip required frames
if
data
.
ndim
==
4
:
for
t
in
frames_to_flip
:
# Flip the frame vertically and horizontally (180 degree rotation)
data
[
t
]
=
np
.
rot90
(
data
[
t
],
k
=
2
,
axes
=
(
1
,
2
))
else
:
raise
ValueError
(
"
Data does not have TCYX shape.
"
)
# Save the modified stack
tf
.
imwrite
(
new_file_path
,
np
.
expand_dims
(
data
,
1
),
imagej
=
True
)
logger
.
debug
(
new_file_path
)
return
new_file_path
def
process
(
path
=
path
,
coords
=
coords
):
out
=
[
flip_frames
(
path
.
format
(
well
=
well
),
frames_to_flip
=
coords
[
well
])
for
well
in
coords
]
return
out
if
__name__
==
"
__main__
"
:
process
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment