Пример #1
0
	if how is not None:
	    print "One of --as_hub or --as_server must be specified."
	    Usage()
	how = key
    elif key == "--service_type":
	stypes.append(value)
    elif key == "--retry":
	retry = 1
    elif key == "--ignore_reinitialize":
	ignore_reinitialize = 1
    elif key == "--frames":
	try:
	    fp = open(value, "r")
	    s = fp.read()
	    fp.close()
	    f_list, ignore = Galaxy._read_irp_value(s)
	    if type(f_list) is not type([]):
		print "Couldn't parse frame file (should be list of frames). Skipping."
	    else:
		for e in f_list:
		    if Galaxy.GetObjectType(e) is not Galaxy.GAL_FRAME:
			print "Element of frame file list is not frame. Skipping."
		    else:
			frame_list.append(e.PPrint())		
	except IOError:
	    print "Couldn't read frame file. Skipping."
if how is None:
    print "One of --as_hub or --as_server must be specified."
    Usage()

if (how == "--as_hub") and stypes:
Пример #2
0
__author__ = 'amarch'
# -*- coding: utf-8 -*-
from Galaxy import *
from utils import plotutils as plotutils
from VelocityDispersion import *


if __name__ == "__main__":
    ngc338 = Galaxy(name="NGC 338 (UGC 624)", path="../data/ngc338", incl=64.0, delta_incl=7.5,
                    description="Inclination according to Zasov 2012, photometry in I band.",
                    resolution=311.0, image="../data/ngc338/ngc338_SDSS.jpeg")
    ngc338.add_param("SDSS DR9 link",
                     "http://skyserver.sdss3.org/dr9/en/tools/explore/obj.asp?ra=15.15164775&dec=30.66902519")
    ngc338.add_img("2MASS image JHK", "../data/ngc338/ngc338_JHK.jpg")
    ngc338.add_img("Image with HI surf. dens.", "../data/ngc338/ugc624.gif")
    ngc338.add_img("SDSS DR9 whole image", "../data/ngc338/sdss_dr9_whole.jpg")
    ngc338.print_info(0)

    ngc338.set_bulge_radius(15.0)

    stars_ma_rc = RotationCurve(ngc338.path + "/v_stars_ma.dat", "Stars MA RC NGC338")
    stars_ma_rc.print_info(0)

    ngc338.initialize_rc_handler()
    ngc338.rc_handler.set_stellar_ma_rc(RotationCurve("../data/ngc338/v_stars_ma.dat", "Stars MA RC NGC338"))
    ngc338.rc_handler.set_stellar_mi_rc(RotationCurve("../data/ngc338/v_stars_mi.dat", "Stars MI RC NGC338"))
    ngc338.rc_handler.add_gas_rc(RotationCurve("../data/ngc338/v_gas_ma.dat", "Gas MA RC NGC338"), "v_gas_ma")
    ngc338.rc_handler.add_gas_rc(RotationCurve("../data/ngc338/v_gas_Katkov.dat", "Gas Katkov RC NGC338"),
                                 "v_gas_Katkov")
    ngc338.rc_handler.add_gas_rc(RotationCurve("../data/ngc338/v_gas_WSRT.dat", "Gas WSRT RC NGC338"), "v_gas_WSRT")
    ngc338.rc_handler.add_gas_rc(RotationCurve("../data/ngc338/v_gas_Court.dat", "Gas Court RC NGC338"), "v_gas_Court")
Пример #3
0
	
	galaxies = []
	zlen = len(model_gqs)

	IDs = np.unique(data['ID'])
	idlen = len(IDs)
#	ID_HI,ID_MgII,ID_SiII,ID_SiIII,ID_SiIV,ID_CIII,ID_OVI = [],[],[],[],[],[],[]

	imHI,imMgII,imSiII,imSiIII,imSiIV,imCIII,imOVI = np.zeros((zlen,idlen)),np.zeros((zlen,idlen)),np.zeros((zlen,idlen)),np.zeros((zlen,idlen)),np.zeros((zlen,idlen)),np.zeros((zlen,idlen)),np.zeros((zlen,idlen))

	imArrays = [imHI,imMgII,imSiII,imSiIII,imSiIV,imCIII,imOVI]
