예제 #1
0
def main():
    # Setup logging
    FORMAT = "%(asctime)-15s:%(levelname)s %(message)s"
    logging.basicConfig(level=logging.DEBUG,format=FORMAT)

    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(sys.argv, 'Narada List Python client')
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # Get Narada units
    ids = mngr.getDaqUnitIds()
    unitPrxs = mngr.getDaqUnitList(ids)
    for unitPrx in unitPrxs:
        unitId = unitPrx.getFields().mIdentifier
        # Get Narada unit channels
        ids = unitPrx.getDaqUnitChannelChildIds()
        channelPrxs = mngr.getDaqUnitChannelList(ids)
        channels = []
        for channelPrx in channelPrxs:
            channelNumber = channelPrx.getFields().mNumber
            channels.append(channelNumber)
        channels.sort()
        print 'Narada unit %s; channels %s' % (unitId, str(channels))

    # All done
    client.close()
예제 #2
0
def main(sensorConfigFile='narada.cfg'):
    # Setup logging
    FORMAT = "%(asctime)-15s:%(levelname)s %(message)s"
    logging.basicConfig(level=logging.DEBUG,format=FORMAT)

    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(config, 'Narada Node Registrar Python client')
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # Create a unit object and channel objects for each defined Narada unit
    f = open(sensorConfigFile, 'r')
    for line in f:
        id = line.strip()
        if not id or id[0] == '#':
            # Skip this line
            continue
        daqUnit = SenStore.DaqUnitFields()
        daqUnit.mModel = "Narada"
        daqUnit.mIdentifier = id
        daqUnit.id = mngr.addDaqUnit(daqUnit)
        logging.info('Created Narada unit %d [oid=%d]' % \
                     (int(id), daqUnit.id))
        for channel in [0,1,2,3]:
            # Create channel object
            channelObj = SenStore.DaqUnitChannelFields()
            channelObj.mUnit = daqUnit.id
            channelObj.mNumber = channel
            channelObj.id = mngr.addDaqUnitChannel(channelObj)
            logging.info('Created Narada channel %d:%d [oid=%d]' % \
                         (int(id), channel, channelObj.id))
            # Create channel data signal object
            signalObj = SenStore.DaqUnitChannelDataFields()
            signalObj.mChannel = channelObj.id
            signalObj.id = mngr.addDaqUnitChannelData(signalObj)
            # Create 1D raw signal data array
            signalPrx = mngr.getDaqUnitChannelData(signalObj.id)
            signalPrx.createSignal([1])
            signalPrx.setSubChannelsAxis([SenStore.Quantity.QuantityRAW])
            logging.info('Created Narada channel data signal %d:%d [oid=%d]' % \
                         (int(id), channel, signalObj.id))

    f.close()

    # All done
    client.close()
예제 #3
0
def main():
    # Setup logging
    FORMAT = "%(asctime)-15s:%(levelname)s %(message)s"
    logging.basicConfig(level=logging.DEBUG,format=FORMAT)

    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(config, 'Narada Sensor Data Saver Python client')
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # (unit, channel) -> signal object ID mapping
    signalPrxTable = {}

    # Get defined signals
    ids = mngr.getDaqUnitChannelDataIds()
    signalPrxs = mngr.getDaqUnitChannelDataList(ids)
    for signalPrx in signalPrxs:
        channelPrx = signalPrx.getChannel()
        unitPrx = channelPrx.getUnit()
        unitNumber = int(unitPrx.getFields().mIdentifier)
        channelNumber = channelPrx.getFields().mNumber
        key = (unitNumber,channelNumber)
        logging.info('Obtained proxy for narada channel signal %d:%d' % key)
        signalPrxTable[key] = signalPrx

    #
    # Example
    #
    t0 = time.time()
    dt = 0.01
    n = 1000
    # Create time axis
    t = numpy.zeros(n)
    for i in range(len(t)):
        t[i] = t0 + i*dt
    # Create dummy data
    data = numpy.random.random_integers(0,2**16-1,n)
    key = (21,2)
    signalPrx = signalPrxTable[key]
    signalPrx.appendToSignal(t.tolist(), data.tolist())
    logging.info('Stored random data in Narada channel signal %d:%d' % key)

    # All done
    client.close()
예제 #4
0
def main():
    # Setup logging
    FORMAT = "%(asctime)-15s:%(levelname)s %(message)s"
    logging.basicConfig(level=logging.DEBUG,format=FORMAT)

    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(config,'Narada Query Python client')
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # Get defined signals
    ids = mngr.getDaqUnitChannelDataIds()
    signalPrxs = mngr.getDaqUnitChannelDataList(ids)
    for signalPrx in signalPrxs:
        # Get Narada channel object proxy
        channelPrx = signalPrx.getChannel()
        # Get Narada unit object proxy
        unitPrx = channelPrx.getUnit()
        # Get unit and channel number, which form the key to the signal proxy
        unitNumber = int(unitPrx.getFields().mIdentifier)
        channelNumber = channelPrx.getFields().mNumber
        key = (unitNumber,channelNumber)
        # Get time range of available signal data
        timeInfo = signalPrx.getTimeAxisInfo([])
        if len(timeInfo.t) > 0:
            t0 = timeInfo.t[0]
            t1 = timeInfo.t[-1]
            print 'Narada unit %d channel %d info:' % key
            s0 = time.strftime("%Y-%b-%d %H:%M:%S (%Z)", time.localtime(t0))
            s1 = time.strftime("%Y-%b-%d %H:%M:%S (%Z)", time.localtime(t1))
            print '  time: %s to %s' % (s0, s1)
            print '  sample index: %d to %d' % (timeInfo.idx[0], timeInfo.idx[-1])
            dimInfo = signalPrx.getSignalSize()
            print "  size: %s" % 'x'.join(['%d' % dim for dim in dimInfo])

    # All done
    client.close()
