Ejemplo n.º 1
0
 def _observe_status(self, change):
     """observer for status. logs booting and closing"""
     if change["type"]!="create":
         if self.status=="Active":
             log_info("BOOTED: {0}".format(self.name))
         elif self.status=="Closed":
             log_info("CLOSED: {0}".format(self.name))
Ejemplo n.º 2
0
 def close_all(cls):
     """attempts to close all instruments, then raises any errors that occurred"""
     cls.abort_all()
     log_info("Closing all instruments")
     for name, instr in cls.get_agents(Instrument).iteritems():
         instr.close()
     log_info("All instruments successfully closed")
Ejemplo n.º 3
0
def start_GPIB(
        instr,
        address,  #delay, timeout, 
        reset,
        selftest,  #send_end,
        identify,
        clear,
        resource_manager,
        session,
        access_key):
    if address == "":
        raise InstrumentError("{0}: GPIB instruments need addresses.".format(
            instr.name))
    instr.address = address
    instr.resource_manager = visa.ResourceManager()

    instr.session = instr.resource_manager.open_resource(
        address)  #visa.instrument(address)
    #self.session = visa.instrument(self.address, lock = lock, timeout = timeout, send_end=send_end, values_format = visa.single) #values_format=visa.single | visa.big_endian)
    if get_tag(instr, "access_key", "do", False):
        instr.access_key = GPIB_lock(instr)
        instr.lock = True
    if get_tag(instr, "clear", "do", False):
        instr.clear()
    if get_tag(instr, "reset", "do", False):
        instr.reset()
    if get_tag(instr, "selftest", "do", False):
        instr.selftest()
    if get_tag(instr, "identify", "do", False):
        instr.receive('identify')
    log_info("GPIB instrument {name} initialized at address {address}".format(
        name=instr.name, address=address))
Ejemplo n.º 4
0
 def do_read(self):
     """reads a text file"""
     templist = []
     with open(self.file_path, 'r') as f:
         for line in f:
             templist.append(line)
     log_info("Read data from text file: {0}".format(self.file_path))
     self.data_distributor(templist)
Ejemplo n.º 5
0
 def makedir(self):
     """creates the directory and data file and log file"""
     if not os_path_exists(self.dir_path):
         os_makedirs(self.dir_path)
         log_info("Made directory at: {0}".format(self.dir_path))
     if not os_path_exists(self.file_path):
         self.save_file = self._default_save_file()  #self.create_file()
         make_log_file(self.log_path, mode="w")
Ejemplo n.º 6
0
 def makedir(self):
     """creates the directory and data file and log file"""
     if not os_path_exists(self.dir_path):
         os_makedirs(self.dir_path)
         log_info("Made directory at: {0}".format(self.dir_path))
     if not os_path_exists(self.file_path):
         self.save_file=self._default_save_file() #self.create_file()
         make_log_file(self.log_path, mode="w")
Ejemplo n.º 7
0
 def do_read(self):
     """reads a text file"""
     templist=[]
     with open(self.file_path, 'r') as f:
         for line in f:
             templist.append(line)
     log_info("Read data from text file: {0}".format(self.file_path))
     self.data_distributor(templist)
Ejemplo n.º 8
0
 def save_code(self, obj):
     """saves the code containing the passed in object"""
     if obj is not None:
         module_path, ext = os_path_splitext(getfile(obj))
         code_file_path = module_path + '.py'   # Should get the py file, not the pyc, if compiled.
         code_file_copy_path = self.dir_path+self.divider+os_path_split(module_path)[1]+".pyb"
         if not os_path_exists(code_file_copy_path):
             copyfile(code_file_path, code_file_copy_path)
             log_info("Saved code to: {0}".format(code_file_copy_path))
Ejemplo n.º 9
0
 def save_code(self, obj):
     """saves the code containing the passed in object"""
     if obj is not None:
         module_path, ext = os_path_splitext(getfile(obj))
         code_file_path = module_path + '.py'  # Should get the py file, not the pyc, if compiled.
         code_file_copy_path = self.dir_path + self.divider + os_path_split(
             module_path)[1] + ".pyb"
         if not os_path_exists(code_file_copy_path):
             copyfile(code_file_path, code_file_copy_path)
             log_info("Saved code to: {0}".format(code_file_copy_path))
Ejemplo n.º 10
0
 def _observe_dir_path(self, change):
     """if the file path exists and the file location is changed, this function moves the
     entire directory to the new location and sets up the log file for appended logging"""
     if change['type'] != 'create':
         old_dir_path = change['oldvalue']
         if not os_path_exists(self.file_path):
             if os_path_exists(old_dir_path):
                 remove_log_file()
                 move(old_dir_path, self.dir_path)
                 make_log_file(self.log_path)
                 log_info("Moved files to: {0}".format(self.dir_path))
