コード例 #1
0
ファイル: Application.py プロジェクト: lewj85/Music-Library
def main():
    sys.stdout = Tracer(sys.stdout)
    sys.stderr = Tracer(sys.stderr)
    app = QtGui.QApplication(sys.argv)
    application = Application(app)
    application.start()
    timer = QtCore.QTimer()
    timer.singleShot(1, application.applyTheme)
    sys.exit(app.exec_())
コード例 #2
0
    def render(self):
        elapsed_time = 0
        print "Starting", self.jobs, "tracer workers."
        jobs = []

        start_time = time.time()
        for i in range(self.jobs):
            t = Tracer(self.width, self.height, i,
                self.jobs, self.canvas,
                self.world, self.camera, self.recursion_depth,
                self.multisampling, self.x_samples, self.y_samples)
            t.name = "Tracer-"+str(i)
            t.start()
            jobs.append(t)

        for j in jobs:
            j.join()

        end_time = time.time()
        elapsed_time += end_time - start_time

        print "Time usage:"
        print "Rendering\t\t", end_time - start_time

        start_time = time.time()
        self.canvas.write()
        end_time = time.time()
        print "Writing\t\t\t", end_time - start_time

        elapsed_time += end_time - start_time
        print "Total time\t\t", elapsed_time
コード例 #3
0
ファイル: command.py プロジェクト: jacksonfylle/Bex
def send_to_fuzz(entrypoint, exploration_memory, exploration_registers,
                 from_memory_addr, dst_addr, q):
    """send a request to the fuzzer

    :param dst_addr (int): The destination address you wishe to reach
    """

    fuzz = Fuzz(exploration_memory, exploration_registers, from_memory_addr,
                dst_addr, q)

    fuzzer = Tracer(program_name, False)

    # set triton parameter
    ctx = TritonContext()
    ctx.setArchitecture(ARCH.X86_64)
    ctx.enableMode(MODE.ALIGNED_MEMORY, True)
    ctx.setAstRepresentationMode(AST_REPRESENTATION.PYTHON)

    fuzzer.tracer_init(ctx)

    # add fuzz callback
    fuzzer.add_start_callback(fuzz.start)
    fuzzer.add_instruction_callback(fuzz.get_instruction)
    fuzzer.add_end_callback(fuzz.end)
    fuzzer.add_memory_callback(fuzz.fuzz_memory)
    fuzzer.add_register_callback(fuzz.fuzz_register)

    p = multiprocessing.Process(target=fuzzer.start,
                                args=(ctx, 30, entrypoint))
    # return [p,ctx,fuzzer, exploration_memory]
    return p
コード例 #4
0
ファイル: test.py プロジェクト: dj44/tracerarduinoread
 def setUp(self):
     tracer = Tracer(16)
     tracer.get_command_bytes = Mock(return_value=fixture_data)
     tracer.add_crc = Mock(return_value=fixture_data)
     tracer.verify_crc = Mock(return_value=True)
     tracer.get_result = Mock(return_value=Command(0x12, fixture_data))
     self.ts = TracerSerial(tracer, None)
コード例 #5
0
    def sub_start_capture(self):
        # Start tracer thread, wait for console input to stop
        if self.login_required and not self.init_login():
            self.logger.debug("Could not login. Stop the capture thread.")
            self._stop.set()
            return

        self.set_data("tcaps", datetime.datetime.now())
        self.logger.debug("data_map:%s" % (self.data_map))
        self.init_capture_file()
        self.logger.info("Start capture (capture_file:'%s')." %
                         (self.cap_file_path))
        url_start = self.base_url + '/cgi-bin/capture_notimeout' + self.start_str + "&ifaceorminor=" + self.cap_interface
        if self.SID != '':
            url = url_start + "&sid=%s" % self.SID
        else:
            url = url_start

        self.logger.debug(
            "Send capture start request to the box          (url:'%s', capture_file:'%s')."
            % (url, self.cap_file_path))
        Tracer(url, self.cap_file_path).start()
        self.logger.debug(
            "Send capture start request to the box finished (url:'%s', capture_file:'%s')."
            % (url, self.cap_file_path))
コード例 #6
0
 def execute_task(self):
     tracer = Tracer()
     span = tracer.create_continuation_span(span_name='w2-{}'.format(
         self.id),
                                            context_id=self.id)
     span.set_tag('job-id', self.id)
     span.log_kv({
         'event': 'debug',
         'message': 'Start execution for job id: {}'.format(self.id)
     })
     try:
         childSpan = tracer.create_span(span_name='load-data',
                                        parent_span=span)
         self.load_data()
         childSpan.finish()
         childSpan = tracer.create_span(span_name='process-data',
                                        parent_span=span)
         self.process_data()
         childSpan.finish()
         childSpan = tracer.create_span(span_name='save-data',
                                        parent_span=span)
         self.save_data()
         childSpan.finish()
     except Exception as e:
         span.set_tag('error', e)
     finally:
         span.log_kv({
             'event':
             'debug',
             'message':
             'End executionfor job id: {}'.format(self.id)
         })
         span.finish()
         tracer.flush_spans()
コード例 #7
0
 def _start_tracer(self):
     """Start a new Tracer object, and store it in self.tracers."""
     tracer = Tracer()
     tracer.data = self.data
     tracer.should_trace = self.should_trace
     tracer.should_trace_cache = self.should_trace_cache
     tracer.start()
     self.tracers.append(tracer)
