def convert_time_format(t_list, dformat=0):
    """
    convert chandra time into either fractional year or day of year
    input:  t_list  --- a list of time in seconds from 1998.1.1
            dformat --- indicator of whether to convert fractional year or doy
                        default= 0: day of year
    output: save    --- a list of time in the specified format
            byear   --- the year of the data; useful to use with day of year 
                note: if the the data are over two years, byear is the year
                      of the starting year and day of year will increase 
                      beyond 365/366. 
    """
    save = []
    byear = 0
    for ent in t_list:
        out = Chandra.Time.DateTime(ent).date
        atemp = re.split(':', out)
        year = int(atemp[0])
        if byear == 0:
            byear = year
            if mcf.is_leapyear(byear):
                base = 366
            else:
                base = 365

        yday = float(atemp[1])
        hh = float(atemp[2])
        mm = float(atemp[3])
        ss = float(atemp[4])
        yday += hh / 24.0 + mm / 1440.0 + ss / 84600.0
        #
        #--- for the case that the time is in yday; assume that the range is always
        #--- smaller than two years
        #
        if dformat == 0:
            if year > byear:
                yday += base

            save.append(yday)
#
#--- for the case that the time is in fractional year
#
        else:
            if year > byear:
                if mcf.is_leapyear(byear):
                    base = 366
                else:
                    base = 365

                byear = year

            fyear = year + yday / base
            save.append(fyear)

    return [save, byear]
示例#2
0
def chandra_time_to_yday(stime, syear):
    """
    convert chandra time to ydate
    input:  stime   --- time in seconds from 1998.1.1
            syear   --- year at the beginning of the data period
    output: ydate   --- ydate
    """
    atime = Chandra.Time.DateTime(stime).date
    btemp = re.split(':', atime)
    year  = float(btemp[0])
    ydate = float(btemp[1])
    hour  = float(btemp[2])
    mins  = float(btemp[3])
    sec   = float(btemp[4])
    ydate = ydate + (hour/24.0 + mins/1440.0 + sec/86400.0)
#
#--- if the date is over two years, keep counting from the first year
#
    if year > syear:
        if mcf.is_leapyear(syear):
            base = 366
        else:
            base = 365

        ydate += base

    return ydate
def convert_stime_into_year(stime):
    """
    convert time in seconds from 1998.1.1 to fractional year
    input:  stime   --- time in seconds from 1998.1.1
    output: ytime   --- time in fractional year
            year    --- year 
            base    --- the number of the days in that year, either 365 or 366
    """

    date = Chandra.Time.DateTime(stime)

    year = float(date.year)
    yday = float(date.yday)
    hrs = float(date.hour)
    mins = float(date.min)
    secs = float(date.sec)

    if mcf.is_leapyear(year):
        base = 366
    else:
        base = 365

    ytime = year + (yday + hrs / 24.0 + mins / 1440.0 + secs / 86400.0) / base

    return [ytime, year, base]
def change_ctime_to_ydate(cdate, yd=1):
    """
    convert chandra time into fractional year or ydate
    input:  cdate   --- chandra time
            yd      --- indicator to create fractional year (0) or ydate (1)
    output: year    --- the year of the date
            date    --- if yd==0, date in fractional year, otherwise, in ydate
    """

    date = Chandra.Time.DateTime(cdate).date
    atemp = re.split(':', date)
    year = float(atemp[0])
    date = float(atemp[1])
    hh = float(atemp[2])
    mm = float(atemp[3])
    ss = float(atemp[4])
    date += (hh + mm / 60.0 + ss / 3600.0) / 24.0

    if yd == 1:
        return [year, date]
    else:
        if mcf.is_leapyear(year):
            base = 366
        else:
            base = 365

        date = year + date / base

        return [year, date]
示例#5
0
def convert_time_to_year(tlist):
    """
    converting Chandra time to fractional year
    input:  tlist   --- a list of time in format of seconds from 1998.1.1
    output: save--- a list of time in format of fractional year
    """
    save = []
    for ent in tlist:
        ldate = Chandra.Time.DateTime(ent).date
        atemp = re.split(':', ldate)
        year = float(atemp[0])
        yday = float(atemp[1])
        hh = float(atemp[2])
        mm = float(atemp[3])
        ss = float(atemp[4])

        if mcf.is_leapyear(year):
            base = 366.0
        else:
            base = 365.0

        fyear = year + (yday + hh / 24.0 + mm / 1440.0 + ss / 86400.0) / base
        save.append(fyear)

    return save