#	IDararys = [ID_HI,ID_MgII,ID_SiII,ID_SiIII,ID_SiIV,ID_CIII,ID_OVI]

	count = 0
	for ID in np.unique(data['ID']):
		gal = Galaxy(ID,l,u,model_width,nbins,ndraws)
		print count, ID, len(gal.coldens)
		if len(gal.coldens) != 0.0:
			for i in range(len(model_gqs)):
				model_name = model_beg+model_gqs[i]+model_mid
				#print model_name
				gal.add_model(gs[i],qs[i],model_name,gal)
				for j in range(len(ions)):
					idx = gal.models[i].line_indices(ions[j])
					if len(idx)>0.0:
						gal.models[i].add_line(ions[j],idx)
						#The line I want should be the last one that was added so
						#This is the line I'm least confident in I guess...
						#imArrays[j][i,count] = gal.models[i].lines[-1].likelihood
						for line in gal.models[i].lines:
							if line.ion == ions[j]:
Пример #4
0
    def XmlizeList(self, key, value):
	theList, ignore = Galaxy._read_irp_value(value)
	return self.XmlizeListObject(key, theList)
def SendMessageToDM(provider, msgtype, msg):
    prog_name = "main"
    
    print  'lets say hello to DM async way'
    
    nets = []
    parse_str = []
    hyp_str = []
    for k, v in msg.iteritems():
        net = Galaxy.Frame("slot", Galaxy.GAL_CLAUSE, {':name':k, ':contents':v})
        nets.append(net)
        parse_str.append('( %s ( %s ) )' %(k, v))
        hyp_str.append(v)
        
     #Log('Test Printing the nets\n %s' %(Galaxy.OPr(nets)))
     #Log('----------THEEND OF NETS -------')
    gfSlot = {}    
    gfParse = {}
    gfSlot[":nets"] = nets
    gfSlot[":numnets"] = len(nets)
    gfSlot[":name"] = msgtype
    gfSlot[":contents"] = ' '.join(hyp_str)
    gfSlot[":frame"] = "Fake Frame"
    gfSlotFrame = Galaxy.Frame("slot", Galaxy.GAL_CLAUSE, gfSlot)
    slots = [gfSlotFrame]
     
     #Log('Test Printing the slots\n %s' %(Galaxy.OPr(slots)))
     #Log('----------THEEND OF SLOTS-------')
    gfParse[":gal_slotsstring"] = Galaxy.OPr(slots)
    gfParse[":slots"] = slots
    gfParse[":numslots"] = 1
    gfParse[":uttid"] = "-1"
    gfParse[":hyp"] = ' '.join(hyp_str)
    gfParse[":hyp_index"] = 0
    gfParse[":hyp_num_parses"] = 1
    gfParse[":decoder_score"] = 0.0
    gfParse[":am_score"] = 0.0
    gfParse[":lm_score"] = 0.0
    gfParse[":frame_num"] = 0
    gfParse[":acoustic_gap_norm"] = 0.0
    gfParse[":avg_wordconf"] = 0.0
    gfParse[":min_wordconf"] = 0.0
    gfParse[":max_wordconf"] = 0.0
    gfParse[":avg_validwordconf"] = 0.0
    gfParse[":min_validwordconf"] = 0.0
    gfParse[":max_validwordconf"] = 0.0
    gfParse[":parsestring"] = ' '.join(parse_str)
    Log('Test printing the parse frame')
    gfParseFrame = Galaxy.Frame("utterance", Galaxy.GAL_CLAUSE, gfParse)
     #gfParseFrame.Print()
    
    parses = [gfParseFrame]
    confhyps = [gfParseFrame]
    
    f = Galaxy.Frame(prog_name, Galaxy.GAL_CLAUSE, {":confhyps": confhyps, 
                                                    ":parses": parses, 
                                                    ':total_numparses': 1, 
                                                    ':input_source': 'gal_be',
                                                    ':gated_input': 'gated_input'})
    Log("Sending the message to DM")
    #Log(f)
    SendToHub(provider, f)
    Log("Sent to DM")