コード例 #8
0
def solve(randsol,
          fitness,
          solver=None,
          budget=None,
          effort=1.5,
          fine_ops=True,
          str_trace=True):

    ##### PARAMETERS

    ### create a tracer object
    tr = Tracer(rs=randsol, tt=str_trace)

    ### associate wrapper and tracer
    tr.acquire_wrapper(wr)

    ### create an instance of the search operators
    ops = OPS(fitness, fine_ops, tr)

    ##### BUDGET AND EFFORT
    if not budget:
        # If budget is given, use that to determine the iteration
        # budget.  This allows us to specify the number of iterations
        # directly, which is useful for fair benchmarking. Otherwise,
        # estimate genotype size and calculate budget.
        budget = int(avg_size_trace(tr)**effort)
        # print(" budget = ", budget)

    ##### SOLVER

    if solver in solver_name:

        #### import solver module
        solver_module = __import__(solver_name[solver])

        #### get solver class
        Solver_Class = getattr(
            solver_module, solver)  # assumes class name same as solver acronym

        #### create an instance of the solver
        search_algorithm = Solver_Class(ops, budget)

        #### run the solver
        (sol, fit) = search_algorithm.run()

        #### collect data
        solve.data = search_algorithm.data

        #### release wrapper
        tr.release_wrapper(wr)

        #### return solution
        return (sol.pheno, fit)

    else:

        print("solver %s not available!" % solver)
        print("solver = RS | HC | LA | EA | PS")
コード例 #9
0
def load_on():
    try:
        port = FakePort(fake_load_on)
        tracer = Tracer(0x16)
        t_ser = TracerSerial(tracer, port)
        t_ser.send_command(0xAA, 0x01, 0x01)
        #data = t_ser.receive_result(13)
        data = t_ser.receive_result()
        load_state = data.load_state
        return render_template('load_on.html', load_state=load_state)
    except (IndexError, IOError) as e:
        return jsonify({'error': str(e)}), 503
コード例 #10
0
ファイル: command.py プロジェクト: jacksonfylle/Bex
def main():
    entrypoint = 0x401094
    fuzzed_address = set()
    queue = multiprocessing.Queue()
    process = list()

    ctx = TritonContext()
    ctx.setArchitecture(ARCH.X86_64)
    ctx.enableMode(MODE.ALIGNED_MEMORY, True)
    ctx.setAstRepresentationMode(AST_REPRESENTATION.PYTHON)

    exploration = Exploration()
    tracer = Tracer(program_name, True)
    tracer.tracer_init(ctx)

    # Sets callbacks
    tracer.add_start_callback(exploration.start)
    tracer.add_instruction_callback(exploration.get_instruction)
    tracer.add_end_callback(exploration.end)
    tracer.add_memory_callback(exploration.symbolized_memory_input)
    tracer.add_register_callback(exploration.symbolized_register_input)

    for i in range(30):
        tracer.start(ctx, 1, entrypoint)

        if exploration.fuzz_is_needed is True:
            untaken_branch = set(exploration.get_untaken_branch())
            for i in untaken_branch:
                if i not in fuzzed_address:
                    if exploration.untaken_branch[i] != 0:
                        process.append(
                            send_to_fuzz(
                                entrypoint,
                                copy.deepcopy(exploration.exploration_memory),
                                copy.deepcopy(
                                    exploration.exploration_registers),
                                copy.copy(exploration.untaken_branch[i]), i,
                                queue))
                        process[-1].start()
                        process[-1].join()

                    fuzzed_address.add(i)

            try:
                new_inputs = queue.get(block=True, timeout=5)
                exploration.add_fuzz_inputs(new_inputs[0], new_inputs[1])
            except Queue.Empty:
                print(map(hex, exploration.get_untaken_branch()))
                print("Can't find more branch")
                break

    exploration.show_exploration()
コード例 #11
0
def start():
    global project, tracer, inspector
    try:
        project = Project.from_directory(find_project_directory(os.getcwd()))
        execution = Execution(project)
        inspector = Inspector(execution)
        tracer = Tracer(inspector)
        tracer.btracer.setup()
        sys.settrace(tracer.tracer)
    except PythoscopeDirectoryMissing:
        print "Can't find .pythoscope/ directory for this project. " \
            "Initialize the project with the '--init' option first. " \
            "Pythoscope tracing disabled for this run."
コード例 #12
0
    def render(self,
               scene,
               camera,
               width,
               height,
               super_sampling=1,
               logging=True,
               gpu=False):
        """Renders a scene"""
        if gpu:
            tracer = Tracer_gpu()
        else:
            tracer = Tracer()
        self.__tiles = Queue()
        self.__rendered_tiles = Queue()
        self.__logging = logging

        # setup rendering threads
        if logging:
            print("render using {0} threads with {1}x{1} tiles".format(
                self.__threads, self.__tilesize))
        workers = []
        for i in range(self.__threads):
            thread = threading.Thread(target=self.__render_portion,
                                      args=(tracer, scene, camera, width,
                                            height, super_sampling))
            thread.start()
            workers.append(thread)

        # split image into tiles -> threads will begin computing
        self.__total_tiles = 0
        for y in range(0, height, self.__tilesize):
            for x in range(0, width, self.__tilesize):
                self.__tiles.put(
                    (x, y, x + self.__tilesize, y + self.__tilesize))
                self.__total_tiles += 1

        # wait and stop workers
        for i in range(self.__threads):
            self.__tiles.put(None)
        for thread in workers:
            thread.join()

        # merge results
        image = {}
        while not self.__rendered_tiles.empty():
            for tile in self.__rendered_tiles.get():
                for k, v in tile.items():
                    image[k] = v

        return image
