def __init__(self, k): Domain.__init__(self) self.charge_loss_factor = 0.9 self.soc_external_losses = -0.05 self.capacity_min = 0.1 self.capacity_max = 0.3 self.soc_min = 0.0 self.soc_max = 1.0 self.tau_min = 0.0 self.tau_max = 1.0 self.load_min = 0.0 self.load_max = 1.0 self.charge_min = 0.0 self.charge_max = 0.5 self.load_mean = 0.5 self.load_std = 0.8 self.initial_value = 0.0 # state and action variables soc = Variable(self.soc_min, self.soc_max, 0.01) # state of charge capacity = Variable(self.capacity_min, self.capacity_max, 0.1) # consumption load a_tau = Variable(self.tau_min, self.tau_max, k) # consumption load charge = Variable(self.charge_min, self.capacity_max, 0.1) # consumption load self.tariff = rt.receive_tariff() self.setStateVariables({'soc':soc, 'capacity':capacity}) # define the state variables self.setActionVariables({'charge':charge, 'tau':a_tau}) # sets the action variables self.current_state = {'capacity':self.capacity_max, 'soc':self.soc_max} # initial state self.previous_state = None self.new_capacity = self.capacity_max
def main(): dom = Domain.int_range(0, 11) set1 = MutableFuzzySet(dom) set1.set(4, 0.2) set1.set(6, 0.4) set1.set(9, 0.5) dom1 = Domain.int_range(-5, 6) print(dom1) set2 = CalculatedFuzzySet( dom1, StandardFuzzySets.lambda_function(dom1.index_of_element(-4), dom1.index_of_element(0), dom1.index_of_element(4))) set3 = CalculatedFuzzySet( dom1, StandardFuzzySets.l_function( dom1.index_of_element(-4), dom1.index_of_element(0), )) Debug.print(set1, "Set1:") print(set2.domain) Debug.print(set2, "Set2:") Debug.print(set3, "Set3:")
def __init__(self, parent=None): super().__init__(parent) self.setAttribute(Qt.WA_QuitOnClose) self.setAttribute(Qt.WA_DeleteOnClose) # create instance variables self._ui = uic.loadUi('mainwindow.ui', self) # create models self._domain = Domain(parent=self) self._vcoCharWidget = VCOCharWidget(parent=self) self._ui.tabWidgetMain.addTab(self._vcoCharWidget, 'VCO characteristics') self._measureModel = MeasureModel(parent=self, domain=self._domain) self._markerModel = MarkerModel(parent=self) self._plotWidget = PhasePlotWidget(parent=self, domain=self._domain) self._ui.layoutPlot = QVBoxLayout() self._ui.layoutPlot.addWidget(self._ui.widgetStats) self._ui.layoutPlot.addWidget(self._plotWidget) self._ui.tabPlot.setLayout(self._ui.layoutPlot) # UI hack self._show_freq = False self._show_amp = False self._show_curr = False self._init()
def load_the_domain(self, domain_params): if domain_params.get('use_available_domain', None): domain = Domain(domain_params['domain_shape'], domain_params['domain_type'], domain_params["domain_number"]) domain.generate_domain_name() stat = domain.load_domain(self.output_folder, domain_params) new_agent_loc = domain_params['new_agent_loc'] if stat: print("Using available domain ...") return domain else: print("Domain is not available") print("Creating a new random domain ... ") domain = create_random_domain(domain_params['domain_shape'], domain_params['domain_type'], domain_params['num_wall'], domain_params['num_storage'], domain_params['num_gold'], domain_params["domain_number"]) # self.save_domain() # self.domain.plot_domain(True, self.output_folder) # self.new_agent_loc = self.domain_params['new_agent_loc'] return domain
def get_parent_domain(self, domain_tag): domain = Domain(self.auth, domain_tag) domain.cache_list("apps/{0}/domains".format(os.environ['NEST_APP_ID']), None, 'tag') if not domain.load(): print "the domain does not exist" return None return domain
def main(): """ Main function """ domain1: Domain = Domain(43690, 'D1', NUM_MAC_ADDRESSES) domain2: Domain = Domain(48059, 'D2', NUM_MAC_ADDRESSES) domain3: Domain = Domain(52428, 'D3', NUM_MAC_ADDRESSES) for domain in [domain1, domain2, domain3]: print(domain)
def domains(self): if not self._domains: self._domains = [ Domain(triple, self.label) for triple in self.triples ] elif len(self._domains) < len(self.triples): # the `geometry` method has computed the first domain already self._domains.extend( Domain(triple, self.label) for triple in self.triples[1:]) return self._domains
def split_domain(domain, pos): """ Splits a domain into two subdomains. """ from domain import Domain section1 = Domain(name=domain.name + "[:{0}]".format(pos), sequence=domain.sequence[:pos]) section2 = Domain(name=domain.name + "[{0}:]".format(pos + 1), sequence=domain.sequence[pos:]) domain.subdomains = [section1, section2]
def __init__(self, model_type, trajectory, N, nb_games): # parameters of the models self.trees_n_estimators = 50 self.model_type = model_type self.trajectory = trajectory self.nb_games = nb_games self.domain = Domain() self.model = self.Q_iter(N)
def equate_coincident_domains(domain1, domain2): assert domain1.length == domain2.length # Make a new Domain with sequence from both domains new_domain = Domain(name="~(" + min(domain1.name, domain2.name) + ")", sequence=domain1.sequence) new_domain.restrict_sequence(domain2.sequence) # Redirect domain1 and domain2 to point to new domain domain1.subdomains = [new_domain] domain2.subdomains = [new_domain]
def test_domain_functional(ids): """ Tests instantiation of three test domains: -checks number of mac addresses generated per instance -checks for uniqueness """ my_domain = Domain(ids, 'Functional Domain Test') my_domain.generate_mac_address() assert len(my_domain.mac_addresses) == 10 # use set function to determine uniqueness assert len(set(my_domain.mac_addresses)) == 10
def add_domain(self, init, domain, domains): _id = domain['_id'] if domain['status'] == 'valid' and _id not in self.domains: domain = Domain(self, domain) if not init: domain.load() self.domains.put(domain) elif domain['status'] == 'invalid' and _id in self.domains: tmp = self.domains.pop(_id).domain if tmp['last'] < self.last: tmp['status'] = 'invalid' domains[_id] = tmp
def bfs_path(self, init_state, max_depth=None, max_states=None): def create_iterator(): return BreadthFirstIterator2(self, init_state, max_depth, max_states) domain = Domain(None, False) domain.create_iterator = create_iterator return domain
def __init__(self, id, nr): self.domain = Domain() self.phrasebase = Phrasebase() self.parsing = Parsing() self.evaluation = Evaluation(self.domain.getTopics(), self.domain.getPraise(), self.domain.getCriticism()) super(L, self).__init__() self.ui = UI(nr) self.id = id L.totalCount += 1 self.displayCount() self.running = True
def build_trajectory(size, from_action_space=False, action_space=None): """ Build a trajctory of four-tuples using ranfom action """ T= [] d = Domain() x = d.initial_state() while len(T) < size: if not from_action_space: # continuous action in (-1,1) u = d.random_action() else: # choose an action from a custom discrete action space u = np.random.choice(action_space, size=1) new_x, r = d.f(u) # add the four-tuple to the trajectory T.append([x, u, r, new_x, d.is_final_state()]) if d.is_final_state(): x = d.initial_state() else: x = new_x # shuffle the trajectory np.random.shuffle(T) return T
def main(num_lights): if num_lights > 10: print(f"Warning: there are {num_lights*2**num_lights} possible " f"actions to switch on {num_lights} ligths. This will take a " f"while...") actions = [Switch(num, "ON") for num in range(1, num_lights + 1)] actions += [Switch(num, "OFF") for num in range(1, num_lights + 1)] lights = Domain(actions) print("\nExample on how to switch {} lights on:\n".format(num_lights)) status = { "LIGHT_{}".format(num): "OFF" for num in range(1, num_lights + 1) } goal = {"LIGHT_{}".format(num): "ON" for num in range(1, num_lights + 1)} lights.solve(status, goal) if num_lights <= 10: print("\nOnce all lights are on, plot domain graph and solution") labels = {node: node_to_label(node) for node in lights.nodes} if num_lights <= 5: lights.plot(labels=labels, font_size=9) else: lights.plot_bokeh(labels=labels, node_size=10) print("\nBye")
def __init__(self): Domain.__init__(self) self.charge_loss_factor = 0.95 self.soc_external_losses = -0.03 self.initial_value = 10.0 self.max_soc = 0.5 self.min_soc = 0.0 self.max_load = 1.0 self.min_load = 0.0 self.max_proc = 2.0 self.min_proc = 0.0 self.max_tariff, self.base_price, self.pr_coeff, self.pr_im_coeff = 9, 0.22, 0.02, 0.4 self.imbalance = 0.0 self.load_mean = 0.0 self.load_std = 0.1
def endpoint_method(endpoint): """The endpoint that drives the dude pipeline""" print("get endpoint") domain = Domain(endpoint, request) importer, driver, transformer = domain.get() if not importer.import_request(request): return jsonify(importer.errors) #print(driver.method(importer.imported)) # # transformer.transform(driver.data) # return Response(jsonify(transformer.data())) return jsonify(driver.call_method(importer.imported))
def plot_miles(df): columns = list(df.columns) data = df.to_numpy() data = data[:, -1].reshape((-1, 1)) # data[data==0] = 1 data[data > 400] = 400 # data = (np.log10(data) * 10).astype(int) temp = int(max(data)) print('max mile', temp) temp_dict = {0: temp + 1} domain = Domain(temp_dict, [ 0, ]) hist = tools.get_marginal(data, domain, (0, )) hist[hist == 0] = 1 hist = np.log10(hist) ptools.plot_list(hist, './evaluate/trip_miles.pdf', size=(20.0, 2.5), zero_line=True)
def NIST3_read_data(data_path, domain_path): print('reading data') df = pd.read_csv(data_path) df.drop(columns=['trip_day_of_week', 'trip_hour_of_day'], inplace=True) by_shift = pd.pivot_table( df.assign(n=1), values="n", index="taxi_id", columns="shift", aggfunc="count", fill_value=0, ) by_pickup = pd.pivot_table( df.assign(n=1), values="n", index="taxi_id", columns="pickup_community_area", aggfunc="count", fill_value=0, ) taxi_df = by_shift.join(by_pickup, rsuffix="p") # print(taxi_df.columns) # print(taxi_df.index) headings = list(df.columns) domain_dict = json.load(open(domain_path)) domain_dict = {i: domain_dict[df.columns[i]] for i in range(len(headings))} domain = Domain(domain_dict, list(range(len(domain_dict)))) # print(df.iloc[0:30].to_numpy()[:, [0, 1, 2, 3, 4, -1]]) return df, domain, headings, taxi_df
def test_consistent_for_partial_assignment(self): # Arrange variables = [ Variable('1', Domain([1, 2, 3])), Variable('2', Domain([1, 2])) ] constraints = [EqualConstraint(variables[0], 2)] csp = ConstraintSatisfactionProblem(variables, constraints) assignment = Assignment() assignment.set(variables[0].name, 2) # Act consistent = csp.consistent(assignment) # Assert self.assertTrue(consistent)
def task_2(): print("Zadatak [2]:\n") domains = (Domain((0, 11)), Domain((-5, 6))) func = Fuzzy.fuzzy_lambda(domains[1].index(-4), domains[1].index(0), domains[1].index(4)) sets = (MutableFuzzySet(domains[0]), CalculatedFuzzySet(domains[1], func)) titles = ("S₁", "S₂ (lambda<-4, 0, 4>(D₂))") for i, value in enumerate((1., 0.8, 0.6, 0.4, 0.2)): sets[0].set(i, value) for t, s in zip(titles, sets): print("{}:\n{}\n".format(t, s)) print("\n")
def main(): dom = Domain.int_range(0, 11) set1 = MutableFuzzySet(dom) set1.set(0, 1.0) set1.set(1, 0.8) set1.set(2, 0.6) set1.set(3, 0.4) set1.set(4, 0.2) Debug.print(set1, "Set1:") notset1 = Operations.unary_operation(set1, Operations.zadeh_not()) Debug.print(notset1, "notSet1:") print() union = Operations.binary_operation(set1, notset1, Operations.zadeh_or()) Debug.print(union, "Set1 union notSet1:") print() intersection = Operations.binary_operation(set1, notset1, Operations.zadeh_and()) Debug.print(intersection, "Set1 intersection notSet1:") print() hinters = Operations.binary_operation(set1, notset1, Operations.hamacher_t_norm(1.0)) Debug.print( hinters, "Set1 intersection with notSet1 using parameterised" " Hamacher T norm with parameter 1.0:")
def get_domains(self, search=""): """Get a list of your :class:`domains <tracker_client.domain.Domain>`. Note that the optional search term is supplied as part of the GraphQL query variables and affects the API response received, rather than filtering results client-side. :param str search: Search term to filter results with. For example, supplying the string "abc" would return only Domains containing "abc" in their domain_name. :return: A list of your domains. :rtype: list[Domain] :raises ValueError: if your domains can't be retrieved. """ params = {"after": "", "search": search} has_next = True domain_list = [] # The maximum number of domains that can be requested at once is 100 # This loop gets 100 domains, checks if there are more, and if there are # it gets another 100 starting after the last domain it got while has_next: result = self.execute_query(queries.GET_ALL_DOMAINS, params) if "error" in result: print("Server error: ", result) raise ValueError("Unable to get your domains.") for edge in result["findMyDomains"]["edges"]: domain_list.append(Domain(self, **edge["node"])) has_next = result["findMyDomains"]["pageInfo"]["hasNextPage"] params["after"] = result["findMyDomains"]["pageInfo"]["endCursor"] return domain_list
def test_contructor_num_mac(self): """ Test if contructed with the right number of mac addresses """ for num_mac_addresses in range(3): domain = Domain(1, 'test', num_mac_addresses) self.assertEqual(len(domain.mac_addresses), num_mac_addresses)
def __init__(self, *args, **kargs): """ Initializes a new Strand object. The following keyword arguments are accepted: name, domains OR sequence. If direct sequence constraints are specified, a new domain is defined with these constraints, and is assigned as the domain list for this Strand. """ # Assign id self.id = Strand.id_counter Strand.id_counter += 1 # Assign DNA object type self._object_type = 'strand' # Assign name if 'name' in kargs: self.name = kargs['name'] else: self.name = 'strand_{0}'.format(self.id) # If sequence constraints were specified, create a dummy domain with # these constraints. Otherwise, assign the given list of domains. if 'domains' in kargs and 'sequence' not in kargs: self._domains = kargs['domains'] elif 'sequence' in kargs and 'domains' not in kargs: d = Domain(name=self.name + "_domain", sequence=kargs['sequence']) self._domains = [d] else: raise ValueError("Must specify strand constraints or domain list.") # Assign length self._length = sum([d.length for d in self._domains])
def composition_of_binary_relations(r1, r2): dom1 = r1.get_domain() dom2 = r2.get_domain() size1_x = dom1.get_component(0).get_cardinality() size1_y = dom1.get_component(1).get_cardinality() size2_x = dom2.get_component(0).get_cardinality() size2_y = dom2.get_component(1).get_cardinality() if size1_x != size2_y: raise DomainsDimensionError( "Invalid domain dimensions for composition.") rows = [[ r1.get_value_at(dom1.element_for_index(j + i * size1_y)) for j in range(size1_y) ] for i in range(size1_x)] columns = [[ r2.get_value_at(dom2.element_for_index(i + j * size2_y)) for j in range(size2_x) ] for i in range(size2_y)] new_domain = Domain.combine(dom1.get_component(0), dom2.get_component(1)) new_fset = MutableFuzzySet(new_domain) for i, elem in enumerate(new_domain): mins = [ min(x, y) for x, y in zip(rows[i // size1_x], columns[i % size2_y]) ] new_fset.set(elem, max(mins)) return new_fset
def _domainListCheck(self): newList = self._getMessagesForDomainListing('add') adds, removes = splitDictLists(newList, self._domainListMessages, RH_Message().keys()) # Removals ids = [r['rhid'] for r in removes] indices = [] if (0 < len(ids)): for i, d in enumerate(self._domains): if (d.getID in ids): d.cleanUp() indices.append(i) self._domains = [ d for i, d in enumerate(self._domains) if i not in indices ] # Additions for a in adds: self._domains.append( Domain( redhawk.attach( a['rhname']), # Return redhawk domain instance '', # No parent ID self.outbox)) # Using the global outbox self._domainListMessages = newList self.domainTask = gevent.spawn_later(self._domainTaskWaitSec, self._domainListCheck)
def from_conf(conf, init_fields=True, init_variables=True, init_equations=True, init_solvers=True): mesh = Mesh.from_file(conf.filename_mesh) eldesc_dir = op.join(install_dir, "eldesc") domain = Domain.from_mesh(mesh, eldesc_dir) domain.setup_groups() domain.fix_element_orientation() domain.setup_neighbour_lists() obj = ProblemDefinition(conf=conf, domain=domain, eldesc_dir=eldesc_dir) # Default output file trunk and format. obj.ofn_trunk = io.get_trunk(conf.filename_mesh) obj.output_format = "vtk" obj.set_regions(conf.regions, conf.materials, conf.funmod) if init_fields: obj.set_fields(conf.fields) if init_variables: obj.set_variables(conf.variables) if init_equations: obj.set_equations(conf.equations) if init_solvers: obj.set_solvers(conf.solvers, conf.options) obj.ts = None return obj
def test_solver_success_many_variables_many_constraints(self): # Arrange variables = [] domain = set([1, 2, 3, 4, 5]) for i in range(5): variable = Variable(str(i), Domain(list(domain))) variables.append(variable) constraints = [ EqualConstraint(variables[2], 3), AllDiffConstraint(variables) ] csp = ConstraintSatisfactionProblem(variables, constraints) solver = Solver() # Act result = solver.solve(csp) # Assert self.assertTrue(result.success) assignment = result.assignment self.assertIsNotNone(assignment) self.assertEqual(3, assignment.get(variables[2].name)) encountered_values = set() for variable in variables: value = assignment.get(variable.name) self.assertTrue(value in domain) self.assertFalse(value in encountered_values) encountered_values.add(value)
def test_public_score(): # df_2018 = pd.read_csv('./data/2018data_final/2018.csv') # df_public = pd.read_csv('./data/ground_truth.csv') # df_public = pd.read_csv('./data/2020data_final/2020.csv') # df_public = pd.read_csv('./data/2014data_final/2014.csv') # df_public = pd.read_csv('./data/2018data_final/2018.csv') df_public = pd.read_csv('./data/2017data_final/2017.csv') # for attr in ['taxi_id', 'trip_day_of_week', 'trip_hour_of_day']: for attr in ['trip_day_of_week', 'trip_hour_of_day']: # df_2018 = df_2018.drop(columns=attr) df_public = df_public.drop(columns=attr) # data_2018 = df_2018.to_numpy() data_public = df_public.to_numpy(dtype=int) for attr in range(data_public.shape[1]): print(attr, np.unique(data_public[:, attr])) # print(df_2018.columns) # print(df_public.columns) domain_dict = json.load(open('./preprocess/domain.json', 'r')) domain_dict = { i: domain_dict[df_public.columns[i]] for i in range(len(df_public.columns)) } domain = Domain(domain_dict, list(range(len(domain_dict)))) print(domain) df_public = df_public.assign(epsilon=10.0) df_public.to_csv('./submission_2017.csv', index=False)
def test_not_consistent_if_assignment_violates_constraint(self): # Arrange variables = [ Variable('1', Domain([1, 2, 3])), Variable('2', Domain([1, 2])) ] constraints = [EqualConstraint(variables[0], 2)] csp = ConstraintSatisfactionProblem(variables, constraints) assignment = Assignment() assignment.set(variables[0].name, 3) # Act consistent = csp.consistent(assignment) # Assert self.assertFalse(consistent)
def index(self, **dom): ''' Returns indexes given domain ''' dd = self.domain dd.update(dom) return Domain(**dd)(self.grid, self.time)
def process_calc(bAuthenticate): # connect to MongoDB client = MongoClient() db = client[database] # DB authentication if required if bAuthenticate: bLoggedIn = db.authenticate(username, password, source=source_database) else: bLoggedIn = True if bLoggedIn: logger.info("Authenticated") pd = db.Project.find_one({"project_code":"MFW001_0-010 Metro Paris-Ligne 15_T2A"}) if pd: logger.info("Project %s found", pd["project_name"]) p = Project(db, pd) p.load() found_domains = Domain.find(db, {"project_id": p._id}) for dom in found_domains: d = Domain(db, dom) d.load() asets = db.AlignmentSet.find({"domain_id": d._id}) for aset in asets: a_set = AlignmentSet(db, aset) a_set.load() #sCode = a_set.item["code"] als = Alignment.find(db, {"alignment_set_id":a_set._id}).sort("PK", 1) cnt = 0. cnt_tot = als.count() for al in als: a = Alignment(db, al) a.setProject(p.item) a.load() cnt+=1. sys.stdout.write("\r{:5s} pk= {:.0f} progress= {:.0%}".format(a_set.item["code"], a.item["PK"], cnt/cnt_tot )) sys.stdout.flush() a.perform_calc(str(datetime.now())) else: logger.error("Authentication failed")
class AcheDashboard(object): def __init__(self, crawl): self.crawl = crawl if self.crawl.crawler != "ache": raise ValueError("Crawl must be using the Ache crawler.") self.harvest = Harvest(crawl) self.domain = Domain(crawl) def get_harvest_plot(self): # TODO: Remove Pokemon exception catching try: script, div = self.harvest.create() except: return [None, None] return [script, div] def get_domain_plot(self): # TODO: Remove Pokemon exception catching try: script, div = self.domain.create() except Exception: return [None, None] return [script, div] def get_relevant_seeds(self): # Converts string to StringIO to allow pandas to read it as a file seeds = pd.read_csv(StringIO(self.domain.get_relevant_data()), delimiter='\t', header=None, names=['url', 'timestamp']) return seeds['url'].to_dict().values() def get_plots(self): harvest_plot = self.get_harvest_plot() domain_plot = self.get_domain_plot() return { 'scripts': [domain_plot[0], harvest_plot[0]], 'divs': [domain_plot[1], harvest_plot[1]], }
def create_vm(args, connection): domains = get_domains(connection) if args.new_vm_name in domains.keys(): print ("Virtual machine \"" + args.vm_name + " already created.") else: domain = Domain(args.new_vm_name, args.memory, args.uuid, args.vcpu, args.os_type, args.type_arch, args.type_machine, args.clock_offset, args.domain_type, args.emulator) if args.disks is not None: for disk in args.disks: domain.add_disk(disk, "disk") if args.cdroms is not None: for cdrom in args.cdroms: domain.add_disk(cdrom, "cdrom") if args.nets is not None: for net in args.nets: domain.add_network(net_name=net) if args.bridges is not None: for br in args.bridges: domain.add_network(net_type="bridge", net_name=br) print ("Try to create \"" + domain.name + "\"") connection.defineXML(xml_to_string(domain.get_xml()))
def back_tracking(letters, debug, value_heuristic="no", most_variable="no", fwck=0): dictionary, frequecy_list = Input.get_source() if value_heuristic == "better_greedy" or value_heuristic == "more_better": frequecy_list = Input.get_new_frequency_list('new_freq_list') assignment = Assignment(letters, 3) constraints = Constraint(3) csp = Csp(dictionary, frequecy_list, constraints) csp.debug = debug csp.value_heuristic = value_heuristic csp.most_variable = most_variable csp.fwck = fwck domain = Domain.get_default_domain(3) return back_track(assignment, csp, domain)
def __init__(self): self.document = Document() self.session = Session() self.session.use_doc('crawler_dashboard') self.session.load_document(self.document) #self.harvest_source = ColumnDataSource(data=dict()) #self.domain_relevant_source = ColumnDataSource(data=dict()) #self.domain_crawled_source = ColumnDataSource(data=dict()) #self.domain_frontier_source = ColumnDataSource(data=dict()) #self.handson_source = ColumnDataSource(data=dict()) #self.termite_source = ColumnDataSource(data=dict()) self.harvest = Harvest() self.domain = Domain() #handson = Handson() self.termite = Termite() self.document.add(self.create_layout()) self.session.store_document(self.document)
def __init__(self, path, url): self.document = Document() self.session = Session(name=url, root_url=url) #self.session = Session('load_from_config=False') self.session.use_doc('crawler_dashboard') self.session.load_document(self.document) #self.harvest_source = ColumnDataSource(data=dict()) #self.domain_relevant_source = ColumnDataSource(data=dict()) #self.domain_crawled_source = ColumnDataSource(data=dict()) #self.domain_frontier_source = ColumnDataSource(data=dict()) #self.handson_source = ColumnDataSource(data=dict()) #self.termite_source = ColumnDataSource(data=dict()) self.harvest = Harvest(path) self.domain = Domain(path) #handson = Handson() #self.termite = Termite() self.document.add(self.create_layout()) self.session.store_document(self.document)
class DashBoard(object): def __init__(self): self.document = Document() self.session = Session() self.session.use_doc('crawler_dashboard') self.session.load_document(self.document) #self.harvest_source = ColumnDataSource(data=dict()) #self.domain_relevant_source = ColumnDataSource(data=dict()) #self.domain_crawled_source = ColumnDataSource(data=dict()) #self.domain_frontier_source = ColumnDataSource(data=dict()) #self.handson_source = ColumnDataSource(data=dict()) #self.termite_source = ColumnDataSource(data=dict()) self.harvest = Harvest() self.domain = Domain() #handson = Handson() self.termite = Termite() self.document.add(self.create_layout()) self.session.store_document(self.document) def render(self): self.create_layout() self.document.add(self.layout) self.update_data() def create_layout(self): #button = Button(label="Randomize data", type="success") #button.on_click(update_data) #top_panel = HBox(children=[button, self.harvest.plot, self.harvest.rate_plot]) top_panel = HBox(children=[self.harvest.plot, self.harvest.rate_plot]) domains = VBox(children=[self.domain.sort_relevant_plot, self.domain.sort_crawled_plot, self.domain.sort_frontier_plot], width=200) #middle_panel = HBox(children=[domains, handson.plot]) middle_panel = HBox(children=[domains]) layout = VBox(children=[top_panel, middle_panel, self.termite.plot]) self.layout = layout return layout def update_data(self): self.harvest.source = self.harvest.update_source() self.domain.sort_relevant_source, self.domain.sort_crawled_source, self.domain.sort_frontier_source = self.domain.update_source() self.termite.data, self.termite.source = self.termite.update_source() #self.session.store_objects(ds) self.session.store_document(self.document) def run(self, poll_interval=0.5): #link = self.session.object_link(self.document.context) #print("Please visit %s to see the plots (press ctrl-C to exit)" % link) try: while True: self.update_data() self.session.load_document(self.document) time.sleep(poll_interval) except KeyboardInterrupt: print() except ConnectionError: print("Connection to bokeh-server was terminated")
def testChooseInitializer_Integer(self): domain = Domain(type=Domain.WHOLE_NUMBER, low=Integer(20), high=Integer(40)) initializer = domain.chooseInitializer() self.assertTrue(initializer.is_integer) self.assertTrue(initializer >= domain.low) self.assertTrue(initializer <= domain.high)
def __init__(self, crawl): self.crawl = crawl if self.crawl.crawler != "ache": raise ValueError("Crawl must be using the Ache crawler.") self.harvest = Harvest(crawl) self.domain = Domain(crawl)
def get_domain(self, domain_name, authentication_token): return Domain.from_existing(domain_name, authentication_token)
def plot_data(bAuthenticate, sPath): # connect to MongoDB client = MongoClient() db = client[database] ##################################################### GIS SETUP driver = ogr.GetDriverByName("ESRI Shapefile") # create the spatial reference, EPSG3949 RGF93 / CC49 - http://spatialreference.org/ref/epsg/3949/ # xMin,yMin 1653513.80,8175914.21 : xMax,yMax 1659996.62,8177877.58 srs = osr.SpatialReference() srs.ImportFromEPSG(3949) # DB authentication if required if bAuthenticate: bLoggedIn = db.authenticate(username,password,source=source_database) else: bLoggedIn = True if bLoggedIn: logger.info("Logged in") pd = db.Project.find_one({"project_code":"MFW001_0-010 Metro Paris-Ligne 15_T2A"}) if pd: logger.info("Project %s found" % pd["project_name"]) p = Project(db, pd) p.load() found_domains = Domain.find(db, {"project_id": p._id}) for dom in found_domains: d = Domain(db,dom) d.load() # Example of query # asets = db.AlignmentSet.find({"$and":[{"domain_id": d._id},{"code": "main_01"}]}) asets = db.AlignmentSet.find({"$and":[{"domain_id": d._id}]}) for aset in asets: a_set = AlignmentSet(db,aset) a_set.load() sCode = a_set.item["code"] # GIS create the data source shpfname=os.path.join(sPath,"gis","smt_%s.shp" % sCode) if os.path.exists(shpfname): os.remove(shpfname) data_source = driver.CreateDataSource(shpfname) layer = data_source.CreateLayer("subsidence", srs, ogr.wkbPoint) # Add the GIS fields we're interested in field_name = ogr.FieldDefn("Name", ogr.OFTString) field_name.SetWidth(24) layer.CreateField(field_name) field_type = ogr.FieldDefn("Type", ogr.OFTString) field_type.SetWidth(24) layer.CreateField(field_type) field_align = ogr.FieldDefn("Alignment", ogr.OFTString) field_align.SetWidth(24) layer.CreateField(field_align) layer.CreateField(ogr.FieldDefn("PK", ogr.OFTInteger)) layer.CreateField(ogr.FieldDefn("Distance", ogr.OFTInteger)) layer.CreateField(ogr.FieldDefn("Latitude", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("Longitude", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("Elevation", ogr.OFTInteger)) layer.CreateField(ogr.FieldDefn("COB", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("BLOWUP", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("SETTLEMENT", ogr.OFTReal)) # layer.CreateField(ogr.FieldDefn("DATETIME", ogr.OFTDateTime)) # GIS end #als = db.Alignment.find({"$and":[{"alignment_set_id":a_set._id},{"PK":{"$gt":2128568}},{"PK":{"$lt":2129768}}]},{"PK":True,"COB":True,"BLOWUP":True, "PH":True, "DEM":True,"SETTLEMENT_MAX":True, "VOLUME_LOSS":True, "REFERENCE_STRATA":True, "SETTLEMENTS":True}).sort("PK", 1) als = db.Alignment.find({"alignment_set_id":a_set._id},{"PK":True,"COB":True,"BLOWUP":True, "PH":True, "DEM":True,"SETTLEMENT_MAX":True, "VOLUME_LOSS":True, "REFERENCE_STRATA":True, "SETTLEMENTS":True}).sort("PK", 1) a_list = list(als) pks =[d['PK'] for d in a_list] # scalo di fattore 100 cobs =[d['COB']/100 for d in a_list] # scalo di fattore 100 blowups =[d['BLOWUP']/100 for d in a_list] # amplifico di fattore 100 max_settlements =[d['SETTLEMENT_MAX']*100 for d in a_list] phs =[d['PH']['coordinates'][2] for d in a_list] dems =[d['DEM']['coordinates'][2] for d in a_list] pkys =[d['PH']['coordinates'][1] for d in a_list] pkxs =[d['PH']['coordinates'][0] for d in a_list] # punti medi pmidx = [] pmidy = [] # punti a distanza 20 e 40 keys, dictValues = processSettlements(a_list) pkxs_d_1 = defaultdict(list) pkys_d_1 = defaultdict(list) pkzs_d_1 = defaultdict(list) pkxs_d_2 = defaultdict(list) pkys_d_2 = defaultdict(list) pkzs_d_2 = defaultdict(list) mypoints = np.zeros((0,2)) myvalues = np.zeros(0,'f') pcalc_x = [] pcalc_y = [] pcalc_z = [] for i,x in enumerate(pkxs): if i==0: pass else: p1 = (pkxs[i-1],pkys[i-1]) p2 = (pkxs[i],pkys[i]) pm = mid_point(p1,p2) pmidx.append(pm[0]) pmidy.append(pm[1]) for key in keys: val = dictValues[key][i-1] if key == 0.0: # pass mypoints = np.append(mypoints,[[pkxs[i-1],pkys[i-1]]],axis=0) myvalues = np.append(myvalues,[val],axis=0) pcalc_x.append(pkxs[i-1]) pcalc_y.append(pkys[i-1]) pcalc_z.append(val) # GIS 1.1 feature = ogr.Feature(layer.GetLayerDefn()) feature.SetField("Name", "PK %f %d" % (pks[i-1],0)) feature.SetField("Type", "Central") feature.SetField("Alignment", str(sCode)) feature.SetField("Distance",0) feature.SetField("PK", int(pks[i-1])) feature.SetField("Latitude", pkys[i-1]) feature.SetField("Longitude", pkxs[i-1]) feature.SetField("Elevation", phs[i-1]) feature.SetField("COB", cobs[i-1]) feature.SetField("SETTLEMENT", val) feature.SetField("BLOWUP", blowups[i-1]) # feature.SetField("DATETIME", str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])) wkt = "POINT(%f %f)" % (float(pkxs[i-1]) , float(pkys[i-1])) # Create the point from the Well Known Txt point = ogr.CreateGeometryFromWkt(wkt) # Set the feature geometry using the point feature.SetGeometry(point) # Create the feature in the layer (shapefile) layer.CreateFeature(feature) # Destroy the feature to free resources feature.Destroy() # GIS 1.1 end else: ret_d = pfromdistance_p1(p1,p2,key) x1 = ret_d[0][0] x2 = ret_d[1][0] y1 = ret_d[0][1] y2 = ret_d[1][1] pkxs_d_1[key].append(x1) pkxs_d_2[key].append(x2) pkys_d_1[key].append(y1) pkys_d_2[key].append(y2) mypoints = np.append(mypoints,[[x1,y1]],axis=0) pcalc_x.append(x1) pcalc_y.append(y1) pcalc_z.append(val) myvalues = np.append(myvalues,[val],axis=0) mypoints = np.append(mypoints,[[x2,y2]],axis=0) pcalc_x.append(x2) pcalc_y.append(y2) pcalc_z.append(val) myvalues = np.append(myvalues,[val],axis=0) # GIS 1.1 feature = ogr.Feature(layer.GetLayerDefn()) feature.SetField("Name", "PK %f +%d" % (pks[i-1],int(key))) feature.SetField("Type", "Distance") feature.SetField("Alignment", str(sCode)) feature.SetField("Distance",int(key)) feature.SetField("PK", int(pks[i-1])) feature.SetField("Latitude", y1) feature.SetField("Longitude", x1) feature.SetField("Elevation", phs[i]) feature.SetField("COB", cobs[i]) feature.SetField("SETTLEMENT", val) feature.SetField("BLOWUP", blowups[i]) #feature.SetField("DATETIME", str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])) wkt = "POINT(%f %f)" % (float(x1) , float(y1)) # Create the point from the Well Known Txt point = ogr.CreateGeometryFromWkt(wkt) # Set the feature geometry using the point feature.SetGeometry(point) # Create the feature in the layer (shapefile) layer.CreateFeature(feature) # Destroy the feature to free resources feature.Destroy() feature = ogr.Feature(layer.GetLayerDefn()) feature.SetField("Name", "PK %f -%d" % (pks[i],int(key))) feature.SetField("Type", "Distance") feature.SetField("Alignment", str(sCode)) feature.SetField("Distance",int(key)) feature.SetField("PK", int(pks[i])) feature.SetField("Latitude", y2) feature.SetField("Longitude", x2) feature.SetField("Elevation", dems[i]) feature.SetField("COB", cobs[i]) feature.SetField("SETTLEMENT", val) feature.SetField("BLOWUP", blowups[i]) #feature.SetField("DATETIME", str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])) wkt = "POINT(%f %f)" % (float(x2) , float(y2)) # Create the point from the Well Known Txt point = ogr.CreateGeometryFromWkt(wkt) # Set the feature geometry using the point feature.SetGeometry(point) # Create the feature in the layer (shapefile) layer.CreateFeature(feature) # Destroy the feature to free resources feature.Destroy() # GIS 1.1 end x_min, x_max, y_min, y_max = layer.GetExtent() data_source.Destroy() ############### END GIS min_x = min(pcalc_x) min_y = min(pcalc_y) max_x = max(pcalc_x) max_y = max(pcalc_y) # Interpolazione ...forse non è la cosa giusta da fare logger.info("x range %d" % (max_x - min_x) ) logger.info("y range %d" % (max_y - min_y) ) gx, gy = np.mgrid[min_x:max_x,min_y:max_y] m_interp_cubic = griddata(mypoints, myvalues, (gx, gy),method='nearest') # plot fig = plt.figure() plt.title("Profilo %s" % sCode) ### visualizza gli strati di riferimento # fillBetweenStrata(a_list) ################################################ plt.plot(pks,phs, linewidth=2,label='Tracciato') plt.plot(pks,dems, linewidth=2,label='DEM' ) plt.plot(pks,cobs, label='COB / 100') plt.plot(pks,blowups, label='BLOWUP / 100') plt.plot(pks,max_settlements, label='SETTLEMENT_MAX * 100') plt.axis([min(pks),max(pks),min(phs)-10,max(dems)+10]) plt.legend() outputFigure(sPath, "profilo_%s.svg" % a_set.item["code"]) logger.info("profilo_%s.png plotted in %s" % (a_set.item["code"], sPath)) plt.close(fig) fig = plt.figure() # stampa planimetria plt.title("Planimetria") # filtro a zero tutto qeullo che sta sotto # m_interp_cubic[ m_interp_cubic < 0.0] = 0.0 clevels = np.arange(0., 0.04, 0.001) cmap = LinearSegmentedColormap.from_list(name="Custom CMap", colors =["white", "blue", "red"], N=11) contours = plt.contourf(gx, gy, m_interp_cubic,cmap = cm.jet, extend='both', levels=clevels) cp = plt.contour(gx, gy, m_interp_cubic,linewidths=0.5,colors='k',levels=clevels) # GIS create the data source attr_name = "SETTLEMENT" shpfname=os.path.join(sPath,"gis","contour_%s.shp" % sCode) if os.path.exists(shpfname): os.remove(shpfname) dst_ds = driver.CreateDataSource(shpfname) dst_layer = dst_ds.CreateLayer("contour_subsidence", srs, ogr.wkbPolygon) # Add the GIS fields we're interested in dst_layer.CreateField(ogr.FieldDefn(attr_name, ogr.OFTReal)) field_align = ogr.FieldDefn("Alignment", ogr.OFTString) field_align.SetWidth(24) dst_layer.CreateField(field_align) field_level = ogr.FieldDefn("LevelID", ogr.OFTString) field_level.SetWidth(24) dst_layer.CreateField(field_level) # dst_layer.CreateField(ogr.FieldDefn("DATETIME", ogr.OFTDateTime)) # GIS end for level in range(len(contours.collections)): paths = contours.collections[level].get_paths() for path in paths: feat_out = ogr.Feature( dst_layer.GetLayerDefn()) feat_out.SetField( attr_name, contours.levels[level] ) feat_out.SetField("Alignment", str(sCode)) feat_out.SetField("LevelID", str(level)) #feat_out.SetField("DATETIME", str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])) pol = ogr.Geometry(ogr.wkbPolygon) ring = None for i in range(len(path.vertices)): point = path.vertices[i] if path.codes[i] == 1: if ring != None: pol.AddGeometry(ring) ring = ogr.Geometry(ogr.wkbLinearRing) ring.AddPoint_2D(point[0], point[1]) pol.AddGeometry(ring) feat_out.SetGeometry(pol) if dst_layer.CreateFeature(feat_out) != 0: print "Failed to create feature in shapefile.\n" exit( 1 ) feat_out.Destroy() """ # Create the destination tiff data source raster_fn=os.path.join(sPath,"smt_%s.tif" % sCode) if os.path.exists(raster_fn): os.remove(raster_fn) # Define pixel_size and NoData value of new raster pixel_size = 1 NoData_value = -9999 x_res = int((max_x - min_x) / pixel_size) y_res = int((max_y - min_y) / pixel_size) target_ds = gdal.GetDriverByName('GTiff').Create(raster_fn, x_res, y_res, 1, gdal.GDT_Float32) target_ds.SetGeoTransform((x_min, pixel_size, 0, y_max, 0, -pixel_size)) band = target_ds.GetRasterBand(1) band.WriteArray(m_interp_cubic) outRasterSRS = osr.SpatialReference() outRasterSRS.ImportFromEPSG(3949) outRaster.SetProjection(outRasterSRS.ExportToWkt()) outband.FlushCache() """ plt.colorbar() plt.plot(pkxs,pkys, "g-",label='Tracciato %s' % a_set.item["code"]) plt.plot(pkxs,pkys, "g.") # Punti medi plt.plot(pmidx,pmidy, "gx") for key in keys: pkzs_d_1[key] = dictValues[key] pkzs_d_2[key] = dictValues[key] plt.plot(pkxs_d_1[key],pkys_d_1[key], "w.", ms=1) plt.plot(pkxs_d_2[key],pkys_d_2[key], "w.", ms=1) array_x = np.asarray(pcalc_x) array_y = np.asarray(pcalc_y) array_z = np.asarray(pcalc_z) plt.axis("equal") outputFigure(sPath, "tracciato_%s.svg" % a_set.item["code"], format="svg") logger.info("tracciato_%s.png plotted in %s" % (a_set.item["code"], sPath)) #plt.show() plt.close(fig) logger.info("plot_data terminated!") else: logger.error("Authentication failed")
def testChooseInitializer_Fraction(self): domain = Domain(type=Domain.FRACTION, low=-23, high=435) initializer = domain.chooseInitializer() self.assertTrue(initializer.is_rational) self.assertTrue(initializer >= Rational(domain.low, domain.high)) self.assertTrue(initializer <= abs(Rational(domain.high, domain.low)))
from suds.client import Client from domain import Domain import sys domain_name = sys.argv[1] postmaster = sys.argv[2] client = Client("http://localhost:8081/config-service/ConfigurationService?wsdl") d = Domain(domain_name,postmaster) d.add_to_config(client)
def testChooseInitializer_Real(self): domain = Domain(type=Domain.REAL, low=Real(20), high=Real(40)) initializer = domain.chooseInitializer() self.assertTrue(initializer.is_real) self.assertTrue(initializer >= domain.low) self.assertTrue(initializer <= domain.high)
def testFraction(self): self.assertTrue(Domain.isValueInDomain(Domain.FRACTION, S.Zero)) self.assertTrue(Domain.isValueInDomain(Domain.FRACTION, Rational(3,5))) self.assertFalse(Domain.isValueInDomain(Domain.FRACTION, S.Pi))
def testWholeNumber(self): self.assertTrue(Domain.isValueInDomain(Domain.WHOLE_NUMBER, S.Zero)) self.assertFalse(Domain.isValueInDomain(Domain.WHOLE_NUMBER, -S.One))
def plot_data(bAuthenticate, sPath): # connect to MongoDB client = MongoClient() db = client[database] # DB authentication if required if bAuthenticate: bLoggedIn = db.authenticate(username,password,source=source_database) else: bLoggedIn = True # cambio font size mpl.rcParams.update({'font.size': 6}) if bLoggedIn: logger.info("Logged in") pd = db.Project.find_one({"project_code":"MFW001_0-010 Metro Paris-Ligne 15_T2A"}) if pd: logger.info("Project %s found" % pd["project_name"]) p = Project(db, pd) p.load() found_domains = Domain.find(db, {"project_id": p._id}) for dom in found_domains: dm = Domain(db,dom) dm.load() # Example of query asets = db.AlignmentSet.find({"domain_id": dm._id}) for aset in asets: a_set = AlignmentSet(db,aset) a_set.load() sCode = a_set.item["code"] als = db.Alignment.find({"alignment_set_id":a_set._id},{"PK":True,"P_TAMEZ":True,"COB":True,"P_EPB":True,"P_WT":True,"BLOWUP":True, "PH":True, "DEM":True,"SETTLEMENT_MAX":True, \ "TILT_MAX":True, "EPS_H_MAX":True, "VOLUME_LOSS":True, "K_PECK":True, "REFERENCE_STRATA":True, "SETTLEMENTS":True, "SENSIBILITY":True, "DAMAGE_CLASS":True, "VULNERABILITY":True, \ "CONSOLIDATION_VALUE":True, "gamma_face":True, "gamma_tun":True, "sensibility_vbr_pk":True, "vibration_speed_mm_s_pk":True, "damage_class_vbr_pk":True, "vulnerability_vbr_pk":True}).sort("PK", 1) a_list = list(als) pks = [] pklabel = [] pkxticks = [] for d in a_list: pk_value = round(d['PK']/10., 0) *10. pks.append(pk_value) hundreds = int(pk_value-int(pk_value/1000.)*1000) if hundreds%100 == 0: pkxticks.append(pk_value) pklabel.append("%d+%03d" % (int(pk_value/1000.),hundreds )) if sCode=='smi': d_press = 0.5 # bar tra calotta e asse d_press_wt = 0.35 else: d_press = 0.7 # bar tra calotta e asse d_press_wt = 0.5 # scalo di fattore 100 # p_wts =[d['P_WT']/100 - d_press_wt for d in a_list] p_wts = [(max(0., d['P_WT']/100. - d_press_wt)) for d in a_list] # scalo di fattore 100 p_epms =[max(0., d['P_EPB']/100. - d_press) for d in a_list] # scalo di fattore 100 p_tamezs=[max(0., d['P_TAMEZ']/100. - d_press) for d in a_list] cobs =[max(0., d['COB']/100. - d_press) for d in a_list] # scalo di fattore 100 blowups =[max(0., d['BLOWUP']/100. - d_press) for d in a_list] # amplifico di fattore 100 volume_losss =[d['VOLUME_LOSS']*100. for d in a_list] k_pecks =[d['K_PECK'] for d in a_list] # amplifico di fattore 1000 max_settlements =[d['SETTLEMENT_MAX']*1000. for d in a_list] tilts =[d['TILT_MAX']*1000. for d in a_list] epshs =[d['EPS_H_MAX']*1000. for d in a_list] consolidations =[d['CONSOLIDATION_VALUE'] for d in a_list] sensibilities =[d['SENSIBILITY'] for d in a_list] damages =[d['DAMAGE_CLASS'] for d in a_list] vulnerabilities =[d['VULNERABILITY'] for d in a_list] young_tuns =[d['gamma_tun'] for d in a_list] young_faces =[d['gamma_face'] for d in a_list] sensibility_vbr_pks =[d['sensibility_vbr_pk'] for d in a_list] vibration_speed_mm_s_pks =[d['vibration_speed_mm_s_pk'] for d in a_list] damage_class_vbr_pks =[d['damage_class_vbr_pk'] for d in a_list] vulnerability_vbr_pks =[d['vulnerability_vbr_pk'] for d in a_list] # "sensibility_vbr_pk":True, "vibration_speed_mm_s_pk":True, "damage_class_vbr_pk":True, "vulnerability_vbr_pk":True # # plot # fig = plt.figure() # fig.set_size_inches(12, 3.54) # plt.plot(pks,young_tuns, label='E_TUN - GPa') # plt.plot(pks,young_faces, label='E_FACE - GPa') # y_min = math.floor(min(min(young_tuns),min(young_faces))/1.)*1. # y_max = math.ceil(max(max(young_tuns),max(young_faces))/1.)*1. # my_aspect = 50./(abs(y_max-y_min)/9.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione # plt.axis([max(pks),min(pks),y_min,y_max]) # plt.xticks(pkxticks, pklabel, rotation='vertical') # ax = plt.gca() # ax.set_aspect(my_aspect) # start, stop = ax.get_ylim() # ticks = np.arange(start, stop + 1., 1.) # ax.set_yticks(ticks) # #ax.grid(True) # plt.legend() # #fig.set_dpi(1600) # outputFigure(sPath, ("profilo_young_%s.svg" % sCode)) # logger.info("profilo_young.svg plotted in %s" % sPath) # plt.show() fig = plt.figure() fig.set_size_inches(12, 3.54) #plt.plot(pks,cobs, label='COB - bar') plt.plot(pks,p_epms, label='P_EPB - bar') plt.plot(pks,blowups, label='BLOWUP - bar') plt.plot(pks,p_wts, label='P_WT - bar') plt.plot(pks,p_tamezs, label='P_TAMEZ - bar') y_min = math.floor(min(min(p_wts),min(cobs), min(p_epms), min(blowups))/.5)*.5-.5 y_max = math.ceil(max(max(p_wts),max(cobs), max(p_epms), max(blowups))/.5)*.5+.5 my_aspect = 50./(abs(y_max-y_min)/9.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() ax.set_aspect(my_aspect) start, stop = ax.get_ylim() ticks = np.arange(start, stop + .5, .5) ax.set_yticks(ticks) #ax.grid(True) plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_pressioni_%s.svg" % sCode)) logger.info("profilo_pressioni.svg plotted in %s" % sPath) plt.show() # """ plt.plot(pks,volume_losss, label='VL percent') plt.plot(pks,k_pecks, label='k peck') y_min = math.floor(min(min(volume_losss), min(k_pecks))/.05)*.05-.05 y_max = math.ceil(max(max(volume_losss), max(k_pecks))/.05)*.05+.05 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/9.0) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) start, stop = ax.get_ylim() ticks = np.arange(start, stop + .05, .05) ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_peck_%s.svg" % sCode)) logger.info("profilo_peck.svg plotted in %s" % sPath) plt.show() plt.plot(pks,max_settlements, label='SETTLEMENT_MAX (mm)') y_min = 0. # math.floor(min(max_settlements))-1. y_max = 30. # math.ceil(max(max_settlements))+1. plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/4.5) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) start, stop = ax.get_ylim() ticks = np.arange(start, stop + 5., 5.) ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_cedimenti_%s.svg" % sCode)) logger.info("profilo_cedimenti.svg plotted in %s" % sPath) plt.show() plt.plot(pks,tilts, label='BETA (0/00)') plt.plot(pks,epshs, label='EPS_H (0/00)') y_min = 0. # math.floor(min(max_settlements))-1. y_max = 3.5 # math.ceil(max(max_settlements))+1. plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/4.5) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) start, stop = ax.get_ylim() ticks = np.arange(start, stop + .5, .5) ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_distorsioni_%s.svg" % sCode)) logger.info("profilo_distorsioni.svg plotted in %s" % sPath) plt.show() plt.plot(pks,sensibilities, label='SENSIBILITY (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) #start, stop = ax.get_ylim() #ticks = np.arange(start, stop + 1., 1.) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_sensibilita_%s.svg" % sCode)) logger.info("profilo_sensibilita.svg plotted in %s" % sPath) plt.show() plt.plot(pks,damages, label='DAMAGE CLASS (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) #start, stop = ax.get_ylim() #ticks = np.arange(start, stop + 1., 1.) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_danni_%s.svg" % sCode)) logger.info("profilo_danni.svg plotted in %s" % sPath) plt.show() plt.plot(pks,vulnerabilities, label='VULNERABILITY (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) #start, stop = ax.get_ylim() #ticks = np.arange(start, stop + 1., 1.) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_vulnerabilita_%s.svg" % sCode)) logger.info("profilo_vulnerabilita.svg plotted in %s" % sPath) plt.show() plt.plot(pks,consolidations, label='CONSOLIDATION (0-1)') y_min = -0.3 y_max = 1.3 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/1.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) #start, stop = ax.get_ylim() #ticks = np.arange(start, stop + 1., 1.) ticks =[0., 1.] ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_consolidamenti_%s.svg" % sCode)) logger.info("profilo_consolidamenti.svg plotted in %s" % sPath) plt.show() plt.plot(pks,sensibility_vbr_pks, label='SENSIBILITY VBR (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) outputFigure(sPath, ("profilo_sensibilita_vbr_%s.svg" % sCode)) logger.info("profilo_sensibilita_vbr.svg plotted in %s" % sPath) plt.show() plt.plot(pks,damage_class_vbr_pks, label='DAMAGE CLASS (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) outputFigure(sPath, ("profilo_danno_vbr_%s.svg" % sCode)) logger.info("profilo_danno_vbr.svg plotted in %s" % sPath) plt.show() plt.plot(pks,vulnerability_vbr_pks, label='VULNERABILITY (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) outputFigure(sPath, ("profilo_vulnerabilita_vbr_%s.svg" % sCode)) logger.info("profilo_vulnerabilita_vbr.svg plotted in %s" % sPath) plt.show() plt.plot(pks,vibration_speed_mm_s_pks, label='VIBRATION SPEED (mm/s)') y_min = -0.5 y_max = 12.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) ticks =[0., 2., 3., 5., 6., 9., 12.] ax.set_yticks(ticks) outputFigure(sPath, ("profilo_velocita_vbr_%s.svg" % sCode)) logger.info("profilo_velocita_vbr.svg plotted in %s" % sPath) plt.show() """ sensibility_vbr_pks =[d['sensibility_vbr_pk'] for d in a_list] vibration_speed_mm_s_pks =[d['vibration_speed_mm_s_pk'] for d in a_list] damage_class_vbr_pks =[d['damage_class_vbr_pk'] for d in a_list] vulnerability_vbr_pks =[d['vulnerability_vbr_pk'] for d in a_list] """ # """ logger.info("plot_data terminated!") else: logger.error("Authentication failed")
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s') fh.setFormatter(formatter) logger.addHandler(fh) # reading config file sCFGName = 'smt.cfg' smtConfig = ConfigParser.RawConfigParser() smtConfig.read(sCFGName) # setup DB parameter host = smtConfig.get('MONGODB','host') database = smtConfig.get('MONGODB','database') source_database = smtConfig.get('MONGODB','source_database') username = smtConfig.get('MONGODB','username') password = smtConfig.get('MONGODB','password') # connect to MongoDB client = MongoClient() db = client[database] # DB authentication db.authenticate(username,password,source=source_database) # Search for project_code = "MFW001_0-010 Metro Paris-Ligne 15_T2A" pd = db.Project.find_one({"project_code":"MFW001_0-010 Metro Paris-Ligne 15_T2A"}) p = Project(db, pd) p.load() found_domains = Domain.find(db, {"project_id": p._id}) for dom in found_domains: d = Domain(db,dom) d.load() # Example of aggregation aggrList = Alignment.aggregate_by_strata(db, d._id) for ii in aggrList: print ii
# make image with map of the file location n.write_map(oFileName + '_map.png') # Reprojected image into stereographic projection # 1. Cancel previous reprojection # 2. Get corners of the image # 3. Create Domain with stereographic projection, corner coordinates and resolution 1000m # 4. Reproject # 5. Write image n.reproject() # 1. lons, lats = n.get_corners() # 2. meanLon = sum(lons, 0.0) / 4. meanLat = sum(lats, 0.0) / 4. srsString = "+proj=stere +lon_0=%f +lat_0=%f +k=1 +ellps=WGS84 +datum=WGS84 +no_defs" % (meanLon, meanLat) extentString = '-lle %f %f %f %f -tr 75 75' % (min(lons), min(lats), max(lons), max(lats)) dStereo = Domain(srs=srsString, ext=extentString) # 3. dStereo.write_map(oFileName + '_stereo_map.png') print dStereo n.reproject(dStereo) # 4. n.write_figure(oFileName + '_pro_stereo.png', bands=[3], clim=[-20,0]) # 5. # Make image reprojected onto map of Northern Europe # 1. Create Domain object. It describes the desired grid of reprojected image: # projection, resolution, size, etc. In this case it is geographic projection; # -10 - 30 E, 50 - 70 W; 2000 x 2000 pixels # 2. Reproject the Nansat object # 3. Make simple image srsString = "+proj=latlong +ellps=WGS84 +no_defs" extentString = '-lle %f %f %f %f -ts 1000 1000' % (min(lons), min(lats), max(lons), max(lats))
def create_domain(self, name, ip_address): return Domain.create_new(name, ip_address, self.authentication_token)
def testInteger(self): self.assertTrue(Domain.isValueInDomain(Domain.INTEGER, S.Zero)) self.assertFalse(Domain.isValueInDomain(Domain.INTEGER, Rational(3,5)))
def testReal(self): self.assertTrue(Domain.isValueInDomain(Domain.REAL, S.Zero)) self.assertTrue(Domain.isValueInDomain(Domain.REAL, Rational(3,5))) self.assertTrue(Domain.isValueInDomain(Domain.REAL, S.Pi)) self.assertFalse(Domain.isValueInDomain(Domain.REAL, S.ImaginaryUnit))
def iterate_states(self, depth, return_depth=False): domain = Domain(None, False) domain.create_iterator = lambda: StatesIterator(self, depth, return_depth) return domain
def get_domain(self): from domain import Domain d = Domain(self) if d.exists(): return d return None