Skip to content
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

Enhancements for Pk2D, Tk3D, Tracer. #923

Merged
merged 26 commits into from
Aug 4, 2022
Merged

Enhancements for Pk2D, Tk3D, Tracer. #923

merged 26 commits into from
Aug 4, 2022

Conversation

nikfilippas
Copy link
Contributor

@nikfilippas nikfilippas commented Apr 10, 2022

This PR adds a number of features to the Pk2D object.

  1. Pk2Ds which are initialized with empty=True never contain attributes extrap_order_hik and extrap_order_lok. This is a bug, and it can be fixed by making both attributes properties of the object.
  2. has_psp has to manually be set every time an empty object is populated with a psp. It makes more sense for has_psp to also be a property that peeks into psp to see if it's there.
  3. Currently, apply_halofit is a class method. It makes more sense for it to be called as an instance method, as it operates using the implicit first argument (which is now passed last, explicitly). Instead of ccl.Pk2D.apply_halofit(cosmo, pk), we can now do pk.apply_halofit(cosmo). I implemented a descriptor that allows it to work both as a class method and as an instance method, with the ultimate goal to deprecate the class method usage in the future.
  4. Simplify call to pk models: ccl.Pk2D.pk_from_model --> ccl.Pk2D.from_model.
  5. eval and eval_dlogpk_dlogk are very similar, so I concatenated them, shortening the code base, but keeping both definitions.
  6. Option to call eval without cosmo. It will fail if a value outside the scale factor range of psp is requested. This was built in the C code already. For some reason, it wasn't ported to Python.
  7. Implement __call__ for Pk2D and Tk3D. Instead of np.array([pk.eval(k_arr, a) for a in a_arr]), we can now do pk(k_arr, a_arr).
  8. Implement copy. Initialization is very fast, so copy will enable us to operate on copies of Pk2D objects.
  9. Does my pk (or tk or tr) have data? bool(pk)!
  10. Is pk1 within the k- and a- boundaries of another pk2? pk1 in pk2! (Useful when operating with different supports.)
  11. Extended binary operations: pk1 - pk2, pk1 / pk2, pk += 0.05, pk *= 1.05, pk -= 0.05, pk /= 0.95, pk **= 2.

@coveralls
Copy link

coveralls commented Apr 10, 2022

Pull Request Test Coverage Report for Build 2796012781

  • 121 of 121 (100.0%) changed or added relevant lines in 4 files are covered.
  • 16 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 97.502%

Files with Coverage Reduction New Missed Lines %
pyccl/pyutils.py 16 90.94%
Totals Coverage Status
Change from base Build 2781888489: 0.2%
Covered Lines: 4840
Relevant Lines: 4964

💛 - Coveralls

pyccl/tests/test_pk2d.py Outdated Show resolved Hide resolved
@nikfilippas nikfilippas changed the title Enhancements for the Pk2D object. Enhancements for the Pk2D, Tk3D, Tracer. May 10, 2022
@nikfilippas nikfilippas changed the title Enhancements for the Pk2D, Tk3D, Tracer. Enhancements for Pk2D, Tk3D, Tracer. May 10, 2022
Copy link
Collaborator

@damonge damonge left a comment

Choose a reason for hiding this comment

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

Alright, a nice one!
Lots of comments, but nothing major.

pyccl/pyutils.py Outdated Show resolved Hide resolved
pyccl/pk2d.py Show resolved Hide resolved
pyccl/pk2d.py Show resolved Hide resolved
pyccl/tracers.py Outdated Show resolved Hide resolved
pyccl/tracers.py Outdated Show resolved Hide resolved
pyccl/pk2d.py Show resolved Hide resolved
pyccl/pk2d.py Outdated Show resolved Hide resolved
pyccl/pk2d.py Show resolved Hide resolved
pyccl/pk2d.py Show resolved Hide resolved
pyccl/tests/test_tk3d.py Show resolved Hide resolved
@nikfilippas
Copy link
Contributor Author

@damonge back to you.

@damonge
Copy link
Collaborator

damonge commented Aug 4, 2022

Alright @nikfilippas , almost there

@nikfilippas
Copy link
Contributor Author

@damonge I think I addressed your final comments, have a look and let me know if you have any more questions/suggestions.

Copy link
Collaborator

@damonge damonge left a comment

Choose a reason for hiding this comment

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

LGTM!

@nikfilippas nikfilippas merged commit ec71862 into master Aug 4, 2022
@nikfilippas nikfilippas deleted the pk2d_extensions branch August 4, 2022 12:40
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.

None yet

3 participants