-
Notifications
You must be signed in to change notification settings - Fork 33
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
Absorption with cubepy #133
base: master
Are you sure you want to change the base?
Conversation
…sorption_with_cubepy
…sorption_with_cubepy
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
@cosimoNigro @jsitarek could you look on my PR? :) |
I will @pawel21, sorry for the delay. I had little time in general and an issue to fix before this PR. |
"source": [ | ||
"SUM_RATIO_LINES_BLR = 30.652\n", | ||
"\n", | ||
"def get_absor_blrs(E, L_disk, R_line, r_blob_bh, z):\n", |
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 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
sorry for a very late feedback on this |
digging through my old e-mails I realized that this PR is still pending. |
Sorry for letting it slip, will do the review later today. |
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 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.
agnpy/absorption/absorption.py
Outdated
# conversions | ||
epsilon_1 = nu_to_epsilon_prime(nu, z) | ||
|
||
def f(x): |
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 think it's not a good idea to define a function within another function.
I think the nested function will be recompiled each time the outer function is called. Could you move it outside?
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.
Done
agnpy/absorption/absorption.py
Outdated
epsilon_line, | ||
R_line, | ||
r, | ||
mu=mu_to_integrate, |
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.
the mu
and phi
arguments are not used in the function, you use directly the default mu_to_integrate
and phi_to_integrate
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.
Done
@@ -0,0 +1,275 @@ | |||
{ |
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.
Line #1. SUM_RATIO_LINES_BLR = 30.652
If this notebook has to be included in the docs I think it needs to be considerably improved, at the moment it has no commentary and it does not explain what its purpose is.
Reply via ReviewNB
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.
Let's remove the notebook for now so we can go further. I would also like to develop other features, but it will be easier if the code for calculation absorption with cubepy is in the main repo. In the next step, I will add notebooks with explanations for the multi-shell BLR model.
Another thing that is missing is an |
…sorption_with_cubepy
What do you mean? Which function is missing? I tried to add a function similar to a function for another target. |
@jsitarek @cosimoNigro Could you please review my code? |
Hi @pgliwny 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 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. |
agnpy/absorption/absorption.py
Outdated
Returns | ||
------- | ||
float | ||
The value of the integrand for the given parameters. |
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.
it would be useful to specify in which units the integrand is specified (I think it should be cm)
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.
Done
**note** these are observed frequencies (observer frame) | ||
z : float | ||
redshift of the source | ||
mu_s : float |
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 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?)
eps_abs: float, optional | ||
Absolute precision for the calculation, default is 1e-6 | ||
""" | ||
SUM_RATIO_LINES_BLR = 30.652 |
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.
hardcoding this is not safe, you should sum up the lines from the dictionary that you will use
XI_TARGET_LINE = self.target.xi_line | ||
tau_z_all = np.zeros(nu.shape) | ||
|
||
blr_shells = dict() |
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.
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
@@ -228,6 +228,31 @@ def test_abs_dt_vs_point_source(self): | |||
# 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): |
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.
the test as it is written now does not test much: only if you do not have a crash because of not matching API, or some internal inconsistency in the code.
Instead you could run a test of comparing tau_blr_cubepy output with tau_blr
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.
Done, added test_tau_accuracy_standard_vs_cubepy
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 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. |
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.
"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
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.
Done
Optical depth values corresponding to the input frequencies. | ||
""" | ||
|
||
sum_ratio_lines = sum(lines_dictionary[line]['L_Hbeta_ratio'] for line in lines_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.
you need to introduce a check or even better throw an exception if any of the requested line is not in lines_dictionary.keys()
---------- | ||
nu : numpy.ndarray | ||
Frequency array for which the absorption will be calculated. | ||
lines_list : list of str |
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.
if you set this as default to lines_dictionary.keys() then you do not need tau_blr_all_lines_cubepy
function any more
XI_TARGET_LINE = self.target.xi_line | ||
tau_z_lines = np.zeros(nu.shape) | ||
|
||
blr_shells = dict() |
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.
copying the comment from the previous function:
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
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #133 +/- ##
==========================================
- Coverage 97.13% 96.31% -0.83%
==========================================
Files 42 42
Lines 3459 3554 +95
==========================================
+ Hits 3360 3423 +63
- Misses 99 131 +32 ☔ View full report in Codecov by Sentry. |
Hi,
I have created PR for my modification of code for absorption using cubepy.
I added example notebook in agnpy/docs/tutorials