Exemplo n.º 1
0
class Menu:
	'''Display menu and respond to choices when run.'''
	def __init__(self):
		self.montage = Montages()
		self.choices = {
		"1": self.montage_dir,
		"2": self.montage_from_csv,
		"3": self.img_scatter,
		"4": self.image_hist_from_csv,
		"5": self.quit
		}

	def display_menu(self):
		print("""
PyMontage Menu
1. Create montages from recursively from given directory and sub-directories
2. Create montages from provided CSV files (split by categories or bins)
3. Create image scatter plote from provided CSV file
4. Create image histogram from provided CSV file
5. Quit 
""")

	def run(self):
		'''Display the menu and responsd to choices'''
		while True:
			self.display_menu()
			choice = input("Enter an option: ")
			action = self.choices.get(str(choice))
			if action:
				action()
			else:
				print("{0} is not a valid choice".format(choice))

	def enter_dir(self, message = "Provide valid directory"):
		while True:
			provided_dir = raw_input(message)
			if os.path.isdir(provided_dir): break
			else: print("Not a valid directory")

		return provided_dir

	def montage_dir(self):
		input_dir = self.enter_dir("Provide full path to directory to create montages: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_dir, dest_path = output_dir)
		print("Creating montages...")
		created_montages = self.montage.montages_from_directory()
		for i, created_montage in enumerate(created_montages):
			created_montage.save(output_dir + "/montage-" + str(i) + ".jpg")
		print("Saving montages complete.")

	def enter_csv(self, message = "provide path to valid csv"):
		while True:
			provided_csv = raw_input(message)
			if os.path.isfile(provided_csv): break
			else: print("Not a valid file")

		return provided_csv

	def montage_from_csv(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating montages: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		print("Creating montages...")
		df = pd.read_csv(input_csv)
		created_montages = self.montage.binned_montage(df)
		for created_montage, bin_name in created_montages:
			created_montage.save(output_dir + "/montage-" + str(bin_name) + ".png")
		print("Saving montages complete.")


	def img_scatter(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating image scatter plot: ")
		output_dir = self.enter_dir("Provide full path and name to valid direcotry to save image scatter plot: ")
		print("Creating image scatter plot...")
		df = pd.read_csv(input_csv)
		created_img_scatter = self.montage.scatter(df)
		created_img_scatter.save(output_dir+"img-scatter.png")

	def image_hist_from_csv(self):
		input_CSV = self.enter_csv("Provide full path to csv file for creating image histogram: ")
		output_dir = self.enter_dir("Provide full path and fielname to  save image histogram: ")
		self.montage.input_data(src_path = input_CSV, dest_path = output_dir)
		print("Creating image histogram...")
		created_img_hist = self.montage.create_image_hist()
        	created_img_hist.save(output_dir+"hist.png")


	def quit(self):
		print("Good bye!")
		sys.exit(0)
Exemplo n.º 2
0
class Menu:
    '''Display menu and respond to choices when run.'''
    def __init__(self):
        self.montage = Montages()
        self.choices = {
            "1": self.montage_dir,
            "2": self.montage_from_csv,
            "3": self.vertical_montage_from_csv,
            "4": self.image_hist_from_csv,
            "5": self.quit
        }

    def display_menu(self):
        print("""
PyMontage Menu

1. Create montages from recursively from given directory and sub-directories
2. Create montages from provided CSV files (split by categories or bins)
3. Create vetical montge from provided CSV file
4. Create image histogram from provided CSV file
5. Quit 
""")

    def run(self):
        '''Display the menu and responsd to choices'''
        while True:
            self.display_menu()
            choice = input("Enter an option: ")
            action = self.choices.get(str(choice))
            if action:
                action()
            else:
                print("{0} is not a valid choice".format(choice))

    def enter_dir(self, message="Provide valid directory"):
        while True:
            provided_dir = raw_input(message)
            if os.path.isdir(provided_dir): break
            else: print("Not a valid directory")

        return provided_dir

    def montage_dir(self):
        input_dir = self.enter_dir(
            "Provide full path to directory to create montages: ")
        output_dir = self.enter_dir(
            "Provide full path to valid direcotry to save montages: ")
        self.montage.input_data(src_path=input_dir, dest_path=output_dir)
        print("Creating montages...")
        self.montage.montages_from_directory()
        print("Saving montages complete.")

    def enter_csv(self, message="provide path to valid csv"):
        while True:
            provided_csv = raw_input(message)
            if os.path.isfile(provided_csv): break
            else: print("Not a valid file")

        return provided_csv

    def montage_from_csv(self):
        input_csv = self.enter_csv(
            "Provide full path to csv file for creating montages: ")
        image_path = self.enter_dir(
            "Provide path to where images are located: ")
        output_dir = self.enter_dir(
            "Provide full path to valid direcotry to save montages: ")
        self.montage.input_data(src_path=input_csv,
                                dest_path=output_dir,
                                image_src_path=image_path)
        print("Creating montages...")
        self.montage.montage_from_csv_binned()

    def vertical_montage_from_csv(self):
        input_csv = self.enter_csv(
            "Provide full path to csv file for creating montages: ")
        image_path = self.enter_dir(
            "Provide path to where images are located: ")
        output_dir = self.enter_dir(
            "Provide full path to valid direcotry to save montages: ")
        self.montage.input_data(src_path=input_csv,
                                dest_path=output_dir,
                                image_src_path=image_path)
        print("Creating montages...")
        self.montage.montage_from_csv_binned(ncols=0, nrows=1)

    def image_hist_from_csv(self):
        input_CSV = self.enter_csv(
            "Provide full path to csv file for creating image histogram: ")
        output_dir = self.enter_dir(
            "Provide full path and fielname to  save image histogram: ")
        self.montage.input_data(src_path=input_CSV, dest_path=output_dir)
        print("Creating image histogram...")
        self.montage.create_image_hist()

    def quit(self):
        print("Good bye!")
        sys.exit(0)
Exemplo n.º 3
0
class Menu:
	'''Display menu and respond to choices when run.'''
	def __init__(self):
		self.montage = Montages()
		self.choices = {
		"1": self.montage_dir,
		"2": self.montage_from_csv,
		"3": self.vertical_montage_from_csv,
		"4": self.image_hist_from_csv,
		"5": self.quit
		}

	def display_menu(self):
		print("""
PyMontage Menu

1. Create montages from recursively from given directory and sub-directories
2. Create montages from provided CSV files (split by categories or bins)
3. Create vetical montge from provided CSV file
4. Create image histogram from provided CSV file
5. Quit 
""")

	def run(self):
		'''Display the menu and responsd to choices'''
		while True:
			self.display_menu()
			choice = input("Enter an option: ")
			action = self.choices.get(str(choice))
			if action:
				action()
			else:
				print("{0} is not a valid choice".format(choice))

	def enter_dir(self, message = "Provide valid directory"):
		while True:
			provided_dir = raw_input(message)
			if os.path.isdir(provided_dir): break
			else: print("Not a valid directory")

		return provided_dir

	def montage_dir(self):
		input_dir = self.enter_dir("Provide full path to directory to create montages: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_dir, dest_path = output_dir)
		print("Creating montages...")
		self.montage.montages_from_directory()
		print("Saving montages complete.")

	def enter_csv(self, message = "provide path to valid csv"):
		while True:
			provided_csv = raw_input(message)
			if os.path.isfile(provided_csv): break
			else: print("Not a valid file")

		return provided_csv

	def montage_from_csv(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating montages: ")
		image_path = self.enter_dir("Provide path to where images are located: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_csv, dest_path = output_dir, image_src_path = image_path)
		print("Creating montages...")
		self.montage.montage_from_csv_binned()

	def vertical_montage_from_csv(self):
		input_csv = self.enter_csv("Provide full path to csv file for creating montages: ")
		image_path = self.enter_dir("Provide path to where images are located: ")
		output_dir = self.enter_dir("Provide full path to valid direcotry to save montages: ")
		self.montage.input_data(src_path = input_csv, dest_path = output_dir, image_src_path = image_path)
		print("Creating montages...")
		self.montage.montage_from_csv_binned(ncols = 0, nrows = 1)		

	def image_hist_from_csv(self):
		input_CSV = self.enter_csv("Provide full path to csv file for creating image histogram: ")
		output_dir = self.enter_dir("Provide full path and fielname to  save image histogram: ")
		self.montage.input_data(src_path = input_CSV, dest_path = output_dir)
		print("Creating image histogram...")
		self.montage.create_image_hist()


	def quit(self):
		print("Good bye!")
		sys.exit(0)
Exemplo n.º 4
0
class ImageHistFromCSV(QDialog):
    def __init__(self, parent=None):  #Constructor
        super(ImageHistFromCSV, self).__init__(parent)
        self.montage = Montages()
        self.error = Error(self)
        self.createLabel = QPushButton(
            'Provide full path to csv file for creating image histogram', self)
        QPushButtonStyleStr = 'QPushButton{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eafaf1, stop: 1 #d5f5e3); } \
            QPushButton:hover{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #b4e6ed, stop: 1 #a6e3ec); } \
            QPushButton:pressed{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #b4e6ed, stop: 1 #60c1dc);}'

        self.createLabel.setStyleSheet(QPushButtonStyleStr)
        self.createLabel.setFixedWidth(350)
        self.createLabel.clicked.connect(self.showPathToCreate)
        self.orLabel1 = QLabel("or", self)
        self.orLabel1.setAlignment(QtCore.Qt.AlignCenter)
        self.browse1 = QPushButton("Browse", self)
        self.browse1.setStyleSheet(QPushButtonStyleStr)
        self.browse1.clicked.connect(self.getCSVPath)
        self.createPath = QLabel("Path: ", self)
        self.saveLabel = QPushButton(
            'Provide full path and filename to save image histogram', self)
        self.saveLabel.setStyleSheet(QPushButtonStyleStr)
        self.saveLabel.setFixedWidth(350)
        self.saveLabel.clicked.connect(self.showPathToSave)
        self.orLabel2 = QLabel("or", self)
        self.orLabel2.setAlignment(QtCore.Qt.AlignCenter)
        self.browse2 = QPushButton("Browse", self)
        self.browse2.setStyleSheet(QPushButtonStyleStr)
        self.browse2.clicked.connect(self.getOutputPath)
        self.savePath = QLabel("Path: ", self)
        self.spacer = QLabel("", self)
        self.apply = QPushButton("Apply", self)
        self.apply.setStyleSheet(QPushButtonStyleStr)
        self.apply.setFixedWidth(200)
        self.apply.clicked.connect(self.createHist)
        self.backToMenu = QPushButton("Back To Menu", self)
        self.backToMenu.setStyleSheet(QPushButtonStyleStr)
        self.backToMenu.setFixedWidth(200)
        self.backToMenu.clicked.connect(self.close)
        self.message = QLabel(self)
        self.layout1 = QVBoxLayout(self)
        layout2 = QHBoxLayout()
        layout3 = QHBoxLayout()
        layout4 = QHBoxLayout()

        layout2.addWidget(self.createLabel)
        layout2.addWidget(self.orLabel1)
        layout2.addWidget(self.browse1)
        self.layout1.addLayout(layout2)
        self.layout1.addWidget(self.createPath)
        layout3.addWidget(self.saveLabel)
        layout3.addWidget(self.orLabel2)
        layout3.addWidget(self.browse2)
        self.layout1.addLayout(layout3)
        self.layout1.addWidget(self.savePath)
        self.layout1.addWidget(self.spacer)
        layout4.addWidget(self.apply)
        layout4.addWidget(self.backToMenu)
        self.layout1.addLayout(layout4)
        self.layout1.addWidget(self.message)

        self.setGeometry(590, 475, 350, 150)
        self.setWindowTitle('Option 4')

        self.inputPath = ""
        self.outputPath = ""

    ## @function showPathToCreate
    #  @brief Member function that gets input path to create montage from user-written path
    def showPathToCreate(self):
        text, ok = QInputDialog.getText(
            self, 'Input Path to Create Image Histogram',
            'Enter path to directory:')
        if ok:
            if os.path.isdir(str(text)):
                self.createPath.clear
                self.createPath.setText("Path: " + str(text))
                self.inputPath = str(text)
            else:
                self.createPath.clear
                self.createPath.setText("Given directory is not valid: " +
                                        str(text))

    ## @function showPathToSave
    #  @brief Member function that gets path to save montage from user-written path
    def showPathToSave(self):
        text, ok = QInputDialog.getText(self,
                                        'Input Path to Save Image Histogram',
                                        'Enter path to directory:')
        if ok:
            if os.path.isdir(str(text)):
                self.savePath.clear
                self.savePath.setText("Path: " + str(text))
                self.outputPath = str(text)
            else:
                self.savePath.clear
                self.savePath.setText("Given directory is not valid: " +
                                      str(text))

    ## @function getCSVPath
    #  @brief Member function that gets path to CSV files from user-chosen folder using browse
    def getCSVPath(self):
        text = QFileDialog.getExistingDirectory(self, 'Select Folder', 'C:\\',
                                                QFileDialog.ShowDirsOnly)
        self.createPath.clear
        self.createPath.setText("Path: " + str(text))
        self.inputPath = str(text)

    ## @function getOutputPath
    #  @brief Member function that gets path to save montages from user-chosen folder using browse
    def getOutputPath(self):
        text = QFileDialog.getExistingDirectory(self, 'Select Folder', 'C:\\',
                                                QFileDialog.ShowDirsOnly)
        self.savePath.clear
        self.savePath.setText("Path: " + str(text))
        self.outputPath = str(text)

    def createHist(self):
        if self.inputPath == "" or self.outputPath == "":
            self.error.exec_()
        else:
            self.montage.input_data(src_path=self.inputPath,
                                    dest_path=self.outputPath)
            self.montage.create_image_hist()
            self.message.setText("Image histogram created and saved.")