예제 #5
0
def main(sensorConfigFile='narada.cfg'):
    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(sys.argv, 'Narada Node Registrar Python client')
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # Load the defined Narada units and channels
    daqUnits = daqlib.loadConfigUnits('narada.cfg')
    
    # Create the units
    daqlib.createUnits(mngr, daqUnits, "NaradaNode")

    # All done
    client.close()
예제 #6
0
def main():
    # Setup logging
    FORMAT = "%(asctime)-15s:%(levelname)s %(message)s"
    logging.basicConfig(level=logging.DEBUG,format=FORMAT)

    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(sys.argv, 'Narada Sensor Data Saver Python client')
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # Load the defined Narada units and channels
    daqUnits = daqlib.loadConfigUnits('narada.cfg')
    
    # Get the signals
    signalPrxTable = daqlib.getChannelDataProxies(mngr, daqUnits.keys())

    # Create time axis
    t0 = time.time()
    dt = 0.01   # Sampled data interval
    n = 5*60*100 # Number of samples per run
    ts = 6*3600   # Interval between runs
    N = 3     # Number of runs
    t = numpy.zeros(n)
    for k in range(-N,0):
        for i in range(-len(t),0):
            t[i] = t0 + i*dt + k*ts

        # Insert dummy data for each signal (channel)
        for key, signalPrx in signalPrxTable.iteritems():
            data = numpy.random.random_integers(0,2**16-1,n)
            signalPrx.appendToSignal(t.tolist(), data.tolist())
            logging.info('Stored random data in Narada channel signal %s:%d' % key)

    # All done
    client.close()
예제 #7
0
def main():
    # Setup logging
    FORMAT = "%(asctime)-15s:%(levelname)s %(message)s"
    logging.basicConfig(level=logging.DEBUG,format=FORMAT)

    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(sys.argv, 'Narada Query Python client')
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # Load the defined Narada units and channels
    daqUnits = daqlib.loadConfigUnits('narada.cfg')
    
    # Get the signals
    signalPrxTable = daqlib.getChannelDataProxies(mngr, daqUnits.keys())
    nSum = 0
    print 'Applied time zone is: %s' % time.strftime("%Z", time.localtime())
    for key, signalPrx in signalPrxTable.iteritems():
        # Get time range of available signal data
        timeInfo = signalPrx.getTimeAxisInfo([])
        if len(timeInfo.t) > 0:
            t0 = timeInfo.t[0]
            t1 = timeInfo.t[-1]
            print 'Narada unit %s channel %d info:' % key
            s0 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t0))
            s1 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t1))
            print '  time: %s to %s' % (s0, s1)
            print '  sample index: %d to %d' % (timeInfo.idx[0], timeInfo.idx[-1])
            dimInfo = signalPrx.getSignalSize()
            print "  size: %s" % 'x'.join(['%d' % dim for dim in dimInfo])
            nSum += timeInfo.idx[-1] - timeInfo.idx[0] + 1
    print 'Total number of samples: %d (%dk, %dM)' % (nSum, nSum/1000, nSum/1000000)

    # All done
    client.close()
예제 #8
0
        print 'Example: %s 115 2 "2010-06-10 12:00:00" > u115_ch2.txt' % progname
        print '  gets all data since the given date'
        print 'Example: %s 115 2 > u115_ch2.txt' % progname
        print '  gets all data'
        sys.exit(1)
    reqUnitId = sys.argv[1]
    reqChannelNumber= int(sys.argv[2])

    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(config)
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # Get unit object ID
    unitFields = SenStore.DaqUnitFields()
    unitFields.mIdentifier = reqUnitId
    ids = mngr.findEqualDaqUnit(unitFields, ['Identifier'])
    if len(ids) == 0:
        logging.error('Unit %d not found' % reqUnitNumber)
        client.close()
        sys.exit(1)
    unitOID = ids[-1]

    # Get channel object ID
    channelFields = SenStore.DaqUnitChannelFields()
