-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
set_attenuation_coefficients function directly into the fnrgf function. #239
Conversation
…rectly into the fnrgf function.
range_mean=None, | ||
range_std=None, |
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.
Can these be set to the defaults in the private function but as a tuple instead of a list?
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.
`def _set_attenuation_coefficients(order, range_mean=None, range_std=None, cutoff=0):
"""
This is a helper function to Fourier Normalizing Radial Gradient Filter
(`sunkit_image.radial.fnrgf`).
This function sets the attenuation coefficients in the one of the following two manners:
If ``cutoff`` is ``0``, then it will set the attenuation coefficients as linearly decreasing between
the range ``range_mean`` for the attenuation coefficients for mean approximation and ``range_std`` for
the attenuation coefficients for standard deviation approximation.
If ``cutoff`` is not ``0``, then it will set the last ``cutoff`` number of coefficients equal to zero
while all the others the will be set as linearly decreasing as described above.
.. note::
This function only describes some of the ways in which attenuation coefficients can be calculated.
The optimal coefficients depends on the size and quality of image. There is no generalized formula
for choosing them and its up to the user to choose a optimum value.
.. note::
The returned maps have their ``plot_settings`` changed to remove the extra normalization step.
Parameters
----------
order : `int`
The order of the Fourier approximation.
range_mean : `tuple`, optional
A tuple of length ``2`` which contains the highest and lowest values between which the coefficients for
mean approximation be calculated in a linearly decreasing manner.
range_std : `tuple`, optional
A tuple of length ``2`` which contains the highest and lowest values between which the coefficients for
standard deviation approximation be calculated in a linearly decreasing manner.
cutoff : `int`, optional
The numbers of coefficients from the last that should be set to ``zero``.
Returns
-------
`numpy.ndarray`
A numpy array of shape ``[2, order + 1]`` containing the attenuation coefficients for the Fourier
coffiecients. The first row describes the attenustion coefficients for the Fourier coefficients of
the mean approximation. The second row contains the attenuation coefficients for the Fourier coefficients
of the standard deviation approximation.
"""
if range_std is None:
range_std = (1.0, 0.0)
if range_mean is None:
range_mean = (1.0, 0.0)
attenuation_coefficients = np.zeros((2, order + 1))
attenuation_coefficients[0, :] = np.linspace(range_mean[0], range_mean[1], order + 1)
attenuation_coefficients[1, :] = np.linspace(range_std[0], range_std[1], order + 1)
if cutoff > (order + 1):
msg = "Cutoff cannot be greater than order + 1."
raise ValueError(msg)
if cutoff != 0:
attenuation_coefficients[:, (-1 * cutoff) :] = 0
return attenuation_coefficients`
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.
Is it correct now?
Can you modify the tests in the PR please? |
Co-authored-by: Nabil Freij <[email protected]>
|
Well either those or changes made to the existing tests. Whatever works. |
Ok Sure.. |
One last question , how can we connect? Is there any weekly calls? |
There is a weekly meeting: https://sunpy.org/about/meetings/ |
Unfortunately, a new file won't work. You have to instead modify the existing tests and add any new tests to that existing test file. |
Another PR was merged in that has created a conflict unfortunately. |
Sorry , but in today's meeting i need to discuss some doubts , because the test script failed when i added to the existing test script. As i am new , please guide me what needs to be done to resolve the conflict also. |
Can you tell me what happened in detail?
Probably better to see a guide like https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts or a stackoverflow answer: https://stackoverflow.com/questions/161813/how-do-i-resolve-merge-conflicts-in-a-git-repository than for me to try and badly explain it. |
Error 2: TypeError: expected non-empty vector for x The error occurs in the _fit_polynomial_to_log_radial_intensity function. The np.polyfit function expects a non-empty vector for the x parameter, but it is receiving an empty array. This happens because the radial_intensity array is empty, which means there are no valid data points to fit the polynomial. Error 3: ValueError: could not broadcast input array from shape (4,4) into shape (4,) Similar to Error 1, this error occurs in the _set_attenuation_coefficients function. The range_mean parameter is expected to be a tuple or list of length 2, but it is being passed as an array of shape (4, 4). The function tries to broadcast this array into a shape (4,), which is not possible and results in a ValueError Error 4: RuntimeWarning: Mean of empty slice The error occurs in the apply_upsilon function. The np.nanmean function is called on an empty array, which results in a RuntimeWarning. This happens because the data[here] array is empty, meaning there are no valid data points to calculate the mean. |
I am not sure I can provide more information based on your comment. Are these the failures from https://github.com/sunpy/sunkit-image/actions/runs/11568097414/job/32199475873?pr=239 ? Or happening locally? |
Ah we forgot to discuss this at the weekly meeting, sorry about that. How do you want to proceed? |
Is this with the main branch merged in? |
Yes |
Can you push the changes so we can debug together? |
I am unsure what happened but you seem to have changes from the main branch here but without main merged in and that has caused there to be more file conflicts. Can you try doing |
radial_test.py
Outdated
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.
So this file will need to be deleted. Any useful tests here will need to be moved to the main test file used for radial functions.
@@ -248,30 +239,6 @@ def test_multifig_rhef(smap): | |||
return fig | |||
|
|||
|
|||
def test_set_attenuation_coefficients(): |
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.
We still need to test the function, so this should be brought back.
Hey @nabobalis please check this. |
Check what? |
PR Description
Removed
set_attenuation_coefficients
from__all__
:This function is now private and not exported.
Integrated
_set_attenuation_coefficients
intofnrgf
:The function is now a private helper function within fnrgf.
Updated
fnrgf
to acceptrange_mean
,range_std
, andcutoff
as parameters:These parameters are used to set the attenuation coefficients internally.
Removed the public
set_attenuation_coefficients
function:It is now a private helper function
_set_attenuation_coefficients
.I have written a testing script for the refactored code.
output of testing script.
This fixes #220