예제 #1
0
def convert_calendar(value, to_cal):
    if value.calendarmodel == JULIAN_CALENDAR and to_cal == STANDARD_CALENDAR:
        if value.precision < 10:
            # No sense to convert for year-precision and lower
            value.calendarmodel = STANDARD_CALENDAR
            return value
        if value.year and value.month and value.day and value.precision >= 11:
            # Convert Julian to Standard
            jday = jdcal.gcal2jd(value.year, value.month, value.day)
            jdate = jdcal.jd2jcal(*jday)
            return pywikibot.WbTime(year=jdate[0],
                                    month=jdate[1],
                                    day=jdate[2],
                                    precision=value.precision,
                                    calendarmodel=STANDARD_CALENDAR)
    return value
예제 #2
0
파일: test_jdcal.py 프로젝트: Jon1ke/script
def test_jcal2jd_and_back_through_jd2jcal():
    """Check round trip from jcal2jd to jd2jcal."""
    import random
    n = 1000
    year = [random.randint(-4699, 2200) for i in range(n)]
    month = [random.randint(1, 12) for i in range(n)]
    day = [random.randint(1, 28) for i in range(n)]

    jd = [jcal2jd(y, m, d)[1] for y, m, d in zip(year, month, day)]

    x = [jd2jcal(MJD_0, i) for i in jd]

    for i in range(n):
        assert x[i][0] == year[i]
        assert x[i][1] == month[i]
        assert x[i][2] == day[i]
        assert x[i][3] <= 1e-15
예제 #3
0
파일: test_jdcal.py 프로젝트: phn/jdcal
def test_jcal2jd_and_back_through_jd2jcal():
    """Check round trip from jcal2jd to jd2jcal."""
    import random
    n = 1000
    year = [random.randint(-4699, 2200) for i in range(n)]
    month = [random.randint(1, 12) for i in range(n)]
    day = [random.randint(1, 28) for i in range(n)]

    jd = [jcal2jd(y, m, d)[1]
          for y, m, d in zip(year, month, day)]

    x = [jd2jcal(MJD_0, i) for i in jd]

    for i in range(n):
        assert x[i][0] == year[i]
        assert x[i][1] == month[i]
        assert x[i][2] == day[i]
        assert x[i][3] <= 1e-15
예제 #4
0
def juld2date(juld):
    if 'float' in str(type(juld)):
        juld = [juld]
    elif hasattr(juld, '__iter__'):
        pass
            
    else:
        raise ValueError('juld must be an int, a float or be iterable')

    ndays = len(juld)
    year = np.zeros((ndays,), dtype=int)
    month = np.zeros((ndays,), dtype=int)
    day = np.zeros((ndays,), dtype=int)
    dayfrac = np.zeros((ndays,))

    for k, jd in enumerate(juld):
        year[k], month[k], day[k], dayfrac[k] = jdcal.jd2jcal(
            calendar_start, jd)

    if len(juld) == 1:
        year, month, day, dayfrac = year[0], month[0], day[0], dayfrac[0]

    return {'YEAR': year, 'MONTH': month, 'DAY': day, 'DAYFRAC': dayfrac}
예제 #5
0
파일: ocal.py 프로젝트: mlv/ocal
 def get_ymd_j(self):
     """return the year, month, and day of the instance, according to the
     Julian calendar"""
     return jdcal.jd2jcal(jdcal.MJD_0, self.date)[:3]