def LaunchQuery(env, dict):
    global requestCounter
    Log("Launching a query")
    
    Log(dict.keys())
    
    propertiesframe = env.GetSessionProperties(dict.keys())
    hub_opaque_data = propertiesframe[':hub_opaque_data']
    provider_id = hub_opaque_data[':provider_id'].strip('[').strip(']')
    
        
    try: prog_name = dict[":program"]
    except: prog_name = "main"
    
        
    inframe = dict[":inframe"]
    inframe = inframe.replace("\n{c inframe \n}", "")
    
    Log("Converting inframe to galaxy frame")
    #Log(inframe)
    
    raw_inframe_str = dict[":inframe"]
    inframe_raw_dict = ReadRawInFrame(raw_inframe_str)

    Log('RAW INFRAME is \n%s' %(str(inframe_raw_dict)))
    user_input = ''
    system_response = random.choice(['pardon me ?','can you say that again ?', 'excuse me?'])
    try:
        user_input = inframe_raw_dict['user_input'].strip('"')
        user_input = user_input.replace('_', ' ')
    except KeyError:
        system_response = 'I am TickTock, how are you doing'
        pass

    if user_input:
        #system_response = user_input
        #system_response = get_response(user_input)
        filehistory = open('input_response_history.txt', 'r')
        system_tail = tail(filehistory, 4)
        filehistory.close()
        Log('USER INPUT is [ %s ]' %(user_input))
        if user_input == '':
            system_response = 'pardon me'
        elif ((user_input.find('repeat')> 0) or (user_input.find('say that again')>0) or (user_input.find('excuse me')>0)):
            filein = open('history.txt', 'r')
            system_response = 'sure ... ' + filein.readline()
            filein.close()
        elif (system_tail[0] == system_tail[2]) and (system_tail[0] == user_input):
            system_response = 'I am having a good time talking to you.{ {BREAK TIME="2s"/}} Do you want to keep going,' \
                              ' if not, you can say goodbye'
        else:
            system_response = get_response(user_input)
            #Log(type(system_response))
        fileout = open('history.txt', 'w')
        fileout.write(str(system_response) + '\n')
        fileout.close()
        prefix = ['', 'well ... ', 'uh ... ', '', 'let me see ... ', 'oh ... ']
        cur_index = -1
        while True:
            random_index = randrange(0, len(prefix))
            if random_index != cur_index:
                break
        cur_index = random_index
        system_response = prefix[cur_index] + system_response
        #system_response_2 = unicodedata.normalize('NFKD',system_response).encode('ascii','ignore')
    resultsFrame = '{\n res %s \n}\n}' %(system_response)

#Log("outframe")
    f = Galaxy.Frame(prog_name, Galaxy.GAL_CLAUSE, {":outframe": resultsFrame})
    #Log(f)        
    

    return f