Ejemplo n.º 11
0
 def _observe_dir_path(self, change):
     """if the file path exists and the file location is changed, this function moves the
     entire directory to the new location and sets up the log file for appended logging"""
     if change['type']!='create':
         old_dir_path=change['oldvalue']
         if not os_path_exists(self.file_path):
             if os_path_exists(old_dir_path):
                 remove_log_file()
                 move(old_dir_path, self.dir_path)
                 make_log_file(self.log_path)
                 log_info("Moved files to: {0}".format(self.dir_path))
Ejemplo n.º 12
0
def start_GPIB(instr, address, delay, timeout, reset, selftest, lock, send_end, identify, clear):
    if address=="":
        raise InstrumentError("{0}: GPIB instruments need addresses.".format(instr.name))
    instr.address=address
    instr.session=visa.instrument(address)
    #self.session = visa.instrument(self.address, lock = lock, timeout = timeout, send_end=send_end, values_format = visa.single) #values_format=visa.single | visa.big_endian)
    if get_tag(instr, "clear", "do", False):
        instr.clear()
    if get_tag(instr, "reset", "do", False):
        instr.reset()
    if get_tag(instr, "selftest", "do", False):
        instr.selftest()
    if get_tag(instr, "identify", "do", False):
        instr.receive('identify')
    log_info("GPIB instrument {name} initialized at address {address}".format(name=instr.name, address=address))
Ejemplo n.º 13
0
def start_GPIB(instr, address, #delay, timeout, 
                   reset, selftest, #send_end,
                   identify, clear,
               resource_manager, session, access_key):
    if address=="":
        raise InstrumentError("{0}: GPIB instruments need addresses.".format(instr.name))
    instr.address=address
    instr.resource_manager=visa.ResourceManager()
    
    instr.session=instr.resource_manager.open_resource(address) #visa.instrument(address)
    #self.session = visa.instrument(self.address, lock = lock, timeout = timeout, send_end=send_end, values_format = visa.single) #values_format=visa.single | visa.big_endian)
    if get_tag(instr, "access_key", "do", False):
        instr.access_key=GPIB_lock(instr)
        instr.lock=True
    if get_tag(instr, "clear", "do", False):
        instr.clear()
    if get_tag(instr, "reset", "do", False):
        instr.reset()
    if get_tag(instr, "selftest", "do", False):
        instr.selftest()
    if get_tag(instr, "identify", "do", False):
        instr.receive('identify')
    log_info("GPIB instrument {name} initialized at address {address}".format(name=instr.name, address=address))
Ejemplo n.º 14
0
            file_path=self.file_path
        save_dxf(verts, color, layer, file_path, write_mode)
        log_info("Direct save of data to: {}".format(file_path))


if __name__=="__main__":
    from taref.core.shower import shower

    a=Save_TXT()
    shower(a)

if __name__=="__main__2":

    a=Save_HDF5(buffer_save=True)
    print a.log_name
    log_info("prowdy")
    a.full_save()
    a.data_save(2, name="a")
    a.data_save([1,2,3], name="b")
    from numpy import array
    a.data_save(array([1,2,3]), name="b")
    a.data_save([4,5], name="b")
    a.data_save(["blah", "bob", True], name="c")
    a.data_save(unicode("bob"), name="c")

    #a.makedir()
    log_info("yo")
    a.quality="less interesting"
    log_info("bro")

    #b=Read_HDF5(file_path=a.file_path)
Ejemplo n.º 15
0
# -*- coding: utf-8 -*-
"""
Created on Thu Mar  5 20:50:49 2015

@author: thomasaref
"""

from taref.core.log import  log_info, log_warning, make_log_file, remove_log_file, log_debug
log_info(1)
from Atom_Filer import Filer
from atom.api import Bool, Dict, Unicode, observe, List, Event, Enum, Typed, Int
log_info(2)
from os.path import exists as os_path_exists, splitext as os_path_splitext, split as os_path_split
from os import makedirs as os_makedirs
from shutil import move, copyfile
from inspect import getfile
log_info(3)
from numpy import ndarray, size
from enaml import imports
from Atom_Read_File import Read_HDF5, Read_NP, Read_TXT, Read_DXF
from collections import OrderedDict
from SHOW_functions import show

class Save_File(Filer):
    data_buffer=Typed(OrderedDict)
    buffer_size=Int(100).tag(desc="size of buffer as number of elements in a list/array")
    save_event=Event()

    def show(self):
        show(self)
