def timestamp(self,tai): """ Converts an TAI timestamp expressed as MJD seconds(!) into a UTC timestamp """ # convert from MJD seconds to MJD days try: mjdtai = float(tai)/86400. except ValueError: logging.warn('unable to convert MJD TAI timestamp: %r',tai) # as a fallback, return the current time return AstroTime.now(UTC) when = AstroTime.fromMJD(mjdtai,TAI) return when.astimezone(UTC)
def generate(): """Returns a randomly generated packet.""" timestamp = AstroTime.now(TAI).MJD()*86400. slewEndTime = float('nan') coordSys = 'Mount' random9 = [random() for i in range(9)] rotType = int(1234) random13 = [random() for i in range(13)] values = [timestamp,slewEndTime,coordSys] + random9 + [rotType] + random13 return Packet(*values)
def start(self): hdr = self.Header() hdr.name = ResourceName(self.name) # set our timestamp origin hdr.timestamp_origin = int(floor(time())) self.timestamp_origin = AstroTime.fromtimestamp(hdr.timestamp_origin,UTC) # describe each record that we will provide updates for for record in self.records.itervalues(): record.appendToHeader(hdr) self.sendHeader(hdr) self.started = True
def got_users(response): users = { 'TCC':0, 'TCCUSER':0 } parser = re.compile('\s*(TCC|TCCUSER)\s+([0-9]+)') for line in response: match = parser.match(line) if match: users[match.group(1)] = int(match.group(2)) for (username,nproc) in users.iteritems(): print '%s is running %d processes' % (username,nproc) utc = AstroTime.now(UTC) archiving.update(utc,'vms',{ 'nproc.tcc': users['TCC'], 'nproc.tccuser': users['TCCUSER'] })