def SetDialogState(env, dict):
    global current_dialog_state
    global home_dialog_state
    global current_dialog_state_counter
    global current_dialog_state_begin
    global global_dialog_state_counter

    inframe = dict[":dialog_state"]
    # extracting the dialog state and turn number
    # main logic of updating the dialog state, such as sleeping, awake, etc
    lines = inframe.split('\n')
    new_dialog_state = None
    turn_counter = 0

    for l in lines:
        components = l.split(' = ')
        if (len(components)!=2):
            continue
        prefix = components[0]
        suffix = components[1]
        if (prefix == "dialog_state"):
            new_dialog_state = suffix
            
            if (global_dialog_state_counter == 0):
                home_dialog_state = new_dialog_state
            
            print "current_dialog_state", current_dialog_state
            print "new_dialog_state", new_dialog_state
            if (current_dialog_state == new_dialog_state):            
                current_dialog_state_counter = turn_counter - current_dialog_state_begin
                current_dialog_state = new_dialog_state
                print "cur == new, cur_counter =", current_dialog_state_counter
            else:                
                current_dialog_state = new_dialog_state
                current_dialog_state_counter = 0
                current_dialog_state_begin = turn_counter
                print "cur != new, cur_begin =", current_dialog_state_begin
                print "cur_counter =", current_dialog_state_counter

            
        elif (prefix == "turn_number"):
            turn_counter = int(suffix)
            print "get turn counter", turn_counter
            if (global_dialog_state_counter == -1 or turn_counter == 0):
                global_dialog_state_counter = 0
                #print "set g_d_s_c to 0"
            else:
                global_dialog_state_counter = turn_counter
                #print "g_d_s_c =", turn_counter

            #print "end of turn counter"
    print "==============================="
    print "DIALOG STATE is", current_dialog_state
    print "CURRENT TURN NUMBER is", current_dialog_state_counter

    state_out = -1

    if (current_dialog_state.endswith(aware_state)):
        print "system is aware of the person but can't see"
        state_out = 4
    elif (current_dialog_state == home_dialog_state):
        print "system is sleeping now ... zzz"
        state_out = 1
    elif (current_dialog_state_counter >= 1):
        print "system is puzzled ... "
        state_out = 2
    else:
        print "system can understand you." 
        state_out = 3

    count = 1
    onDialogState(state_out)
    print "==============================="
    # end of the main logic
    
    prog_name = "main"
    outframe = "got dialog state"
    f = Galaxy.Frame(prog_name, Galaxy.GAL_CLAUSE, {":outframe": outframe})
    return f
Пример #8
0
    def __init__(self):
        tk.Frame.__init__(self)

        # If these are not equal, then orbitals need to be an oval
        self.canvasH = 1000
        self.canvasW = 1000
        # Left Canvas is the planetary treeview
        self.leftCanvas = tk.Canvas(self,
                                    height=self.canvasH,
                                    width=100,
                                    bg='white')
        self.leftCanvas.pack(side=tk.LEFT, expand=1, fill=tk.Y)
        self.tree = ttk.Treeview(self.leftCanvas,
                                 columns=('Systems'),
                                 height=100)
        # Shows the planet and ships n stuff
        self.canvas = tk.Canvas(self,
                                height=self.canvasH,
                                width=self.canvasW,
                                bg='grey')
        self.canvas.pack(side=tk.LEFT)
        self.zoomLevelDefault = 1
        self.zoomLevel = 1
        self.zoomLevelChange = 0.2
        # Current centre of the system - the star centre upon creation
        self.starX = self.canvasW / 2
        self.starY = self.canvasH / 2
        # The centre of the canvas
        self.centreX = self.starX
        self.centreY = self.starY

        self.zoomOffsetX = 0
        self.zoomOffsetY = 0

        self.starRadius = 25
        self.planetRadius = 5
        self.moonRadius = 3
        self.starTextOffset = 5 + self.starRadius * 1.3
        self.planetTextOffset = 5 + self.planetRadius * 1.3

        # Generate the galaxy here, TODO need to move this to a main at some point
        self.galaxy = Galaxy.Galaxy()
        self.mySystem = self.galaxy.systems[0]

        self.planetWidgets = []
        self.planetName = []

        # tkinter stuff related to the class
        button1 = tk.Button(self,
                            text="Update",
                            width=75,
                            command=self.redrawCanvas)
        button1.pack(side=tk.BOTTOM)

        # keybindngs
        self.bind('=', self.keyonCanvas)
        self.bind('-', self.keyonCanvas)
        self.bind('w', self.keyonCanvas)
        self.bind('s', self.keyonCanvas)
        self.bind('a', self.keyonCanvas)
        self.bind('d', self.keyonCanvas)
        # Mouse button events
        self.canvas.bind('<Button-1>', self.focusOnClickedObject)
        self.bind('<Enter>', self.mouseFocus)
        # Generate Widgets
        self.generateLeftCanvas()
        self.lastItemOnTreeview = ":".join(
            ("STAR", self.galaxy.systems[0].name))
        self.createTreeviewSystemData(self.mySystem, self.lastItemOnTreeview)
        self.treeview.item(self.lastItemOnTreeview, open=True)

        self.generateCanvas()