Ejemplo n.º 16
0
 def log_save(self):
     log_info("save not implemented! file not saved: {0}".format(self.file_path))
Ejemplo n.º 17
0
@author: thomasaref
"""
from taref.core.log import log_info
from taref.core.atom_extension import (set_tag, set_all_tags, get_tag, get_all_tags, get_map, get_inv, get_type,
        get_reserved_names, get_all_params, get_all_main_params, get_main_params, set_log, lowhigh_check, private_property, tag_Callable, tag_Property)

from atom.api import Atom, Int, Float, Enum, Unicode, Bool, List, Dict
from taref.core.universal import Array
from numpy import array




print
log_info("test code:")
print """class Test(Atom):
    a=Int().tag(tg=4)
    b=Float()
t=Test()"""
class Test(Atom):
    a=Int().tag(tg=4)
    b=Float()
t=Test()
print
print 'set_tag(t, "a", z="p")'
set_tag(t, "a", z="p")
print 'print t.get_member("a").metadata'
print t.get_member("a").metadata
print 'print t.get_member("b").metadata'
print t.get_member("b").metadata
Ejemplo n.º 18
0
 def do_read(self):
     self.data=read_hdf5(self.file_path)
     log_info("Read data from hdf5 file: {0}".format(self.file_path))
Ejemplo n.º 19
0
 def run_measurement(cls):
     """shortcut method for running all measurements defined in run_func_dict"""
     log_info("Measurement started")
     for func in cls.run_func_dict.values():
         func()
     log_info("Measurement finished")
Ejemplo n.º 20
0
 def _default_save_file(self):
     log_info("Created hdf5 file at: {0}".format(self.file_path))
     return File(self.file_path, 'w')
Ejemplo n.º 21
0
if __name__ == "__main__":
    from taref.core.shower import shower
    from taref.filer.read_file import Read_NP

    #a=Save_TXT()
    a = Save_NP()
    b = Read_NP(show_data_str=True, file_path=a.file_path)
    a.save([[1, 2, 3], [4, 5, 6], [7, 7, 7]])
    b.read()
    shower(a, b)

if __name__ == "__main__2":

    a = Save_HDF5(buffer_save=True)
    print a.log_name
    log_info("prowdy")
    a.full_save()
    a.data_save(2, name="a")
    a.data_save([1, 2, 3], name="b")
    from numpy import array
    a.data_save(array([1, 2, 3]), name="b")
    a.data_save([4, 5], name="b")
    a.data_save(["blah", "bob", True], name="c")
    a.data_save(unicode("bob"), name="c")

    #a.makedir()
    log_info("yo")
    a.quality = "less interesting"
    log_info("bro")

    #b=Read_HDF5(file_path=a.file_path)
Ejemplo n.º 22
0
 def log_save(self):
     log_info("Data saved to hdf5 file at: {0}".format(self.file_path))
Ejemplo n.º 23
0
def set_log(obj, name, value):
   """called when parameter of given name is set to value i.e. instr.parameter=value. Customized messages for different types. Also saves data"""
   if get_tag(obj, name, 'log', True) and not get_tag(obj, name, "tracking", False):
       label=get_tag(obj, name, 'label', name)
       unit=get_tag(obj, name, 'unit', "")
       obj_name=getattr(obj, "name", "NO_NAME")
       typer=get_type(obj, name)
       if typer==Coerced:
           typer=type(getattr(obj, name))
       if typer==Enum:
           log_info("Set {instr} {label} to {value} ({map_val})".format(
                 instr=obj_name, label=label, value=value,
                 map_val=get_map(obj, name, value)))
       elif typer in (List, ContainerList, list):
           log_info("Set {instr} {label} to {length} list".format(
               instr=obj_name, label=label, length=shape(value)))
       elif typer==ndarray:
           log_info("Set {instr} {label} to {length} array".format(
               instr=obj_name, label=label, length=shape(value)))
       elif typer==Dict:
           log_info("Set {instr} {label} dict".format(instr=obj_name, label=label))
       elif typer in (Unicode, Str):
           log_info("Set {instr} {label} to {length} length string".format(instr=obj_name, label=label, length=len(value)))
       elif typer==Float:
           log_info("Set {instr} {label} to {value:g} {unit}".format(
                             instr=obj_name, label=label, value=float(value), unit=unit), n=1)
       elif typer==Int:
           log_info("Set {instr} {label} to {value} {unit}".format(
                             instr=obj_name, label=label, value=int(value), unit=unit))
       else:
           log_info("Set {instr} {label} to {value} {unit}".format(
                             instr=obj_name, label=label, value=value, unit=unit))
Ejemplo n.º 24
0
 def close(self, **kwargs):
     """Close the instrument using closer function if it exists"""
     if self.status == "Active":
         log_info("CLOSED: {0}".format(self.name))
         self.status = "Closed"
         self.closer(**kwargs)
Ejemplo n.º 25
0
 def log_create(self):
     log_info("Created text file at: {0}".format(self.file_path))
Ejemplo n.º 26
0
# -*- coding: utf-8 -*-
"""
Created on Tue Nov  3 15:45:12 2015