示例#6
0
def convert_time(time_list, format  = 0):

    """
    convert time format from seconds from 1998.1.1 to dom or fractional year
    Input:  time    --- a list of time in seconds
            format  --- if 0, convert into dom. if 1, ydate,  otherwise, fractional year
    Output: timeconverted --- a list of conveted time
    """

    timeconverted = []
    for ent in time_list:
        out   = Chandra.Time.DateTime(ent).date
        atemp = re.split(':', out)
        year  = float(atemp[0])
        ydate = float(atemp[1]) 
        tpart = float(atemp[2]) / 24. + float(atemp[3]) / 1440. + float(atemp[4]) / 86400.
        if format == 0: 
            dom = mcf.ydate_to_dom(year, ydate)
            timeconverted.append(dom + tpart)
        elif format == 1:
            timeconverted.append(ydate + tpart)
        else:
            if mcf.is_leapyear(year):
                base = 366
            else:
                base = 365
            year += (ydate + tpart) /base

            timeconverted.append(year)
        
    return timeconverted
示例#7
0
def convert_to_fyear(year, mon, day, hh, mm, ss):
    """
    convert calendar date to a fractional year
    input:  year    --- year
            mon     --- month
            day     --- day
            hh      --- hour
            mm      --- minute
            ss      --- second
    output: fyear   --- time in fractional year
    """
    if mcf.is_leapyear(year):
        base = 366.0
    else:
        base = 365.0

    line = str(year) + ':' + str(mon) + ':' + str(day)
    out = time.strftime('%Y:%j', time.strptime(line, '%Y:%m:%d'))
    atemp = re.split(':', out)
    year = float(atemp[0])
    yday = float(atemp[1])

    fyear = year + (yday + hh / 24.0 + mm / 1440.0 + ss / 86400.0) / base

    return fyear
示例#8
0
def convert_time_list(time_list):
    """
    convert time format to fractional year for the entire array
    Input:  time_list   --- a list of time (format: <yyyy>-<mm>-<dd>Thh:mm:ss)
    Output: converted   --- a list of time in  fractional year
    """
    converted = []
    for ent in time_list:
        out = time.strftime('%Y:%j:%H:%M:%S',
                            time.strptime(ent, "%Y-%m-%dT%H:%M:%S"))
        atemp = re.split(':', out)
        year = float(atemp[0])
        yday = float(atemp[1])
        hh = float(atemp[2])
        mm = float(atemp[3])
        ss = float(atemp[4])

        if mcf.is_leapyear(year):
            base = 366.0
        else:
            base = 365.0

        fyear = year + (yday + hh / 24.0 + mm / 1440.0 + ss / 86400.0) / base
        converted.append(fyear)

    return converted
示例#9
0
def convert_to_fyear(val):
    """
    convert sim temp database time format to fractional year
    input:  val     --- sim temp time  
    output: fyear   --- fractional year e.g. 2014.11345
    """

    v = str(val)
    year = v[0] + v[1] + v[2] + v[3]
    year = float(year)
    yday = v[4] + v[5] + v[6]
    yday = float(yday)
    hh = v[7] + v[8]
    hh = float(hh)
    mm = v[9] + v[10]
    mm = float(mm)
    ss = v[11] + v[12]
    ss = float(ss)

    if mcf.is_leapyear(year):
        base = 366
    else:
        base = 365

    fyear = year + (yday + hh / 24.0 + mm / 1440.0 + ss / 86400.0) / base

    return fyear
示例#10
0
def convert_to_ydate_list(t_list):
    """
    convert time data in a list from time in seconds to y date
    input:  t_list  --- a list/an array of time data in seconds from 1998.1.1
    output: t_list  --- an array of time data in y date
    """
    save = []

    [byear, ydate] = chandratime_to_yday(t_list[0])

    if mcf.is_leapyear(byear):
        base = 366
    else:
        base = 365

    for ent in t_list:
        [year, ydate] = chandratime_to_yday(ent)
        #
        #--- if year changes, make it to the extension of the base year
        #
        if year > byear:
            ydate += base

        save.append(ydate)

    save = numpy.array(save)

    return save
示例#11
0
def convert_time_format(stime):

    atemp = re.split('T', stime)
    btemp = re.split('-', atemp[0])
    year = btemp[0]
    mon = int(float(btemp[1]))
    yday = int(float(btemp[2]))

    if mcf.is_leapyear(year):
        alist = mday_list2
    else:
        alist = mday_list

    if mon > 1:
        for k in range(0, mon - 1):
            yday += alist[k]

    lyday = str(yday)
    if yday < 10:
        lyday = '00' + lyday
    elif yday < 100:
        lyday = '0' + lyday

    date = year + ':' + lyday + ':' + atemp[1]

    stday = Chandra.Time.DateTime(date).secs

    return stday
