Esempio n. 1
0
def calculateDist(dist):
    listInit = np.zeros(len(dist))
    listFin = np.zeros(len(dist))
    listDist = np.zeros(len(dist))

    for i in range(len(dist)):
        listInit[i] = dist[i].inicio
        listFin[i] = dist[i].fin
        listDist[i] = dist[i].distancia

    gaussInit = ndimage.gaussian_filter1d(listInit, 20)
    gaussFin = ndimage.gaussian_filter1d(listFin, 20)

    distancias = np.abs(np.subtract(gaussFin, gaussInit))
    for i in range(len(distancias)):
        dist[i].distanciaSuav = distancias[i]

    dist2 = []
    for i in range(len(dist)):
        dist2.append(
            positions.Positions(dist[i].colum, dist[i].inicio, dist[i].fin))
        dist2[i].distanciaSuav = dist[i].distanciaSuav

    calcularErro2(dist2)
    dt, ml = desviacionTipica(dist)
    return listDist, distancias, dt, ml
    def test_a_from_d(self):
        "Test the Puzzle object creation from text where we need to move the A from the D room"

        # 1. Create Positions object from text
        myobj = positions.Positions(text=A_FROM_D)

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 19)
        self.assertEqual(myobj.hall_len, 11)
        self.assertEqual(myobj.room_len, 2)
        self.assertEqual(myobj.room_num, 4)
        self.assertEqual(myobj.spaces, list(A_FROM_D))
        self.assertEqual(myobj.doorways, EXAMPLE_DOORWAYS)
        self.assertEqual(myobj.homerooms, EXAMPLE_HOMEROOMS)

        # 3. Check methods
        self.assertEqual(myobj.doorway_for_room(18), 8)
        self.assertEqual(myobj.can_leave_room(18), True)
        self.assertEqual(myobj.moves_from_room(18), [9, 10])
        self.assertEqual(myobj.moves_from(18), [9, 10])
        self.assertEqual(myobj.all_moves(who='A'), [(18, 9), (18, 10)])
        self.assertEqual(myobj.steps((18, 9)), 3)
        self.assertEqual(myobj.cost((18, 9)), 3)
        self.assertEqual(myobj.execute((18, 9)), ".....D.D.A.BAC.BC..")