@author: thomasaref
"""

from taref.core.agent import SubAgent, Spy, Agent
from atom.api import Int, Float, ContainerList, Dict, Atom
from taref.core.log import log_info, log_debug
from taref.core.shower import shower

log_info(1)
class Test(SubAgent):
    a=Float()
    b=Int()
t=Test()
t2=Test()

print type(t2).agent_dict
def run_test():
    print t.agent_dict
    t.a=5
    print "ran run_test"

def run_test2():
    t2.b=3
    print "ran run_test2"

t.add_func(run_test)
#t.chief.add_func(run_test2)
Ejemplo n.º 27
0
 def log_create(self):
     log_info("save not implemented! file not created at {0}".format(self.file_path))
Ejemplo n.º 28
0
 def direct_save(self, data, write_mode='a'):
     save_txt(file_path=self.file_path, data=data, write_mode=write_mode)
     log_info("Direct save of data to: {}".format(self.file_path))
Ejemplo n.º 29
0
 def direct_save(self, verts, color, layer, file_path=None, write_mode='w'):
     if file_path is None:
         file_path = self.file_path
     save_dxf(verts, color, layer, file_path, write_mode)
     log_info("Direct save of data to: {}".format(file_path))
Ejemplo n.º 30
0
 def _default_save_file(self):
     log_info("Created txt file at: {0}".format(self.file_path))
     return open(self.file_path, 'w')
Ejemplo n.º 31
0
 def log_create(self):
     log_info("save not implemented! file not created at {0}".format(
         self.file_path))
Ejemplo n.º 32
0
 def boot_all(cls):
     log_info("Booting all instruments")
     for instr in cls.get_agents(Instrument).values():
         instr.boot()
     log_info("All instruments successfully booted")
Ejemplo n.º 33
0
 def log_read(self):
     log_info("Read data from hdf5 file: {0}".format(self.file_path))
Ejemplo n.º 34
0
def set_log(obj, name, value):
    """called when parameter of given name is set to value i.e. instr.parameter=value. Customized messages for different types. Also saves data"""
    if get_tag(obj, name, 'log',
               True) and not get_tag(obj, name, "tracking", False):
        label = get_tag(obj, name, 'label', name)
        unit = get_tag(obj, name, 'unit', "")
        obj_name = getattr(obj, "name", "NO_NAME")
        typer = get_type(obj, name)
        if typer == Coerced:
            typer = type(getattr(obj, name))
        if typer == Enum:
            log_info("Set {instr} {label} to {value} ({map_val})".format(
                instr=obj_name,
                label=label,
                value=value,
                map_val=get_map(obj, name, value)))
        elif typer in (List, ContainerList, list):
            log_info("Set {instr} {label} to {length} list".format(
                instr=obj_name, label=label, length=shape(value)))
        elif typer == ndarray:
            log_info("Set {instr} {label} to {length} array".format(
                instr=obj_name, label=label, length=shape(value)))
        elif typer == Dict:
            log_info("Set {instr} {label} dict".format(instr=obj_name,
                                                       label=label))
        elif typer in (Unicode, Str):
            log_info("Set {instr} {label} to {length} length string".format(
                instr=obj_name, label=label, length=len(value)))
        elif typer == Float:
            log_info("Set {instr} {label} to {value:g} {unit}".format(
                instr=obj_name, label=label, value=float(value), unit=unit),
                     n=1)
        elif typer == Int:
            log_info("Set {instr} {label} to {value} {unit}".format(
                instr=obj_name, label=label, value=int(value), unit=unit))
        else:
            log_info("Set {instr} {label} to {value} {unit}".format(
                instr=obj_name, label=label, value=value, unit=unit))
Ejemplo n.º 35
0
 def log_save(self):
     log_info("Data saved to hdf5 file at: {0}".format(self.file_path))
Ejemplo n.º 36
0
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 30 20:44:22 2015

@author: thomasaref
"""

from taref.core.log import log_info, log_warning, make_log_file, remove_log_file

