Example #1
0
File: ocal.py Project: mlv/ocal
    def __init__(self, **kw):
        """Initialize.

        Ideally called with constructor methods. Optional parameters include:
        * year, month, day: year, month, day according to the calendar system.
        * date: modified julian date
        * gregorian: if true (the default), use the Gregorian calendar to
        * convert year,month,day to a julian date.julian: if true, use the
        * Julian calendar to convert year,month,day to a julian date.
        """
        if 'calendar' in kw:
            cal = kw['calendar']
        else:
            # default calendar: Gregorian
            cal = GREGORIAN
        if 'date' in kw:
            self.date = kw['date']
        else:
            y = kw['year']
            m = kw['month']
            d = kw['day']
            if cal == GREGORIAN:
                self.date = int(jdcal.gcal2jd(y, m, d)[1])
            elif cal == JULIAN:
                self.date = int(jdcal.jcal2jd(y, m, d)[1])
            else:
                raise ValueError("Unknown calendar:{}".format(cal))
        self.calendar = cal
        self.sync_ymd()
Example #2
0
    def getJulian(self, gDate=None):
        #
        if gDate == None:
            date = datetime.now()
        else:
            if gDate.find(" ") < 0:
                date = datetime.strptime(gDate, "%m/%d/%Y")
            else:
                date = datetime.strptime(gDate, "%m/%d/%Y %H:%M:%S")

        jTplDate = jdcal.jcal2jd(date.year, date.month, date.day)
        return int(jTplDate[0] + jTplDate[1] +
                   float("0." + str(jTplDate[1]).split(".")[1]))
Example #3
0
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
Example #4
0
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
def toJulianDay(year,month,day):
	jd=jcal2jd(year,month,day)
	jd2=jcal2jd(year,'1','1')
	jd=str(int(jd[1]-jd2[1]) + 1)
	return(jd)
Example #6
0
def toJulianDay(year, month, day):
    jd = jcal2jd(year, month, day)
    jd2 = jcal2jd(year, '1', '1')
    jd = str(int(jd[1] - jd2[1]) + 1)
    return (jd)
    year2, month2, day2 = endDate.split('-')
    print year2, month2, day2

    #    MJD0 = jdcal.jcal2jd(year1,refMonth,refDay)[1]

    #    exit()

    fpath = "/home/xuj/work/project/novaFloat/"
    foutPath = "/home/xuj/work/project/novaFloat/output/"

    fdataPath = "/home/xuj/work/project/novaFloat/data"

    #    dayStart = jdcal.jcal2jd(year1,month1,day1)[1]-MJD_JD2000+1
    #    dayEnd   = jdcal.jcal2jd(year2,month2,day2)[1]-MJD_JD2000+1

    dstart0, dayStart = jdcal.jcal2jd(year1, month1, day1)
    dend0, dayEnd = jdcal.jcal2jd(year2, month2, day2)

    #    print dstart0,dayStart,dend0,dayEnd

    #    exit(1)

    #    daytime=[]
    datenum = []
    lat = []
    lon = []

    salinity = []
    temperature = []
    pressure = []