Skip to content

Icchen/79 render vector overlay#83

Merged
confluence merged 50 commits intodevfrom
icchen/79_render_vector_overlay
Oct 27, 2023
Merged

Icchen/79 render vector overlay#83
confluence merged 50 commits intodevfrom
icchen/79_render_vector_overlay

Conversation

@I-Chenn
Copy link
Copy Markdown
Contributor

@I-Chenn I-Chenn commented Mar 13, 2023

This PR is to resolve #79.

@kswang1029 @confluence, I haven't finished this issue yet, but would like to ask a question before going on.

I have added configure_vector_overlay, set_vector_overlay_color, set_vector_overlay_colormap, apply_vector_overlay and clear_vector_overlay to image.py.

The configure_vector_overlay is a huge method with 9 parameters within since VectorOverlayStore in the frontend stuck all the parameters into setVectorOverlayConfiguration action to set the Configuration panel. Nevertheless, for the Styling panel, it seems that all the parameters are divided into respective actions.

My question is: do you prefer the way of dividing these actions into different Python functions? or do you prefer to stuck all these actions into one function , like a set_vector_overlay_styling function, for setting up the styling panel?

@confluence
Copy link
Copy Markdown
Collaborator

I think that this split is OK for now. You can, however, eliminate the boolean parameters enabling or disabling certain features, because you can deduce them from the other parameters. Set pixel_averaging_enabled to True if pixel_averaging is not None, otherwise False, and so on (in this particular case, make sure you change the validation for pixel_averaging so that None is allowed). You can do the same for threshold.

For debiasing, are both error values required? If the user specifies one, does it make sense to use it for both errors, or are they likely to be completely different magnitudes? Does either of them have a sensible default? Depending on the answer to this, you can enable debiasing either if both error parameters are given, or if at least one is given.

Everything under Styling (except the colour, which I think it makes sense to keep separate for consistency) should maybe be grouped under a set_vector_overlay_line, or maybe set_vector_overlay_style (in which case set_contour_dash should perhaps be renamed to set_contour_style to match).

@kswang1029
Copy link
Copy Markdown
Contributor

I think that this split is OK for now. You can, however, eliminate the boolean parameters enabling or disabling certain features, because you can deduce them from the other parameters. Set pixel_averaging_enabled to True if pixel_averaging is not None, otherwise False, and so on (in this particular case, make sure you change the validation for pixel_averaging so that None is allowed). You can do the same for threshold.

For debiasing, are both error values required? If the user specifies one, does it make sense to use it for both errors, or are they likely to be completely different magnitudes? Does either of them have a sensible default? Depending on the answer to this, you can enable debiasing either if both error parameters are given, or if at least one is given.

errors for stokes Q and U could be different so we need them as separate parameters.

Everything under Styling (except the colour, which I think it makes sense to keep separate for consistency) should maybe be grouped under a set_vector_overlay_line, or maybe set_vector_overlay_style (in which case set_contour_dash should perhaps be renamed to set_contour_style to match).

Vector overlay can be line segments or filled squares. Need to consider this in the naming convention.

@confluence
Copy link
Copy Markdown
Collaborator

errors for stokes Q and U could be different so we need them as separate parameters.

Yes, there will definitely be two parameters. But is the user ever likely to use the same value for both, or is it very unlikely?

(Actually, it probably doesn't matter -- it would be way too magical to make one default to the other, so we shouldn't do it either way. :) )

@kswang1029
Copy link
Copy Markdown
Contributor

errors for stokes Q and U could be different so we need them as separate parameters.

Yes, there will definitely be two parameters. But is the user ever likely to use the same value for both, or is it very unlikely?

(Actually, it probably doesn't matter -- it would be way too magical to make one default to the other, so we shouldn't do it either way. :) )

If stokes Q and U images are created with different clean processes (clean regions, depth, etc), errors can be different. I think we can set them as 0 as default and they are only effective when debiasing is True.

@confluence
Copy link
Copy Markdown
Collaborator

We're trying to eliminate the boolean parameters and deduce them from the options. So in this case, we need to decide if we need both of the errors to be provided, or just one. Will it ever make sense to use one error value and one default error of zero, or are both errors always required to do anything meaningful?

@kswang1029
Copy link
Copy Markdown
Contributor

We're trying to eliminate the boolean parameters and deduce them from the options. So in this case, we need to decide if we need both of the errors to be provided, or just one. Will it ever make sense to use one error value and one default error of zero, or are both errors always required to do anything meaningful?

We need both to be provided if debiasing is True. If one is missing, we should throw an error.

@confluence
Copy link
Copy Markdown
Collaborator

OK, but we don't want the user to have to duplicate information in the high-level API by enabling debiasing explicitly -- we want to deduce whether the user wants to enable debiasing from the debiasing options provided. So if both errors are always needed, it's fine to keep the defaults of None, and enable debiasing if both the error parameters are provided. This is in line with removing e.g. the flag that enables the threshold, and enabling the threshold automatically if a threshold value is provided.