log_info("balh")

log_info("yoy")
log_warning("yay")
make_log_file("/Users/thomasaref/Documents/TA_software/test_code/ztestlog2.txt", mode='w')

log_info(2)
log_info(3)
log_info(4)
log_info(5)
remove_log_file()
#dir_path, divider, log_name=memory_handler.target.baseFilename.rpartition("/")
#print dir_path, divider, log_name #memory_handler.target.baseFilename.split(log_name)
log_info(6)
#make_log_file("/Users/thomasaref/Documents/TA_software/ztestlog2.txt")

log_info(7)
log_info(8)
log_info(9)
log_info(10)
#
#make_log_file("/Users/thomasaref/Documents/TA_software/ztestlog3.txt")
Ejemplo n.º 37
0
 def direct_save(self, data, write_mode='a'):
     save_txt(file_path=self.file_path, data=data, write_mode=write_mode)
     log_info("Direct save of data to: {}".format(self.file_path))
Ejemplo n.º 38
0
 def do_read(self):
     self.data={"data":loadtxt(self.file_path)}
     log_info("Read data from numpy text file: {0}".format(self.file_path))
Ejemplo n.º 39
0
 def makedir(self):
     """creates the directory and data file and log file"""
     if not os_path_exists(self.folder.dir_path):
         os_makedirs(self.folder.dir_path)
         log_info("Made directory at: {0}".format(self.folder.dir_path))
Ejemplo n.º 40
0
 def receive_log(self, name):
     """Log for receiving. can be overwritten in child classes for customization of message"""
     label = get_tag(self, name, 'label', name)
     log_info("RECEIVE: {instr} {label}".format(instr=self.name,
                                                label=label))
Ejemplo n.º 41
0
 def direct_save(self, verts, color, layer, file_path=None, write_mode='w'):
     if file_path is None:
         file_path=self.file_path
     save_dxf(verts, color, layer, file_path, write_mode)
     log_info("Direct save of data to: {}".format(file_path))
Ejemplo n.º 42
0
 def makedir(self):
     """creates the directory and data file and log file"""
     if not os_path_exists(self.folder.dir_path):
         os_makedirs(self.folder.dir_path)
         log_info("Made directory at: {0}".format(self.folder.dir_path))
Ejemplo n.º 43
0
 def send_log(self, name):
     """Log for sending. can be overwritten in child classes to allow customization of message"""
     label = get_tag(self, name, 'label', name)
     log_info("SEND: {instr} {label}".format(instr=self.name, label=label))
Ejemplo n.º 44
0
 def log_create(self):
     log_info("Created text file at: {0}".format(self.file_path))
Ejemplo n.º 45
0
 def run_measurement(cls):
     log_info("Measurement started")
     for func in cls.run_func_dict.values():
         func()
     log_info("Measurement finished")
Ejemplo n.º 46
0
 def log_save(self):
     log_info("save not implemented! file not saved: {0}".format(
         self.file_path))
Ejemplo n.º 47
0
# -*- coding: utf-8 -*-
"""
Created on Thu Mar  5 20:50:49 2015

@author: thomasaref
"""

from taref.core.log import log_info, log_warning, make_log_file, remove_log_file, log_debug
log_info(1)
from Atom_Filer import Filer
from atom.api import Bool, Dict, Unicode, observe, List, Event, Enum, Typed, Int
log_info(2)
from os.path import exists as os_path_exists, splitext as os_path_splitext, split as os_path_split
from os import makedirs as os_makedirs
from shutil import move, copyfile
from inspect import getfile
log_info(3)
from numpy import ndarray, size
from enaml import imports
from Atom_Read_File import Read_HDF5, Read_NP, Read_TXT, Read_DXF
from collections import OrderedDict
from SHOW_functions import show


class Save_File(Filer):
    data_buffer = Typed(OrderedDict)
    buffer_size = Int(100).tag(
        desc="size of buffer as number of elements in a list/array")
    save_event = Event()

    def show(self):
Ejemplo n.º 48
0
 def log_read(self):
     log_info("read not implemented! file not read: {0}".format(self.file_path))
Ejemplo n.º 49
0
 def _default_save_file(self):
     log_info("Created hdf5 file at: {0}".format(self.file_path))
     return File(self.file_path, 'w')
Ejemplo n.º 50
0
 def log_read(self):
     log_info("Read data from numpy text file: {0}".format(self.file_path))
Ejemplo n.º 51
0
 def _default_save_file(self):
     log_info("Created txt file at: {0}".format(self.file_path))
     return open(self.file_path, 'w')