コード例 #1
0
    def runTest(self):

        self.modelName = "ThemiTest"
        self.homeDir = os.path.realpath(os.path.join(os.path.dirname(__file__), "testEnvironment"))

        # Rename first observation file to have todays date.
        imomoDir = os.path.join(self.homeDir, "app", self.modelName, "data", "raw", "imomo")
        date = jdutil.date_to_jd(
            int(datetime.now().strftime("%Y")), int(datetime.now().strftime("%m")), float(datetime.now().strftime("%d"))
        )
        date = jdutil.jd_to_mjd(date)
        # Convert to matlab datenum
        date = date + 678942
        datenum = "%d" % date
        filename = os.path.join(imomoDir, (datenum + "DLoad.csv"))
        shutil.copy(os.path.join(imomoDir, "736239DLoad.csv"), os.path.join(imomoDir, filename))

        # Call to observationsAvailable.
        self.bol = observationsAvailable(self.homeDir, self.modelName)

        # AssertTrue
        self.assertEqual(self.bol, True)

        # Test false case.
        shutil.copy(os.path.join(imomoDir, "736238DLoad.csv"), os.path.join(imomoDir, filename))

        # Call to observationsAvailable.
        self.bol = observationsAvailable(self.homeDir, self.modelName)

        # AssertTrue
        self.assertEqual(self.bol, False)
コード例 #2
0
def observationsAvailable(homeDirectory, modelName):
    """
    Check if observations are available for the current time step.
    
    - Figure out todays date in matlab datenum format to get the filename
    - If there is a file with todays measurements read it in and figure out if
    there is discharge data available.
    
    If there are discharge observations available return true, else return false.
    """
    date = jdutil.date_to_jd(
        int(datetime.now().strftime("%Y")), int(datetime.now().strftime("%m")), float(datetime.now().strftime("%d"))
    )
    date = jdutil.jd_to_mjd(date)
    # Convert to matlab datenum
    date = date + 678942
    datenum = "%d" % date
    obsDir = os.path.join(homeDirectory, "app", modelName, "data", "raw", "imomo")
    filename = os.path.join(obsDir, (datenum + "DLoad.csv"))
    if os.path.exists(filename):
        # Scan line by line until the second entry (variable ID) of a line matches 25
        # (discharge).
        for line in open(filename):
            if re.search("^\d+\.*\d*,25,.+", line):
                return True
        return False  # No match while reading the lines.
    else:  # Return False if there is no new data.
        return False
コード例 #3
0
ファイル: satOrbit.py プロジェクト: daihui/TimeTransfer
def groundStationSec(groundList, startTime, passSec, interNum):
    year, month, day, hour, minute, sec = startTime
    jd = jdutil.date_to_jd(year, month, day)
    mjd = jdutil.jd_to_mjd(jd)
    print jd, mjd
    J = len(groundList[0])
    silde = []
    groundSecList = []
    groundfun = range(J)
    index = 0
    found = False
    while not found:
        if int(groundList[index][0]) == int(mjd):
            found = True
        else:
            index += 1
    for j in range(1, J):
        x = [
            float(groundList[index + i - interNum][0])
            for i in range(2 * interNum + 1)
        ]
        fx = [
            groundList[index + ii - interNum][j]
            for ii in range(2 * interNum + 1)
        ]
        groundfun[j] = lagInterpolation.get_Lxfunc(x, fx)
    for i in range(passSec):
        time = mjd + hour / 24. + minute / (24 * 60.) + (sec + i) / (24 * 60 *
                                                                     60.)
        silde.append(i)
        for j in range(1, J):
            silde.append(groundfun[j](time))
        groundSecList.append(silde[i * J:])
    print 'ground station position interpolation calculated by second !'
    return groundSecList
コード例 #4
0
    def time2sec(self):
        def get_min(hr):
            return int((hr - int(hr)) * 60.0)

        def get_msec(hr):
            minute = (hr - int(hr)) * 60.0
            second = (minute - int(minute)) * 60.0
            return int((second - int(second)) * 1000000.0)

        def get_sec(hr):
            minute = (hr - int(hr)) * 60.0
            return int((minute - int(minute)) * 60.0)

        #ss = 23.45
        #print get_min(ss),get_sec(ss), get_msec(ss)
        if 'DY' not in self.data.keys():
            self.data['DY'] = [None] * len(self.data['YR'])
        years = [x if x is not None else 0 for x in self.data['YR']]
        months = [x if x is not None else 0 for x in self.data['MO']]
        days = [x if x is not None else 1 for x in self.data['DY']]
        hours = [int(x) if x is not None else 0 for x in self.data['HR']]
        minutes = [get_min(x) if x is not None else 0 for x in self.data['HR']]
        seconds = [get_sec(x) if x is not None else 0 for x in self.data['HR']]
        mseconds = [
            get_msec(x) if x is not None else 0 for x in self.data['HR']
        ]
        date = [
            '%s%02d%02d' % (x, y, z) if z is not None else '%s%02d99' % (x, y)
            for x, y, z in zip(self.data['YR'], self.data['MO'],
                               self.data['DY'])
        ]
        self.data['DATE'] = date
        #print years,months,days,hours,minutes,seconds,mseconds
        #self.data['SECONDS'] = [time.mktime(datetime.datetime(year,month,day,hour,minute,second,msecond).timetuple()) for year,month,day,hour,minute,second,msecond in zip(years,months,days,hours,minutes,seconds,mseconds)]
        self.data['Julian'] = [
            jdutil.date_to_jd(
                year, month, day + jdutil.hmsm_to_days(
                    hour=hour, minute=minute, sec=second, micro=msecond))
            for year, month, day, hour, minute, second, msecond in zip(
                years, months, days, hours, minutes, seconds, mseconds)
        ]
        # julian day of 1662-10-15 12:00:00 = 2328381
        self.data['Julian1'] = [x - 2328381 for x in self.data['Julian']]

        return
コード例 #5
0
    logger.error('OSError %d: %s.', ose.errno, ose.strerror)
    return 1

  ## Write RRMDA.oda
  try:
    DOMTree = xml.dom.minidom.parse("RRMDA.oda")
    openDaApplication = DOMTree.documentElement
    restartInFile = openDaApplication.getElementsByTagName("restartInFile")
    restartInFileName = restartInFile[0].childNodes[0].nodeValue
    restartOutFile = openDaApplication.getElementsByTagName("restartOutFilePrefix")
    restartOutFilePrefix = restartOutFile[0].childNodes[0].nodeValue
    logger.info('Parsing RRMDA.oda')
    logger.debug('restartOutFilePrefix = %s',restartOutFilePrefix)
    # Change fileName
    date = jdutil.date_to_jd(int(datetime.now().strftime('%Y')),
                             int(datetime.now().strftime('%m')),
                             float(datetime.now().strftime('%d')))
    date = jdutil.jd_to_mjd(date)
    # Convert to matlab datenum
    date = date + 678942
    datenum = "%d" % date
    logger.debug('datenum of today = %d', date)
    restartInFileName = restartOutFilePrefix + datenum + '.zip'
    logger.debug('new restartInFileName = %s',restartInFileName)
    restartInFile[0].childNodes[0].replaceWholeText(restartInFileName)
    file = open('RRMDA.oda','w')
    DOMTree.writexml(file)
    file.close()
  except Exception, e:
    logger.error('Problem parsing and writing RRMDA.oda. Error: %s.',e)
    return 1