Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module managment simplify #32

Merged
merged 16 commits into from
Apr 16, 2021
Merged

Module managment simplify #32

merged 16 commits into from
Apr 16, 2021

Conversation

jeaunrg
Copy link
Collaborator

@jeaunrg jeaunrg commented Apr 10, 2021

This branch restructure the module management to achieve greater freedom with widget connections.
And add 'rename' in menu to rename nodes (thanks to restructuring).

@@ -0,0 +1,60 @@
MODULES = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the reasons that lead you to change modules configuration save from json to python dict?
I would prefer the use of a json file. You can then load this json inside this init into your MODULES variable.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can do that, I removed it because I didnt see the purpose of a json file, since we need python scripting in order to create a new module in any case..
But in fact its useful if we want to personalize the menu.

if t == "load image":
widget.browse.clicked.connect(lambda: modules_fn.browse_image(widget))

if t == "save image":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elif is maybe more logical?

Comment on lines 113 to 117
for need_ref, cbox, function in zip([False, False, True, True],
[widget.addition, widget.multiplication,
widget.substraction, widget.division],
[core.add_images, core.multiply_images,
core.substract_images, core.divide_images]):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds great, but it is a little bit complicated to read, don't you think that using list of need_ref, cbox, function directly could help understand code quickly?.
Or if you prefer to keep this zip to organize it, maybe instantiate something in the file or in the config, to be easier to read?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

Comment on lines 141 to 144
for cbox, function in zip([widget.addition, widget.multiplication,
widget.substraction, widget.division],
[core.add_value, core.multiply_value,
core.substract_value, core.divide_value]):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

Comment on lines 85 to 86
im_sum = im.astype(float)
im_sum += value
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can factorize it into one line? Like

im_sum = im.astype(float) + value

Or consider the use of numpy.add where you can directly specify a dtype

im_sum = np.add(im.astype(float), value, dtype=...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I will use the add function, same for other operations

im_sum = im_sum.astype(get_minimum_dtype(im_sum))
return im_sum


def add_images(ims, value=None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function is ONLY made for images add, you maybe can remove value from parameters?

@@ -95,15 +102,19 @@ def add_images(ims, value=None):
im_sum: 2d/3d numpy array
"""
im_sum = ims[0].astype(float)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering reading thos functions, why do you force operations to be made with float array?

Copy link
Collaborator Author

@jeaunrg jeaunrg Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I add a value to an image of dtype int8, the output image will be also of dtype int8. By converting to float64 I ensure the result to be free of dtype.
Ex: with an image of dtype int8, for one pixel if I have 253 + 5 the result will be 3, not 258.
Maybe I can work around this issue with numpy.add, will check that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[#36] Lets talk about that on this issue s'il vous plait

@jeaunrg
Copy link
Collaborator Author

jeaunrg commented Apr 15, 2021

All the issues mentionned above are fixed if we consider the commit [889ff8f], which get around them.
What do you think about this update @Hboni ?

src/utils.py Outdated
def inner(*args, **kwargs):
try:
return foo(*args, **kwargs)
except ValueError as e:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use this decorator only for ValueError? For the divide by 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No only for empty input, but I anticipate other unknown issues, we will add error we encounter to this except

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 division is handled with inf/nan values

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it should be a KeyError, I change that

@jeaunrg jeaunrg merged commit 4894f7f into main Apr 16, 2021
@Hboni Hboni deleted the module_managment_simplify branch May 22, 2021 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants