GithubHelp home page GithubHelp logo

Comments (10)

steven-murray avatar steven-murray commented on August 14, 2024

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.

StephenJTurnbull avatar StephenJTurnbull commented on August 14, 2024

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.

steven-murray avatar steven-murray commented on August 14, 2024

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.

StephenJTurnbull avatar StephenJTurnbull commented on August 14, 2024

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.

steven-murray avatar steven-murray commented on August 14, 2024

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.

StephenJTurnbull avatar StephenJTurnbull commented on August 14, 2024

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.

steven-murray avatar steven-murray commented on August 14, 2024

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.

steven-murray avatar steven-murray commented on August 14, 2024

Hi did this ever get sorted out?

from hmf.

StephenJTurnbull avatar StephenJTurnbull commented on August 14, 2024

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.

steven-murray avatar steven-murray commented on August 14, 2024

Thank you!

from hmf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.