Ejemplo n.º 1
0
    def to_mags_old(self, b, z=0., d=None, magnification=1.):
        from pystella.rf.star import Star
        from pystella.rf import band
        # from pystella.rf.lc import LightCurve, SetLightCurve

        if b is None:
            raise ValueError("Band must be defined.")
        if not self.is_time:
            return ValueError("No spectral time points.")

        # mags = np.zeros(len(self.Time))
        times = []
        mags = []
        for k, t in enumerate(self.Time):
            try:
                star = Star(k, self.get_spec(k), is_flux_eq_luminosity=True)
                star.set_distance(d)
                star.set_redshift(z)
                star.set_magnification(magnification)
                # mag = star.flux_to_mag(b)
                if b.Name == band.Band.NameBol:
                    mag = star.magBol(b)
                else:
                    mag = star.magAB(b)
                times.append(t)
                mags.append(mag)
            except ValueError as ex:
                logger.error("Could not compute mag {} for band {} at {} due to {}.".
                             format(self.Name, b.Name, t, ex))
        return times, mags
Ejemplo n.º 2
0
    def to_mag(self, b, z=0., d=phys.pc2cm(10.), magnification=1.):
        """
        Compute the magnitude for the band
        :param b: photometric band
        :param z: redshift,  default: 0
        :param d: distance [cm], default: 10 pc
        :param magnification: , default: 1
        :return:
        """
        if b is None:
            raise ValueError("Band must be defined.")

        from pystella.rf.star import Star
        from pystella.rf import band

        star = Star('', self, is_flux_eq_luminosity=True)
        star.set_distance(d)
        star.set_redshift(z)
        star.set_magnification(magnification)
        # mag = star.flux_to_mag(b)
        if b.Name in [band.Band.NameBol, band.Band.NameBolQuasi, band.Band.NameUBVRI]:
            mag = star.magBol(b)
        else:
            mag = star.magAB(b)
        return mag
Ejemplo n.º 3
0
    def flux_to_mags(self, b, z=0., d=0., magnification=1.):
        from pystella.rf.star import Star

        if b is None:
            raise ValueError("Band must be defined.")
        if not self.is_time:
            return ValueError("No spectral time points.")

        mags = np.zeros(len(self.Time))
        for k, t in enumerate(self.Time):
            star = Star(k, self.get_spec(k))
            star.set_distance(d)
            star.set_redshift(z)
            star.set_magnification(magnification)
            # mag = star.flux_to_mag(b)
            mag = star.magAB(b)
            mags[k] = mag
            # if self.times[k] > 50:
            #     spec.plot_spec(title="t=%f, mag=%f" % (self.times[k], mag))

        return mags
Ejemplo n.º 4
0
    def flux_to_mags(self, b, z=0., d=0., magnification=1.):
        if b is None:
            return None
        if not self.is_time:
            return None

        mags = np.zeros(len(self.Time))
        for k in range(len(self.Time)):
            star = Star(k, self.get_spec(k))
            star.set_distance(d)
            star.set_redshift(z)
            star.set_magnification(magnification)
            # mag = star.flux_to_mag(b)
            mag = star.magAB(b)
            mags[k] = mag
            # if self.times[k] > 50:
            #     spec.plot_spec(title="t=%f, mag=%f" % (self.times[k], mag))

        return mags
Ejemplo n.º 5
0
def epsilon(theta, freq, mag, bands, radius, dist, z):
    temp_color, zeta = theta
    e = 0
    if temp_color < 0 or zeta < 0:
        for b in bands:
            e += mag[b] ** 2
        return e
    # sp = spectrum.SpectrumDilutePlanck(freq, temp_color, W=zeta**2)
    sp = spectrum.SpectrumDilutePlanck(freq, temp_color, W=zeta ** 2)
    # sp.correct_zeta(zeta)

    star = Star("bb", sp)
    star.set_radius_ph(radius)
    star.set_distance(dist)
    star.set_redshift(z)
    mag_bb = {b: star.magAB(band.band_by_name(b)) for b in bands}
    for b in bands:
        e += (mag[b] - mag_bb[b]) ** 2
    return e