コード例 #13
0
def load_on():
    try:
        port = Serial('/dev/ttyAMA0', 9600, timeout=1)
        tracer = Tracer(0x16)
        t_ser = TracerSerial(tracer, port)
        t_ser.send_command(0xAA, 0x01, 0x01)
        #data = t_ser.receive_result(13)
        data = t_ser.receive_result()
        port.close()
        load_state = data.load_state
        return render_template('load_on.html', load_state=load_state)        
    except (IndexError, IOError) as e:
        port.reset_input_buffer()
        port.reset_output_buffer()
        return jsonify({'error': str(e)}), 503
コード例 #14
0
def get_data():
    try:
        port = Serial('/dev/ttyAMA0', 9600, timeout=1)
        port.reset_input_buffer()
        port.reset_output_buffer()
        tracer = Tracer(0x16)
        t_ser = TracerSerial(tracer, port)
        t_ser.send_command(0xA0)
        #sleep(1)
        #data = t_ser.receive_result(36)
        data = t_ser.receive_result()
        port.close()
        # operating parameters
        batt_voltage =  data.batt_voltage
        batt_full_voltage = data.batt_full_voltage
        batt_overdischarge_voltage = data.batt_overdischarge_voltage
        batt_temp = data.batt_temp
        pv_voltage = data.pv_voltage
        charge_current = data.charge_current
        load_on = data.load_on
        load_amps = data.load_amps
        load_overload = data.load_overload
        load_short = data.load_short
        batt_overdischarge = data.batt_overdischarge
        batt_full = data.batt_full
        batt_overload = data.batt_overload
        batt_charging = data.batt_charging

        return render_template('data.html',
                         batt_voltage=batt_voltage,
                         batt_full_voltage=batt_full_voltage,
                         batt_overdischarge_voltage=batt_overdischarge_voltage,
                         batt_temp=batt_temp,
                         pv_voltage=pv_voltage,
                         charge_current=charge_current,
                         load_on=load_on,
                         load_amps=load_amps,
                         load_overload=load_overload,
                         load_short=load_short,
                         batt_overdischarge=batt_overdischarge,
                         batt_full=batt_full,
                         batt_overload=batt_overload,
                         batt_charging=batt_charging)

    except (IndexError, IOError) as e:
        port.reset_input_buffer()
        port.reset_output_buffer()
        return jsonify({'error': str(e)}), 503
コード例 #15
0
    def Create(cls, plugin_config, **kwargs):
        tracing_config = plugin_config.TRACING_CONFIG
        span_decorator = kwargs.pop('span_decorator', None)
        service_name = plugin_config.TRACING_SERVICE_NAME
        validate = plugin_config.TRACING_VALIDATE
        config = Config(config=tracing_config,
                        service_name=service_name,
                        validate=validate)

        tracer = config.initialize_tracer()
        tracer_interceptor = open_tracing_server_interceptor(
            tracer,
            log_payloads=plugin_config.TRACING_LOG_PAYLOAD,
            span_decorator=span_decorator)

        return Tracer(tracer, tracer_interceptor, intercept_server)
コード例 #16
0
def solve_with_options(algorithm_to_run, seed, run_time, inst):
    print(
        f'''Running algorithm {algorithm_to_run} on file {inst} with a time limit of {run_time} seconds and a random seed of {seed}'''
    )
    np.random.seed(seed)
    random.seed(np.random.randint(999999))
    instance_name, city_data = load_data(inst)
    tracer = Tracer(method=algorithm_to_run,
                    instance=instance_name,
                    seed=seed,
                    cutoff=run_time)
    score, solution = None, None
    if algorithm_to_run == 'LS1':
        score, solution = genetic_algorithm.solve(
            data=city_data,
            timer=early_stop_checker(seconds=run_time),
            tracer=tracer)
    elif algorithm_to_run == 'BnB':
        score, solution = BnB.solve(data=city_data,
                                    timer=early_stop_checker(seconds=run_time),
                                    tracer=tracer)
    elif algorithm_to_run == 'LS2':
        score, solution = two_opt.solve(
            data=city_data,
            timer=early_stop_checker(seconds=run_time),
            tracer=tracer)
    elif algorithm_to_run == 'LS3':
        score, solution = genetic_algorithm_opt_2_hybrid.solve(
            data=city_data,
            timer=early_stop_checker(seconds=run_time),
            tracer=tracer)
    elif algorithm_to_run == 'Approx':
        score, solution = nearest_neighbor.solve(
            data=city_data,
            timer=early_stop_checker(seconds=run_time),
            tracer=tracer)

    if not os.path.exists('output'):
        os.makedirs('output')

    save_solution_file(score,
                       solution,
                       method=algorithm_to_run,
                       instance=instance_name,
                       seed=seed,
                       cutoff=run_time)
    tracer.write_to('output/')
コード例 #17
0
    def __init__(self, loggingServer, loggingDb, loggingUsername,
                 loggingPassword, instanceUsername, instancePassword,
                 storageAccountKey, environment):
        self.loggingServerName = loggingServer
        self.loggingDatabaseName = loggingDb
        self.loggingUsername = loggingUsername
        self.loggingPassword = loggingPassword
        self.instanceUsername = instanceUsername
        self.instancePassword = instancePassword
        self.storageAccountKey = storageAccountKey
        self.environment = environment

        self.tracer = Tracer(loggingServer, loggingDb, loggingUsername,
                             loggingPassword, environment)

        self.orch = Orchestrator(loggingServer, loggingDb, loggingUsername,
                                 loggingPassword, environment, self.tracer)
コード例 #18
0
def update_tracers(tracers, program_names):
    existing = set(tracers.keys())
    running = set(p.pid for p in process_iter()
                  if process_matches(p, program_names))
    forbidden = set(t.gdb.process.pid
                    for t in tracers.itervalues()).union(set([getpid()]))
    running -= forbidden
    new = running - existing
    finished = existing - running

    for pid in finished:
        del tracers[pid]

    for pid in new:
        try:
            tracers[pid] = Tracer(pid)
        except (NoSuchProcess, AccessDenied):
            pass
