def SIM(saliency_map1, saliency_map2): ''' Similarity between two different saliency maps when viewed as distributions (SIM=1 means the distributions are identical). This similarity measure is also called **histogram intersection**. Parameters ---------- saliency_map1 : real-valued matrix If the two maps are different in shape, saliency_map1 will be resized to match saliency_map2. saliency_map2 : real-valued matrix Returns ------- SIM : float, between [0,1] ''' map1 = np.array(saliency_map1, copy=False) map2 = np.array(saliency_map2, copy=False) if map1.shape != map2.shape: map1 = resize( map1, map2.shape, order=3, mode='constant' ) # bi-cubic/nearest is what Matlab imresize() does by default # Normalize the two maps to have values between [0,1] and sum up to 1 map1 = normalize(map1, method='range') map2 = normalize(map2, method='range') map1 = normalize(map1, method='sum') map2 = normalize(map2, method='sum') # Compute histogram intersection intersection = np.minimum(map1, map2) return np.sum(intersection)
def process_features(features, fetdim, nchannels, freq, nfet=None): features = np.array(features, dtype=np.float32) nspikes, ncol = features.shape if nfet is not None: nextrafet = nfet - fetdim * nchannels else: nextrafet = ncol - fetdim * nchannels # get the spiketimes spiketimes = features[:,-1].copy() spiketimes *= (1. / freq) # normalize normal features while keeping symmetry features_normal = normalize(features[:,:fetdim * nchannels], symmetric=True) features_time = spiketimes.reshape((-1, 1)) * 1. / spiketimes[-1] * 2 - 1 # features_time = spiketimes.reshape((-1, 1)) * 1. / spiketimes[-1]# * 2 - 1 # normalize extra features without keeping symmetry if nextrafet > 1: features_extra = normalize(features[:,-nextrafet:-1], symmetric=False) features = np.hstack((features_normal, features_extra, features_time)) else: features = np.hstack((features_normal, features_time)) return features, spiketimes
def locate_sprint(self, duration, num_of_sprints): test = np.arange(0, duration) speed = tls.normalize(self.data["enhanced_speed"]) power = tls.normalize(self.data["power"]) offset = len(speed) - len(power) speed = speed[offset:] t = self.data["timestamp"] offset = len(t) - len(power) t = t[offset:] func = lambda x: np.float64(x) / np.float64(duration) power_c = tls.forward_convolution(power, duration, func) power_c -= np.median(power_c) peack_conv, _ = find_peaks(power_c, prominence=1, width=duration / 6) peack_conv = np.partition(peack_conv, -num_of_sprints)[-num_of_sprints - 1:-1] return t[peack_conv]
def __init__(self, laserX, laserZ, scan_settings): """ m_maxLaserWidth, m_minLaserWidth: red dots width within this range will be considered valid laser points firstRowLaserCol : red dot location of previous scanning step, reference for next step RANGE_DISTANCE_THRESHOLD : two range will be merged if their distance is small than this variable """ self.settings = scan_settings self.m_laserRanges = [] self.m_maxLaserWidth = scan_settings.MAXLaserRange self.m_minLaserWidth = scan_settings.MINLaserRange self.MAX_MAGNITUDE_SQ = (255 * 3.0 ) # doesn't really matter(just for scaling) self.m_laserMagnitudeThreshold = scan_settings.MagnitudeThreshold # main threshold, diff value from 0.0 to 255? self.firstRowLaserCol = 0.5 * self.settings.img_width self.RANGE_DISTANCE_THRESHOLD = scan_settings.LaserRangeMergeDistance self.numSuspectedBadLaserLocations = 0 self.results = [] if laserX > 0: d = (scan_settings.cab_r - scan_settings.cab_m) * 35 / 125 self.laser_plane = [[d, 0, 0], normalize([laserZ, 0, -1 * (laserX - d)])] else: d = (scan_settings.cab_l - scan_settings.cab_m) * 35 / 125 self.laser_plane = [[d, 0, 0], normalize([laserZ, 0, -1 * (laserX - d)])] self.place = {}
def load_data(dataset, norm='none'): datadir = './data' if os.name == 'posix' else 'd:\\sleep\\data' sleep = sleeploader.SleepDataset(datadir) sleep.load_object(str(dataset)) data, target, groups = sleep.get_all_data(groups=True) target[target == 4] = 3 target[target == 5] = 4 target[target > 5] = 0 if norm is 'all': print('Normalizing {} over whole set\n...'.format(dataset), end='') data = tools.normalize(data) elif norm == 'none': pass elif norm == 'group': print('Normalizing {} per patient\n...'.format(dataset), end='') data = tools.normalize(data, groups=groups) else: print('Normalizing {} with reference {}\n...'.format(dataset, norm), end='') compdata, _, _ = load_data(norm, norm='none') print('...', end='') data = tools.normalize(data, comp=compdata) target = keras.utils.to_categorical(target) return deepcopy(data), deepcopy(target), deepcopy(groups)
def build(self, shape): h = tf.range(shape[1], dtype=tf.float32) w = tf.range(shape[2], dtype=tf.float32) h, w = normalize(h), normalize(w) hw = tf.stack(tf.meshgrid(h, w, indexing='ij'), axis=-1) hw = tf.expand_dims(hw, 0) self.hw = tf.tile(hw, [shape[0], 1, 1, 1]) super().build(shape)
def flow_vector(self): v = [0, 0, 0] this_efd = self.effective_flow_decay for i, j in tools.cross: blk = self.grid.get_block(self.x + i, self.y, self.z + j) efd = blk.effective_flow_decay if efd < 0: if not blk.material.blocks_movement: blk = self.grid.get_block(self.x + i, self.y - 1, self.z + j) efd = blk.effective_flow_decay if efd >= 0: va = efd - (this_efd - 8) v = [i * va, 0, j * va] elif efd >= 0: va = efd - this_efd v = [i * va, 0, j * va] if self.meta >= 8: t = False if t or self.is_solid_block(self.grid.get_block(self.x, self.y, self.z - 1), 2): t = True if t or self.is_solid_block(self.grid.get_block(self.x, self.y, self.z + 1), 3): t = True if t or self.is_solid_block(self.grid.get_block(self.x - 1, self.y, self.z), 4): t = True if t or self.is_solid_block(self.grid.get_block(self.x + 1, self.y, self.z), 5): t = True if t or self.is_solid_block(self.grid.get_block(self.x, self.y + 1, self.z - 1), 2): t = True if t or self.is_solid_block(self.grid.get_block(self.x, self.y + 1, self.z + 1), 3): t = True if t or self.is_solid_block(self.grid.get_block(self.x - 1, self.y + 1, self.z), 4): t = True if t or self.is_solid_block(self.grid.get_block(self.x + 1, self.y + 1, self.z), 5): t = True if t: v = tools.normalize(v) v = [v[0], v[1] - 6.0, v[2]] return tools.normalize(v)
def initialize(self, observed_evidence): self.instantiations = observed_evidence for n in self.net.ordered_vars: self.pi_inbox[n] = {} self.lambda_inbox[n] = {} self.pi_values[n] = normalize(np.ones(len(self.net.domain[n]))) self.lambda_values[n] = normalize(np.ones(len(self.net.domain[n]))) for p in self.net.parents[n]: self.pi_inbox[n][p] = normalize( np.ones(len(self.net.domain[p]))) for c in self.net.children[n]: self.lambda_inbox[n][c] = normalize( np.ones(len(self.net.domain[n])))
def lambda_value(self, node): pi_array = multiply \ ( self.lambda_inbox[node].values() , self.lambda_message_to_self(node) ) return normalize(pi_array)
def recipe_check(): code_dict = r.hgetall('lol:item_code') recipe_dict = r.hgetall('lol:item_recipe') recipe_str_dict = { normalize(k.decode()): v.decode() for k, v in recipe_dict.items() } items = list(map(lambda x: normalize(x.decode()), code_dict.keys())) for item in items: recipe = recipe_str_dict.get(item, None) if recipe is None: continue ingres = list(map(normalize, recipe.split(':'))) for ingre in ingres: if ingre not in items: print(item, ingre)
def calculateCameraRay(self, x, y): """ calculate a ray at x, y, z, direction from camera to x, y, z return ray : [[x,y,z], [direction_x, direction_y, direction_z]] warning coord change!!!!!!!!!!! in image:y goes down, in realworld :y goes up """ # if (x, y) in self.place: # return self.place[(x, y)] # portion, We subtract by one because the image is 0 indexed x = float(x) / (self.settings.img_width - 1) y = float(self.settings.img_height - 1 - y) / (self.settings.img_height - 1) # x = (x * self.settings.sensorWidth) + self.settings.cameraX - (self.settings.sensorWidth * 0.5) + 0.125 # rule of thumb number # y = (y * self.settings.sensorHeight) + self.settings.cameraY - (self.settings.sensorHeight * 0.5) + 0.31 # rule of thumb number x = (x * self.settings.sensorWidth) + self.settings.cameraX - ( self.settings.sensorWidth * 0.5) # rule of thumb number y = (y * self.settings.sensorHeight) + self.settings.cameraY - ( self.settings.sensorHeight * 0.5) # rule of thumb number z = self.settings.cameraZ + self.settings.focalLength ray = [[x, y, z], normalize([ x - self.settings.cameraX, y - self.settings.cameraY, z - self.settings.cameraZ ])] # self.place[(x, y)] = ray return ray
def infer(net: BayesNet, variable: str, evidence: Dict[str, str]): factors_left = [] vars_left = [] # initialize factors for node in net.ordered_vars: factor = _createFactor(net, node, evidence) factors_left.append(factor) if node != variable and node not in evidence.keys(): vars_left.append(node) while len(vars_left) > 0: node = vars_left.pop(_min_fill_var(net, vars_left, factors_left)) to_merge = [] to_pop = [] for f_index, factor in enumerate(factors_left): if factor.involves(node): to_merge.append(factor) to_pop.append(f_index) while len(to_pop) != 0: factors_left.pop(to_pop.pop()) if len(to_merge) >= 1: newfactor = to_merge[0].merge(to_merge[1:], node, net.domain[node]) factors_left.append(newfactor) r = np.ones(len(net.domain[variable])) for i, f in enumerate(factors_left): for i, v in enumerate(net.domain[variable]): r[i] = r[i] * f.apply({variable: v}) return normalize(r)
def lambda_msg(self, src, dtn): """The λ message a node (src) sends to its parent (dtn)""" pi_msgs_to_src = self.pi_inbox[src] lambda_vals_of_src = self.lambda_values[src] msg_array = np.ones(self.net.domain[dtn].size) for dtn_value_index, dtn_value in enumerate(self.net.domain[dtn]): outer_sum = 0 for src_value_index, src_value in enumerate(self.net.domain[src]): src_lambda_value = lambda_vals_of_src[src_value_index] inner_sum = 0 for parent_values in self.net.get_parent_combinations(src): if parent_values[dtn] == dtn_value_index: src_cpt = self.net.cpt_using_indexes( src, parent_values) inner_product = 1 for src_parent, src_parent_val_index in parent_values.items( ): if src_parent != dtn: inner_product *= pi_msgs_to_src[src_parent][ src_parent_val_index] inner_sum += src_cpt[src_value_index] * inner_product outer_sum += src_lambda_value * inner_sum msg_array[dtn_value_index] = outer_sum return normalize(msg_array)
def updateHATVP(): types_doc = { 'dia': u'Déclaration d’intérêts et d’activités', 'diam': u'Déclaration de modification substantielle des intérêts et des activités', 'di': u'Déclaration d’intérêts', 'dim': u'Déclaration de modification substantielle des intérêts', 'dsp': u'Déclaration de situation patrimoniale', 'dspm': u'Déclaration de modification substantielle de situation patrimoniale', 'dspfm': u'Déclaration de modification substantielle de situation patrimoniale', 'appreciation': u'Appréciation de la HATVP' } import requests import csv import json from cStringIO import StringIO from tools import normalize r = requests.get('http://www.hatvp.fr/files/open-data/liste.csv') f = StringIO(r.content) csv = csv.DictReader(f, delimiter=';', quotechar='"') declarations = {} for row in csv: drow = dict((k,v.decode('utf8') if isinstance(v,basestring) else v) for k,v in row.iteritems()) id = normalize(drow['civilite']+' '+drow['prenom']+' '+drow['nom']) drow['docurl'] = 'http://www.hatvp.fr/livraison/dossiers/'+drow['nom_fichier'] drow['typedoc'] = types_doc[drow['type_document']] declarations[id] = declarations.get(id,[])+ [drow] with open(output_path+'/hatvp.json','w') as f: f.write(json.dumps(declarations))
def _lnT(self): """ Normalised CDM log transfer function """ return tools.normalize(self.sigma_8, self._unnormalised_lnT, self.lnk, self.mean_dens)[0]
def _lnP_0(self): """ Normalised CDM log power at z=0 [units :math:`Mpc^3/h^3`] """ return tools.normalize(self.sigma_8, self._unnormalised_lnP, self.lnk, self.mean_dens)[0]
def draw_pline(self, df, x=0, n=20, colour='black'): """ draws the phaseline """ if str(colour) in clrs.info: colour = clrs[colour] vector_length = max(opts.sw, opts.sh) / (2 * n) for y in np.linspace(self.lo_y, self.hi_y, num=n): strt = (0, y) if abs(df(x, y)) < 0.05: continue elif df(x, y) > 0: head = np.array((0, 1)) else: head = np.array((0, -1)) screen_strt = self.to_screen(strt) screen_head = self.to_screen(strt + head) screen_diff = screen_head - screen_strt screen_endp = screen_strt + tools.normalize( screen_diff) * vector_length #pgdraw.circle(self.screen, colour, strt, 10) #pgdraw.line(self.screen, colour, strt, head) self._draw_arrow(screen_strt, screen_endp, colour, width=1, rel_spoke_len=0.5)
def pi_msg(self, src, dtn): """The π message a node (src) sends to its child (dtn)""" lambda_msgs_product = multiply \ ( [msg[1] for msg in self.lambda_inbox[src].items() if msg[0]!=dtn] , self.lambda_message_to_self(src) ) return normalize(self.pi_values[src] * lambda_msgs_product)
def load_data(datadir): sleep = sleeploader.SleepDataset(datadir) sleep.load_object() data, target, groups = sleep.get_all_data(groups=True) data = tools.normalize(data , groups=groups) # target[target==5] = 4 target[target==8] = 0 target = keras.utils.to_categorical(target) return data, target, groups
def call(self, x): shape = tf.shape(x) coords = tf.range(shape[1]) coords = tf.expand_dims(coords, 0) coords = tf.expand_dims(coords, -1) coords = tf.tile(coords, [shape[0], 1, 1]) coords = tf.cast(coords, tf.float32) coords = normalize(coords) return tf.concat([x, coords], -1)
def convert(self, pos, projection, view, left_view): p, r, y = view lp, lr, ly = left_view wp = len(projection) hp = len(projection[0]) i_mid = wp/2 j_mid = hp/2 #direction of camera's view vect = tools.pitch([0,0,1], p, do_round=self.do_round) vect = tools.roll(vect, r, do_round=self.do_round) vect = tools.yaw(vect, y, do_round=self.do_round) #parallel to top and bottom of view frame, runs from right to left horz = tools.pitch([-1,0,0], lp, do_round=self.do_round) horz = tools.roll(horz, lr, do_round=self.do_round) horz = tools.yaw(horz, ly, do_round=self.do_round) #parallel to left and right of view frame, runs from bottom to top vert = tools.ortho(vect, horz) new_pts = set() i_temp = np.zeros((8, 8)) j_temp = np.zeros((8, 8)) #j = all the rows, i = all the columns for j in range(len(projection)): for i in range(len(projection[j])): #get radians difference from center i_rad = -(i + 0.5 - i_mid)/wp * self.wr j_rad = (j + 0.5 - j_mid)/hp * self.hr #get rotation m_i = tools.rmatrix_to_vector(tools.invert(tools.make_unit_vector(vert)), j_rad) m_j = tools.rmatrix_to_vector(tools.invert(tools.make_unit_vector(horz)), i_rad) max_vect = tools.normalize(vect, tools.len_vector(vect)) max_vect = tools.vector_multiplier(max_vect, self.darkest) #get vector from camera to pixel, with vector in objective 3D space pix_dist = self.darkest - float(projection[i][j]) / 255 * self.darkest pv = [tools.dot_product(vect, m_i[0]), tools.dot_product(vect, m_i[1]), tools.dot_product(vect, m_i[2])] pv = [tools.dot_product(pv, m_j[0]), tools.dot_product(pv, m_j[1]), tools.dot_product(pv, m_j[2])] pv = tools.make_unit_vector(pv) pix_vect = tools.vector_multiplier(pv, pix_dist) #get position of this point in 3D space pix_pt = tools.sum_vectors(pos, pix_vect) if self.do_round: new_pts.add(tuple(tools.make_ints(pix_pt))) else: new_pts.add(tuple(pix_pt)) return list(new_pts), vert, horz
def make_colors(phc, cmap_id='cividis'): cmap = plt.get_cmap(cmap_id) flat_phc = tools.normalize(tf.reshape(phc, [-1])) colors = cmap(flat_phc) colors[:, 3] = flat_phc cbar = matplotlib.cm.ScalarMappable(cmap=plt.get_cmap(cmap_id)) cbar.set_array([]) return colors, cbar
def _power_cdm_0(self): """ The power spectrum at z=0 for CDM (normalised) """ try: return self.__power_cdm_0 except: self.__power_cdm_0, self._normalization = tools.normalize(self.cosmo_params['sigma_8'], self._unnormalized_power, self.lnkh, self.cosmo_params['mean_dens']) return self.__power_cdm_0
def mb_table(self, variable, state): """probability table of a variable given its markov blanket (in state)""" updated_state = {**state} table = self.cpt_table(variable, updated_state) for i, val in enumerate(self.domain[variable]): updated_state[variable] = val for c in self.children[variable]: table[i] *= self.cpt_probability(c, updated_state) return normalize(table, force=True)
def EMD(saliency_map1, saliency_map2, sub_sample=1 / 32.0): ''' Earth Mover's Distance measures the distance between two probability distributions by how much transformation one distribution would need to undergo to match another (EMD=0 for identical distributions). Parameters ---------- saliency_map1 : real-valued matrix If the two maps are different in shape, saliency_map1 will be resized to match saliency_map2. saliency_map2 : real-valued matrix Returns ------- EMD : float, positive ''' map2 = np.array(saliency_map2, copy=False) # Reduce image size for efficiency of calculation map2 = resize(map2, np.round(np.array(map2.shape) * sub_sample), order=3, mode='nearest') map1 = resize(saliency_map1, map2.shape, order=3, mode='nearest') # Histogram match the images so they have the same mass map1 = match_hist(map1, *exposure.cumulative_distribution(map2)) # Normalize the two maps to sum up to 1, # so that the score is independent of the starting amount of mass / spread of fixations of the fixation map map1 = normalize(map1, method='sum') map2 = normalize(map2, method='sum') # Compute EMD with OpenCV # - http://docs.opencv.org/modules/imgproc/doc/histograms.html#emd # - http://stackoverflow.com/questions/5101004/python-code-for-earth-movers-distance # - http://stackoverflow.com/questions/12535715/set-type-for-fromarray-in-opencv-for-python r, c = map2.shape x, y = np.meshgrid(range(c), range(r)) signature1 = cv.CreateMat(r * c, 3, cv.CV_32FC1) signature2 = cv.CreateMat(r * c, 3, cv.CV_32FC1) cv.Convert(cv.fromarray(np.c_[map1.ravel(), x.ravel(), y.ravel()]), signature1) cv.Convert(cv.fromarray(np.c_[map2.ravel(), x.ravel(), y.ravel()]), signature2) return cv.CalcEMD2(signature2, signature1, cv.CV_DIST_L2)
def propgate(self, observed_evidence): self.initialize(observed_evidence) old_belifs = { v: normalize(np.ones(len(self.net.domain[v]))) for v in self.net.ordered_vars } new_belifs = { v: normalize(np.zeros(len(self.net.domain[v]))) for v in self.net.ordered_vars } count = 0 while self.has_belief_changed(old_belifs, new_belifs) and count < self.LIMIT: count += 1 old_belifs = deepcopy(new_belifs) pi_values = deepcopy(self.pi_values) lambda_values = deepcopy(self.lambda_values) pi_inbox = deepcopy(self.pi_inbox) lambda_inbox = deepcopy(self.lambda_inbox) # combine messages and update belifs for n in self.net.ordered_vars: pi_values[n] = self.pi_value(n) lambda_values[n] = self.lambda_value(n) new_belifs[n] = self.belifs(lambda_values[n], pi_values[n]) self.pi_values = deepcopy(pi_values) self.lambda_values = deepcopy(lambda_values) # write new messages for next iteration for n in self.net.ordered_vars: for p in self.net.parents[n]: lambda_inbox[p][n] = self.lambda_msg(n, p) for c in self.net.children[n]: pi_inbox[c][n] = self.pi_msg(n, c) self.pi_inbox = deepcopy(pi_inbox) self.lambda_inbox = deepcopy(lambda_inbox) return new_belifs
def load_data(dataset): datadir = './data' if os.name == 'posix' else 'd:\\sleep\\data' sleep = sleeploader.SleepDataset(datadir) sleep.load_object(str(dataset)) data, target, groups = sleep.get_all_data(groups=True) data = tools.normalize(data) # data = zscore(data,1) target[target==4] = 3 target[target==5] = 4 target[target>5] = 0 target = keras.utils.to_categorical(target) return data, target, groups
def _update_blobs(cls, update_blobs, state=None, delete=True): update_blobs = tools.normalize(update_blobs) blobs = cls.get_blobs() for blob in update_blobs: if state not in blobs: blobs[state] = [] if blob not in blobs[state]: blobs[state].append(blob) if state is not None and not state.startswith( 'delete') and delete is True: # If state is said to be delete_* or delete then there is no need to # store them in delete queue. cls._update_blobs(update_blobs, 'delete')
def _pre_processing(x_data, y_data, ratio): """ 数据预处理:标准化 + 拆分成验证集 :param x_data: :param y_data: :param ratio: 验证集的比例 :return: """ print("Data pre-processing...") # 标准化 x_normalized = tools.normalize(x_data) # 拆分成验证集 return tools.split_to_validation(x_normalized, y_data, ratio)
def __init__(self, laserX, laserZ, scan_settings): """ m_maxLaserWidth, m_minLaserWidth: red dots width within this range will be considered valid laser points firstRowLaserCol : red dot location of previous scanning step, reference for next step RANGE_DISTANCE_THRESHOLD : two range will be merged if their distance is small than this variable """ self.settings = scan_settings self.m_laserRanges = [] self.m_maxLaserWidth = scan_settings.MAXLaserRange self.m_minLaserWidth = scan_settings.MINLaserRange self.MAX_MAGNITUDE_SQ = (255 * 3.0) # doesn't really matter(just for scaling) self.m_laserMagnitudeThreshold = scan_settings.MagnitudeThreshold # main threshold, diff value from 0.0 to 255? self.firstRowLaserCol = 0.5 * self.settings.img_width self.RANGE_DISTANCE_THRESHOLD = scan_settings.LaserRangeMergeDistance self.numSuspectedBadLaserLocations = 0 self.results = [] if laserX > 0: d = (scan_settings.cab_r - scan_settings.cab_m) * 35 / 125 self.laser_plane = [[d, 0, 0], normalize([laserZ, 0, -1 * (laserX - d)])] else: d = (scan_settings.cab_l - scan_settings.cab_m) * 35 / 125 self.laser_plane = [[d, 0, 0], normalize([laserZ, 0, -1 * (laserX - d)])] self.place = {}
def load_data(dataset): sleep = sleeploader.SleepDataset(datadir) sleep.load_object(dataset) data, target, groups = sleep.get_all_data(groups=True) data = data[0:5000] target = target[0:5000] groups = groups[0:5000] data = tools.normalize(data, groups=groups) target[target == 4] = 3 target[target == 5] = 4 target[target > 5] = 0 target = keras.utils.to_categorical(target) print(np.unique(groups)) return deepcopy(data), deepcopy(target), deepcopy(groups)
def load_data(tsinalis=False): sleep = sleeploader.SleepDataset(datadir) gc.collect() # sleep.load() # sleep.save_object() sleep.load_object() data, target, groups = sleep.get_all_data(groups=True) data = tools.normalize(data) target[target == 4] = 3 target[target == 5] = 4 target[target == 8] = 0 target = keras.utils.to_categorical(target) return deepcopy(data), deepcopy(target), deepcopy(groups)
def updateAssemblee(): updateHATVP() updateDeputyWatch() launchScript('assemblee') deputes = getJson('deputes') deputywatch = getJson('deputywatch') departements = getData('departements','departement') professions = getData('deputes_professions','id') professions2 = getData('deputes_professions','profession') hatvp = getJson('hatvp') csp_incomplet = [] for d in deputes: d['depute_sexe'] = 'Homme' if d['depute_nom']=='M.' else 'Femme' d['depute_id'] = normalize(d['depute_nom']) d['depute_age'] = int((datetime.datetime.now() - datetime.datetime.strptime(d['depute_ddn'],'%d/%m/%Y')).days / 365.25) d['depute_classeage'] = '%d-%d ans' % ((d['depute_age']/10)*10,(1+(d['depute_age']/10))*10) d['depute_deputywatch'] = deputywatch.get(d['depute_id'],None) d['depute_hatvp'] = hatvp.get(d['depute_id'],[]) d['depute_region'] = departements[d['depute_departement']]['region'] d['depute_typeregion'] = departements[d['depute_departement']]['typeregion'] d['depute_departement_id'] = departements_ids[d['depute_departement']] d['depute_circo_id'] = d['depute_departement_id']+'-'+('00'+d['depute_circo'])[-2:] m = professions.get(d['depute_uid'],None) if not m: m = professions2.get(d['depute_profession'],None) csp = "" if m: csp = m['csp'] if not csp and not d['depute_uid'] in professions.keys(): addData('deputes_professions',(d['depute_uid'],d['depute_nom'],d['depute_profession'],'')) d['depute_csp'] = csp mdb.deputes.update_one({'depute_uid': d['depute_uid']}, {'$set': d}, upsert = True) groupes = getJson('groupes') for g in groupes: membres = mdb.deputes.find({'groupe_uid':g['groupe_uid']}) g['groupe_membres'] = [ dict(qualite=m['groupe_qualite'],uid=m['depute_uid'],actif = m['depute_actif']) for m in membres] g['groupe_nbmembres'] = len([ m for m in g['groupe_membres'] if m['actif']]) mdb.groupes.update_one({'groupe_uid':g['groupe_uid']},{'$set':g}, upsert= True) # initialise les champs stats mdb.deputes.update_many({'stats':None},{'$set':{'stats':{'nbmots':0,'nbitvs':0}}}) mdb.groupes.update_many({'stats':None},{'$set':{'stats':{'nbmots':0,'nbitvs':0}}}) mdb.groupes.update_many({'groupe_mots':None},{'$set':{'groupe_mots':{}}}) mdb.deputes.update_many({'depute_mots':None},{'$set':{'depute_mots':{}}}) return mdb.deputes.find().count()
def handle_water_movement(self, b_obj): is_in_water = False water_current = (0, 0, 0) bb = b_obj.aabb.expand(-0.001, -0.4010000059604645, -0.001) top_y = tools.grid_shift(bb.max_y + 1) for blk in self.world.grid.blocks_in_aabb(bb): if isinstance(blk, blocks.BlockWater): if top_y >= (blk.y + 1 - blk.height_percent): is_in_water = True water_current = blk.add_velocity_to(water_current) if tools.vector_size(water_current) > 0: water_current = tools.normalize(water_current) wconst = 0.014 water_current = (water_current[0] * wconst, water_current[ 1] * wconst, water_current[2] * wconst) b_obj.velocities = [b_obj.velocities[0] + water_current[0], b_obj.velocities[1] + water_current[1], b_obj.velocities[2] + water_current[2]] return is_in_water
def calculateCameraRay(self, x, y): """ calculate a ray at x, y, z, direction from camera to x, y, z return ray : [[x,y,z], [direction_x, direction_y, direction_z]] warning coord change!!!!!!!!!!! in image:y goes down, in realworld :y goes up """ # if (x, y) in self.place: # return self.place[(x, y)] # portion, We subtract by one because the image is 0 indexed x = float(x) / (self.settings.img_width - 1) y = float(self.settings.img_height - 1 - y) / (self.settings.img_height - 1) # x = (x * self.settings.sensorWidth) + self.settings.cameraX - (self.settings.sensorWidth * 0.5) + 0.125 # rule of thumb number # y = (y * self.settings.sensorHeight) + self.settings.cameraY - (self.settings.sensorHeight * 0.5) + 0.31 # rule of thumb number x = (x * self.settings.sensorWidth) + self.settings.cameraX - (self.settings.sensorWidth * 0.5) # rule of thumb number y = (y * self.settings.sensorHeight) + self.settings.cameraY - (self.settings.sensorHeight * 0.5) # rule of thumb number z = self.settings.cameraZ + self.settings.focalLength ray = [[x, y, z], normalize([x - self.settings.cameraX, y - self.settings.cameraY, z - self.settings.cameraZ])] # self.place[(x, y)] = ray return ray
def process_probe(probe): return normalize(probe)
def process_waveforms(waveforms, nsamples, nchannels): waveforms = np.array(waveforms, dtype=np.float32) waveforms = normalize(waveforms, symmetric=True) waveforms = waveforms.reshape((-1, nsamples, nchannels)) return waveforms