def gravity_drop(self): sdd = self.meta["sdd"] wavelength = self.meta["wavelength"] radius = self._parser.getMetadata("Header/west_wing_det_radius_m") path_length = sdd - radius y_drop = calculate_neutron_gravitational_drop(path_length, wavelength) logger.info("Correcting for gravity: %f m" % y_drop) return y_drop
def on_continue(self, msg): """docstring for on_continue""" #print('nice, continue with:') request = msg.get('request', None) sender = msg.get('sender', '') req_from = msg.get('from', '') error = msg.get('error', '') #logger.info('error %s..........................' % error) #logger.info('req_from %s..........................' % req_from) #logger.info('request %s..........................' % request) sess = Session() #exctract sender email email = sender.split('/')[0] #find user profile by primary email profile = sess.query(Profile).filter(Profile.email == email).one() #logger.info('profile %s..........................' % profile) if error: if agree(request): report_bug('user %s can not find cronjobs ' % profile.uuid) response = 'ok, reported.. ' response += 'by the way, you can add a reminder with command: *remind me every day at 10:00 with message "Do not forget to drink coffee"* ' else: response = 'ok' response += ' by the way, you can add a reminder with command: \ *remind me every day at 10:00 with message "Do not forget to drink coffee"* ' self.response = {'text': response, 'jmsg': response, 'type': 'response', 'continue': 0} return self.response cron = CronTab(getuser()) if agree(request): logger.info('deleting all cronjobs for %s' % ( profile.email)) for j in cron: if profile.uuid in j.render(): cron.remove(j) cron.write() response = 'ok, done' else: response = "ok" if req_from == 'jabber': todo = {'text': response, 'jmsg': response, 'type': 'response', 'continue': 0} self.response = todo if req_from == 'julius': from core.broadcast import say, bang bang() todo = {'say': response, 'text': response, 'type': 'response', 'continue': 0} self.response = say(self.request.replace('say', '').upper()) return self.response
def find_center_of_mass(data_2d): ''' Somehow unreliable ''' center_guess_y, center_guess_x = ndimage.measurements.center_of_mass( data_2d) logger.info("Beam Center of Mass = (%2f,%2f) pixels." % (center_guess_x, center_guess_y)) return center_guess_x, center_guess_y
def find_maxs_along_axes(data_2d): ''' Works well! ''' x_sums = np.sum(data_2d, axis=1) print(x_sums) x_max_index = np.argmax(x_sums) y_sums = np.sum(data_2d, axis=0) print(y_sums) y_max_index = np.argmax(y_sums) logger.info("Beam Maximums along axes = (%2f,%2f) pixels." % (x_max_index, y_max_index)) return y_max_index, x_max_index
def parse_query_string(name): form_json = YML_JSON.get(name) returnvalue = form_json.get('returnvalue') logger.info(request.args) return [request.args.get(x) for x in returnvalue]
def parse_json_form(name): form_json = YML_JSON.get(name) returnvalue = form_json.get('returnvalue') logger.info(request.json) return [request.json.get(x) for x in returnvalue]
def run(self): """default method""" logger.debug(self.req_obj) uuid = self.req_obj.get('uuid', '') sender = self.req_obj.get('sender', '') sess = Session() self.response = { 'text': "I couldn't find your profile by %s, error happened" % uuid, 'jmsg': "I couldn't find your profile by %s, error happened" % uuid, 'type': 'response'} ######################################### # check and get profile # ######################################### if uuid: try: profile = sess.query(Profile).filter( Profile.uuid == uuid).one() except Exception as e: logger.exception(e) return self.response if sender: #exctract sender email email = sender.split('/')[0] try: profile = sess.query( Profile).filter( Profile.email == email).one() except Exception as e: logger.exception(e) return self.response if not self.cmd_stack[-1]: request_to_user = '******' else: request_to_user = '******' % self.cmd_stack[-1] todo = {'request': request_to_user, 'from': 'jabber', 'type': 'response', 'continue': 0, 'text': request_to_user, 'jmsg': request_to_user, 'sender': str(profile.email)} ######################################### # If executed by crontab # ######################################### if self.req_from == 'cron': #args = self.req_obj.get('cmd_args', '') logger.info('Sending cron notification to user.') #logger.info('Trying to connect jabber socket and send a message.') #context = zmq.Context() #sock = context.socket(zmq.REQ) #sock.connect('ipc:///tmp/smarty-jabber') #sock.send_json({'request': request_to_user, #'from': 'jabber', #'type': 'response', #'continue': 1, #'sender': str(profile.email)}) #res_obj = sock.recv_json() #logger.info('=========== response obj================') #logger.debug(res_obj) #self.xmpp.Message(profile.email, request_to_user) #self.response = res_obj if self.req_from == 'jabber': self.response = todo if self.req_from == 'julius': from core.broadcast import say, bang bang() todo['type'] = 'response' todo['say'] = request_to_user self.response = say(self.request.replace('say', '').upper()) return self.response
def _parse(self, filename): logger.info("Parsing: %s." % filename) tree = ET.parse(filename) root = tree.getroot() return root
def on_continue(self, msg): """docstring for on_continue""" #print('nice, continue with:') request = msg.get('request', None) sender = msg.get('sender', '') uuid = msg.get('uuid', '') req_from = msg.get('from', '') error = msg.get('error', '') #logger.info('error %s.....................' % error) #logger.info('req_from %s..................' % req_from) #logger.info('request %s...................' % request) #logger.info('uuid %s......................' % uuid) sess = Session() last_command = self.cmd_stack[-2] #exctract sender email if sender: email = sender.split('/')[0] if email: #find user profile by primary email self.profile = sess.query(Profile).filter( Profile.email == email).one() elif uuid: #find user profile by uuid self.profile = sess.query( Profile).filter(Profile.uuid == uuid).one() if error: if agree(request): report_bug('no prev commands found for %s' % self.profile.uuid) response = 'ok, reported.. ' else: response = 'ok' self.response = { 'text': response, 'jmsg': response, 'type': 'response', 'continue': 0} return self.response if agree(request) and len(last_command) > 0: #repeat last_command command here response = 'ok, got it.. one moment' logger.info('going to repeat %s' % last_command) self.response = { 'req_obj': { 'request': last_command, 'from': req_from, 'sender': sender, 'uuid': uuid, 'type': 'request', 'continue': 1 }, 'jmsg': response, 'text': response, 'type': 'response', 'continue': 1 } return self.response else: response = "ok" todo = {'text': response, 'jmsg': response, 'type': 'response'} if req_from == 'jabber': self.response = todo if req_from == 'julius': from core.broadcast import say, bang bang() todo = {'say': response, 'text': response, 'type': 'response', 'continue': 0} self.response = say(self.request.replace('say', '').upper()) return self.response
def __init__(self, filename): if not os.path.exists(filename): logger.error("File %s does not exist!"%(filename)) sys.exit() logger.info("Using file %s."%(filename)) self._filename = filename
def fit_gaussian(data_2d): params = fitgaussian(data_2d) _, x, y, _, _ = params logger.info("Beam Gaussian Fit = (%2f,%2f) pixels." % (x, y)) return y, x