Пример #1
0
    def view_eep_fit(self, mass, feh, plot_fit=True, order=5, p0=None, plot_p0=False):
        import holoviews as hv
        hv.extension('bokeh')
        subdf = self.df.xs((mass, feh), level=('initial_mass', 'initial_feh'))

        ds = hv.Dataset(subdf)
        pts = hv.Points(ds, kdims=['age', 'eep'], vdims=['phase', 'interpolated']).options(tools=['hover'], width=800, height=400, marker='+')
        primary_eeps = self.primary_eeps
        primary_ages = [subdf.loc[e].age for e in primary_eeps if e < subdf.eep.max()]

        from isochrones.eep import eep_fn, eep_jac, eep_fn_p0
        from scipy.optimize import curve_fit
        if p0 is None:
            p0 = eep_fn_p0(subdf.age.values, subdf.eep.values, order=order)

        m = subdf.eep < 808
        if plot_fit:
            pfit, _ = curve_fit(partial(eep_fn, order=order), subdf.age.values[m], subdf.eep.values[m], p0, jac=partial(eep_jac, order=order))
            fit = hv.Points([(a, eep_fn(a, *pfit)) for a in subdf.age])
        if plot_p0:
            p0_fit = hv.Points([(a, eep_fn(a, *p0)) for a in subdf.age])

        olay = pts * hv.Points([(a, e) for a, e in zip(primary_ages, primary_eeps)]).options(size=8)
        if plot_fit:
            olay = olay * fit
        if plot_p0:
            olay = olay * p0_fit
        return olay
Пример #2
0
    def view_eep_fit(self,
                     mass,
                     feh,
                     plot_fit=True,
                     order=5,
                     p0=None,
                     plot_p0=False):
        import holoviews as hv
        hv.extension('bokeh')
        subdf = self.df.xs((mass, feh), level=('initial_mass', 'initial_feh'))

        ds = hv.Dataset(subdf)
        pts = hv.Points(ds,
                        kdims=['age', 'eep'],
                        vdims=['phase',
                               'interpolated']).options(tools=['hover'],
                                                        width=800,
                                                        height=400,
                                                        marker='+')
        primary_eeps = self.primary_eeps
        primary_ages = [
            subdf.loc[e].age for e in primary_eeps if e < subdf.eep.max()
        ]

        from isochrones.eep import eep_fn, eep_jac, eep_fn_p0
        from scipy.optimize import curve_fit
        if p0 is None:
            p0 = eep_fn_p0(subdf.age.values, subdf.eep.values, order=order)

        m = subdf.eep < 808
        if plot_fit:
            pfit, _ = curve_fit(partial(eep_fn, order=order),
                                subdf.age.values[m],
                                subdf.eep.values[m],
                                p0,
                                jac=partial(eep_jac, order=order))
            fit = hv.Points([(a, eep_fn(a, *pfit)) for a in subdf.age])
        if plot_p0:
            p0_fit = hv.Points([(a, eep_fn(a, *p0)) for a in subdf.age])

        olay = pts * hv.Points([
            (a, e) for a, e in zip(primary_ages, primary_eeps)
        ]).options(size=8)
        if plot_fit:
            olay = olay * fit
        if plot_p0:
            olay = olay * p0_fit
        return olay
Пример #3
0
 def get_eep_fit(self, mass, age, feh, approx=False):
     eep_fn_pars = self.approx_eep_interp([feh, mass], 'all')
     eep = eep_fn(age, *eep_fn_pars)
     if approx:
         return eep
     else:
         i, _ = searchsorted(self.primary_eeps_arr, eep)
         try:
             return polyval(self.eep_interps[i-1]([feh, mass], 'all'), age)
         except IndexError:
             if age > eep_fn_pars[-2]:
                 return polyval(self.eep_interps[-1]([feh, mass], 'all'), age)  # assume you're in last bit
             else:
                 logging.warning('EEP conversion failed for mass={}, age={}, feh={} (approx eep = {}).  Returning nan.'.format(mass, age, feh, eep))
                 return np.nan
Пример #4
0
 def get_eep_fit(self, mass, age, feh, approx=False):
     eep_fn_pars = self.approx_eep_interp([feh, mass], 'all')
     eep = eep_fn(age, *eep_fn_pars)
     if approx:
         return eep
     else:
         i, _ = searchsorted(self.primary_eeps_arr, eep)
         try:
             return polyval(self.eep_interps[i - 1]([feh, mass], 'all'),
                            age)
         except IndexError:
             if age > eep_fn_pars[-2]:
                 return polyval(self.eep_interps[-1]([feh, mass], 'all'),
                                age)  # assume you're in last bit
             else:
                 getLogger().warning(
                     'EEP conversion failed for mass={}, age={}, feh={} (approx eep = {}).  Returning nan.'
                     .format(mass, age, feh, eep))
                 return np.nan