Esempio n. 3
0
def countPx(img):
    filas, columnas = img.shape
    out = img.copy()
    totalPX = 0
    valueComunas = np.zeros(columnas)
    dist = []

    for i in range(columnas):
        countR1 = 0
        posInit = 0
        blanco = True
        for j in range(filas):
            if (img[j][i] == 0): blanco = False
            if (blanco): continue

            if (img[j][i] == 255):
                break
            if (countR1 == 0):
                posInit = j
            totalPX = totalPX + 1
            countR1 = countR1 + 1
            out[j][i] = 255

        dist.append(positions.Positions(i, posInit, posInit + countR1))
        valueComunas[i] = countR1

    return out, dist
    def test_one_move(self):
        "Test the Puzzle object creation from text that needs only one move"

        # 1. Create Positions object from text
        myobj = positions.Positions(text=ONE_MOVE)

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 19)
        self.assertEqual(myobj.hall_len, 11)
        self.assertEqual(myobj.room_len, 2)
        self.assertEqual(myobj.room_num, 4)
        self.assertEqual(myobj.spaces, list(ONE_MOVE))
        self.assertEqual(myobj.doorways, EXAMPLE_DOORWAYS)
        self.assertEqual(myobj.homerooms, EXAMPLE_HOMEROOMS)

        # 3. Check methods
        self.assertEqual(myobj.can_enter_room('A', 13), False)
        self.assertEqual(myobj.can_enter_room('A', 11), True)
        self.assertEqual(myobj.moves_from_hall(9, who='A'), [11])
        self.assertEqual(myobj.moves_from(9, who='A'), [11])
        self.assertEqual(myobj.all_moves(), [(9, 11)])
        self.assertEqual(myobj.steps((9, 11)), 8)
        self.assertEqual(myobj.cost((9, 11)), 8)
        self.assertEqual(myobj.execute((9, 11)), SOLUTION)
    def test_text_init(self):
        "Test the Positions object creation from text"

        # 1. Create Positions object from text
        myobj = positions.Positions(text=EXAMPLE_TEXT)

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 19)
        self.assertEqual(myobj.hall_len, 11)
        self.assertEqual(myobj.room_len, 2)
        self.assertEqual(myobj.room_num, 4)
        self.assertEqual(myobj.spaces, list(EXAMPLE_TEXT))
        self.assertEqual(myobj.doorways, EXAMPLE_DOORWAYS)
        self.assertEqual(myobj.homerooms, EXAMPLE_HOMEROOMS)

        # 3. Check methods
        self.assertEqual(str(myobj), EXAMPLE_TEXT)
        self.assertEqual(myobj.display(), EXAMPLE_DISPLAY)

        self.assertEqual(myobj.are_all_home(), False)
        self.assertEqual(myobj.frozen(), [12, 16])
        self.assertEqual(myobj.doorway_for_who('A'), 2)
        self.assertEqual(myobj.doorway_for_who('C'), 6)
        self.assertEqual(myobj.hall_steps([0, 11], who='A'), 3)
        self.assertEqual(myobj.hall_steps([0, 12], who='A'), 4)
        self.assertEqual(myobj.hall_steps([7, 11], who='A'), 6)
        self.assertEqual(myobj.hall_steps([7, 12], who='A'), 7)
        self.assertEqual(myobj.hall_steps([9, 11], who='A'), 8)
        self.assertEqual(myobj.room_steps([12, 7]), 7)
        self.assertEqual(myobj.room_steps([13, 3]), 2)
        self.assertEqual(myobj.steps([9, 11], who='A'), 8)
        self.assertEqual(myobj.steps([13, 3], who='B'), 2)
        self.assertEqual(myobj.steps([13, 12], who='A'), 5)
        self.assertEqual(myobj.cost([9, 18], who='D'), 3000)

        self.assertEqual(myobj.moves_from_room(11), [0, 1, 3, 5, 7, 9, 10])

        self.assertEqual(myobj.all_moves(who='A'), [])
        self.assertEqual(myobj.all_moves(who='B'), [(11, 0), (11, 1), (11, 3),
                                                    (11, 5), (11, 7), (11, 9),
                                                    (11, 10), (15, 0), (15, 1),
                                                    (15, 3), (15, 5), (15, 7),
                                                    (15, 9), (15, 10)])
        self.assertEqual(myobj.all_moves(who='C'), [(13, 0), (13, 1), (13, 3),
                                                    (13, 5), (13, 7), (13, 9),
                                                    (13, 10)])
        self.assertEqual(myobj.all_moves(who='D'), [(17, 0), (17, 1), (17, 3),
                                                    (17, 5), (17, 7), (17, 9),
                                                    (17, 10)])
Esempio n. 6
0
    def organize(self, verbose=False):
        "Organize the amphipods into their proper rooms"

        # 1. Make sure there is a burrow
        if not self.burrow:
            return None

        # 2. Have to start somewhere
        pos = positions.Positions(text=self.burrow.positions(),
                                  part2=self.part2)
        queue = [State(cost=0, text=str(pos))]
        result = 1000 * 16
        if self.part2:
            result *= 3

        # 3. Loop with there is something to do
        while queue:

            # 4. Take an entry off the queue
            current = queue.pop()
            # print("q=%4d c=%5d t=%s" % (len(queue), current.cost, current.text))

            # 5. Create the position
            pos.spaces = list(current.text)

            # 6. Are we done yet?
            if pos.are_all_home():
                if current.cost < result:
                    result = current.cost
                    if verbose:
                        print("New cost=%s, queue=%d" % (result, len(queue)))
                continue

            # 7. Is this state unproductive?
            if current.cost > result:
                continue

            # 8. Get all of the possible move from here
            moves = pos.all_moves()

            # 9. Add all of those moves
            for move in moves:
                new_position = pos.execute(move)
                queue.append(
                    State(cost=current.cost + pos.cost(move),
                          text=new_position))

        # 10. Return the total cost of moving the amphipods
        return result
    def test_empty_init(self):
        "Test the default Positions creation"

        # 1. Create default Positions object
        myobj = positions.Positions()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)
        self.assertEqual(myobj.hall_len, 11)
        self.assertEqual(myobj.room_len, 2)
        self.assertEqual(myobj.room_num, 4)
        self.assertEqual(myobj.spaces, EXAMPLE_VALUES)
        self.assertEqual(myobj.doorways, EXAMPLE_DOORWAYS)
        self.assertEqual(myobj.homerooms, EXAMPLE_HOMEROOMS)
