Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
model_server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Christopher Randolph Rhodes
model_server
Commits
7695e1f0
Commit
7695e1f0
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up batch runner script with filepath utility functions
parent
b7738938
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extensions/chaeo/examples/batch_run_patches.py
+11
-28
11 additions, 28 deletions
extensions/chaeo/examples/batch_run_patches.py
extensions/chaeo/util.py
+36
-0
36 additions, 0 deletions
extensions/chaeo/util.py
with
47 additions
and
28 deletions
extensions/chaeo/examples/batch_run_patches.py
+
11
−
28
View file @
7695e1f0
from
pathlib
import
Path
import
re
from
time
import
localtime
,
strftime
#
from time import localtime, strftime
import
pandas
as
pd
from
extensions.chaeo.util
import
autonumber_new_directory
,
get_matching_files
from
extensions.chaeo.workflows
import
export_patches_from_multichannel_zstack
from
model_server.accessors
import
InMemoryDataAccessor
,
write_accessor_data_to_file
if
__name__
==
'
__main__
'
:
where_czi
=
Path
(
'
z:/rhodes/projects/proj0004-marine-photoactivation/data/exp0038/AutoMic/20230906-163415/Selection
'
)
where_output_root
=
Path
(
'
c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output
'
)
yyyymmdd
=
strftime
(
'
%Y%m%d
'
,
localtime
())
idx
=
0
for
ff
in
Path
(
where_output_root
).
iterdir
():
ma
=
re
.
match
(
f
'
batch-output-
{
yyyymmdd
}
-([\d]+)
'
,
ff
.
name
)
if
ma
:
idx
=
max
(
idx
,
int
(
ma
.
groups
()[
0
])
+
1
)
where_czi
=
'
z:/rhodes/projects/proj0004-marine-photoactivation/data/exp0038/AutoMic/20230906-163415/Selection
'
where_output
=
Path
(
where_output_root
/
f
'
batch-output-
{
yyyymmdd
}
-
{
idx
:
04
d
}
'
where_output
=
autonumber_new_directory
(
'
c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output
'
,
'
batch-output
'
)
csv_args
=
{
'
mode
'
:
'
w
'
,
'
header
'
:
True
}
# when creating file
...
...
@@ -32,25 +22,18 @@ if __name__ == '__main__':
#TODO: try/catch blocks and error handling around workflow calls
#TODO: pack JSON-serializable workflow inputs
for
ff
in
where_czi
.
iterdir
():
pattern
=
'
Selection--W([\d]+)--P([\d]+)-T([\d]+)
'
ma
=
re
.
match
(
pattern
,
ff
.
stem
)
print
(
ff
)
if
not
ff
.
suffix
.
upper
()
==
'
.CZI
'
:
continue
if
int
(
ma
.
groups
()[
1
])
>
10
:
# skip second half of set
continue
input_files
=
get_matching_files
(
where_czi
,
'
czi
'
,
coord_filter
=
{
'
P
'
:
(
0
,
10
)})
for
ff
in
input_files
:
export_kwargs
=
{
'
input_zstack_path
'
:
(
where_czi
/
ff
)
.
__str__
(),
'
input_zstack_path
'
:
Path
(
where_czi
)
/
ff
.
__str__
(),
'
ilastik_project_file
'
:
px_ilp
.
__str__
(),
'
pxmap_threshold
'
:
0.25
,
'
pixel_class
'
:
0
,
'
zmask_channel
'
:
0
,
'
patches_channel
'
:
4
,
'
where_output
'
:
where_output
.
__str__
()
,
'
where_output
'
:
where_output
,
'
mask_type
'
:
'
boxes
'
,
'
zmask_filters
'
:
{
'
area
'
:
(
1e3
,
1e8
)},
'
zmask_expand_box_by
'
:
(
128
,
3
),
...
...
This diff is collapsed.
Click to expand it.
extensions/chaeo/util.py
0 → 100644
+
36
−
0
View file @
7695e1f0
from
pathlib
import
Path
import
re
from
time
import
localtime
,
strftime
def
autonumber_new_directory
(
where
:
str
,
prefix
:
str
)
->
str
:
yyyymmdd
=
strftime
(
'
%Y%m%d
'
,
localtime
())
idx
=
0
for
ff
in
Path
(
where
).
iterdir
():
ma
=
re
.
match
(
f
'
{
prefix
}
-
{
yyyymmdd
}
-([\d]+)
'
,
ff
.
name
)
if
ma
:
idx
=
max
(
idx
,
int
(
ma
.
groups
()[
0
])
+
1
)
return
(
Path
(
where
)
/
f
'
batch-output-
{
yyyymmdd
}
-
{
idx
:
04
d
}
'
).
__str__
()
def
get_matching_files
(
where
:
str
,
ext
:
str
,
coord_filter
:
dict
=
{})
->
str
:
files
=
[]
def
is_filtered_out
(
ff
):
if
ff
.
suffix
.
upper
()
!=
f
'
.
{
ext
}
'
.
upper
():
return
True
coords
=
{
m
[
0
]:
int
(
m
[
1
])
for
m
in
re
.
findall
(
'
-([a-zA-Z])(\d+)
'
,
ff
.
name
)
}
for
fk
in
coord_filter
.
keys
():
if
fk
in
coords
.
keys
():
cmin
,
cmax
=
coord_filter
[
fk
]
if
coords
[
fk
]
<
cmin
or
coords
[
fk
]
>
cmax
:
return
True
return
False
for
ff
in
Path
(
where
).
iterdir
():
if
is_filtered_out
(
ff
):
continue
files
.
append
(
ff
.
__str__
())
return
files
\ 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