示例#12
0
def convert_time(stime):
    """
    convert the time format from <yyyy>-<mm>-<dd>T<hh>:<mm>:<ss> to fractional year
    input:  stime   --- time in the fromat of <yyyy>-<mm>-<dd>T<hh>:<mm>:<ss>
    output: fyear   --- time in the foramt of the fractional year
    """
    atemp = re.split('T', stime)
    btemp = re.split('-', atemp[0])
    ctemp = re.split(':', atemp[1])

    year = float(btemp[0])
    mon = int(float(btemp[1]))
    day = float(btemp[2])
    yday = day + m_list[mon - 1]
    hh = float(ctemp[0])
    mm = float(ctemp[1])
    ss = float(ctemp[2])

    if mcf.is_leapyear(btemp[0]):
        base = 366.0
        if mon > 2:
            yday += 1
    else:
        base = 365.0

    fyear = year + (yday + hh / 24.0 + mm / 1440.0 + ss / 86400.0) / base

    return fyear
示例#13
0
def convert_time(otime):
    """
    convert timer format from <year>:<ydate>:<hours>:<mins>:<sec> to fractional year
    input:  otime   --- time in <year>:<ydate>:<hours>:<mins>:<sec>
    output  fyear   --- time in fractional year
    """
    #
    #--- input data sometime comes with an extra ":" at the front; check whether it is the case
    #
    k = 0
    if otime[0] == ':':
        k = 1

    atemp = re.split(':', otime)
    year = float(atemp[k])
    ydate = float(atemp[k + 1])
    hours = float(atemp[k + 2])
    mins = float(atemp[k + 3])
    secs = float(atemp[k + 4])

    if mcf.is_leapyear(year):
        base = 366.0
    else:
        base = 365.0

    fday = hours / 24.0 + mins / 1440.0 + secs / 86400.0
    fyear = year + (ydate + fday) / base

    return fyear
示例#14
0
def convert_to_ydate(ltime, syear):
    """
    convert the time in second to ydate
    input:  ltime   --- a value or a list of time in seconds from 1998.1.1
            syear   --- the year of the first data point
    output: xdate   --- a value or a list of day of year
    """
    if mcf.is_leapyear(syear):
        base = 366
    else:
        base = 365

    if isinstance(ltime, list):
        xdate = []
        for ent in ltime:
            [year, ydate] = itrf.ctime_to_ydate(ent)
            if year > syear:
                ydate += base
            xdate.append(ydate)

        return xdate

    else:
        [year, ydate] = itrf.ctime_to_ydate(ltime)
        if year > syear:
            ydate += base

        return ydate
示例#15
0
def find_base_data(year):

    if mcf.is_leapyear(year):
        base = 366
    else:
        base = 365

    return base
示例#16
0
def find_date_and_year_for_report():
    """
    find nearest Thursday date 
    input:  none
    output: date    --- date of the nearest Thu in the format of mmdd (e.g. 0910)
            year    --- year of the nearest Thu
    """
    #
    #--- find today's date information (in local time)
    #
    tlist = time.localtime()

    year = tlist[0]
    mon = tlist[1]
    day = tlist[2]
    wday = tlist[6]
    yday = tlist[7]
    #
    #--- find the differnce to Thursday. wday starts on Monday (0)
    #
    diff = 3 - wday

    if diff != 0:
        yday += diff
        if yday < 1:
            year -= 1
            if mcf.is_leapyear(year):
                base = 366
            else:
                base = 365

            yday = base - yday
#
#--- converting the year and ydate into the standard date output
#
        tline = str(year) + ' ' + str(yday)
        tlist = time.strptime(tline, "%Y %j")

        year = tlist[0]
        mon = tlist[1]
        day = tlist[2]
#
#--- change the date foramt to mmdd (e.g. 0910)
#
    smon = str(mon)
    if mon < 10:
        smon = '0' + smon
    sday = str(day)
    if day < 10:
        sday = '0' + sday

    date = smon + sday

    year = str(year)

    return [date, year]
