Closed segasai closed 5 years ago
:+1: thanks! I don't suppose you have any tests already built for this? I'll go ahead and merge, but it would be great if we had some correctness / consistency tests.
No I didn't. How do yo run your tests ? I wasn't able to run them due to 'from .. import imf' lines
Either cd to the source directory and run pytest
(this is the automated framework) or, with imf
installed, do something like:
python -c "import imf.tests.test_imf; imf.tests.test_imf.test_kroupa_integral()"
That's exactly what I tried before and it didn't work for me I'm using python 3.5
__________________ ERROR collecting imf/tests/test_imf.py ____________________
imf/tests/test_imf.py:4: in <module>
from .. import imf
E SystemError: Parent module '' not loaded, cannot perform relative import
I think something changed in relative imports in python, that I don't fully understand
That's my mistake. In order for tests/
to be a module, a (blank) __init__.py
file is required. I had created one locally but forgot to push it to github. Grab the latest master
and try again?
thanks, it works now
I've put a new pull request with rudimentary tests
Here is the infrastructure to create any arbitrary distribution from segments of normal distributions.
Here is how you define a Chabrier2005-like IMF dd=distributions.CompositeDistribution([distributions.TruncatedLogNormal(0.3,0.5,0.08,1),distributions.PowerLaw(-2.55,1,np.inf)])
The distributions support .pdf() .cdf() and .rvs() methods to generate samples. All the distributions -- are proper probability distributions (not densities) so they are all by construction integrate to 1.
My suggestion, is to replace piece by piece the imf.py code by this.