lc.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:PyCS 作者: COSMOGRAIL 项目源码 文件源码
def factory(jds, mags, magerrs=None, telescopename="Unknown", object="Unknown", verbose=False):
    """Returns a valid lightcurve object from the provided arrays.
    The numpy arrays jds and mags are mandatory. If you do not specify a third array containing the magerrs,
    we will calculate them "automatically" (all the same value), to avoid having 0.0 errors.

    @type   jds: 1D numpy array
    @param  jds: julian dates
    @type   mags: 1D numpy array
    @param  mags: magnitudes
    @type   magerrs: 1D numpy array
    @param  magerrs: optional magnitude errors

    @todo: improve it and use this in file importing functions

    """
    # Make a brand new lightcurve object :
    newlc = lightcurve()

    # Of couse we can/should check a lot of things, but let's be naive :

    newlc.jds = np.asarray(jds)
    newlc.mags = np.asarray(mags)

    if magerrs is None:
        newlc.magerrs = np.zeros(len(newlc.jds)) + 0.1
    else:
        newlc.magerrs = np.asarray(magerrs)

    if len(newlc.jds) != len(newlc.mags) or len(newlc.jds) != len(newlc.magerrs):
        raise RuntimeError, "lightcurve factory called with arrays of incoherent lengths"

    newlc.mask = newlc.magerrs >= 0.0   # This should be true for all !

    newlc.properties = [{}] * len(newlc.jds)

    newlc.telescopename = telescopename
    newlc.object = object

    newlc.setindexlabels()
    newlc.commentlist = []

    newlc.sort() # not sure if this is needed / should be there

    newlc.validate()

    if verbose: print "New lightcurve %s with %i points" % (str(newlc), len(newlc.jds))

    return newlc
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号