示例#17
0
def updateLongTermTable2(html_dir, event, this_year):
    """
    update long term sub data tables
    Input:   html_dir    web directory path
             event    name of the event  such as te3_3
             this_year    the latest year
    Output:  sub data file suchas te3_3_out
    """

    line = ''
    ytop = int(this_year) + 1
    for year in range(1999, ytop):
        #
        #--- check leap year
        #
        if mcf.is_leapyear(year):
            base = 366.0
        else:
            base = 365.0
#
#--- read each year's data
#
        fname = html_dir + 'Year' + str(year) + '/' + event.lower() + '_out'
        data = mcf.read_data_file(fname)
        if len(data) == 0:
            continue

        for ent in data:
            atemp = re.split('\t+|\s+', ent)
            try:
                val = float(atemp[0])
                btemp = re.split(':', atemp[1])
                #
                #--- convert time to year date to fractional year
                #
                time = float(year) + (float(btemp[0]) +
                                      float(btemp[1]) / 86400.0) / base
                time = round(time, 3)
                dlen = len(atemp)
                dlst = dlen - 1

                for j in range(0, dlen):
                    if j == 1:
                        line = line + str(time) + '\t'
                    elif j == dlst:
                        line = line + atemp[j] + '\n'
                    else:
                        line = line + atemp[j] + '\t'
            except:
                pass

    oname = html_dir + 'Long_term/' + event.lower() + '_out'
    with open(oname, 'w') as fo:
        fo.write(line)
示例#18
0
def update_acis_ctemp():
    """
    """
    #
    #--- read msid list
    #
    afile = house_keeping + 'msid_list_compaciscent'
    data = mcf.read_data_file(afile)
    acis_list = []
    for ent in data:
        atemp = re.split('\s+', ent)
        acis_list.append(atemp[0])

    for year in range(1999, 2019):
        nyear = year
        if mcf.is_leapyear(year):
            mon_list = mon_list2
        else:
            mon_list = mon_list1

        for mon in range(0, 12):
            if year == 1999:
                if mon < 7:
                    continue
            if year == 2018:
                if mon > 1:
                    break

            if mon == 11:
                bday = mon_list[mon]
                eday = 1
                nyear += 1
            else:
                bday = mon_list[mon]
                eday = mon_list[mon + 1]

            cbday = str(bday)
            if bday < 10:
                cbday = '00' + cbday
            elif bday < 100:
                cbday = '0' + cbday

            ceday = str(eday)
            if eday < 10:
                ceday = '00' + ceday
            elif eday < 100:
                ceday = '0' + ceday

            start = str(year) + ':' + cbday + ':00:00:00'
            stop = str(nyear) + ':' + ceday + ':00:00:00'

            get_data(start, stop, year, acis_list)
示例#19
0
def read_file(infile):
    """
    read hz 43 data file
    input:  infile      --- data file name
    output: time_list   --- a list of time data
            data_list   --- a list of value data either sumamp or pi
            err_list    --- a list of the error of the value
            obsid_list  --- a list of obsid of the observations
    """
    data  = mcf.read_data_file(infile)
    if data == []:
        return False

    time_list  = []
    data_list  = []
    err_list   = []
    obsid_list = []

    for ent in data:
        atemp = re.split('\s+', ent)
        out   = time.strftime('%Y:%j:%H:%M:%S', time.strptime(atemp[2], '%Y-%m-%dT%H:%M:%S'))
        btemp = re.split(':', out)
        year  = float(btemp[0])
        if mcf.is_leapyear(year): 
            base = 366.0
        else:
            base = 365.0
        ytime = year + (float(btemp[1]) + float(btemp[2])/24.0  + float(btemp[3])/1440.0 + float(btemp[4])/86400.) / base

        if ytime < 2000:
            continue

        obsid = str(atemp[1].strip())
        if  obsid in exclude_list:
            continue

        avg   = float(atemp[4])
        err   = float(atemp[5])
        med   = float(atemp[6])
        if avg == -999 or err == -999 or pi == -999:
            continue
        else:
            time_list.append(ytime)
            data_list.append(avg)
            err_list.append(err)
            obsid_list.append(atemp[1])

    zmin = min(data_list)
    zmax = max(data_list)

    return [time_list, data_list, err_list, obsid_list]