Esempio n. 8
0
    def do_one_tick(self):
        positions.Positions()
        self.world.update()
        self.world.latest_input_image.save("tmp/window.bmp")

        self.c1.delete()
        self.bmpimg = ImageTk.PhotoImage(self.world.latest_input_image)
        self.c1.create_image(0, 0, image=self.bmpimg, anchor=tk.NW)
        self.c1.pack(expand=True)

        self.mini = ImageTk.PhotoImage(self.world.minimap.latest_minimap)

        # print("mini: ", self.mini.width(), self.mini.height())
        self.c2.create_image(0, 0, image=self.mini, anchor=tk.NW)
        self.mini2 = ImageTk.PhotoImage(self.world.minimap.latest_result_map)
        # self.c2.create_image(self.mini.width(), self.mini.height(), image = self.mini2, anchor = tk.SW)
        self.c2.create_image(0, self.mini.height(), image=self.mini2, anchor=tk.NW)

        self.pos_text.insert(1.0, str(self.world.minimap.pos) + "\n")

        self.gui.after(50, self.do_one_tick)
Esempio n. 9
0
    def __init__(self, parameters, parent=None):
        QtGui.QMainWindow.__init__(self, parent)

        # Coordinate system setup, the internal scale is 1 pixel is 100nm.
        coord.Point.pixels_to_um = 0.1

        # variables
        self.current_center = coord.Point(0.0, 0.0, "um")
        self.current_offset = coord.Point(0.0, 0.0, "um")
        self.debug = parameters.debug
        self.file_filter = "\S+.dax"
        self.parameters = parameters
        self.picture_queue = []
        self.regexp_str = ""
        self.requested_stage_pos = False
        self.stage_tracking_timer = QtCore.QTimer(self)
        self.taking_pictures = False
        self.snapshot_directory = self.parameters.directory
        self.spin_boxes = []
        self.stage_tracking_timer.setInterval(500)

        # ui setup
        self.ui = steveUi.Ui_MainWindow()
        self.ui.setupUi(self)

        # hide some things that we don't currently use & resize group-box.
        self.ui.backgroundComboBox.hide()
        self.ui.backgroundLabel.hide()
        self.ui.moveAllSectionsCheckBox.hide()
        self.ui.showFeaturesCheckBox.hide()
        self.ui.thresholdLabel.hide()
        self.ui.thresholdSlider.hide()
        self.ui.sectionViewSettingsGroupBox.setMaximumHeight(50)

        self.setWindowIcon(QtGui.QIcon("steve.ico"))

        # handling file drops
        self.ui.centralwidget.__class__.dragEnterEvent = self.dragEnterEvent
        self.ui.centralwidget.__class__.dropEvent = self.dropEvent
        self.ui.centralwidget.setAcceptDrops(True)

        # Create a validator for scaleLineEdit.
        self.scale_validator = QtGui.QDoubleValidator(1.0e-6, 1.0e+6, 6,
                                                      self.ui.scaleLineEdit)
        self.ui.scaleLineEdit.setValidator(self.scale_validator)

        # Initialize view.
        self.view = mosaicView.MosaicView(parameters, self.ui.mosaicFrame)
        layout = QtGui.QGridLayout(self.ui.mosaicFrame)
        layout.addWidget(self.view)
        self.ui.mosaicFrame.setLayout(layout)
        self.view.show()

        # Initialize positions list.
        self.positions = positions.Positions(parameters, self.view.getScene(),
                                             self.ui.positionsFrame)
        layout = QtGui.QGridLayout(self.ui.positionsFrame)
        layout.addWidget(self.positions)
        self.ui.positionsFrame.setLayout(layout)
        self.positions.show()

        # Initialize sections.
        self.sections = sections.Sections(parameters, self.view.getScene(),
                                          self.ui.sectionsDisplayFrame,
                                          self.ui.sectionsScrollArea,
                                          self.ui.sectionsTab)

        # Initialize communications.
        self.comm = capture.Capture(parameters)

        # signals
        self.ui.actionQuit.triggered.connect(self.quit)
        self.ui.actionAdjust_Contrast.triggered.connect(
            self.handleAdjustContrast)
        self.ui.actionDelete_Images.triggered.connect(self.handleDeleteImages)
        self.ui.actionLoad_Movie.triggered.connect(self.handleLoadMovie)
        self.ui.actionLoad_Mosaic.triggered.connect(self.handleLoadMosaic)
        self.ui.actionLoad_Positions.triggered.connect(
            self.handleLoadPositions)
        self.ui.actionSave_Mosaic.triggered.connect(self.handleSaveMosaic)
        self.ui.actionSave_Positions.triggered.connect(
            self.handleSavePositions)
        self.ui.actionSave_Snapshot.triggered.connect(self.handleSnapshot)
        self.ui.actionSet_Working_Directory.triggered.connect(
            self.handleSetWorkingDirectory)
        self.ui.foregroundOpacitySlider.valueChanged.connect(
            self.handleOpacityChange)
        self.ui.getStagePosButton.clicked.connect(self.handleGetStagePosButton)
        self.ui.imageGridButton.clicked.connect(self.handleImageGrid)
        self.ui.scaleLineEdit.textEdited.connect(self.handleScaleChange)
        self.ui.tabWidget.currentChanged.connect(self.handleTabChange)
        self.ui.trackStageCheckBox.stateChanged.connect(self.handleTrackStage)
        self.ui.xSpinBox.valueChanged.connect(self.handleGridChange)
        self.ui.ySpinBox.valueChanged.connect(self.handleGridChange)

        self.stage_tracking_timer.timeout.connect(
            self.handleStageTrackingTimer)

        self.view.addPosition.connect(self.addPositions)
        self.view.addSection.connect(self.addSection)
        self.view.getObjective.connect(self.handleGetObjective)
        self.view.gotoPosition.connect(self.gotoPosition)
        self.view.mouseMove.connect(self.updateMosaicLabel)
        self.view.scaleChange.connect(self.updateScaleLineEdit)
        self.view.takePictures.connect(self.takePictures)

        self.sections.addPositions.connect(self.addPositions)
        self.sections.takePictures.connect(self.takePictures)

        self.comm.captureComplete.connect(self.addImage)
        self.comm.changeObjective.connect(self.handleChangeObjective)
        self.comm.disconnected.connect(self.handleDisconnected)
        self.comm.getPositionComplete.connect(self.handleGetPositionComplete)
        self.comm.newObjectiveData.connect(self.handleNewObjectiveData)
        self.comm.otherComplete.connect(self.handleOtherComplete)

        self.ui.objectivesGroupBox.valueChanged.connect(
            self.handleMOValueChange)

        # Try and get settings from HAL.
        self.comm.commConnect()
        self.comm.getSettings()
