Repository: skypyproject/skypy

Issue:
Sheth-Tormen halo mass function
## Description
Sophistication on the Press-Schechter halo mass function which includes effects from non-spherical collapse of haloes and has parameters tuned to a (relatively) primitive N-body simulation.

## Inputs
- Background cosmology
- Linear perturbation matter power spectrum

## Outputs
 - Catalogue of halo masses and redshifts

## References
- https://ui.adsabs.harvard.edu/link_gateway/2002MNRAS.329...61S/doi:10.1046/j.1365-8711.2002.04950.x

Discussion:
skypybot: Hello @Lucia-Fonseca! Thanks for opening this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:

* In the file [`skypy/halo_sampler.py`](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py):

> [Line 1:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L1): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1:80](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L1): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (95 > 79 characters)
> [Line 2:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L2): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 10:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L10): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 11:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L11): [E302](https://duckduckgo.com/?q=pep8%20E302) expected 2 blank lines, found 1
> [Line 12:26](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L12): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 12:32](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L12): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 12:37](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L12): [E261](https://duckduckgo.com/?q=pep8%20E261) at least two spaces before inline comment
> [Line 12:38](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L12): [E262](https://duckduckgo.com/?q=pep8%20E262) inline comment should start with '# '
> [Line 13:6](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L13): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 13:24](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L13): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 13:30](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L13): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 17:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L17): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 18:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L18): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 19:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L19): [E302](https://duckduckgo.com/?q=pep8%20E302) expected 2 blank lines, found 1
> [Line 19:37](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L19): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 20:6](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L20): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 20:24](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L20): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 20:30](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L20): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 23:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L23): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 24:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L24): [E302](https://duckduckgo.com/?q=pep8%20E302) expected 2 blank lines, found 1
> [Line 25:26](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L25): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 25:32](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L25): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 26:26](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L26): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 26:32](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L26): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 27:80](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L27): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (111 > 79 characters)
> [Line 31:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L31): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 31:80](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L31): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (101 > 79 characters)
> [Line 32:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L32): [E302](https://duckduckgo.com/?q=pep8%20E302) expected 2 blank lines, found 1
> [Line 33:59](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L33): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 36:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L36): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 37:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L37): [E302](https://duckduckgo.com/?q=pep8%20E302) expected 2 blank lines, found 1
> [Line 37:19](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L37): [E261](https://duckduckgo.com/?q=pep8%20E261) at least two spaces before inline comment
> [Line 37:19](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L37): [E262](https://duckduckgo.com/?q=pep8%20E262) inline comment should start with '# '
> [Line 37:54](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L37): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 38:5](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L38): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 38:60](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L38): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 39:5](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L39): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 39:80](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L39): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (107 > 79 characters)
> [Line 40:7](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L40): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 40:23](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L40): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 40:27](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L40): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 41:80](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L41): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (106 > 79 characters)
> [Line 44:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L44): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 45:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L45): [E302](https://duckduckgo.com/?q=pep8%20E302) expected 2 blank lines, found 1
> [Line 45:13](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L45): [E261](https://duckduckgo.com/?q=pep8%20E261) at least two spaces before inline comment
> [Line 45:13](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L45): [E262](https://duckduckgo.com/?q=pep8%20E262) inline comment should start with '# '
> [Line 45:48](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L45): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 46:5](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L46): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 46:60](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L46): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 47:5](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L47): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 47:80](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L47): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (88 > 79 characters)
> [Line 48:7](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L48): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 48:23](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L48): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 48:27](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L48): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 53:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L53): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 54:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L54): [E302](https://duckduckgo.com/?q=pep8%20E302) expected 2 blank lines, found 1
> [Line 54:20](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L54): [E261](https://duckduckgo.com/?q=pep8%20E261) at least two spaces before inline comment
> [Line 54:20](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L54): [E262](https://duckduckgo.com/?q=pep8%20E262) inline comment should start with '# '
> [Line 54:63](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L54): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 55:5](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L55): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 55:60](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L55): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 56:5](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L56): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 56:80](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L56): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (88 > 79 characters)
> [Line 57:7](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L57): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 57:23](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L57): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 57:27](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L57): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 60:33](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L60): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 60:35](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L60): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 63:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L63): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 64:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L64): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 65:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L65): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 66:2](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L66): [E114](https://duckduckgo.com/?q=pep8%20E114) indentation is not a multiple of four (comment)
> [Line 66:2](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L66): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 66:2](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L66): [E303](https://duckduckgo.com/?q=pep8%20E303) too many blank lines (3)
> [Line 66:62](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L66): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace
> [Line 67:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L67): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 68:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L68): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 69:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L69): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 70:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L70): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 70:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L70): [E303](https://duckduckgo.com/?q=pep8%20E303) too many blank lines (3)
> [Line 71:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L71): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 72:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L72): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 75:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L75): [E305](https://duckduckgo.com/?q=pep8%20E305) expected 2 blank lines after class or function definition, found 3
> [Line 75:10](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L75): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 75:26](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L75): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 75:31](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L75): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 76:19](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L76): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 77:15](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L77): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 83:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L83): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 83:1](https://github.com/skypyproject/skypy/blob/f8db5213adce8c7e445db73cdf5a038bf78a0f29/skypy/halo_sampler.py#L83): [W391](https://duckduckgo.com/?q=pep8%20W391) blank line at end of file


codecov[bot]: # [Codecov](https://codecov.io/gh/skypyproject/skypy/pull/186?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@0560b72`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/skypyproject/skypy/pull/186/graphs/tree.svg?width=650&height=150&src=pr&token=9jNO45edcU)](https://codecov.io/gh/skypyproject/skypy/pull/186?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##             master     #186   +/-   ##
=========================================
  Coverage          ?   95.75%           
=========================================
  Files             ?       21           
  Lines             ?      565           
  Branches          ?        0           
=========================================
  Hits              ?      541           
  Misses            ?       24           
  Partials          ?        0           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/skypyproject/skypy/pull/186?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/skypyproject/skypy/pull/186?src=pr&el=footer). Last update [0560b72...28839d8](https://codecov.io/gh/skypyproject/skypy/pull/186?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Lucia-Fonseca: I would appreciate some help here. I have written the code in terms of mass. Is that what the user would expect from this code? If so, I would start writing the test file.
Lucia-Fonseca: I am also uncertain whether this code should be inside `skypy\halo\mass.py`.
Lucia-Fonseca: This code breaks for `m_max > 1.0e12` solar masses. 
Also, we are following Mo, H. and van den Bosch, F. and White, S. (2010), Cambridge University Press, ISBN: 9780521857932.
I would suggest using https://arxiv.org/pdf/1306.6721.pdf as a reference. It's much easier to follow. Also,  results can be compared using the HMF calculator https://hmf.icrar.org. 
For now, I can't make my results agree with this but it helped me fix the units.
Lucia-Fonseca: The code is producing good results now.
I would appreciate if someone could obtain the mass function for, let's say, `m = 10**np.arange(9.0, 12.0, 2)` . I do not seem to have problems locally in a Juyter notebook. However, it gives me `NaN` when I run `tox -e test-scipy14`. Any idea?
itrharrison: > The code is producing good results now.
> I would appreciate if someone could obtain the mass function for, let's say, `m = 10**np.arange(9.0, 15.5, 2)` . I do not seem to have problems locally in a Juyter notebook. However, it gives me `NaN` when I run `tox -e test-scipy14`. Any idea?

The tests pass for me locally.
```
(base) Ians-MBP:halo harrison$ git branch
  adr-02
  camb
  camb-rename
  develop
  eisenstein_hu
  growth-carroll
* halo_sampler
  master
(base) Ians-MBP:halo harrison$ nosetests
...
----------------------------------------------------------------------
Ran 3 tests in 0.009s

OK
```
Lucia-Fonseca: I have issues passing the test here. I keep getting `NaN` that, locally, I do not.

Also, please feel free to suggest more tests  

Patch:
diff --git a/skypy/halo/mass.py b/skypy/halo/mass.py
index b2e2b05..20cef27 100644
--- a/skypy/halo/mass.py
+++ b/skypy/halo/mass.py
@@ -1,63 +1,319 @@
-r'''Halo mass module.
-
-This module provides methods to sample the  masses of dark matter halos.
+r'''Halo mass sampler.
+This code samples halos from their mass function.
 
 Models
 ======
-
 .. autosummary::
    :nosignatures:
    :toctree: ../api/
 
    press_schechter
-
+   halo_mass_function
+   halo_mass_sampler
+   ellipsoidal_collapse_function
+   press_schechter_collapse_function
+   sheth_tormen_collapse_function
+   press_schechter
+   sheth_tormen
 '''
 
 import numpy as np
+from scipy import integrate
+from functools import partial
+from astropy import units
 
-from skypy.utils.random import schechter
+__all__ = [
+    'halo_mass_function',
+    'halo_mass_sampler',
+    'sheth_tormen_collapse_function',
+    'press_schechter_collapse_function',
+    'sheth_tormen_mass_function',
+    'press_schechter_mass_function',
+    'sheth_tormen',
+    'press_schechter',
+ ]
 
 
-def press_schechter(n, m_star, size=None, x_min=0.00305,
-                    x_max=1100.0, resolution=100):
-    """Sampling from Press-Schechter mass function (1974).
-
-    Masses following the Press-Schechter mass function following the
-    Press et al. [1]_ formalism.
+def halo_mass_function(M, wavenumber, power_spectrum, growth_function,
+                       cosmology, collapse_function, params):
+    r'''Halo mass function.
+    This function computes the halo mass function, defined
+    in equation 7.46 in [1]_.
 
     Parameters
+    -----------
+    M : (nm,)
+        Array for the halo mass, in units of solar masses.
+    wavenumber : (nk,) array_like
+        Array of wavenumbers at which the power spectrum is evaluated,
+        in units of [Mpc^-1].
+    power_spectrum: (nk,) array_like
+        Linear power spectrum at redshift 0 in [Mpc^3].
+    growth_function : float
+        The growth function evaluated at a given redshift for the given
+        cosmology.
+    cosmology : astropy.cosmology.Cosmology
+        Cosmology object providing methods for the evolution history of
+        omega_matter and omega_lambda with redshift.
+    collapse_function: function
+        Collapse function to choose from a variety of models:
+        `sheth_tormen_collapse_function`, `press_schechter_collapse_function`.
+    params: tuple
+        List of parameters that determines the model used for
+        the collapse function.
+
+    Returns
+    --------
+    mass_function: (nm,) array_like
+        Halo mass function for a given mass array, cosmology and redshift, in
+        units of :math:`Mpc^{-3} M_{Sun}^{-1}`.
+
+    Examples
+    ---------
+    >>> import numpy as np
+    >>> from skypy.halo import mass
+    >>> from skypy.power_spectrum import eisenstein_hu
+
+    This example will compute the halo mass function for elliptical and
+    spherical collapse, for a Planck15 cosmology at redshift 0.
+    The power spectrum is given by the Eisenstein and Hu fitting formula:
+
+    >>> from astropy.cosmology import Planck15
+    >>> cosmo = Planck15
+    >>> D0 = 1.0
+    >>> k = np.logspace(-3, 1, num=1000, base=10.0)
+    >>> A_s, n_s = 2.1982e-09, 0.969453
+    >>> Pk = eisenstein_hu(k, A_s, n_s, cosmo, kwmap=0.02, wiggle=True)
+
+    The Sheth and Tormen mass function at redshift 0:
+
+    >>> m = 10**np.arange(9.0, 12.0, 2)
+    >>> mass.sheth_tormen_mass_function(m, k, Pk, D0, cosmo)
+    array([3.07523240e-11, 6.11387743e-13])
+
+    And the Press-Schechter mass function at redshift 0:
+
+    >>> mass.press_schechter_mass_function(m, k, Pk, D0, cosmo)
+    array([3.46908809e-11, 8.09874945e-13])
+
+    For any other collapse models:
+
+    >>> params_model = (0.3, 0.7, 0.3, 1.686)
+    >>> mass.halo_mass_function(m, k, Pk, D0, cosmo,
+    ...     ellipsoidal_collapse_function, params=params_model)
+    array([2.85598921e-11, 5.67987501e-13])
+
+    References
     ----------
-    n : float or int
-        The n parameter in the Press-Schechter mass function.
-    m_star : float or int
-        Factors parameterising the characteristic mass.
+    .. [1] Mo, H. and van den Bosch, F. and White, S. (2010), Cambridge
+        University Press, ISBN: 9780521857932.
+    '''
+    sigma = np.sqrt(_sigma_squared(M, wavenumber, power_spectrum,
+                                   growth_function, cosmology))
+    f_c = collapse_function(sigma, params)
+
+    dlognu_dlogm = _dlns_dlnM(sigma, M)
+    rho_bar = (cosmology.critical_density0.to(units.Msun / units.Mpc ** 3)).value
+    rho_m0 = cosmology.Om0 * rho_bar
+
+    return rho_m0 * f_c * dlognu_dlogm / np.power(M, 2)
+
+
+def halo_mass_sampler(m_min, m_max, resolution, wavenumber, power_spectrum,
+                      growth_function, cosmology,
+                      collapse_function, params, size=None):
+    r'''Halo mass sampler.
+    This function samples haloes from their mass function,
+    see equation 7.46 in [1]_.
+
+    Parameters
+    -----------
+    m_min, m_max : array_like
+        Lower and upper bounds for the random variable m.
+    resolution: int
+        Resolution of the inverse transform sampling spline.
+    wavenumber : (nk,) array_like
+        Array of wavenumbers at which the power spectrum is evaluated,
+        in units of [Mpc^-1].
+    power_spectrum: (nk,) array_like
+        Linear power spectrum at redshift 0 in [Mpc^3].
+    growth_function : float
+        The growth function evaluated at a given redshift for the given
+        cosmology.
+    cosmology : astropy.cosmology.Cosmology
+        Cosmology object providing methods for the evolution history of
+        omega_matter and omega_lambda with redshift.
+    collapse_function: function
+        Collapse function to choose from a variety of models:
+        `sheth_tormen_collapse_function`, `press_schechter_collapse_function`.
+    params : tuple
+        List of parameters that determines the model used for
+        the halo mass function. The first parameter should be the name of
+        collapse function, followed by a second tuple with the parameters
+        of the chosen collapse model.
     size: int, optional
-         Output shape of luminosity samples.
-    x_min, x_max : float or int, optional
-        Lower and upper bounds in units of M*.
-    resolution : int, optional
-        Resolution of the inverse transform sampling spline. Default is 100.
+        Output shape of samples. Default is None.
 
     Returns
-    -------
-    mass : array_like
-        Drawn masses from the Press-Schechter mass function.
+    --------
+    sample: (size,) array_like
+        Samples drawn from the mass function, in units of solar masses.
 
     Examples
+    ---------
+    >>> import numpy as np
+    >>> from skypy.halo import mass
+    >>> from skypy.power_spectrum import eisenstein_hu
+
+    This example will sample from the halo mass function for
+    a Planck15 cosmology at redshift 0. The power spectrum is given
+    by the Eisenstein and Hu fitting formula:
+
+    >>> from astropy.cosmology import Planck15
+    >>> cosmo = Planck15
+    >>> D0 = 1.0
+    >>> k = np.logspace(-3, 1, num=100, base=10.0)
+    >>> A_s, n_s = 2.1982e-09, 0.969453
+    >>> Pk = eisenstein_hu(k, A_s, n_s, cosmo, kwmap=0.02, wiggle=True)
+
+    Sampling from the Sheth and Tormen mass function:
+
+    >>> mass.sheth_tormen(10**9, 10**12, 100, k, Pk, D0, cosmo)
+    29585260719.18...
+
+    And from the Press-Schechter mass function:
+
+    >>> mass.press_schechter(10**9, 10**12, 100, k, Pk, D0, cosmo)
+    29281420133.34...
+
+    For any other collapse models:
+
+    >>> params_model = (0.3, 0.7, 0.3, 1.686)
+    >>> mass.halo_mass_sampler(10**9, 10**12, 100, k, Pk, D0, cosmo,
+    ...     ellipsoidal_collapse_function, params=params_model)
+    1504984926.64...
+
+    References
+    ----------
+    .. [1] Mo, H. and van den Bosch, F. and White, S. (2010), Cambridge
+        University Press, ISBN: 9780521857932.
+    '''
+    m = np.logspace(np.log10(m_min), np.log10(m_max), resolution)
+
+    massf = halo_mass_function(
+            m, wavenumber, power_spectrum, growth_function,
+            cosmology, collapse_function, params=params)
+
+    CDF = integrate.cumtrapz(massf, m, initial=0)
+    CDF = CDF / CDF[-1]
+    n_uniform = np.random.uniform(size=size)
+    return np.interp(n_uniform, CDF, m)
+
+
+def ellipsoidal_collapse_function(sigma, params):
+    r'''Spherical collapse function.
+    This function computes the mass function for ellipsoidal
+    collapse, see equation 10 in [1]_ or [2]_.
+
+    Parameters
+    -----------
+    sigma: (ns,) array_like
+        Array of the mass variance at different scales and at a given redshift.
+    params: float
+        The :math:`{A,a,p, delta_c}` parameters of the Sheth-Tormen formalism.
+
+    Returns
     --------
-    >>> import skypy.halo.mass as mass
-    >>> n, m_star = 1, 1e9
-    >>> sample = mass.press_schechter(n, m_star, size=1000, x_min=1e-10,
-    ...                               x_max=1e2, resolution=1000)
+    f_c: array_like
+        Array with the values of the collapse function.
+
+    Examples
+    ---------
+    >>> import numpy as np
+    >>> from skypy.halo import mass
+    >>> from skypy.power_spectrum import eisenstein_hu
+    >>> from skypy.power_spectrum import growth_function
+
+    This example will compute the mass function for
+    ellipsoidal collapse and a Planck15 cosmology at redshift 0.
+    The power spectrum is given by the Eisenstein and Hu fitting formula:
+
+    >>> from astropy.cosmology import Planck15
+    >>> cosmo = Planck15
+    >>> D0 = 1.0
+    >>> k = np.logspace(-3, 1, num=5, base=10.0)
+    >>> A_s, n_s = 2.1982e-09, 0.969453
+    >>> Pk = eisenstein_hu(k, A_s, n_s, cosmo, kwmap=0.02, wiggle=True)
+
+    The Sheth-Tormen collapse function at redshift 0:
+
+    >>> m = 10**np.arange(9.0, 12.0, 2)
+    >>> sigma = np.sqrt(_sigma_squared(m, k, Pk, D0, cosmo))
+    >>> mass.sheth_tormen_collapse_function(sigma)
+    array([0.17947815, 0.19952375])
+
+    And the Press-Schechter collapse function at redshift 0:
+
+    >>> mass.press_schechter_collapse_function(sigma)
+    array([0.17896132, 0.21613726])
+
+    For any other collapse models:
+
+    >>> params_model = (0.3, 0.7, 0.3, 1.686)
+    >>> mass.ellipsoidal_collapse_function(sigma, params=params_model)
+    array([0.16667541, 0.18529452])
 
     References
     ----------
-    .. [1] Press, W. H. and Schechter, P., APJ, (1974).
+    .. [1] R. K. Sheth and G. Tormen,  Mon. Not. Roy. Astron. Soc. 308, 119
+        (1999), astro-ph/9901122.
+    .. [2] https://www.slac.stanford.edu/econf/C070730/talks/
+        Wechsler_080207.pdf
+    '''
+    A, a, p, delta_c = params
+
+    return A * np.sqrt(2.0 * a / np.pi) * (delta_c / sigma) * \
+        np.exp(- 0.5 * a * (delta_c / sigma)**2) * \
+        (1.0 + np.power(np.power(sigma / delta_c, 2.0) / a, p))
+
+
+press_schechter_collapse_function = partial(ellipsoidal_collapse_function,
+                                            params=(0.5, 1, 0, 1.69))
+sheth_tormen_collapse_function = partial(ellipsoidal_collapse_function,
+                                         params=(0.3222, 0.707, 0.3, 1.686))
+sheth_tormen_mass_function = partial(
+                             halo_mass_function,
+                             collapse_function=ellipsoidal_collapse_function,
+                             params=(0.3222, 0.707, 0.3, 1.686))
+press_schechter_mass_function = partial(
+                                halo_mass_function,
+                                collapse_function=ellipsoidal_collapse_function,
+                                params=(0.5, 1, 0, 1.69))
+sheth_tormen = partial(halo_mass_sampler,
+                       collapse_function=ellipsoidal_collapse_function,
+                       params=(0.3222, 0.707, 0.3, 1.686))
+press_schechter = partial(halo_mass_sampler,
+                          collapse_function=ellipsoidal_collapse_function,
+                          params=(0.5, 1, 0, 1.69))
+
+
+def _sigma_squared(M, k, Pk, growth_function, cosmology):
+    M = np.atleast_1d(M)[:, np.newaxis]
+
+    # Growth function
+    Dz2 = np.power(growth_function, 2)
+
+    # Matter mean density today
+    rho_bar = (cosmology.critical_density0.to(units.Msun / units.Mpc ** 3)).value
+    rho_m0 = cosmology.Om0 * rho_bar
 
-    """
+    R = np.power(3 * M / (4 * np.pi * rho_m0), 1.0 / 3.0)
+    top_hat = 3. * (np.sin(k * R) - k * R * np.cos(k * R)) / ((k * R)**3.)
+    integrand = Pk * np.power(top_hat * k, 2)
 
-    alpha = - 0.5 * (n + 9.0) / (n + 3.0)
+    return Dz2 * integrate.simps(integrand, k) / (2. * np.pi**2.)
 
-    x_sample = schechter(alpha, x_min, x_max, resolution=resolution, size=size)
 
-    return m_star * np.power(x_sample, 3.0 / (n + 3.0))
+def _dlns_dlnM(sigma, M):
+    ds = np.gradient(sigma, M)
+    return np.absolute((M / sigma) * ds)


Test patch:
diff --git a/skypy/halo/tests/test_mass.py b/skypy/halo/tests/test_mass.py
index 089e6d8..1970f7b 100644
--- a/skypy/halo/tests/test_mass.py
+++ b/skypy/halo/tests/test_mass.py
@@ -1,26 +1,103 @@
 import numpy as np
-import scipy.stats
-import scipy.integrate
+from astropy.cosmology import Planck15
+from astropy.units import allclose
+from skypy.power_spectrum import eisenstein_hu
 
 
 import skypy.halo.mass as mass
 
+# Precomputed values for the test, for a Planck15 cosmology at redshift 0 and a
+# power spectrum given by the Eisenstein and Hu fitting formula
+# Models: Press-Schechter and Sheth-Tormen
+mass_array = [1.00000000e+10, 3.16227766e+10, 1.00000000e+11, 3.16227766e+11,
+              1.00000000e+12, 3.16227766e+12, 1.00000000e+13, 3.16227766e+13,
+              1.00000000e+14, 3.16227766e+14]
+ST_fsigma = [0.22851856, 0.24659885, 0.27788, 0.30138876, 0.31338251,
+             0.32004239, 0.31068427, 0.2676586, 0.16714694, 0.0957242]
+PS_fsigma = [0.27373595, 0.31173523, 0.38096078, 0.4358908, 0.4651783,
+             0.48375949, 0.46491057, 0.37505525, 0.18939675, 0.08453155]
+E_fsigma = [0.21224081, 0.22905786, 0.25820042, 0.28018667, 0.29148879,
+            0.29805329, 0.28973637, 0.25038455, 0.1574158, 0.09077113]
+ST_massf = [5.91918389e-12, 2.04006848e-12, 3.90033154e-13, 3.43105199e-14,
+            2.47935792e-15, 3.85619829e-16, 2.77447365e-17, 3.53176402e-18,
+            2.69047690e-19, 1.13766655e-20]
+PS_massf = [7.09042387e-12, 2.57893025e-12, 5.34717624e-13, 4.96224201e-14,
+            3.68030594e-15, 5.82882944e-16, 4.15174583e-17, 4.94886632e-18,
+            3.04862034e-19, 1.00464376e-20]
+E_massf = [5.49755090e-12, 1.89495500e-12, 3.62410841e-13, 3.18968432e-14,
+           2.30614353e-15, 3.59125102e-16, 2.58740463e-17, 3.30383237e-18,
+           2.53383973e-19, 1.07880011e-20]
 
-def test_press_schechter():
-    # Test the schechter function, sampling dimensionless x values
-    n, m_star = 1, 1e9
-    alpha = - 0.5 * (n + 9.0) / (n + 3.0)
+cosmo = Planck15
+k = np.logspace(-3, 1, num=10, base=10.0)
+A_s, n_s = 2.1982e-09, 0.969453
+Pk = eisenstein_hu(k, A_s, n_s, cosmo, kwmap=0.02, wiggle=True)
 
-    def calc_cdf(m):
-        x = np.power(m/m_star, 1 + n/3)
-        pdf = np.power(x, alpha) * np.exp(- x)
-        cdf = scipy.integrate.cumtrapz(pdf, x, initial=0)
-        cdf = cdf / cdf[-1]
-        return cdf
 
-    sample = mass.press_schechter(n, m_star, x_min=1e-1, x_max=1e2,
-                                  resolution=100, size=1000)
+def test_halo_mass_function():
+    # Test the output and shape is correct given an array of masses
+    m_array = np.asarray(mass_array)
 
-    # Test the distribution of galaxy mass follows the right distribution
-    p_value = scipy.stats.kstest(sample, calc_cdf)[1]
-    assert p_value > 0.01
+    # Any particular ellipsoidal collapse model
+    params_E = (0.3, 0.7, 0.3, 1.686)
+    fE = mass.ellipsoidal_collapse_function
+    array_output_E = mass.halo_mass_function(m_array, k, Pk, 1.0, cosmo,
+                                             fE, params=params_E)
+    assert array_output_E.shape == m_array.shape
+    assert allclose(array_output_E, E_massf)
+
+    # Sheth and Tormen collapse model
+    array_output_ST = mass.sheth_tormen_mass_function(m_array, k, Pk,
+                                                      1.0, cosmo)
+    assert array_output_ST.shape == m_array.shape
+    assert allclose(array_output_ST, ST_massf)
+
+    # Press-Schechter collapse model
+    array_output_PS = mass.press_schechter_mass_function(m_array, k, Pk,
+                                                         1.0, cosmo)
+    assert array_output_PS.shape == m_array.shape
+    assert allclose(array_output_PS, PS_massf)
+
+
+def halo_mass_sampler():
+    # Test the output shape is correct given the sample size
+    n_samples = 1000
+    m_min, m_max, resolution = 10**9, 10**12, 100
+    # Any particular ellipsoidal collapse model
+    params_E = (0.3, 0.7, 0.3, 1.686)
+    fE = mass.ellipsoidal_collapse_function
+    array_output_E = mass.halo_mass_sampler(m_min, m_max, resolution, k, Pk,
+                                            1.0, cosmo, fE, params=params_E,
+                                            size=n_samples)
+    assert len(array_output_E) == n_samples
+
+    # Sheth and Tormen collapse model
+    array_output_PS = mass.sheth_tormen(10**9, 10**12, 100, k,
+                                        Pk, 1.0, cosmo)
+    assert len(array_output_PS) == n_samples
+
+    # Press-Schechter collapse model
+    array_output_PS = mass.press_schechter(10**9, 10**12, 100, k,
+                                           Pk, 1.0, cosmo)
+    assert len(array_output_PS) == n_samples
+
+
+def test_ellipsoidal_collapse_function():
+    # Test any ellipsoidal model against precomputed values
+    m_array = np.asarray(mass_array)
+    sigma = np.sqrt(mass._sigma_squared(m_array, k, Pk, 1.0, cosmo))
+    params_E = (0.3, 0.7, 0.3, 1.686)
+    fE = mass.ellipsoidal_collapse_function(sigma, params_E)
+    assert allclose(fE, E_fsigma)
+
+    # Test the Sheth and Tormen model against precomputed values
+    m_array = np.asarray(mass_array)
+    sigma = np.sqrt(mass._sigma_squared(m_array, k, Pk, 1.0, cosmo))
+    fst = mass.sheth_tormen_collapse_function(sigma)
+    assert allclose(fst, ST_fsigma)
+
+    # Test the Press-Schechter model against precomputed values
+    m_array = np.asarray(mass_array)
+    sigma = np.sqrt(mass._sigma_squared(m_array, k, Pk, 1.0, cosmo))
+    fps = mass.press_schechter_collapse_function(sigma)
+    assert allclose(fps, PS_fsigma)