estimate  from mag
501714
def expected_magy(RAW_IMU, ATTITUDE, inclination, declination):
    ''''''
    v = expected_mag(RAW_IMU, ATTITUDE, inclination, declination)
    return v.y
793142
def mag_calibration(self):
        """"""
        self.calibration_state = self.CAL_MAG
        self.mag_dialog = SK8MagDialog(self.sk8.get_imu(self.spinIMU.value()), self)
        if self.mag_dialog.exec_() == QDialog.Rejected:
            return

        self.calculate_mag_calibration(self.mag_dialog.samples)
747021
def mag_discrepancy(RAW_IMU, ATTITUDE, inclination, declination=None):
    ''''''
    if declination is None:
        import mavutil
        declination = degrees(mavutil.mavfile_global.param('COMPASS_DEC', 0))
    expected = expected_mag(RAW_IMU, ATTITUDE, inclination, declination)
    mag = Vector3(RAW_IMU.xmag, RAW_IMU.ymag, RAW_IMU.zmag)
    return degrees(expected.angle(mag))
281035
def mag_pmf(matrix):
    
    nmags, ndists, nlons, nlats, neps = matrix.shape
    mag_pmf = numpy.zeros(nmags)
    for i in range(nmags):
        mag_pmf[i] = numpy.prod(
            [1. - matrix[i, j, k, l, m]
             for j in range(ndists)
             for k in range(nlons)
             for l in range(nlats)
             for m in range(neps)])
    return 1. - mag_pmf
628606
def mag_roll(RAW_IMU, inclination, declination):
    ''''''
    m = mag_rotation(RAW_IMU, inclination, declination)
    (r, p, y) = m.to_euler()
    return degrees(r)
246238
def _compute_mean(self, C, mag, rjb):
        
        m1 = 6.4
        r1 = 50.
        h = 6.
        R = np.sqrt(rjb ** 2 + h ** 2)
        R1 = np.sqrt(r1 ** 2 + h ** 2)
        less_r1 = rjb < r1
        ge_r1 = rjb >= r1

        mean = (C['c1'] + C['c4'] * (mag - m1) * np.log(R) + C['c5'] * rjb +
                C['c8'] * (8.5 - mag) ** 2)

        mean[less_r1] += C['c3'] * np.log(R[less_r1])
        mean[ge_r1] += (C['c3'] * np.log(R1) +
                        C['c6'] * (np.log(R[ge_r1]) - np.log(R1)))

        if mag < m1:
            mean += C['c2'] * (mag - m1)
        else:
            mean += C['c7'] * (mag - m1)

        return mean
1233027
def measure_mags(measures):
    
    import daophot

    image_downloader = ImageDownloader()

    observations = {}
    for measure in measures:
        for reading in measure:
            if reading.obs not in observations:
                observations[reading.obs] = {'x': [],
                                             'y': [],
                                             'source': image_downloader.download(reading, needs_apcor=True)}
            assert isinstance(reading.obs, Observation)
            observations[reading.obs]['x'].append(reading.x)
            observations[reading.obs]['y'].append(reading.y)

    for observation in observations:
        source = observations[observation]['source']
        assert isinstance(source, SourceCutout)
        source.update_pixel_location(observations[observation]['x'],
                                     observations[observation]['y'])
        hdulist_index = source.get_hdulist_idx(observation.ccdnum)
        observations[observation]['mags'] = daophot.phot(source._hdu_on_disk(hdulist_index),
                                                         observations[observation]['x'],
                                                         observations[observation]['y'],
                                                         aperture=source.apcor.aperture,
                                                         sky=source.apcor.sky,
                                                         swidth=source.apcor.swidth,
                                                         apcor=source.apcor.apcor,
                                                         zmag=source.zmag,
                                                         maxcount=30000,
                                                         extno=0)

    return observations
50194
def _compute_weight_std(self, C, mag):
        
        if mag < 6.0:
            return C['a1']
        elif mag >= 6.0 and mag < 6.5:
            return C['a1'] + (C['a2'] - C['a1']) * ((mag - 6.0) / 0.5)
        else:
            return C['a2']
833436
def _compute_magnitude_scaling_term(self, C, mag):
        
        c1 = self.CONSTS['c1']
        if mag <= c1:
            return C['b1'] + C['b2'] * (mag - c1) + C['b3'] * (8.5 - mag) ** 2
        else:
            return C['b1'] + C['b7'] * (mag - c1) + C['b3'] * (8.5 - mag) ** 2
1266311
def _compute_distance_term(self, C, mag, rrup):
        
        term1 = C['b'] * rrup
        term2 = - np.log(rrup + C['c'] * np.exp(C['d'] * mag))

        return term1 + term2
1050783
def hour(self):
        ''''''
        self.magnification = 3600
        self._update(self.baseNumber, self.magnification)
        return self
1198801
def get_cusum(self, mag):
        

        c = np.cumsum(mag - self.weighted_mean) / len(mag) / self.weighted_std

        return np.max(c) - np.min(c)
754220
def mag_to_fnu(self, mag):
        
        return cgs.cgsperjy * self._zeropoints[self.band] * 10**(-0.4 * mag)
554770
def _compute_linear_magnitude_term(self, C, mag):
        
        if mag <= self.c1:
            # this is the second term in eq. (1a), p. 2981
            return C['a2'] * (mag - self.c1)
        else:
            # this is the second term in eq. (1b), p. 2982
            return C['a3'] * (mag - self.c1)
545059
def starmodel_props(self):
        
        props = {}
        mags = self.mags
        mag_errs = self.mag_errs
        for b in mags.keys():
            if np.size(mags[b])==2:
                props[b] = mags[b]
            elif np.size(mags[b])==1:
                mag = mags[b]
                try:
                    e_mag = mag_errs[b]
                except:
                    e_mag = 0.05
                props[b] = (mag, e_mag)

        if self.Teff is not None:
            props['Teff'] = self.Teff
        if self.logg is not None:
            props['logg'] = self.logg
        if self.feh is not None:
            props['feh'] = self.feh

        return props
1065723
def _compute_f4(self, C, mag, rrup):
        
        fhw_m = 0
        fhw_r = np.zeros_like(rrup)

        if mag <= 5.5:
            fhw_m = 0
        elif 5.5 < mag < 6.5:
            fhw_m = mag - 5.5
        else:
            fhw_m = 1

        idx = (rrup > 4) & (rrup <= 8)
        fhw_r[idx] = C['a9'] * (rrup[idx] - 4.) / 4.

        idx = (rrup > 8) & (rrup <=18)
        fhw_r[idx] = C['a9']

        idx = (rrup > 18) & (rrup <= 24)
        fhw_r[idx] = C['a9'] * (1 - (rrup[idx] - 18.) / 7.)

        return fhw_m * fhw_r
555461
def _get_geometric_attenuation_term(self, C, mag, rrup):
        
        return (C["c5"] + C["c6"] * mag) * np.log(np.sqrt((rrup ** 2.) +
                                                          (C["c7"] ** 2.)))