예제 #9
0
def main():
    # Setup logging
    FORMAT = "%(asctime)-15s:%(levelname)s %(message)s"
    logging.basicConfig(level=logging.DEBUG,format=FORMAT)

    progname = os.path.basename(sys.argv[0])
    if len(sys.argv) < 3 :
        print 'Usage: %s <unit> <channel> [<start date/time> [<end date/time> [<dt>]]]' % progname
        print 'Gets the signal data from the requested unit/channel from the database.'
        print 'The first column is time [s], since 1970-01-01 Epoch UTC'
        print 'The second column is the Narada unit channel data'
        print ''
        print 'The date arguments are in local time of the computer running this command.'
        print ''
        print 'Example: %s 115 2 "2010-06-10 12:00:00" "2010-06-12 13:00:00" 0.1 > u115_ch2.txt' % progname
        print '  gets data at an interval of at most 100ms between the two dates'
        print 'Example: %s 115 2 "2010-06-10 12:00:00" "2010-06-12 13:00:00" > u115_ch2.txt' % progname
        print '  gets all data between the two dates'
        print 'Example: %s 115 2 "2010-06-10 12:00:00" > u115_ch2.txt' % progname
        print '  gets all data since the given date'
        print 'Example: %s 115 2 > u115_ch2.txt' % progname
        print '  gets all data'
        sys.exit(1)
    reqUnitId = sys.argv[1]
    reqChannelNumber= int(sys.argv[2])

    # Load configuration
    config = ConfigParser.ConfigParser()
    config.read(['config/client/SenStore.cfg'])
    
    #
    # Connect to server and get manager proxy
    #
    client = SenStoreClient(sys.argv, 'Narada Data Loader Python client')
    mngr = client.getManager()
    logging.info('Connected to SenStore')

    # Get unit object ID
    unitFields = SenStore.DaqUnitFields()
    unitFields.mIdentifier = reqUnitId
    ids = mngr.findEqualDaqUnit(unitFields, ['Identifier'])
    if len(ids) == 0:
        logging.error('Unit %s not found' % reqUnitId)
        client.close()
        sys.exit(1)
    unitOID = ids[-1]

    # Get channel object ID
    channelFields = SenStore.DaqUnitChannelFields()
    channelFields.mNumber = reqChannelNumber
    channelFields.mUnit = unitOID
    ids = mngr.findEqualDaqUnitChannel(channelFields, ['Number','Unit'])
    if len(ids) == 0:
        logging.error('Channel %s:%d not found' % (reqUnitId,reqChannelNumber))
        client.close()
        sys.exit(1)
    channelOID = ids[-1]
    
    # Get channel signal proxy
    signalFields = SenStore.DaqUnitChannelDataFields()
    signalFields.mChannel = channelOID
    ids = mngr.findEqualDaqUnitChannelData(signalFields, ['Channel'])
    if len(ids) == 0:
        logging.error('Signal %s:%d not found' % (reqUnitId,reqChannelNumber))
        client.close()
        sys.exit(1)
    signalOID = ids[-1]
    signalPrx = mngr.getDaqUnitChannelData(signalOID)

    #
    # Get signal data
    #
    logging.info('Getting signal data')
    timeInfo = signalPrx.getTimeAxisInfo([])
    if len(timeInfo.t) == 0:
        logging.warn('Signal %s:%d is empty' % (reqUnitId,reqChannelNumber))
        client.close()
        sys.exit(0)
    # Set up defaults: all data
    t0 = timeInfo.t[0]
    t1 = timeInfo.t[-1]
    dt = 0.0
    # Override defaults with user provided arguments
    if len(sys.argv) >= 4:
        t0 = time.mktime(time.strptime(sys.argv[3], '%Y-%m-%d %H:%M:%S'))
    if len(sys.argv) >= 5:
        t1 = time.mktime(time.strptime(sys.argv[4], '%Y-%m-%d %H:%M:%S'))
    if len(sys.argv) >= 6:
        dt = float(sys.argv[5])
    if dt > 0.0:
        # Get data no closer than specified sampling interval
        if True:
            # Get sample numbers, for info only
            timeInfo = signalPrx.getTimeAxisInfo([t0,t1])
            idxStart = timeInfo.idx[0]
            idxEnd = timeInfo.idx[-1]
            logging.debug('Getting sample %d to %d' % (idxStart,idxEnd))
        result = signalPrx.getSignalData(t0, dt, t1, [])
        t = numpy.array(result.t)
        y = numpy.array(result.data).reshape(result.shape)
        for i in range(len(t)):
            print t[i], y[i][0]
    else:
        # Get all data, chunked to avoid message size overflow
        timeInfo = signalPrx.getTimeAxisInfo([t0,t1])
        idxStart = timeInfo.idx[0]
        idxEnd = timeInfo.idx[-1]
        idxStep = 10000
        done = False
        while not done:
            idxNext = idxStart + idxStep + 1
            if idxNext >= idxEnd:
                done = True
                idxNext = idxEnd
            result = signalPrx.getSignalDataByIndexRange(idxStart, 1, idxNext, [])
            logging.debug('Getting sample %d to %d' % (idxStart,idxNext))
            t = numpy.array(result.t)
            y = numpy.array(result.data).reshape(result.shape)
            for i in range(len(t)):
                print t[i], y[i][0]
            idxStart = idxNext
            
    # All done
    logging.info('Done')
    client.close()