示例#20
0
def run_script():

    for year in range(1999,2015):

        if mcf.is_leapyear(year):
            dend = 367
        else:
            dend = 366
        syear = str(year)
        lyear = syear[2] + syear[3]

        for yday in range(1,dend):
            if year == 1999 and yday < 239:
                continue

            if year == 2014 and yday > 316:
                break

            lyday = str(yday)
            if yday < 10:
                lyday = '00' + lyday
            elif yday < 100:
                lyday = '0'  + lyday
            dtime = str(year) + ':' + lyday

            start = dtime + ':00:00:00'
            stop  = dtime + ':23:59:59'

            line  = 'operation = retrieve\n'
            line  = line + 'dataset = flight\n'
            line  = line + 'detector = telem\n'
            line  = line + 'level = raw\n'
            line  = line + 'tstart = ' + start + '\n'
            line  = line + 'tstop  = ' + stop  + '\n'
            line  = line + 'go\n'

            out   = mcf.run_arc5gl_process(line)

            cmd = 'ls * > ' + zspace
            os.system(cmd)
            test = open(zspace, 'r').read()
            mc   = re.search('sto', test)
            if mc is not None:
                os.system('rm *log*')
                os.system('gzip -fd *gz')
                os.system('ls *.sto > xtmpnew')
                os.system('nice  ./filters_ccdm')
                esd.extract_sim_data()

            os.system('rm  -rf *.sto *.tl')
示例#21
0
def chandratime_to_yday(ctime, byear):
    """
    convert chandra time into ydate from the 001 day of byear
    input:  ctime   --- chandra time; seconds from 1998.1.1
            byear   --- the base year
    output: ydate   --- ydate from 001 day of byear
    """

    out = Chandra.Time.DateTime(ctime).date
    atemp = re.split(':', out)
    year = int(float(atemp[0]))
    ydate = float(atemp[1])
    hh = float(atemp[2])
    mm = float(atemp[3])
    ss = float(atemp[4])

    ydate += hh / 24.0 + mm / 1440.0 + ss / 86400.0

    if year < byear:
        for tyear in range(year, byear):
            if mcf.is_leapyear(tyear):
                base = 366
            else:
                base = 365

            ydate -= base

    elif year > byear:
        for tyear in range(byear, year):
            if mcf.is_leapyear(tyear):
                base = 366
            else:
                base = 365

            ydate += base

    return ydate
示例#22
0
def adjust_year_date(byear, x):

    if mcf.is_leapyear(byear):
        base = 366
    else:
        base = 365

    nx = []
    for ent in x:
        if ent[0] != byear:
            val = float(ent[1]) + base
            nx.append(val)
        else:
            nx.append(float(ent[1]))

    return nx
示例#23
0
def create_monthly_bins(ystart, ystop, mstop):
    """
    create a month wide bin for given periods
    input:  ystart  --- starting year
            ystop   --- stopping year
            mstop   --- stopping month of the stopping month
    output: [blist, elist] a list of lists of starting and stoping period in fractional year
    """

    interval1 = [
        0.0, 31.0, 59.0, 90.0, 120.0, 151.0, 181.0, 212.0, 243.0, 273.0, 304.0,
        334.0, 365.0
    ]
    interval2 = [
        0.0, 31.0, 60.0, 91.0, 121.0, 152.0, 182.0, 213.0, 244.0, 274.0, 305.0,
        335.0, 366.0
    ]

    blist = []
    elist = []

    for year in range(ystart, ystop + 1):
        #
        #--- check leap year
        #
        if mcf.is_leapyear(year):
            interval = interval2
            base = 366.0
        else:
            interval = interval1
            base = 365.0
#
#--- go around 12 months
#
        for i in range(0, 12):
            if year == ystop and i >= mstop:
                break
            begin = year + interval[i] / base
            end = year + interval[i + 1] / base
            if int(end) > year:
                end = year + 1

            blist.append(begin)
            elist.append(end)

    return [blist, elist]
def convert_to_ydate_list(x):

    nx = []
    byear = ''
    for val in x:
        cdata = change_ctime_to_ydate(val)
        if byear == '':
            byear = cdata[0]
            if mcf.is_leapyear(byear):
                base = 366
            else:
                base = 365
        if cdata[0] > byear:
            nx.append(cdata[1] + base)
        else:
            nx.append(cdata[1])

    return nx
示例#25
0
def update_acis_power():
    """
    """
    for year in range(1999, 2019):
        nyear = year 
        if mcf.is_leapyear(year):
            mon_list = mon_list2
        else:
            mon_list = mon_list1

        for mon in range(0, 12):
            if year ==  1999:
                if mon < 7:
                    continue
            if year == 2018:
                if mon > 1:
                    break

            if mon == 11:
                bday   = mon_list[mon]
                eday   = 1
                nyear += 1
            else:
                bday = mon_list[mon]
                eday = mon_list[mon+1]

            cbday = str(bday)
            if bday < 10:
                cbday = '00' + cbday
            elif bday < 100:
                cbday = '0'  + cbday


            ceday = str(eday)
            if eday < 10:
                ceday = '00' + ceday
            elif eday < 100:
                ceday = '0'  + ceday

            start =  str(year)  + ':' + cbday + ':00:00:00'
            stop  =  str(nyear) + ':' + ceday + ':00:00:00'

            get_data(start, stop, year)
