Comments (10)
HI Stephen,
It's a bit odd that you got an error on the simple example! The particular error that you got is because you haven't set up a logger to report the true error. I do need to fix this behaviour (it is very unintuitive and clunky) at some point (hopefully soon, but I have a Thesis to complete!). In any case, you can see the actual error by setting up a logger like this:
import logging
hmflog = logging.getLogger("hmf")
hmflog.addHandler(logging.StreamHandler())
That is something you shouldn't have to do yourself, but as I said, I need to fix it at some point. In any case, that should print to screen the actual error that is occurring, which we can then try to fix. My bet is that the error says that you don't have CAMB installed ;)
from hmf.
When I installed CAMB it didn't complain.
and
import pycamb
Works as advertised . . . I think.
import sys
import logging
from hmf import MassFunction
ch = logging.StreamHandler(sys.stdout)
hmflog = logging.getLogger("hmf")
hmflog.addHandler(logging.StreamHandler())
mass_func = hmf.dndlnmfrom hmf import MassFunction
hmf = MassFunction()
mass_func = hmf.dndlnm
mass_variance = hmf.sigma
hmf.update(omegab = 0.05,z=10)
cumulative_mass_func = hmf.ngtm
The specified mass-range was almost entirely outside of the limits from the fit. Ignored fit range...
The specified mass-range was almost entirely outside of the limits from the fit. Ignored fit range...
from hmf.
Hi Stephen,
Okay, the error there is coming up because the mass range specified is mostly (I think >80%) outside the range of the fit that you're using (I think the default fit is Tinker08, but you can check which it's using by hmf.mf_fit
).
In general, there's two ways of getting rid of this warning -- either change the mass range, or when instantiating, use hmf = MassFunction(cut_fit=False)
. However, the latter should give you exactly the same result that you have now (just without the warning).
The odd thing is, this warning shouldn't be coming up for the default example. The default mass range is 10^10 - 10^15 h^-1 M_sun, which is precisely the Tinker08 mass range. So you can check those values (check hmf.Mmin
and hmf.Mmax
).
Cheers,
Steven
from hmf.
As you said, the mass ranges are correct.
hmf.mf_fit
Out[8]: hmf.fitting_functions.Tinker08
In [7]: hmf.Mmin
Out[7]: 10
In [6]: hmf.Mmax
Out[6]: 15In [8]:
Should I simply ignore the warning?
from hmf.
Hi Stephen,
I was wrong about the exact mass cuts for Tinker08 -- I just had a look at the code and it says:
if cut_fit:
if self.z == 0.0:
vfv[np.logical_or(self.lnsigma / np.log(10) < -0.6 ,
self.lnsigma / np.log(10) > 0.4)] = np.nan
else:
vfv[np.logical_or(self.lnsigma / np.log(10) < -0.2 ,
self.lnsigma / np.log(10) > 0.4)] = np.nan
So if you're using the default redshift 0, then the function should be cut at log_10(1/sigma) = -0.6 and 0.4. You can check the values you're generating for this quantity by
hmf.lnsigma.min()/np.log(10)
hmf.lnsigma.max()/np.log(10)
For your mass range, most of the masses should be inside this range. For instance, I just ran it now and got
In [6]: hmf.lnsigma.min()/log(10)
Out[6]: -0.58428901837496061
In [7]: hmf.lnsigma.max()/log(10)
Out[7]: 0.28098077288873397
If these values are wildly different, then something weird is going on.
from hmf.
In [18]: h.lnsigma.min()/math.log(10)
Out[18]: -0.58725447038011647
In [19]: h.lnsigma.max()/math.log(10)
Out[19]: 0.25693207174218674
Mine and yours agree to within the stochastic expectations.
Why is mine giving me a warning on runtime then?
from hmf.
Hmmm very strange. If I were in this situation now, I would do the following (which you can temporarily as well if you can edit the source code of hmf). Replace the fsigma
method of Tinker08 (situated at about line 490 of the fitting_functions.py module) with
def fsigma(self, cut_fit):
vfv = self.A * ((self.sigma / self.b) ** (-self.a) + 1) * np.exp(-self.c / self.sigma ** 2)
print "NANS IN ORIGINAL VFV: ", np.sum(np.isnan(vfv))
if cut_fit:
if self.z == 0.0:
vfv[np.logical_or(self.lnsigma / np.log(10) < -0.6 ,
self.lnsigma / np.log(10) > 0.4)] = np.nan
print "NANS IN CUT VFV: ", np.sum(np.isnan(vfv)), vfv[0], vfv[-1]
print "MIN/MAX LNSIGMA: ", self.lnsigma.min()/np.log(10),self.lnsigma.max()/np.log(10)
else:
vfv[np.logical_or(self.lnsigma / np.log(10) < -0.2 ,
self.lnsigma / np.log(10) > 0.4)] = np.nan
return vfv
This should tell you where the NaN's are coming from. Basically, this result is passed back to the fsigma
method of the main MassFunction
class, which checks what percentage of NaN's there are in the array. If most are NaN's, it (probably unreasonably, this is fixed in the development branch at the moment) issues your warning, and forces cut_fit to be False, and redoes the calculation.
Sorry about all the hassle -- I do hope it's worth sorting out!
from hmf.
Hi did this ever get sorted out?
from hmf.
Yes, sorry, adding the 'include logger' got it working.
Thank you again.
Date: Wed, 19 Aug 2015 21:12:45 -0700
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [hmf] No handlers could be found for logger "hmf" (#4)
Hi did this ever get sorted out?
—
Reply to this email directly or view it on GitHub.
from hmf.
Thank you!
from hmf.
Related Issues (20)
- [BUG] neutrino mass incorrectly implemented HOT 3
- [BUG] RTD Isn't showing latest vesion HOT 1
- [Feature Req] Have default hi-res CAMB transfers for common cosmologies
- [Feature Req] Add smooth filter from Leo+2018
- [Feature Req] Direct calculation of growth factor for alternative dark energy models HOT 5
- [BUG] Remove ignoring D200
- [BUG] Remove Flake8 D400
- [BUG] Check E501
- [BUG] Typo in Watson SO parameters HOT 2
- [Question] Reference for Tinker+08 parameters HOT 2
- [BUG] Deployment Is Wonky
- [BUG] ModuleNotFoundError on Python 3.10.4 HOT 1
- HMF sampler does not take into account Mmax (upper limit on logmass) [BUG] HOT 2
- Calculating Cumulative Stellar Mass Density for a given redshift range. HOT 11
- [Feature Req] Including Planck 18 Cosmology HOT 7
- [BUG] Developer installation ends with an error HOT 1
- [Feature Req] Upcoming Features - Discussion HOT 5
- [Question] Getting HMF components HOT 1
- Calculation of the unnormalized sigma and dlns/dlnm parameters HOT 2
- [Question]How do I input my own power spectrum? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hmf.