Returns the *Kepler* magnitude for a given EPIC target.
493166
def KepMag(EPIC, campaign=None):
    '''
    

    '''

    if campaign is None:
        campaign = Campaign(EPIC)
    if hasattr(campaign, '__len__'):
        raise AttributeError(
            "Please choose a campaign/season for this target: %s." % campaign)
    stars = GetK2Stars()[campaign]
    i = np.argmax([s[0] == EPIC for s in stars])
    return stars[i][1]
310434
def coord(self):
        """"""
        if self._coordinate is None:
            self._coordinate = SkyCoord(self.origin.ra, self.origin.dec + 45 * units.arcsec)
        return self._coordinate
630747
def _get_magnitude_vector_properties(catalogue, config):
    ''''''

    mmin = config.get('input_mmin', np.min(catalogue['magnitude']))
    neq = np.float(np.sum(catalogue['magnitude'] >= mmin - 1.E-7))
    return neq, mmin
1344356
def _get_nsymop(self):
        """"""
        if self.centrosymmetric:
            return 2 * len(self._rotations) * len(self._subtrans)
        else:
            return len(self._rotations) * len(self._subtrans)
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
276372
def MASTRADec(ra, dec, darcsec, stars_only=False):
    '''
    

    '''

    # coordinate limits
    darcsec /= 3600.0
    ra1 = ra - darcsec / np.cos(dec * np.pi / 180)
    ra2 = ra + darcsec / np.cos(dec * np.pi / 180)
    dec1 = dec - darcsec
    dec2 = dec + darcsec

    # build mast query
    url = 'http://archive.stsci.edu/k2/epic/search.php?'
    url += 'action=Search'
    url += '&k2_ra=' + str(ra1) + '..' + str(ra2)
    url += '&k2_dec=' + str(dec1) + '..' + str(dec2)
    url += '&max_records=10000'
    url += '&selectedColumnsCsv=id,k2_ra,k2_dec,kp'
    url += '&outputformat=CSV'
    if stars_only:
        url += '&ktc_target_type=LC'
        url += '&objtype=star'

    # retrieve results from MAST
    try:
        lines = urllib.request.urlopen(url)
    except:
        log.warn('Unable to retrieve source data from MAST.')
        lines = ''

    # collate nearby sources
    epicid = []
    kepmag = []
    ra = []
    dec = []
    for line in lines:

        line = line.strip().decode('ascii')

        if (len(line) > 0 and 'EPIC' not in line and 'integer' not in line and
                              'no rows found' not in line):

            out = line.split(',')
            r, d = sex2dec(out[1], out[2])
            epicid.append(int(out[0]))
            kepmag.append(float(out[3]))
            ra.append(r)
            dec.append(d)

    epicid = np.array(epicid)
    kepmag = np.array(kepmag)
    ra = np.array(ra)
    dec = np.array(dec)

    return epicid, ra, dec, kepmag
576122
def _get_magnitude_term(self, C, mag):
        
        f_mag = C["c0"] + C["c1"] * mag
        if (mag > 4.5) and (mag <= 5.5):
            return f_mag + (C["c2"] * (mag - 4.5))
        elif (mag > 5.5) and (mag <= 6.5):
            return f_mag + (C["c2"] * (mag - 4.5)) + (C["c3"] * (mag - 5.5))
        elif mag > 6.5:
            return f_mag + (C["c2"] * (mag - 4.5)) + (C["c3"] * (mag - 5.5)) +\
                (C["c4"] * (mag - 6.5))
        else:
            return f_mag
716383
def lookat(eye, target=[0, 0, 0], up=[0, 1, 0]):
  """"""
  eye = np.float32(eye)
  forward = normalize(target - eye)
  side = normalize(np.cross(forward, up))
  up = np.cross(side, forward)
  M = np.eye(4, dtype=np.float32)
  R = M[:3, :3]
  R[:] = [side, up, -forward]
  M[:3, 3] = -R.dot(eye)
  return M
1080138
def get_magnitude_scaling_term(self, C, rup):
        
        m_c = self.CONSTANTS["m_c"]
        if rup.mag <= m_c:
            return C["cSL"] * rup.mag +\
                C["cSL2"] * ((rup.mag - self.CONSTANTS["m_sc"]) ** 2.)
        else:
            return C["cSL"] * m_c +\
               C["cSL2"] * ((m_c - self.CONSTANTS["m_sc"]) ** 2.) +\
               C["dSL"] * (rup.mag - m_c)
562491
def get_magnitude_scaling_term(self, C, rup):
        
        if rup.ztor > 25.0:
            # Deep interface events
            c_int = C["cint"]
        else:
            c_int = C["cintS"]

        if rup.mag <= self.CONSTANTS["m_c"]:
            return c_int * rup.mag
        else:
            return (c_int * self.CONSTANTS["m_c"]) +\
                (C["dint"] * (rup.mag - self.CONSTANTS["m_c"]))
120777
def get_rotation_and_scale(header, skew_threshold=0.001):
    """"""
    ((xrot, yrot),
     (cdelt1, cdelt2)) = get_xy_rotation_and_scale(header)

    if math.fabs(xrot) - math.fabs(yrot) > skew_threshold:
        raise ValueError("Skew detected: xrot=%.4f yrot=%.4f" % (
            xrot, yrot))
    rot = yrot

    lonpole = float(header.get('LONPOLE', 180.0))
    if lonpole != 180.0:
        rot += 180.0 - lonpole

    return (rot, cdelt1, cdelt2)
428057
def get_ras(repi, theta, mag, coeff):
    
    rx = 100.
    ras = 200.
    #
    # calculate the difference between epicentral distances
    dff = fnc(ras, repi, theta, mag, coeff)
    while abs(dff) > 1e-3:
        # update the value of distance computed
        if dff > 0.:
            ras = ras - rx
        else:
            ras = ras + rx
        dff = fnc(ras, repi, theta, mag, coeff)
        rx = rx / 2.
        if rx < 1e-3:
            break
    return ras
1209994
def magnitude(self, allow3d=True):
        """"""
        ret = self.x**2 + self.y**2
        if allow3d: ret += self.z**2
        return ret**0.5 # square root
1111140
def unit(self):
        """"""
        return Vector(
            (self.x / self.magnitude()),
            (self.y / self.magnitude()),
            (self.z / self.magnitude())
        )
756334
def _createMagConversionDict():
    
    magnitude_conversion_filepath = resource_stream(__name__, 'data/magnitude_conversion.dat')
    raw_table = np.loadtxt(magnitude_conversion_filepath, '|S5')

    magDict = {}
    for row in raw_table:
        if sys.hexversion >= 0x03000000:
            starClass = row[1].decode("utf-8")  # otherwise we get byte ints or b' caused by 2to3
            tableData = [x.decode("utf-8") for x in row[3:]]
        else:
            starClass = row[1]
            tableData = row[3:]
        magDict[starClass] = tableData

    return magDict
535571
def get_scaled(self, magnitude):
        
        result = self.copy()
        result.scale(magnitude)
        return result
486662
def _keplerian_mean_to_keplerian(cls, coord, center):
        
        a, e, i, Ω, ω, M = coord
        E = cls._m_to_e(e, M)
        cos_ν = (cos(E) - e) / (1 - e * cos(E))
        sin_ν = (sin(E) * sqrt(1 - e**2)) / (1 - e * cos(E))

        ν = arctan2(sin_ν, cos_ν) % (np.pi * 2)

        return np.array([a, e, i, Ω, ω, ν], dtype=float)