If the user provides only one of the errors, we should disable debiasing, but also print a warning (since this is likely to be a mistake).

@I-Chenn
Copy link
Copy Markdown
Contributor Author

I-Chenn commented Mar 13, 2023

I think that this split is OK for now. You can, however, eliminate the boolean parameters enabling or disabling certain features, because you can deduce them from the other parameters. Set pixel_averaging_enabled to True if pixel_averaging is not None, otherwise False, and so on (in this particular case, make sure you change the validation for pixel_averaging so that None is allowed). You can do the same for threshold.

@confluence, sorry for the late reply since I am a bit busy this evening. I will take a close look for all your comments tomorrow but would like to make a quick confirmation:

Is the modification in 32aae92 what you mean in the quotation above?

@confluence
Copy link
Copy Markdown
Collaborator

Is the modification in 32aae92 what you mean in the quotation above?

Yes, that's correct! I also suggest that you do the same for debiasing, but as discussed, it should be enabled if both the error parameters are not None. If only one error parameter is provided, the debiasing should be disabled, but a warning should be printed.

I'll also make a few review comments.

Copy link
Copy Markdown
Collaborator

@confluence confluence left a comment

Choose a reason for hiding this comment

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

Some nitpicks about the phrasing in the docstring.

Comment thread carta/image.py Outdated
Comment on lines +621 to +624
if pixel_averaging is not None:
pixel_averaging_enabled = True
else:
pixel_averaging_enabled = False
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can simplify this and the conditional below like this: pixel_averaging_enabled = pixel_averaging is not None.

Comment thread carta/image.py Outdated
# VECTOR OVERLAY

@validate(Constant(VectorOverlaySource), Constant(VectorOverlaySource), NoneOr(Number()), Boolean(), NoneOr(Number()), Boolean(), NoneOr(Number()), NoneOr(Number()))
def configure_vector_overlay(self, angular_source=VectorOverlaySource.CURRENT, intensity_source=VectorOverlaySource.CURRENT, pixel_averaging=4, fractional_intensity=False, threshold=None, debiasing=False, qError=None, uError=None):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Naming convention: qError and uError should be q_error and u_error.

Comment thread carta/image.py Outdated
intensity_source : {1}
The intensity source.
pixel_averaging : {2}
The pixel averaging width. Set it to None to disable the usage pixel averaging width.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When you mention literals like None in the code, use the ReST markup for code, which is double backticks:

blah blah ``None`` ...

This will format the word as code in the final Sphinx document.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should also mention that the default is 4 (plus the units; not sure what those are).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would change the last sentence to: "Set to None to disable pixel averaging."

Comment thread carta/image.py Outdated
pixel_averaging : {2}
The pixel averaging width. Set it to None to disable the usage pixel averaging width.
fractional_intensity : {3}
Set polarization intensity to absolute or fractional.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd rephrase this as: "Enable fractional polarization intensity. By default absolute polarization intensity is used."

Comment thread carta/image.py Outdated
Comment on lines +604 to +607
angular_source : {0}
The angular source.
intensity_source : {1}
The intensity source.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Both of these should mention that the default is the current image.

Comment thread carta/image.py Outdated
fractional_intensity : {3}
Set polarization intensity to absolute or fractional.
threshold : {4}
The threshold. Set it to None to disable the usage of threshold.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would say: The threshold. By default the threshold is disabled.

(We should probably also mention the units here.)