示例#26
0
def convert_time_format(ft):
    """
    convert otg time format to fractional year
    input:  ft      --- otg time (e.g. 2019036.0239520)
    output: otime   --- fractional year
    """
    year = float(ft[0] + ft[1] + ft[2] + ft[3])
    yday = float(ft[4] + ft[5] + ft[6])
    hh = float(ft[8] + ft[9])
    mm = float(ft[10] + ft[11])
    ss = float(ft[12] + ft[13])

    if mcf.is_leapyear(year):
        base = 366.0
    else:
        base = 365.0

    otime = year + (yday + hh / 24.0 + mm / 3600.0 + ss / 86400.0) / base

    return otime
示例#27
0
def set_x_range(xdata):
    """
    set several x axis related values
    input:  xdata   --- x data
    output: ndata   --- x data set for the short time span (less than 2 yrs)
            xmin    --- x min
            xmax    --- x max
            xlabel  --- label of x axis
            xtext   --- x position of the text to be printed
    """
    xmin = min(xdata)
    year = int(xmin)
    xmax = max(xdata)

    xdiff = xmax - xmin
    if xdiff < 2.0:
        if mcf.is_leapyear(year):
            base = 366
        else:
            base = 365

        ndata = []
        for ent in xdata:
            val = base * (ent - year)
            ndata.append(val)

            xlabel = 'Time (year=' + str(year) + ' yday)'

            xmin = 0
            xmax = base

    else:
        ndata = xdata
        xmin = int(xmin)
        xmax = int(xmax) + 1
        xlabel = 'Time (year)'

    xdiff = xmax - xmin
    xtext = xmin + 0.02 * xdiff

    return [ndata, xmin, xmax, xlabel, xtext]
示例#28
0
def get_frac_year(date):
    """
    convert date into a fractional year format
    input: date    --- date in the format of <yyyy>-<mm>-<dd>T<hh>:<mm>:<ss>
    output: fyear  --- date in fractional year. less than a day will be ignored
    """
    atemp = re.split('T',  date)
    btemp = re.split('\-', atemp[0])
    fyear = float(btemp[0])
    mon   = int(float(btemp[1]))
    day   = int(float(btemp[2]))

    if (mon == 2) and (mcf.is_leapyear(fyear)):
        lday = mday[mon-1] + 1
    else:
        lday = mday[mon-1]

    mon   += day / lday
    fyear += mon / 12.0

    return fyear
def check_year_data_complete(tyear):
    """
    check whether the database for the given year is filled till the end
    input:  tyear   --- the year of the data to be examined
    output: True/False
    """
    name = web_dir + 'Year' + str(tyear) + '/data' + str(tyear)
    data = mcf.read_data_file(name)
    atemp = re.split('\s+', data[-1])
    btemp = re.split(':', atemp[1])
    ldate = float(btemp[0])

    if mcf.is_leapyear(tyear):
        base = 366
    else:
        base = 365

    if ldate == base:
        return True
    else:
        return False
示例#30
0
def set_x_range(xdata):
    """
    setting x range. if less than 2 years, use yday, otherwise, fractional year
    input:  xdata   --- x data
    output: ndata   --- modified data (for the case if it is in yday)
            xmin    --- x min
            xmax    --- x max
            xlabel  --- label for x axis 
            xtext   --- x location for the text display
    """
    xmin = min(xdata)
    year = int(xmin)
    xmax = max(xdata)

    xdiff = xmax - xmin
    if xdiff < 2.0:
        if mcf.is_leapyear(year):
            base = 366
        else:
            base = 365

        ndata = []
        for ent in xdata:
            val = base * (ent - year)
            ndata.append(val)

            xlabel = 'Time (yday @ year=' + str(year) + ')'

            xmin = 0
            xmax = base
    else:
        ndata = xdata
        xmin = int(xmin)
        xmax = int(xmax) + 1
        xlabel = 'Time (year)'

    xdiff = xmax - xmin
    xtext = xmin + 0.1 * xdiff

    return [ndata, xmin, xmax, xlabel, xtext]