コード例 #19
0
def marzullo_stream(threshold):
    global start
    global end

    start = time.perf_counter()

    # Initialize our cache
    cache = IntervalCache(100000, threshold)

    trace = Tracer()

    def generateTransaction(min, max):
        cache.add(min, max)

    trace.start(generateTransaction)

    end = time.perf_counter()

    return cache
コード例 #20
0
def get_data():
    try:
        port = FakePort(fake)
        tracer = Tracer(0x16)
        t_ser = TracerSerial(tracer, port)
        t_ser.send_command(0xA0)
        #data = t_ser.receive_result(36)
        data = t_ser.receive_result()
        # operating parameters
        batt_voltage = data.batt_voltage
        batt_full_voltage = data.batt_full_voltage
        batt_overdischarge_voltage = data.batt_overdischarge_voltage
        batt_temp = data.batt_temp
        pv_voltage = data.pv_voltage
        charge_current = data.charge_current
        load_on = data.load_on
        load_amps = data.load_amps
        load_overload = data.load_overload
        load_short = data.load_short
        batt_overdischarge = data.batt_overdischarge
        batt_full = data.batt_full
        batt_overload = data.batt_overload
        batt_charging = data.batt_charging

        return render_template(
            'data.html',
            batt_voltage=batt_voltage,
            batt_full_voltage=batt_full_voltage,
            batt_overdischarge_voltage=batt_overdischarge_voltage,
            batt_temp=batt_temp,
            pv_voltage=pv_voltage,
            charge_current=charge_current,
            load_on=load_on,
            load_amps=load_amps,
            load_overload=load_overload,
            load_short=load_short,
            batt_overdischarge=batt_overdischarge,
            batt_full=batt_full,
            batt_overload=batt_overload,
            batt_charging=batt_charging)

    except (IndexError, IOError) as e:
        return jsonify({'error': str(e)}), 503
コード例 #21
0
print(sue.pay())

print(bob.name)
print(bob.pay())
print([bob.fetches, sue.fetches])


##################################################
from tracer import Tracer        # In module tracer.py
@Tracer
class MyList(list): pass         # MyList = Tracer(MyList)

x = MyList([1, 2, 3])            # will call Wrapper()
x.append(4)                      # will call __getattr__, append
x.wrapped
WrapList = Tracer(list)          # Handmade decoration
x = WrapList([4, 5, 6])
x.append(7)
x.wrapped


##################################################
class Tracer:
    def __init__(self, aClass):      # At the stage of decoration @
        self.aClass = aClass         # Uses attributes of an instance
    def __call__(self, *args, **kwargs):       # At the stage of an instance creation
        self.wrapped = self.aClass(*args, **kwargs)     # THE ONLY ONE (RECENT) INSTANCE FOR EACH CLASS!
        return self
    def __getattr__(self, attrname):
        print('Trace: ' + attrname)
        return getattr(self.wrapped, attrname)
コード例 #22
0
ファイル: test.py プロジェクト: dj44/tracerarduinoread
 def setUp(self):
     self.t = Tracer(16)
