Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DCT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
graintracking
DCT
Commits
331b3308
Commit
331b3308
authored
3 years ago
by
Joao P C Bertoldo
Browse files
Options
Downloads
Patches
Plain Diff
correct a bug in zmoving medians
parent
342c7ddf
No related branches found
Branches containing commit
No related tags found
1 merge request
!6
Draft: Resolve "py-bkg-rm"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
zUtil_Python/pydct/orangecontrib/pydct/widgets/xyfilter_median.py
+174
-0
174 additions, 0 deletions
...thon/pydct/orangecontrib/pydct/widgets/xyfilter_median.py
zUtil_Python/pydct/pydct/preprocess/xyfilter_median.py
+1
-1
1 addition, 1 deletion
zUtil_Python/pydct/pydct/preprocess/xyfilter_median.py
with
175 additions
and
1 deletion
zUtil_Python/pydct/orangecontrib/pydct/widgets/xyfilter_median.py
0 → 100644
+
174
−
0
View file @
331b3308
""""
todo
"""
import
logging
from
enum
import
Enum
from
multiprocessing.sharedctypes
import
RawArray
from
typing
import
List
,
Tuple
import
_ctypes
import
numpy
as
np
from
numpy
import
ndarray
from
Orange.widgets
import
gui
,
settings
,
widget
from
Orange.widgets.utils.signals
import
Input
,
Output
from
Orange.widgets.widget
import
OWWidget
from
orangewidget.settings
import
Setting
from
pydct.preprocess.main
import
normalize_margin_mean
from
pydct.preprocess.moving_median_removal
import
remove_moving_medians
from
silx.gui.qt
import
QThread
from
pydct.preprocess.xyfilter_median
import
xyfilter_median
_logger
=
logging
.
getLogger
(
"
orangecontrib.pydct
"
)
class
XYFilterMedianThread
(
QThread
):
"""
todo
"""
def
__init__
(
self
,
parent
,
data
:
ndarray
,
multiprocessing_array
:
RawArray
,
filter_dimensions
:
Tuple
[
int
,
int
]):
super
().
__init__
(
parent
=
parent
)
self
.
data
=
data
self
.
multiprocessing_array
=
multiprocessing_array
self
.
filter_dimensions
=
filter_dimensions
self
.
data_processed
=
None
def
run
(
self
):
try
:
self
.
data_processed
=
xyfilter_median
(
data
=
self
.
data
,
multiprocessing_rawarray
=
self
.
multiprocessing_array
,
filter_dimensions
=
self
.
filter_dimensions
,
)
except
Exception
as
ex
:
_logger
.
exception
(
ex
)
self
.
parent
.
error
(
f
"
exception in `
{
self
.
__class__
.
__name__
}
`
"
)
class
XYFilterMedian
(
OWWidget
):
"""
todo
"""
name
=
"
xy-filter median
"
description
=
"
todo
"
# todo
icon
=
"
icons/xy-filter-median.svg
"
want_main_area
=
False
resizing_enabled
=
True
class
Inputs
:
shared_data
=
Input
(
"
shared_data
"
,
tuple
)
# todo document this properly
# Tuple[ndarray, RawArray]
class
Outputs
:
data_shared
=
Output
(
"
data_shared
"
,
tuple
)
# todo document this properly
data
=
Output
(
"
data
"
,
ndarray
)
kernel_size_x
=
Setting
(
3
,
schema_only
=
True
)
kernel_size_y
=
Setting
(
3
,
schema_only
=
True
)
def
__init__
(
self
):
super
().
__init__
()
self
.
data
=
None
self
.
multiprocessing_array
=
None
self
.
median_validity_spin
=
gui
.
spin
(
self
.
controlArea
,
self
,
"
kernel_size_x
"
,
minv
=
1
,
maxv
=
10000
,
step
=
1
,
label
=
"
kernel_size_x
"
,
disabled
=
False
,
spinType
=
int
,
)
self
.
median_validity_spin
=
gui
.
spin
(
self
.
controlArea
,
self
,
"
kernel_size_y
"
,
minv
=
1
,
maxv
=
10000
,
step
=
1
,
label
=
"
kernel_size_y
"
,
disabled
=
False
,
spinType
=
int
,
)
self
.
_computing
=
False
self
.
run_button
=
gui
.
button
(
widget
=
self
.
controlArea
,
master
=
self
,
label
=
"
go
"
,
callback
=
self
.
_run
)
self
.
run_button
.
setDisabled
(
True
)
@Inputs.shared_data
def
set_shared_data
(
self
,
shared_data
):
if
shared_data
is
None
:
self
.
data
,
self
.
multiprocessing_array
=
None
,
None
else
:
self
.
data
,
self
.
multiprocessing_array
=
shared_data
self
.
_on_input_change
()
def
_on_input_change
(
self
):
if
self
.
_computing
:
_logger
.
warning
(
"
inputs changed while computing the normalization, terminating...
"
)
self
.
_thread
.
quit
()
# todo check if this works
self
.
_computing
=
False
self
.
Outputs
.
data_shared
.
send
(
None
)
self
.
Outputs
.
data
.
send
(
None
)
if
self
.
data
is
None
or
self
.
multiprocessing_array
is
None
:
self
.
run_button
.
setDisabled
(
True
)
self
.
information
()
return
else
:
self
.
run_button
.
setDisabled
(
False
)
self
.
information
(
"
data ready, waiting to run
"
)
def
_run
(
self
):
if
self
.
_computing
:
_logger
.
error
(
"
already running
"
)
return
if
self
.
data
is
None
or
self
.
multiprocessing_array
is
None
:
_logger
.
error
(
"
trying to run with missing inputs, this shouldn
'
t happen
"
)
return
self
.
run_button
.
setDisabled
(
True
)
self
.
_thread
=
XYFilterMedianThread
(
parent
=
self
,
data
=
self
.
data
,
multiprocessing_array
=
self
.
multiprocessing_array
,
filter_dimensions
=
(
self
.
kernel_size_x
,
self
.
kernel_size_y
),
)
self
.
_thread
.
finished
.
connect
(
self
.
_send_signal
)
self
.
_computing
=
True
self
.
information
(
"
computing...
"
)
self
.
_thread
.
start
()
def
_send_signal
(
self
):
self
.
_thread
.
finished
.
disconnect
(
self
.
_send_signal
)
_logger
.
info
(
"
done normalizing
"
)
self
.
_computing
=
False
if
self
.
_thread
.
data_processed
is
not
None
:
self
.
Outputs
.
data_shared
.
send
((
self
.
_thread
.
data_processed
,
self
.
multiprocessing_array
))
self
.
Outputs
.
data
.
send
(
self
.
_thread
.
data_processed
)
self
.
information
(
"
done
"
)
else
:
self
.
run_button
.
setDisabled
(
False
)
self
.
error
(
"
something went wrong and the worker thread did not return the result properly
"
)
This diff is collapsed.
Click to expand it.
zUtil_Python/pydct/pydct/preprocess/xyfilter_median.py
+
1
−
1
View file @
331b3308
...
...
@@ -63,7 +63,7 @@ def _worker_do(zstart, zstop):
def
xyfilter_median
(
data
,
filter_dimensions
,
filter_dimensions
:
Tuple
[
int
,
int
]
,
nprocs
:
Optional
[
int
]
=
None
,
multiprocessing_rawarray
:
Optional
[
RawArray
]
=
None
,
)
->
Union
[
ndarray
,
Tuple
[
ndarray
,
RawArray
]]:
...
...
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