def novafloatReader(fdataPath, dayi, novaFloatSN):

    yeari, monthi, dayi, houri = jdcal.jd2jcal(MJD_0, dayi)

    folderName = str(yeari) + '-' + str(monthi).rjust(
        2, '0') + '-' + str(dayi).rjust(2, '0')

    print "folderName:", folderName
    fpathc = fdataPath + '/' + folderName + '/'

    novaFloatDeployment = []
    for dirname, dirnames, filenames in os.walk(fpathc):
        #        print len(filenames)
        if len(filenames) > 0:
            print filenames

            #            exit(1)
            ctdFilename = []
            ctdFilenameDecent = []

            for filenamei in filenames:

                if novaFloatSN in filenamei:
                    if "CTD_CTD_ASCENT" in filenamei:
                        """
                        there are some folders with more than one day's files
                        there is just one DECENT Profile? rest are the ASCENT profiles 
                        
                        """
                        ctdFilename.append(filenamei)

                    if "CTD_CTD_DESCENT" in filenamei:
                        ctdFilenameDecent.append(filenamei)


#                    print filenamei

            if len(ctdFilename) > 1:
                #                pass
                print ctdFilename
                for filei in ctdFilename:
                    if folderName in filei:
                        #                        currentDay = filei
                        if "PARTIAL" in filei:
                            fHK = filei.replace("_CTD_ASCENT_PARTIAL_", "_HK_")
                        else:
                            fHK = filei.replace("_CTD_ASCENT_", "_HK_")

                        floatdata = readDay(fpathc + filei, fpathc + fHK)

                        if len(floatdata) > 0:
                            novaFloatDeployment.append(floatdata)
                    else:
                        substr = "ASCENT_"
                        lenSubStr = len(substr)
                        indx = filei.find(substr)
                        print filei
                        print indx, filei[indx:indx + lenSubStr]
                        print filei[indx + lenSubStr:indx + lenSubStr + 10]

                        if "PARTIAL" in filei:
                            fHK = filei.replace("_CTD_ASCENT_PARTIAL_", "_HK_")
                        else:
                            fHK = filei.replace("_CTD_ASCENT_", "_HK_")

                        floatdata = readDay(fpathc + filei, fpathc + fHK)
                        if len(floatdata) > 0:
                            novaFloatDeployment.append(floatdata)
            else:
                for filei in ctdFilename:
                    if folderName in filei:
                        #                        currentDay = filei
                        if "PARTIAL" in filei:
                            fHK = filei.replace("_CTD_ASCENT_PARTIAL_", "_HK_")
                        else:
                            fHK = filei.replace("_CTD_ASCENT_", "_HK_")

                        floatdata = readDay(fpathc + filei, fpathc + fHK)

                        if len(floatdata) > 0:
                            novaFloatDeployment.append(
                                floatdata
                            )  #            exit(1)novaFloatDeployment

    return novaFloatDeployment
예제 #7
0
def mjd2year( X ):
	year = jdcal.jd2jcal(2400000.5, X+13)
	return float( year[0] )+( ( year[1]-1 )*30+year[2] )/365.0
예제 #8
0
    MO: 'Monday',
    TU: 'Tuesday',
    WE: 'Wednesday',
    TH: 'Thursday',
    FR: 'Friday',
    SA: 'Saturday'
}
weekdays = {x: [] for x in day_mapping.values()}

# Add all dates for all days of the week between 500 and 1000
for day in (day_mapping.items()):
    for dt in rrule(WEEKLY,
                    byweekday=day[0],
                    dtstart=parse('05000101'),
                    until=parse('10001231')):
        x = jdcal.jd2jcal(*jdcal.gcal2jd(dt.year, dt.month, dt.day))
        weekdays[day[1]].append('{:04}-{:02}-{:02}'.format(x[0], x[1], x[2]))

# Add all dates for Easter
weekdays['Easter'] = []
for y in range(500, 1001):
    weekdays['Easter'].append(str(easter.easter(y, method=1)))

# Add the date ranges for Lent
weekdays['Lent'] = []
for e in weekdays['Easter']:
    ash = str(datetime.date(parse(e) + relativedelta.relativedelta(days=-46)))
    lent_end = str(
        datetime.date(parse(e) + relativedelta.relativedelta(days=-1)))
    if ash in weekdays['Wednesday']:
        weekdays['Lent'].append((ash, lent_end))