コード例 #23
0
    def processAlgorithm(self, parameters, context, feedback):
        try:
            dir_path = os.path.dirname(os.path.realpath(__file__))
            sys.path.insert(0, dir_path)
            import porepy as pp
            import numpy as np
            import scipy.sparse as sps
            import flow as f
            from fcts import read_cart_grid, bc_flag, argsort_cart_grid
            from tracer import Tracer
        except Exception as e:
            feedback.reportError(
                QCoreApplication.translate('Error', '%s' % (e)))
            feedback.reportError(QCoreApplication.translate('Error', ''))
            feedback.reportError(
                QCoreApplication.translate(
                    'Error', 'Please install porepy dependencies'))
            return {}

        #Parameters
        layer = self.parameterAsLayer(parameters, self.Grid, context)
        xx = self.parameterAsString(parameters, self.xx, context)
        xy = self.parameterAsString(parameters, self.xy, context)
        yy = self.parameterAsString(parameters, self.yy, context)
        steps = self.parameterAsInt(parameters, self.steps, context)
        end = self.parameterAsDouble(parameters, self.end, context) * pp.SECOND
        dV = self.parameterAsInt(parameters, self.Direction, context)
        tol = 1e-4 * pp.METER
        lP = parameters[self.lowPressure] * pp.PASCAL
        hP = parameters[self.highPressure] * pp.PASCAL
        mu = 1e-3 * pp.PASCAL * pp.SECOND  #Define here the dynamic viscosity of the liquid phase in [Pa s]

        if dV == 0:
            direction = "left_to_right"
        elif dV == 1:
            direction = "right_to_left"
        elif dV == 2:
            direction = "bottom_to_top"
        else:
            direction = "top_to_bottom"

        try:
            field_check = layer.fields().indexFromName('Rotation')
            if field_check == -1:
                feedback.reportError(
                    QCoreApplication.translate(
                        'Error',
                        'Invalid Contour Grid layer - please run the contour grid tool prior to the 2D Flow tool'
                    ))
                return {}

        except Exception:
            feedback.reportError(
                QCoreApplication.translate(
                    'Error',
                    'No attribute table found. Do not use the "Selected features only" option'
                ))
            return {}

        if lP > hP:
            feedback.reportError(
                QCoreApplication.translate(
                    'Error',
                    'Low pressure value is higher than high pressure value.'))
            return {}
        newFields = [
            'Pressure', 'Flux', 'Azimuth', 'Tracer', 'StartTime', 'EndTime',
            'Step'
        ]

        fields = QgsFields()
        for field in layer.fields():
            if field.name() not in newFields:
                fields.append(QgsField(field.name(), field.type()))

        for field in newFields[:-3]:
            fields.append(QgsField(field, QVariant.Double))
        fields.append(QgsField('StartTime', QVariant.DateTime))
        fields.append(QgsField('EndTime', QVariant.DateTime))
        fields.append(QgsField('Step', QVariant.Double))

        (writer, dest_id) = self.parameterAsSink(parameters, self.outGrid,
                                                 context, fields,
                                                 QgsWkbTypes.Polygon,
                                                 layer.sourceCrs())

        #Define xx,yy and xy perm
        kxx = []
        kyy = []
        kxy = []

        #Get dictionary of features
        features = {
            feature['Sample_No_']: feature
            for feature in layer.selectedFeatures()
        }
        if len(features) == 0:
            features = {
                feature['Sample_No_']: feature
                for feature in layer.getFeatures()
            }
            extent = layer.extent()
        else:
            extent = layer.boundingBoxOfSelected()
        total = len(features)

        if total == 0:
            feedback.reportError(
                QCoreApplication.translate(
                    'Error', 'No grid cells found in the input dataset'))
            return {}

        c = 0

        # Sort data by Sample No
        features = collections.OrderedDict(sorted(features.items()))
        W = False
        for FID, feature in features.items():
            c += 1
            if total != -1:
                feedback.setProgress(int(c * total))

            xxV, yyV, xyV = feature[xx], feature[yy], feature[xy]
            if xxV == 0 and yyV == 0 and xyV == 0:
                feedback.reportError(
                    QCoreApplication.translate(
                        'Info',
                        'Warning: Grid sample no. %s contains a pereambility of 0 for XX, XY and YY'
                        % (FID)))
                W = True

            kxx.append(xxV * pp.MILLIDARCY)
            kyy.append(yyV * pp.MILLIDARCY)
            kxy.append(xyV * pp.MILLIDARCY)

            if type(xxV) != float or type(xyV) != float or type(yyV) != float:
                feedback.reportError(
                    QCoreApplication.translate(
                        'Info',
                        'Warning: Grid sample no. %s contains non-float values for pereambility measurements'
                        % (FID)))
                W = True
        if W:
            feedback.reportError(
                QCoreApplication.translate(
                    'Info',
                    'Invalid permeability measurements created an empty 2D flow grid!'
                ))
            return {}

        kxx, kyy, kxy = np.array(kxx), np.array(kyy), np.array(kxy)

        rotation = feature['Rotation']
        spacing = feature['Spacing']

        P = 10  #Precision
        #Read grid geometry

        extentGeom = QgsGeometry.fromRect(extent)
        extentGeom = extentGeom.orientedMinimumBoundingBox()

        dWidth = round(extentGeom[4], P)
        dHeight = round(extentGeom[3], P)  #Domain width and height

        Ny = round(dHeight / spacing)
        Nx = round(dWidth / spacing)

        count = Nx * Ny
        if count != c:
            feedback.reportError(
                QCoreApplication.translate(
                    'Warning',
                    'Warning: Selected contour grid does not appear to be a rectangle.'
                ))
            feedback.reportError(QCoreApplication.translate('Warning', ''))

        # Read the grid
        gb = read_cart_grid(Nx, Ny, dWidth, dHeight)

        feedback.pushInfo(
            QCoreApplication.translate(
                'Output',
                'Constructing grid with %s columns and %s rows a domain size (width x height) of %s x %s.'
                % (Nx, Ny, dWidth, dHeight)))

        # mask that map the permeability from qgis to pp, and vice-versa
        mask, inv_mask = argsort_cart_grid(Nx, Ny)

        param_flow = {
            "tol": tol,
            "kxx": kxx[mask] / mu,
            "kyy": kyy[mask] / mu,
            "kxy": kxy[mask] / mu,
            "flow_direction": direction,
            "low_value": lP,
            "high_value": hP,
            "north": np.array([0, 1, 0]),
        }
        try:
            flow = f.Flow(gb)
            flow.set_data(param_flow, bc_flag)
            flow.solve()
        except Exception as e:
            feedback.reportError(QCoreApplication.translate('Error', str(e)))
            return {}

        if steps > 1:
            param_tracer = {
                "tol": tol,
                "num_steps": steps,
                "end_time": end,
                "flow_direction": direction,
                "low_value": lP,
                "high_value": hP
            }

            tracer = Tracer(gb)
            tracer.set_data(param_tracer, bc_flag)
            tracer.solve()

        t = []
        for g, d in gb:
            p = d[pp.STATE][flow.pressure]
            v = d[pp.STATE][flow.norm_flux]
            a = d[pp.STATE][flow.azimuth]
            if steps > 1:
                for time_step, current_time in enumerate(tracer.all_time):
                    var_name = tracer.variable + "_" + str(time_step)
                    traceD = d[pp.STATE][var_name]
                    traceD = traceD[inv_mask]
                    t.append(traceD)

        #Reshape the output data
        p = p[inv_mask]
        v = v[inv_mask]
        a = a[inv_mask]

        feedback.pushInfo(
            QCoreApplication.translate('Output', 'Updating Feature Layer'))

        #Update the dataset
        fet = QgsFeature()
        for enum, FID in enumerate(features):
            feature = features[FID]
            FID = feature.id()
            geom = feature.geometry()
            if total != -1:
                feedback.setProgress(int(enum * total))

            rows = []
            for field in layer.fields():
                if field.name() not in newFields:
                    rows.append(feature[field.name()])

            aV = math.degrees(float(a[enum])) + rotation
            if type(aV) == float:
                aV %= 360
            if dV < 2:
                if aV < 180:
                    aV += 180
                else:
                    aV -= 180

            rows.extend([
                round(float(p[enum]), P),
                round(float(v[enum]), P),
                round(float(aV), 2)
            ])

            if steps > 1:

                time = datetime.datetime(1, 1, 1, 0, 0, 0)
                deltaTime = datetime.timedelta(seconds=end / steps)

                for n in range(len(t)):
                    newRows = rows.copy()
                    newRows.append(round(float(t[n][enum]), P))
                    newRows.append(str(time))
                    time += deltaTime
                    newRows.append(str(time))
                    newRows.append(int(n))

                    fet.setGeometry(geom)
                    fet.setAttributes(newRows)
                    writer.addFeature(fet, QgsFeatureSink.FastInsert)
            else:
                fet.setGeometry(geom)
                fet.setAttributes(rows)
                writer.addFeature(fet, QgsFeatureSink.FastInsert)

        return {self.outGrid: dest_id}
