Skip to content

Conversation

@pawel21
Copy link
Collaborator

@pawel21 pawel21 commented Jan 10, 2023

Hi,

I have created PR for my modification of code for absorption using cubepy.
I added example notebook in agnpy/docs/tutorials

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@pawel21
Copy link
Collaborator Author

pawel21 commented Mar 12, 2023

@cosimoNigro @jsitarek could you look on my PR? :)

@cosimoNigro
Copy link
Owner

I will @pawel21, sorry for the delay. I had little time in general and an issue to fix before this PR.
Will try in the next two weeks.

"source": [
"SUM_RATIO_LINES_BLR = 30.652\n",
"\n",
"def get_absor_blrs(E, L_disk, R_line, r_blob_bh, z):\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function would be useful to be included in the main code of agnpy
XI_LINE and eps_abs should be then among the function parameters

@jsitarek
Copy link
Collaborator

sorry for a very late feedback on this
@pawel21 - I left a few comments on the PR
@cosimoNigro - how do you prefer to proceed - should this function substitute the current integration? or should it be added as a separate function (like Paweł did now)? In the latter case a test comparing the two methods should be added.
The former case might be more reasonable, because this method is more precise and do not have those crazy memore requirements of the standard integration scheme.

@jsitarek
Copy link
Collaborator

jsitarek commented Jul 6, 2023

digging through my old e-mails I realized that this PR is still pending.
@pawel21 I think that still 2 of my comments are not implemented/responded
@cosimoNigro any feedback about the general implementation and relation to the older code?

@cosimoNigro
Copy link
Owner

Sorry for letting it slip, will do the review later today.

Copy link
Owner

@cosimoNigro cosimoNigro left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your work @pawel21, and apologies again if I got disconnected and took a while to review it.

I think once you fix mine and @jsitarek's comments we can merge it in.
Discussing how to handle the general approach towards integration (e.g. allowing to choose between trapezoidal and adaptive integration) is something we should discuss together at a certain point in the future, along with the re-organisation of the package, not in this PR.

@cosimoNigro
Copy link
Owner

Another thing that is missing is an absorption function returning the actual attenuation factor in the cubepy case, now only tau is computed.

@jsitarek
Copy link
Collaborator

jsitarek commented Oct 3, 2024

Hi @pgliwny
The automatic CI checks fail:

FAILED agnpy/fit/tests/test_fit.py::TestFit::test_mrk_421_fit - IndexError: boolean index did not match indexed array along dimension 2; dimension is 1 but corresponding boolean dimension is 9
FAILED agnpy/fit/tests/test_fit.py::TestFit::test_pks_1510_fit - ValueError: non-broadcastable output operand with shape (6,1,1) doesn't match the broadcast shape (6,1,6)

maybe your PR changed something in the API

EDIT: I had a deeper look and the new code does not modify any of the existing functions so it should not be the reason for the fail of the tests.

**note** these are observed frequencies (observer frame)
z : float
redshift of the source
mu_s : float
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this function is following evaluate_tau_blr that is only valid for mu_s=1 (otherwise integration over path of the photon and over the distance from the black hole is not equivalent), so it should not have it as a parameter (@cosimoNigro can you also have a look at this?)

XI_TARGET_LINE = self.target.xi_line
tau_z_all = np.zeros(nu.shape)

blr_shells = dict()
Copy link
Collaborator

@jsitarek jsitarek Oct 3, 2024

Choose a reason for hiding this comment

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

why do you define those dictionaries? I guess it is a remnant of a script where you were also plotting the effect of individual lines, but this is either way not possible this function.

here you are using the dictionaries only to sum up over all the lines, so you could instead created SphericalShellBLR and Absorption as temporary variables directly in the for loop

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

Copy link
Collaborator

@jsitarek jsitarek left a comment

Choose a reason for hiding this comment

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

I left some comments. In particular the test should be rewritten.


def tau_blr_lines_cubepy(self, nu, lines_list, eps_abs=1e-6):
"""
Calculate the absorption in all available BLR (Broad Line Region) shells.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"all available BLR shells" is a copy paste from the original function, better write "multiple BLR ..." or something like this since now you specify exaclty the list of lines to consider

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is still written "all available BLR shells"

Optical depth values corresponding to the input frequencies.
"""

sum_ratio_lines = sum(lines_dictionary[line]['L_Hbeta_ratio'] for line in lines_list)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you need to introduce a check or even better throw an exception if any of the requested line is not in lines_dictionary.keys()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not see the check

@codecov
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 82.05128% with 14 lines in your changes missing coverage. Please review.

Project coverage is 96.80%. Comparing base (506c038) to head (a2b1aaf).

Files with missing lines Patch % Lines
agnpy/absorption/absorption.py 67.44% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #133      +/-   ##
==========================================
- Coverage   97.13%   96.80%   -0.34%     
==========================================
  Files          42       42              
  Lines        3459     3535      +76     
==========================================
+ Hits         3360     3422      +62     
- Misses         99      113      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

nu = E.to("Hz", equivalencies=u.spectral())
tau_blr = abs_blr.tau(nu)
tau_blr_cubepy = abs_blr.tau_blr_cubepy(nu, eps_abs=1e-3)
assert np.allclose(tau_blr, tau_blr_cubepy, rtol=1e-1, atol=1e-1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

have you checked what are the tau values obtained in this case? It might happen that there is very little absorption with tau << 1 and then the test will pass always even if the two numbers are far from one another because of atol.

radius of the BLR spherical shell
r : :class:`~astropy.units.Quantity`
distance between the Broad Line Region and the blob
mu, phi : :class:`~numpy.ndarray`
Copy link
Collaborator

Choose a reason for hiding this comment

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

those two are not in the list of parameters

# set boundary for integration
low = np.array(
[
[min(mu_to_integrate)],
Copy link
Collaborator

Choose a reason for hiding this comment

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

the integration of mu and phi should be simply -1 to 1 and 0 to 2 pi.

# requires a 10% deviation from the two SED points
assert check_deviation(nu, tau_dt, tau_ps_dt, 0.1)

def test_abs_blr_cubepy(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

now that you added test_tau_accuracy_standard_vs_cubepy this test does not seem to add anything to it, so I think you can remove test_abs_blr_cubepy

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.

4 participants