def search(self, searchId, query, searchPoint=None): """Trigger an asynchronous search (specified by search id) for the given term :param str query: search query """ online = self.gui.m.get("onlineServices", None) if online: # construct result handling callback callback = lambda x: self._searchCB(searchId, x) # get search function corresponding to the search id searchFunction = self._getSearchFunction(searchId) # start the search and remember the search thread id # so we can use it to track search progress # (there might be more searches in progress so we # need to know the unique search thread id) if searchId == "local" and searchPoint: pointInstance = point.Point(searchPoint.latitude, searchPoint.longitude) threadId = searchFunction(query, callback, around=pointInstance) else: threadId = searchFunction(query, callback) self._threadsInProgress[threadId] = searchId return threadId
def createMeshHomo(self, name, chem, init_conc, coord_x_start, coord_y_start): """ Create mesh for this compartment with homogeneous properties, i.e. the partition and diffusion properties are all uniform Args: name: two-letter string to indicate the name of this compartment coord_x_start, coord_y_start: starting coordinates """ dx = self.x_length / self.nx dy = self.y_length / self.ny self.meshes = [mesh.Mesh() for i in range(self.nx * self.ny) ] # organised in row dominant coord_x = coord_x_start coord_y = coord_y_start current_point = point.Point(coord_x, coord_y, dx, dy, name, name) for i in range(self.nx): # verticle direction up to down for j in range(self.ny): # lateral direction left to right idx = i * self.ny + j self.meshes[idx].setup(name, chem, init_conc, self.Kw, self.D, current_point.x_coord, current_point.y_coord, current_point.dx, current_point.dy, self.dz_dtheta) if j == self.ny - 1: # last element in the lateral direction, move down coord_x += dx coord_y = coord_y_start else: # not the last element in the lateral direction, thus move to the right coord_y += dy current_point.setPoint(coord_x, coord_y, dx, dy, name, name)
plt.subplot(131) plt.plot(range(len(x)), x, 'o-') plt.title("x(t)") plt.subplot(132) plt.plot(range(len(y)), y, 'o-') plt.title("y(t)") plt.subplot(133) plt.plot(x, y, 'o-') plt.title("(x,y)") plt.subplots_adjust(top=0.8) plt.show() def add_point(self, point): last_point = self.trajectory.pop() self.trajectory.append(point) self.trajectory.append(last_point) if __name__ == '__main__': start = pt.Point(0, 0) middle = pt.Point(1, 5) end = pt.Point(10, 10) tr = Trajectory(start, end) tr.add_point(middle) tr.plot_trajectory()
def createMesh(self, chem, coord_x_start, coord_y_start, water_frac_surface=.55): """ Create mesh for this compartment Args: coord_x_start, coord_y_start: starting coordinates water_frac_surface : water content (w/w); saturation at .55; dry skin at .25 """ # some initial settings bOffset = False cc_subtype = 0 # 0 = d_n; 1 = s; 2 = d_m, 3 = s; dx_lipid = self.geom_g / self.nx_grids_lipid dx_cc = self.geom_t / self.nx_grids_cc dy_lipid = self.geom_s / self.ny_grids_lipid dy_cc = self.geom_dn / self.ny_grids_cc_dn self.meshes = [mesh.Mesh() for i in range(self.nx * self.ny) ] # organised in row dominant # work out the starting point from given offset length = self.geom_d + self.geom_s len_vec = [self.geom_dn, self.geom_s, self.geom_dm, self.geom_s] while self.offset_y > length: self.offset_y -= length length = .0 for i in range(4): length += len_vec[i] if self.offset_y < length: break cc_subtype_offset = i length = self.offset_y - length + len_vec[i] if cc_subtype_offset == 0 or cc_subtype_offset == 2: # corneocyte width idx_y_offset = int(length / dy_cc) dy_offset = dy_cc elif cc_subtype_offset == 1 or cc_subtype_offset == 3: # lipid width idx_y_offset = int(length / dy_lipid) dy_offset = dy_lipid else: raise ValueError('Invalid subtype name') # Now prepare values for the loop to create meshes water_frac_sat = 0.55 # saturated water content (w/w) water_increment_per_x = (water_frac_sat - water_frac_surface) / self.x_length idx_x = 0 idx_y = idx_y_offset cc_subtype = cc_subtype_offset coord_x = coord_x_start coord_y = coord_y_start # starting from lipid on the top layer current_point = point.Point(coord_x, coord_y, dx_lipid, dy_offset, 'LP', 'LP') init_conc = 0 for i in range(self.nx): # verticle direction up to down water_frac = water_frac_surface + ( current_point.x_coord - coord_x_start) * water_increment_per_x for j in range(self.ny): # lateral direction left to right idx = i * self.ny + j # assign type if current_point.x_type == 'LP' or current_point.y_type == 'LP': # Entire lipid layer (1st ==) or lateral lipid between two coreneocytes (2nd ==) name = 'LP' else: # corneocyte name = 'CC' # and then create meshes Kw, D = self.compParDiff(name, chem, water_frac, water_frac_sat, self.V_mortar, self.V_brick, self.V_all, self.eta) self.meshes[idx].setup(name, chem, init_conc, Kw, D, current_point.x_coord, current_point.y_coord, current_point.dx, current_point.dy, self.dz_dtheta) ### update current_point, fairly complicated if j == self.ny - 1: # last element in the lateral direction, move down idx_x += 1 coord_y = coord_y_start if current_point.x_type == 'LP': coord_x += dx_lipid if idx_x == self.nx_grids_lipid: # reaching end of lateral lipid layer if cc_subtype_offset == 0 or cc_subtype_offset == 2: current_point.setPoint(coord_x, coord_y, dx_cc, dy_offset, 'CC', 'CC') elif cc_subtype_offset == 1: if not bOffset: current_point.setPoint( coord_x, coord_y, dx_cc, dy_offset, 'CC', 'CC') else: current_point.setPoint( coord_x, coord_y, dx_cc, dy_offset, 'CC', 'LP') elif cc_subtype_offset == 3: if not bOffset: current_point.setPoint( coord_x, coord_y, dx_cc, dy_offset, 'CC', 'LP') else: current_point.setPoint( coord_x, coord_y, dx_cc, dy_offset, 'CC', 'CC') else: raise ValueError('Invalid subtype name') idx_x = 0 else: # NOT reaching end of lateral lipid layer current_point.setPoint(coord_x, coord_y, dx_lipid, dy_offset, 'LP', 'LP') elif current_point.x_type == 'CC': coord_x += dx_cc if idx_x == self.nx_grids_cc: # reaching end of lateral corneocyte layer current_point.setPoint(coord_x, coord_y, dx_lipid, dy_offset, 'LP', 'LP') idx_x = 0 bOffset = not bOffset else: # NOT reaching end of lateral corneocyte layer if cc_subtype_offset == 0 or cc_subtype_offset == 2: current_point.setPoint(coord_x, coord_y, dx_cc, dy_offset, 'CC', 'CC') elif cc_subtype_offset == 1: if not bOffset: current_point.setPoint( coord_x, coord_y, dx_cc, dy_offset, 'CC', 'CC') else: current_point.setPoint( coord_x, coord_y, dx_cc, dy_offset, 'CC', 'LP') elif cc_subtype_offset == 3: if not bOffset: current_point.setPoint( coord_x, coord_y, dx_cc, dy_offset, 'CC', 'LP') else: current_point.setPoint( coord_x, coord_y, dx_cc, dy_offset, 'CC', 'CC') else: raise ValueError('Invalid subtype name') else: raise ValueError('Invalid current_point.x_type') idx_y = idx_y_offset cc_subtype = cc_subtype_offset else: # not the last element in the lateral direction, thus move to the right idx_y += 1 if current_point.x_type == 'LP': # current row is lipid if cc_subtype == 0: # now within dh coord_y += dy_cc if idx_y == self.ny_grids_cc_dn: current_point.setPoint(coord_x, coord_y, dx_lipid, dy_lipid, 'LP', 'LP') idx_y = 0 cc_subtype += 1 else: current_point.setPoint(coord_x, coord_y, dx_lipid, dy_cc, 'LP', 'LP') elif cc_subtype == 1: # now within s coord_y += dy_lipid if idx_y == self.ny_grids_lipid: current_point.setPoint(coord_x, coord_y, dx_lipid, dy_cc, 'LP', 'LP') idx_y = 0 cc_subtype += 1 else: current_point.setPoint(coord_x, coord_y, dx_lipid, dy_lipid, 'LP', 'LP') elif cc_subtype == 2: # now wtihin dm coord_y += dy_cc if idx_y == self.ny_grids_cc_dn * self.w: current_point.setPoint(coord_x, coord_y, dx_lipid, dy_lipid, 'LP', 'LP') idx_y = 0 cc_subtype += 1 else: current_point.setPoint(coord_x, coord_y, dx_lipid, dy_cc, 'LP', 'LP') elif cc_subtype == 3: # now within the 2nd s coord_y += dy_lipid if idx_y == self.ny_grids_lipid: current_point.setPoint(coord_x, coord_y, dx_lipid, dy_cc, 'LP', 'LP') idx_y = 0 cc_subtype = 0 else: current_point.setPoint(coord_x, coord_y, dx_lipid, dy_lipid, 'LP', 'LP') else: raise ValueError('Invalid cc_subtype') elif current_point.x_type == 'CC': # current row is corneocyte if cc_subtype == 0: # now within dh coord_y += dy_cc if idx_y == self.ny_grids_cc_dn: if bOffset: current_point.setPoint( coord_x, coord_y, dx_cc, dy_lipid, 'CC', 'LP') else: current_point.setPoint( coord_x, coord_y, dx_cc, dy_lipid, 'CC', 'CC') idx_y = 0 cc_subtype += 1 else: current_point.setPoint(coord_x, coord_y, dx_cc, dy_cc, 'CC', 'CC') elif cc_subtype == 1: # now within s coord_y += dy_lipid if idx_y == self.ny_grids_lipid: current_point.setPoint(coord_x, coord_y, dx_cc, dy_cc, 'CC', 'CC') idx_y = 0 cc_subtype += 1 else: if bOffset: current_point.setPoint( coord_x, coord_y, dx_cc, dy_lipid, 'CC', 'LP') else: current_point.setPoint( coord_x, coord_y, dx_cc, dy_lipid, 'CC', 'CC') elif cc_subtype == 2: # now wtihin dm coord_y += dy_cc if idx_y == self.ny_grids_cc_dn * self.w: if bOffset: current_point.setPoint( coord_x, coord_y, dx_cc, dy_lipid, 'CC', 'CC') else: current_point.setPoint( coord_x, coord_y, dx_cc, dy_lipid, 'CC', 'LP') idx_y = 0 cc_subtype += 1 else: current_point.setPoint(coord_x, coord_y, dx_cc, dy_cc, 'CC', 'CC') elif cc_subtype == 3: # now within the 2nd s coord_y += dy_lipid if idx_y == self.ny_grids_lipid: current_point.setPoint(coord_x, coord_y, dx_cc, dy_cc, 'CC', 'CC') idx_y = 0 cc_subtype = 0 else: if bOffset: current_point.setPoint( coord_x, coord_y, dx_cc, dy_lipid, 'CC', 'CC') else: current_point.setPoint( coord_x, coord_y, dx_cc, dy_lipid, 'CC', 'LP') else: raise ValueError('Invalid cc_subtype') else: raise ValueError('Invalid current_point.x_type')