コード例 #24
0
ファイル: main.py プロジェクト: derekgeng15/COVIDTracer
post_parser.add_argument('lng', type=float, help='No lng given')
post_parser.add_argument('day', type=int, help='No Day given')
post_parser.add_argument('month', type=int, help='No Month Given')
post_parser.add_argument('year', type=int, help='No Year Given')
post_parser.add_argument('list', type=str, help='No help given')
post_parser.add_argument('covid', type=bool, help='No covid boolean given')

resource_fields = {
    'address': fields.String,
    'name': fields.String,
    'adjList': fields.String,
    'lat': fields.Float,
    'lng': fields.Float,
    'covid': fields.Boolean
}
tracer = Tracer(len(User.query.all()))


def sendWarning(ad):
    result = User.query.filter_by(address=ad).first()
    result.covid = True
    db.session.commit()


class DataBase(Resource):
    @marshal_with(resource_fields)
    def get(self, a):
        result = User.query.filter_by(address=a).first()
        if not result:
            abort(404, message='Address does not exists')
        return result
コード例 #25
0
ファイル: Flow1D.py プロジェクト: BjornNyberg/NetworkGT
    def processAlgorithm(self, parameters, context, feedback):
        try:
            dir_path = os.path.dirname(os.path.realpath(__file__))
            sys.path.insert(0, dir_path)
            import porepy as pp
            from flow import Flow_Model1
            from tracer import Tracer
            from fcts import read_network, bc_flag
            from math import ceil
            import numpy as np
        except Exception as e:
            feedback.reportError(
                QCoreApplication.translate('Error', '%s' % (e)))
            feedback.reportError(QCoreApplication.translate('Error', ''))
            feedback.reportError(
                QCoreApplication.translate(
                    'Error', 'Please install porepy dependencies'))
            return {}

        #Parameters
        layer = self.parameterAsLayer(parameters, self.Network, context)
        h = self.parameterAsDouble(parameters, self.boundSize,
                                   context) * pp.METER
        steps = self.parameterAsInt(parameters, self.steps, context)
        endv = self.parameterAsInt(parameters, self.end, context) * pp.SECOND
        tol = 1e-8 * pp.METER
        d = self.parameterAsInt(parameters, self.Direction, context)
        lP = parameters[self.lowPressure] * pp.PASCAL
        hP = parameters[self.highPressure] * pp.PASCAL
        mu = parameters[self.mu] * pp.PASCAL * pp.SECOND

        if d == 0:
            direction = "left_to_right"
        elif d == 1:
            direction = "right_to_left"
        elif d == 2:
            direction = "bottom_to_top"
        else:
            direction = "top_to_bottom"

        if lP > hP:
            feedback.reportError(
                QCoreApplication.translate(
                    'Error',
                    'Low pressure value is higher than high pressure value.'))
            return {}

        params = {'INPUT': layer, 'OUTPUT': 'memory:'}
        explode = st.run("native:explodelines",
                         params,
                         context=context,
                         feedback=feedback)

        layer2 = explode['OUTPUT']

        #Create new field to fracture line
        newFields = [
            'ID', 'Pressure', 'Flux', 'Azimuth', 'Tracer', 'StartTime',
            'EndTime'
        ]

        if layer.fields().indexFromName('Transmisiv') == -1:
            feedback.reportError(
                QCoreApplication.translate(
                    'Error',
                    'Please calculate the transmissivity using the Aperture tool or define a new transmissivity field labelled "Transmisiv" in mD.m'
                ))
            return {}

        fields = QgsFields()

        for field in layer.fields():
            if field.name() not in newFields:
                fields.append(QgsField(field.name(), field.type()))

        for field in newFields[:-2]:
            fields.append(QgsField(field, QVariant.Double))
        fields.append(QgsField('StartTime', QVariant.DateTime))
        fields.append(QgsField('EndTime', QVariant.DateTime))

        (writer, dest_id) = self.parameterAsSink(parameters, self.outLine,
                                                 context, fields,
                                                 QgsWkbTypes.LineString,
                                                 layer.sourceCrs())

        #Define fracture geometries
        outDir = os.path.join(tempfile.gettempdir(), 'PorePy')
        if not os.path.exists(outDir):
            os.mkdir(outDir)
        fname = ''.join(
            random.choice(string.ascii_lowercase) for i in range(10))
        outName = os.path.join(outDir, '%s.txt' % (fname))

        k, l = {}, {
        }  #k is the pereambility in m2, l is the fracture length in m
        data = {}

        P = 1000000  #Tolerance for the point precision

        feedback.pushInfo(
            QCoreApplication.translate('Info', 'Reading Fracture Network'))
        field_check = layer2.fields().indexFromName('origLen')
        if field_check != -1:
            feedback.reportError(
                QCoreApplication.translate(
                    'Info',
                    'Warning: Applying the origLen field to calculate fracture length'
                ))
        W = False
        with open(outName, 'w') as f:
            f.write('ID,startx,starty,endx,endy')
            f.write('\n')
            for enum, feature in enumerate(layer2.getFeatures()):
                try:
                    geom = feature.geometry().asPolyline()
                except Exception:
                    geom = feature.geometry().asMultiPolyline()[0]
                start, end = geom[0], geom[-1]

                startx, endx = ceil(start.x() * P) / P, ceil(end.x() * P) / P
                starty, endy = ceil(start.y() * P) / P, ceil(end.y() * P) / P

                t = feature['Transmisiv']
                if t == 0:
                    W = True

                if field_check != -1:
                    lValue = feature['origLen']
                    if type(lValue) != float:
                        feedback.reportError(
                            QCoreApplication.translate(
                                'Info',
                                'Warning: origLen field contains non-float values'
                            ))
                        return {}
                    l[feature.id()] = lValue / feature.geometry().length()
                else:
                    l[feature.id()] = feature.geometry().length()

                if type(t) != float:
                    feedback.reportError(
                        QCoreApplication.translate(
                            'Info',
                            'Warning: Transmisivity field contains non-float values'
                        ))
                    return {}

                k[feature.id()] = t * pp.MILLIDARCY * pp.METER

                row = '%s,%s,%s,%s,%s' % (feature.id(), startx, starty, endx,
                                          endy)
                f.write(row)  #ID,startx,starty,endx,endy
                f.write('\n')

                rows = []
                for field in layer.fields():
                    if field.name() not in newFields:
                        rows.append(feature[field.name()])
                data[feature.id()] = rows

        if len(data) == 0:
            feedback.reportError(
                QCoreApplication.translate(
                    'Info', 'No fractures found in the input dataset'))
            return {}
        elif enum > 2000:
            feedback.reportError(
                QCoreApplication.translate(
                    'Info',
                    'Warning - Fracture network exceeds 2000 branches. To improve performance consider subsampling and/or simplifying the Fracture Network using the "Simplify Network" tool.'
                ))

        if W:
            feedback.reportError(
                QCoreApplication.translate(
                    'Info',
                    'Warning - Transmisivity value(s) of 0 in the fracture network will not produce flow'
                ))

        network, mask, pts_shift = read_network(outName, tol=tol)

        mesh_args = {
            "mesh_size_frac": h,
            "mesh_size_bound": h,
            'file_name': outDir
        }

        feedback.pushInfo(
            QCoreApplication.translate('Info',
                                       'Creating Mesh from %s' % (network)))

        try:
            gb = network.mesh(
                mesh_args,
                dfn=True,
                tol=tol,
            )
        except Exception as e:
            feedback.reportError(QCoreApplication.translate('Info', str(e)))
            feedback.reportError(QCoreApplication.translate('Info', ''))
            feedback.reportError(
                QCoreApplication.translate(
                    'Info',
                    'Failure creating the fracture network mesh. Please check that NetworkGT was properly configured to use gmsh meshing according to the installation guidelines'
                ))
        flow = Flow_Model1(gb)

        param_flow = {
            "tol": tol,
            "k": np.array([k[m] for m in mask]) / mu,
            "length_ratio": np.array([l[m] for m in mask]),
            "flow_direction": direction,
            "low_value": lP,
            "high_value": hP,
            "north": np.array([0, 1, 0])
        }

        param_tracer = {
            "tol": tol,
            "num_steps": steps,
            "end_time": endv,
            "flow_direction": direction,
            "low_value": lP,
            "high_value": hP
        }

        flow.set_data(param_flow, bc_flag)

        feedback.pushInfo(
            QCoreApplication.translate('Info', 'Solving Fluid Flow'))
        flow.solve()

        # get the results for qgis
        if steps > 1:
            feedback.pushInfo(
                QCoreApplication.translate('Info', 'Solving Tracer'))
            tracer = Tracer(gb)
            tracer.set_data(param_tracer, bc_flag)
            tracer.solve()

        feedback.pushInfo(
            QCoreApplication.translate('Info', 'Creating Feature Layer'))
        fet = QgsFeature()
        for g, d in gb:
            # avoid to consider the 0d grids
            if g.dim == 0:
                continue

            # get the data for the current grid
            p = d[pp.STATE][flow.pressure]
            norm_flux = d[pp.STATE][flow.norm_flux]
            azimuth = d[pp.STATE][flow.azimuth]

            # get the cell to nodes map
            cell_nodes = g.cell_nodes()
            indptr = cell_nodes.indptr
            indices = cell_nodes.indices

            # all the data that need to be exported are given as cell_SOMETHING
            for c in np.arange(g.num_cells):
                nodes_loc = indices[indptr[c]:indptr[c + 1]]
                # each column gives a node for the segment
                # NOTE: the nodes are translated compared to the original network
                pnt = g.nodes[:2, nodes_loc] + pts_shift
                # value of the computed fields
                cell_pressure = p[c]
                # flux norm
                cell_norm_flux = norm_flux[c]
                # the fracture id and data
                cell_frac_id = mask[g.frac_num]
                rows = data[cell_frac_id].copy()
                # value of the azimuth
                # NOTE: velocity zero gives nan as azimuth angle
                cell_azimuth = math.degrees(azimuth[c])

                if cell_norm_flux == 0:
                    rows.extend([
                        float(cell_frac_id),
                        float(cell_pressure),
                        float(cell_norm_flux), NULL
                    ])
                else:
                    #cell_azimuth %= 360
                    rows.extend([
                        float(cell_frac_id),
                        float(cell_pressure),
                        float(cell_norm_flux),
                        float(cell_azimuth)
                    ])

                points = [
                    QgsPointXY(pnt[0][0], pnt[1][0]),
                    QgsPointXY(pnt[0][1], pnt[1][1])
                ]
                geom = QgsGeometry.fromPolylineXY(points)
                fet.setGeometry(geom)

                if steps > 1:

                    time = datetime.datetime(1, 1, 1, 0, 0, 0)
                    deltaTime = datetime.timedelta(seconds=endv / steps)

                    for time_step, current_time in enumerate(tracer.all_time):
                        var_name = tracer.variable + "_" + str(time_step)
                        tr = d[pp.STATE][var_name]
                        cell_tracer = tr[c]

                        newRows = rows.copy()
                        newRows.append(float(round(cell_tracer, 6)))
                        newRows.append(str(time))
                        time += deltaTime
                        newRows.append(str(time))

                        fet.setAttributes(newRows)
                        writer.addFeature(fet, QgsFeatureSink.FastInsert)
                else:
                    fet.setAttributes(rows)
                    writer.addFeature(fet, QgsFeatureSink.FastInsert)

        try:
            os.remove(outName)  #Delete temp csv file
        except Exception:
            pass

        return {self.outLine: dest_id}