(If the user doesn't want to enable the threshold, they are more likely to omit the parameter and fall back to the default than to pass in an explicit None.)

Comment thread carta/image.py Outdated
Comment on lines +616 to +619
qError : {6}
The stoke Q Error.
uError : {7}
The stoke U Error.
Copy link
Copy Markdown
Collaborator

@confluence confluence Mar 13, 2023

Choose a reason for hiding this comment

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

stoke -> Stokes, but Error -> error

Once the debiasing parameter is removed, I would revise each of these to be something like: "The Stokes _ error in [units]. Set both this and [other variable name] to enable debiasing. By default debiasing is disabled."

(Edited to swap sentence order in suggested wording and simplify it.)

@I-Chenn
Copy link
Copy Markdown
Contributor Author

I-Chenn commented Mar 14, 2023

@kswang1029 @confluence
I have made a commit (cb56287) to make several modifications to configure_vector_overlay function following your comments. Nevertheless, I found some further problems and would like to discuss with you:

  1. angular_source and intensity_source setting:
    These two parameters actually do not set "Current" as default. It depends on what kind of image you open; if an image with polarization info is opened, these two parameters are set to "Computed" as default automatically. See below:
    image
    May I have some hint of setting up the default values of angular_source and intensity_source under such circumstance?

  2. The management of the situation "q_error is set but u_error is not set" (or vise versa):
    I am now dealing with the situation with the code:
    image
    But do I need to set debiasing to some None value rather than just print the message?

  3. Intensity area in the Styling panel:
    These two input fields seem to automatically update themselves after we apply the vector overlay. I don't know if we need to fill them up manually in advance (perhaps for some circumstances) or we just keep it a None?
    image

Copy link
Copy Markdown
Collaborator

@confluence confluence left a comment

Choose a reason for hiding this comment

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

Minor followup comments; it's looking good!

Comment thread carta/image.py Outdated
Comment on lines +621 to +626
if q_error is not None and u_error is not None:
debiasing = True
elif q_error is None and u_error is None:
debiasing = False
else:
print("q_error and u_error must be both set to enable debiasing.")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use the logger for this message (you'll have to import it at the top; it's in .util -- see how it's used in e.g. session.py).

You could compact this using syntax similar to the previous lines (as shown below), but it does mean restating part of the same conditional, so I don't feel that strongly about it -- maybe the way it is now is clearer to read.

debiasing = q_error is not None and u_error is not None
if not debiasing and (q_error is not None or u_error is not None):
    logger.warning(...)

In the message, please swap "be both" -> "both be". I would also refer to the error variables by their descriptions rather than their variable names here ("The Stokes Q error and the Stokes U error must...")

Comment thread carta/image.py Outdated
Comment on lines +615 to +617
The Stokes Q error in Jy/beam. Set both this and ``u_error`` to enable debiasing. The debiasing is disabled by default.
u_error : {6}
The Stokes U error in Jy/beam. Set both this and ``q_error`` to enable debiasing. The debiasing is disabled by default.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"The debiasing..." should just be "Debiasing..." in the last sentence(s) here.

Comment thread carta/image.py Outdated
The angular source. By default the current image is used.
intensity_source : {1}
The intensity source. By default the current image is used.
pixel_averaging : {2}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"in pixel" -> "in pixels"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(And it needs the default -- I think it's fine to put "The default is 4." as the middle sentence; you don't need to restate the units.)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry; I selected the wrong lines somehow -- this is related to the pixel averaging description.

@confluence
Copy link
Copy Markdown
Collaborator

confluence commented Mar 14, 2023

I made my previous comments before I saw your questions -- answers below.

  1. Perhaps the default parameter should be None, and the default source determined in the function using the same criteria that the frontend uses. You can use the image functions for determining if particular polarizations are available. The way that this default is selected would then be described in the documentation for the parameter. Edit: I was overthinking this. You should be able to get the default that was already computed by the frontend using get_value.

  2. The debiasing can't be undefined -- it's either on or off (and it should be off unless both errors are provided). I suggested how you could rewrite this conditional -- in that syntax, debiasing is already set to False unless both errors are not None. If you keep the current syntax, you should also set it to False explicitly when you print the warning.

  3. It looks like these intensity defaults are computed from the file. I don't think that this is necessarily going to be a problem. There's a single action for setting both the min and the max. We're planning to have a single style function for calling this and a few other actions (although maybe we should split this up further). If the user doesn't provide any intensity parameters we don't have to call this action at all; if they provide both parameters then we override both at the same time; if they provide only one, we can fetch the other one using get_value so that we don't override it. The only thing I'm not sure about is whether those defaults will be populated correctly if we apply the overlay from the scripting interface -- we should test that to make sure.

@I-Chenn
Copy link
Copy Markdown
Contributor Author

I-Chenn commented Mar 15, 2023

@confluence , I added set_vector_overlay_style, plot_vector_overlay, set_vector_overlay_visible, show_vector_overlay, hide_vector_overlay to image.py and made some modifications to configure_vector_overlay following your suggestions in 401652e.
I haven't dealt with the action that need to be taken if user set one of the input field for Intensity area of set_vector_overlay_style yet, but the function is workable with the default setting under my simple test.
Nevertheless, I also tested configure_vector_overlay, but there seems to be some error at the last line of that function (the call_action line). I haven't figured out what the problem is and will work on it tomorrow.
Please take a look at the parameter descriptions in set_vector_overlay_style and see if it's OK for you if it's convenient to you. Thank you very much.

Comment thread carta/image.py Outdated
Comment thread carta/image.py Outdated
@I-Chenn
Copy link
Copy Markdown
Contributor Author

I-Chenn commented Jun 2, 2023

@confluence, all the descriptions for vector_overlay functions are optimized, and I also added the descripted default value for color and colormap for contour. Please take a look and see if it's OK for you.

@I-Chenn I-Chenn requested a review from confluence June 2, 2023 14:40
@confluence confluence self-assigned this Aug 7, 2023
@confluence confluence requested review from confluence and removed request for confluence August 7, 2023 16:12
Copy link
Copy Markdown
Collaborator

@confluence confluence left a comment

Choose a reason for hiding this comment

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

Clearing my own review.

@confluence confluence marked this pull request as ready for review October 25, 2023 19:36
@confluence
Copy link
Copy Markdown
Collaborator

confluence commented Oct 25, 2023

@kswang1029 this is now ready for review.

(I would like to merge this first, and finalise making the raster / vector overlay / contours interface consistent in #123.)

@confluence confluence merged commit 543fb57 into dev Oct 27, 2023
@confluence confluence deleted the icchen/79_render_vector_overlay branch October 27, 2023 14:23
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.

support vector overlay rendering

3 participants