-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add notebook to use sectorPhi #5
Conversation
ask @caitwolf and @pbeaucage and @dehoni to look at before merging. @celinedurniak would appreciate feedback. |
I have tested the Jupyter notebook. It is working straight-away. The examples are well-worked out and clear, and show how a user can get access to 2D data manipulation from Sasview. I am sure this notebook will serve as inspiration and important starting point for future users. There are a few suggestions to enhance the documentation (new issues outside this PR) and a few improvements.
Improvements: |
As of this today, the You will need to update your references and clone the package:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed the notebook and appreciate the provided examples; I learned a lot from them while I was going through the review! I have the following comments and suggestions:
Note: Items 1-3 echo those described by @dehoni above and I've only included them here for additional comments.
- I agree, the sign convention should start with phi=0 pointing along the positive x-axis; the "Sign convention" figure should be updated to show this but I believe the sectors in the rest of the notebook are applying the angle phi correctly with phi=0 to the right.
- I ran into the same MatplotLib Deprecation Warning.
- I agree this is due to the qx and qy binning. However, I did notice that the circle/disk was being centered around qx=0.001 and qy=0.001 with the currently implemented indexing rather than qx=0, qy=0 due to the even number of qx and qy points centered around 0 but not at zero, i.e., values of -0.001 and 0.001 are in the qx and qy points. The section of code generating the disk could be slightly modified to something like:
for i, x in enumerate(qx_data_1d):
for j, y in enumerate(qy_data_1d):
if np.sqrt(x**2 + y**2) <= 0.04:
data_circle[i, j] = 1
This would result in an equal number of points in each quadrant and a constant integrated intensity.
I also note that this change only partially fixes the visual offset in the disk on the plot. I think this is due to matplotlib assuming the qx and qy points are the bin edges rather than centers as @dehoni mentions above. Perhaps there is a way to modify this setting so that the four bins surrounding the origin appear to be in their respective quadrants. I do think the underlying sectors, however, are being implemented properly based on the integrated intensities.
This also translates to the Case 3: circle centered at 0, 0 with zeros at the sectors' edges. The zeros appear to be placed when qy = 0.001 or qx = 0.001 and so they are slightly offset from the axes. The integrated intensity was constant across the quadrants since this offset was also balancing with the circle center at 0.001, 0.001 rather than 0, 0 due to the indexing described above. A similar fix described above for the the disk could be implemented here to account for the origin offset and also zeros could be placed when qx is 0.001 or -0.001 or when qy is 0.001 or -0.001. Again, this only partially fixes the visual offset on the quadrant plot but does ensure the circle is centered at (0, 0) and that the sector edges run in between the zeros along the axes.
Further discussion on this topic would be good; I made the assumption that the qx and qy values are to be interpreted as the bin/pixel centers and so if this assumption is incorrect, I will need to modify my suggestions above.
- In the section "Visualise azimuthal sectors" I noticed that the dashed sector lines cut through the entire circle, and so if a phi_min=0 and phi_max=pi/2 were set, the dashed line would show through the phi angles 0 to pi/2 as well as pi to 3pi/2. I'm less familiar if this tool is used this way to only section off a part of the image, but if so, my suggestion would be to use the origin as one endpoint and the max radius as the other endpoint for each dash line so that if the user wants to change the phi range it will only plot the utilized section. For example:
lines_sectors = np.zeros((sect.nbins, 2, 2))
for i in range(sect.nbins):
lines_sectors[i, 0, 1] = np.cos((sect.phi_max - sect.phi_min) / sect.nbins * i) * np.sqrt(np.max(qx_data_1d)**2+np.max(qy_data_1d**2))
lines_sectors[i, 1, 1] = np.sin((sect.phi_max - sect.phi_min) / sect.nbins * i) * np.sqrt(np.max(qx_data_1d)**2+np.max(qy_data_1d**2))
Then when you plot the dashed sector lines, you can reference the start and stop points with:
# plot sectors' limits
for i in range(sect.nbins):
ax.plot(lines_sectors[i,0,:], lines_sectors[i,1,:], 'c--')
Thanks @caitwolf and @dehoni for your comments.
But I also checked the code: In In the code of
|
I finally found time to review this; I'm very sorry that it took so long. Overall I think this is a nice demonstration of the features and use of sectorPhi. It's not out of place for the notebooks directory, but it is a little confusing as a worked-example because it both contains some nice semi-instructional content and then the last section which feels a lot like just unit tests in long form. Right now there is a lot of code, a lot of which is unfortunately not super approachable, and not a lot of explanation. In the 'unit test' section, I'd avoid the One specific thing I'd like to call out is that the first thing a user sees in the notebook is a massive wall of matplotlib graphics commands to make the sign convention figure. This is a nice demonstration of how to do drawing in matplotlib, I guess, but it's hardly "welcome to an example on a specific science thing".... You can embed images into notebooks -- maybe just take the output of this cell, embed it where the cell currently is for the sign convention (which does need to be introduced this early), and then throw the generation code at the end of the nb for users who really want to see it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see earlier comment
@pbeaucage thanks for the review.
I hope these modifications make the notebook clearer and easier to use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @celinedurniak, the code is looking good! You are correct about phi=0 pointing along the negative qx axis. Requested changes before merge:
- Can you make a fix to the code I suggested in item 4 above and that was implemented in your notebook? I had assumed phi=0 along the positive qx axis and so it just needs to be modified slightly with an additional np.pi in the cos and sin functions so sectors defined with a phi range less than 0 to 2pi will show in the correct quadrant.
Outside of this pull request but in regards to the phi=0 convention, @butlerpd and I did some investigating and this shift was implemented to account for the SasView gui convention of phi=0 along the negative qx axis and a range of -pi to pi. However, this is confusing if one switches between scripting in the gui, and so I'm working on a separate issue that describes this in greater detail so the conventions can be made consistent moving forward. I'll link the new issue here when it's created for future reference. |
Thanks @caitwolf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @celinedurniak!
No description provided.