コード例 #26
0
intruder_type = intruder.NonFlocker

FPR = np.zeros((3, 2))
TPR = np.zeros((3, 2))
for i in range(0, len(layouts)):
    layout = layouts[i]
    for j in range(0, len(intruders)):
        intruder_type = intruders[j]
        TPRs = []
        FPRs = []
        for k in range(0, 3):
            w = layout(width, height, good_count, bad_count, p_std, v_std,
                       intruder_type)
            w.positions = [pygame.Vector2(0, 0)] * bird_count

            charter = Tracer(width, 10, 100, good_count, bad_count)

            for step in range(0, layout_time[i]):
                w.update(1)
                charter.track(w)
            P = charter.TP + charter.FN
            N = charter.TN + charter.FP
            FPRs.append(charter.FP / N)
            TPRs.append(charter.TP / P)
        TPR[i][j] = sum(TPRs) / len(TPRs)
        FPR[i][j] = sum(FPRs) / len(FPRs)
        print(i, j)

for j in range(0, len(intruders)):
    print('\\multirow{2}{5em}{Nonflocker} & TPR &', end='')
    for i in range(0, len(layouts)):
コード例 #27
0
ファイル: main.py プロジェクト: kiraka42/Raytracing
    ], Camera(np.array([3, 2, 4]), np.array([-1, 0.5, 0])))