Esempio n. 10
0
    def __init__(self, parameters, parent=None):
        QtGui.QMainWindow.__init__(self, parent)

        # coordinate system setup
        coord.Point.pixels_to_um = parameters.pixels_to_um

        # variables
        self.current_center = coord.Point(0.0, 0.0, "um")
        self.current_magnification = 1.0
        self.current_objective = False
        self.current_offset = coord.Point(0.0, 0.0, "um")
        self.debug = parameters.debug
        self.parameters = parameters
        self.picture_queue = []
        self.taking_pictures = False

        # ui setup
        self.ui = steveUi.Ui_MainWindow()
        self.ui.setupUi(self)

        # hide some things that we don't currently use & resize group-box.
        self.ui.backgroundComboBox.hide()
        self.ui.backgroundLabel.hide()
        self.ui.moveAllSectionsCheckBox.hide()
        self.ui.showFeaturesCheckBox.hide()
        self.ui.thresholdLabel.hide()
        self.ui.thresholdSlider.hide()
        self.ui.sectionViewSettingsGroupBox.setMaximumHeight(50)

        self.setWindowIcon(QtGui.QIcon("steve.ico"))

        # Initialize objectives.
        objectives = []
        for i in range(10):
            mag = "mag" + str(i)
            if hasattr(self.parameters, mag):
                data = getattr(self.parameters, mag)
                obj_name = data.split(",")[0]
                objectives.append(data)
                self.ui.magComboBox.addItem(obj_name, data)

        # Create labels and spin boxes for objective settings.
        self.spin_boxes = []
        layout = QtGui.QGridLayout(self.ui.objectivesFrame)

        for i, label_text in enumerate(
            ["Objective", "Magnification", "X Offset", "Y Offset"]):
            text_item = QtGui.QLabel(label_text, self.ui.objectivesFrame)
            layout.addWidget(text_item, 0, i)

        # The first objective is assumed to be the 100x & is not adjustable.
        data = objectives[0].split(",")
        self.current_objective = data[0]
        for j, datum in enumerate(data):
            text_item = QtGui.QLabel(datum, self.ui.objectivesFrame)
            layout.addWidget(text_item, 1, j)

        # The other objectives are adjustable.
        for i, obj in enumerate(objectives[1:]):
            data = obj.split(",")
            text_item = QtGui.QLabel(data[0], self.ui.objectivesFrame)
            layout.addWidget(text_item, i + 2, 0)

            for j, btype in enumerate(["magnification", "xoffset", "yoffset"]):
                sbox = MagOffsetSpinBox(data[0], btype, float(data[j + 1]))
                layout.addWidget(sbox, i + 2, j + 1)
                sbox.moValueChange.connect(self.handleMOValueChange)
                self.spin_boxes.append(sbox)

        # Create a validator for scaleLineEdit.
        self.sce_validator = QtGui.QDoubleValidator(1.0e-6, 1.0e+6, 6,
                                                    self.ui.scaleLineEdit)
        self.ui.scaleLineEdit.setValidator(self.sce_validator)

        # Initialize view.
        self.view = mosaicView.MosaicView(parameters, self.ui.mosaicFrame)
        layout = QtGui.QGridLayout(self.ui.mosaicFrame)
        layout.addWidget(self.view)
        self.ui.mosaicFrame.setLayout(layout)
        self.view.show()

        # Initialize positions list.
        self.positions = positions.Positions(parameters, self.view.getScene(),
                                             self.ui.positionsFrame)
        layout = QtGui.QGridLayout(self.ui.positionsFrame)
        layout.addWidget(self.positions)
        self.ui.positionsFrame.setLayout(layout)
        self.positions.show()

        # Initialize sections.
        self.sections = sections.Sections(parameters, self.view.getScene(),
                                          self.ui.sectionsDisplayFrame,
                                          self.ui.sectionsScrollArea,
                                          self.ui.sectionsTab)

        # Initialize communications.
        self.comm = capture.Capture(parameters)

        # signals
        self.ui.abortButton.clicked.connect(self.handleAbort)
        self.ui.actionQuit.triggered.connect(self.quit)
        self.ui.actionDelete_Images.triggered.connect(self.handleDeleteImages)
        self.ui.actionLoad_Dax.triggered.connect(self.handleLoadDax)
        self.ui.actionLoad_Mosaic.triggered.connect(self.handleLoadMosaic)
        self.ui.actionLoad_Positions.triggered.connect(
            self.handleLoadPositions)
        self.ui.actionSave_Mosaic.triggered.connect(self.handleSaveMosaic)
        self.ui.actionSave_Positions.triggered.connect(
            self.handleSavePositions)
        self.ui.actionSave_Snapshot.triggered.connect(self.handleSnapshot)
        self.ui.actionSet_Working_Directory.triggered.connect(
            self.handleSetWorkingDirectory)
        self.ui.foregroundOpacitySlider.valueChanged.connect(
            self.handleOpacityChange)
        self.ui.magComboBox.currentIndexChanged.connect(
            self.handleObjectiveChange)
        self.ui.scaleLineEdit.textEdited.connect(self.handleScaleChange)
        self.ui.tabWidget.currentChanged.connect(self.handleTabChange)
        self.ui.xSpinBox.valueChanged.connect(self.handleGridChange)
        self.ui.ySpinBox.valueChanged.connect(self.handleGridChange)

        self.view.addPosition.connect(self.addPositions)
        self.view.addSection.connect(self.addSection)
        self.view.gotoPosition.connect(self.gotoPosition)
        self.view.mouseMove.connect(self.updateMosaicLabel)
        self.view.scaleChange.connect(self.updateScaleLineEdit)
        self.view.takePictures.connect(self.takePictures)

        self.sections.addPositions.connect(self.addPositions)
        self.sections.takePictures.connect(self.takePictures)

        self.comm.captureComplete.connect(self.addImage)
        self.comm.disconnected.connect(self.handleDisconnected)
        self.comm.gotoComplete.connect(self.handleGotoComplete)

        self.handleObjectiveChange(0)