def create_bonus():
    return Scene([
        Plan(np.array([0, 1, 0]), 0, CheckSurface()),
        Sphere(MirrorSurface(), np.array([0, 1, -0.25]), 1),
        Sphere(RedSurface(), np.array([-1, 0.5, 1.5]), 0.5)
    ], [
        Light(np.array([-2, 2.5, 0]), np.array([0.8, 0.8, 0.8])),
        Light(np.array([1.5, 2.5, 1.5]), np.array([0.8, 0.8, 0.8]))
    ], Camera(np.array([3, 2, 4]), np.array([-1, 0.5, 0])))


width = 250
height = 250

img = Image.new('RGB', (width, height), "black")
pixels = img.load()

start = time.time()
tracer = Tracer(5)
tracer.render(create_def(), pixels, width, height)

end = time.time()

print("Time spent : {}".format(end - start))
img.show()

img.save("result.bmp")
コード例 #28
0
def init():
   global tracer_serial, query
   port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=1)
   tracer = Tracer(0x16)
   tracer_serial = TracerSerial(tracer, port)
   query = QueryCommand()
コード例 #29
0
ファイル: app.py プロジェクト: ellefsen/solar-app
from flask import Flask, jsonify
from time import sleep
from serial import Serial

import sys
sys.path.append('/app/tracer/python')
from tracer import Tracer, TracerSerial, QueryCommand

port = Serial('/dev/ttyAMA0', 9600, timeout=1)
port.flushInput()
port.flushOutput()
tracer = Tracer(0x16)
t_ser = TracerSerial(tracer, port)
query = QueryCommand()

# Rest API
app = Flask(__name__)

@app.route('/', methods=['GET'])
def get_data():
    try:
        t_ser.send_command(query)
        data = t_ser.receive_result()

        return jsonify(batt_voltage=data.batt_voltage,
                       pv_voltage=data.pv_voltage,
                       charge_current=data.charge_current,
                       load_amps=data.load_amps)

    except (IndexError, IOError) as e:
        port.flushInput()
コード例 #30
0
ファイル: tracer-tk.py プロジェクト: Maltergate/Tracer
        def accept(self, event=None):
            self.accepted = True
            self.close()

        @staticmethod
        def get_band_n_rate(oldband, oldrate, parent=None):
            popup = TkTracerWindow.BandAndRateWindow(oldband, oldrate, parent)
            popup.window.grab_set()
            popup.window.wait_window(popup.window)
            if popup.accepted:
                try:
                    if len(popup.band_value) != 0:
                        int(popup.band_value)
                    float(popup.rate_value)
                except ValueError:
                    messagebox.showerror('Error', 'Bad entry !')
            return popup.accepted, popup.band_value, popup.rate_value


if __name__ == '__main__':

    main_tracer = Tracer()
    main_tracer.run(show=False)

    app = tk.Tk()

    main_window = TkTracerWindow(app, main_tracer)

    app.mainloop()