Esempio n. 1
0
class Runner:
    def __init__(self, scan_dir, work_dir):
        self.recog = Recog.recog16()
        self.store = Store()
        self.plot = Plot()
        self.work_dir = work_dir
        self.scanner = Scanner(scan_dir, work_dir)
        self.main_process()

    def process(self, imgpath, amount):
        place_id = ''.join(self.recog.recog(imgpath, box_view=True))
        print(place_id)
        parts_id = self.store.store(place_id, amount)
        self.plot.plotAt(parts_id)
        self.plot.plot()

    def get_imgpath(self, imgpath):
        return ''.join([self.work_dir, "/", imgpath])

    def main_process(self):
        while True:
            if self.scanner.have_imgname:
                imgname = self.scanner.get_imgname()
                print("new image load: ", imgname)
                self.process(self.get_imgpath(imgname), 1)
            sleep(1)
Esempio n. 2
0
 def __init__(self, scan_dir, work_dir):
     self.recog = Recog.recog16()
     self.store = Store()
     self.plot = Plot()
     self.work_dir = work_dir
     self.scanner = Scanner(scan_dir, work_dir)
     self.main_process()
Esempio n. 3
0
    def plot_binned_energies_against_cp_phi_and_cp_theta(self):

        (
            cp_phi_values,
            cp_theta_values,
            free_energy_values,
            count_values,
        ) = self.sort_cp_phi_cp_theta_binned_energies_for_contour()

        scatter_params = {
            "x_label": r"$\phi$",
            "y_label": r"$\theta$",
            "countour_levels": range(0, 6, 1),
        }

        plot_file_path = "custom_scripts/output/cp_phi_theta_free_energy_contour.png"

        Plot().contour_plot(
            cp_phi_values,
            cp_theta_values,
            free_energy_values,
            plot_file_path,
            scatter_params=scatter_params,
        )

        scatter_params = {
            "x_label": r"$\phi$",
            "y_label": r"$\theta$",
            "x_major_tick": 60,
            "x_end": 360,
            "x_start": 0,
            "y_end": 180,
            "y_start": 0,
        }

        cp_phi_1d_values = [
            cp_params["cp_phi"]
            for cp_params in self.cp_trajectory_pucker_params.values()
        ]

        cp_theta_1d_values = [
            cp_params["cp_theta"]
            for cp_params in self.cp_trajectory_pucker_params.values()
        ]

        Plot().two_dimensional_scatter(
            cp_phi_1d_values,
            cp_theta_1d_values,
            "custom_scripts/output/cp_phi_theta_scatter.png",
            scatter_params=scatter_params,
        )
Esempio n. 4
0
    def test_hist_unique(self):
        """Test hist_unique

        Args:
            self: TestPlot

        Returns:
            None

        Raises:
            None
        """
        Plot.hist_unique([1, 2, 3, 4, 5, 1, 2], 'numbers', 'count',
                         'numbers-count', self.TEST_PLOT_FILE_PATH,
                         self.TEST_SHOULD_SHOW_PLOT)
        if not os.path.exists(self.TEST_PLOT_FILE_PATH):
            self.assertTrue(False, 'Plot file not found')

        # Invalid data_list
        with self.assertRaises(PreconditionException) as context:
            Plot.hist_unique(None, 'numbers', 'count', 'numbers-count',
                             self.TEST_PLOT_FILE_PATH,
                             self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid data_list' in str(context.exception))

        # Invalid x_label
        with self.assertRaises(PreconditionException) as context:
            Plot.hist_unique([1, 2, 3, 4, 5, 1, 2], None, 'count',
                             'numbers-count', self.TEST_PLOT_FILE_PATH,
                             self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid x_label' in str(context.exception))

        # Invalid y_label
        with self.assertRaises(PreconditionException) as context:
            Plot.hist_unique([1, 2, 3, 4, 5, 1, 2], 'numbers', None,
                             'numbers-count', self.TEST_PLOT_FILE_PATH,
                             self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid y_label' in str(context.exception))

        # Invalid title
        with self.assertRaises(PreconditionException) as context:
            Plot.hist_unique([1, 2, 3, 4, 5, 1, 2], 'numbers', 'count', None,
                             self.TEST_PLOT_FILE_PATH,
                             self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid title' in str(context.exception))
    def plot_free_energy_against_cp_theta(self):

        free_energies = [
            bin_value["free_energy_diff"]
            for bin_value in self.cp_theta_bin_values.values()
        ]

        scatter_params = {
            "y_label": "delta G (kcal/mol)",
            "x_label": "CP theta (deg)",
            "y_start": 0,
            "y_end": 8,
            "x_major_tick": 30,
            "x_end": 180,
            "color": "black",
        }

        plot_file_path = "custom_scripts/output/free_energy_against_cp_theta.png"

        Plot().two_dimensional_scatter(
            self.cp_theta_bin_values.keys(),
            free_energies,
            plot_file_path,
            scatter_params=scatter_params,
        )
Esempio n. 6
0
    def plot_energy_with_average(self):

        scatter_params = {
            "y_label": "PE (kcal/mol)",
            "x_label": "time (ns)",
            "y_start": 230,
            "y_end": 310,
            "x_major_tick": 200,
            "x_end": 2000,
            "color": "black",
        }

        plot_file_path = "custom_scripts/output/trajectory_single_point_potential_energy_with_average.png"

        # time_series = np.arange(0, 1500, 1500 / 60000)
        time_series = np.arange(0, 2000, 2000 / 80000)

        Plot().two_dimensional_scatter_plot_with_average(
            time_series,
            self.trajectory_pe_values,
            np.arange(12.5, 2000, 25),
            self.pe_periodic_mean_values,
            plot_file_path,
            scatter_params=scatter_params,
        )
Esempio n. 7
0
    def _get_phase(self, phase_key, phase_dict):

        if "generator" == phase_key:

            return Generator.get_instance(self, self._base_dir,
                                          self._global_dict, phase_dict,
                                          self._failfast)
        elif "solver" == phase_key:

            return Solver.get_instance(self, self._base_dir, self._global_dict,
                                       phase_dict, self._failfast)
        elif "model" == phase_key:

            return Model.get_instance(self, self._base_dir, self._global_dict,
                                      phase_dict, self._failfast)
        elif "leapfrog" == phase_key:

            return Leapfrog.get_instance(self, self._base_dir,
                                         self._global_dict, phase_dict,
                                         self._failfast)
        elif "plotter" == phase_key:

            return Plot.get_instance(self, self._base_dir, self._global_dict,
                                     phase_dict, self._failfast)
        else:

            assert False
            return None
    def plot_energy_against_cp_theta(
        self, cp_trajectory_pucker_params, trajectory_energy_per_frame
    ):

        trajectory_cp_theta = [
            cp_params["cp_theta"] for cp_params in cp_trajectory_pucker_params.values()
        ]

        scatter_params = {
            "y_label": "PE (kcal/mol)",
            "x_label": "CP theta (deg)",
            "y_start": 260,
            "y_end": 350,
            "x_major_tick": 30,
            "x_end": 180,
            "color": "black",
        }

        plot_file_path = "custom_scripts/output/pe_against_cp_theta.png"

        Plot().two_dimensional_scatter(
            trajectory_cp_theta,
            trajectory_energy_per_frame,
            plot_file_path,
            scatter_params=scatter_params,
        )
Esempio n. 9
0
 def test_plot(self):
     shelf = np.array(pd.read_csv("datasets/shelf.csv", header=None))
     samples = np.random.randint(0,shelf.shape[0],20)
     # print(samples)
     plot = Plot()
     for sample in samples:
         plot.plotAt(sample)
         plot.plot()
     self.assertTrue(True)
Esempio n. 10
0
    def plot_energy_with_average(self):

        scatter_params = {
            "y_label": "rmsd (A)",
            "x_label": "time (ns)",
            "y_start": 0,
            "y_end": 3,
            "x_major_tick": 200,
            "x_end": 1500,
            "color": "black",
        }

        plot_file_path = "/home/timol/C6W/Studies/structure_analysis/output/aLRha13bDGlcNAc_3_10-aDGlc14bDGlcNAc_-31_-45_attempt_2/rmsd/rmsd.png"

        time_series = np.arange(0, 1500, 1500 / 60000)

        Plot().two_dimensional_scatter_plot_with_average(
            time_series,
            self.trajectory_pe_values,
            np.arange(12.5, 1500, 25),
            self.pe_periodic_mean_values,
            plot_file_path,
            scatter_params=scatter_params,
        )
Esempio n. 11
0
    def test_bar(self):
        """Test bar

        Args:
            self: TestPlot

        Returns:
            None

        Raises:
            None
        """
        Plot.bar(['a', 'e', 'i', 'o', 'u'], [1, 2, 3, 4, 5], 'vowels',
                 'counts', 'vowels-count', self.TEST_PLOT_FILE_PATH,
                 self.TEST_SHOULD_SHOW_PLOT)
        if not os.path.exists(self.TEST_PLOT_FILE_PATH):
            self.assertTrue(False, 'Plot file not found')

        # Invalid data_list1
        with self.assertRaises(PreconditionException) as context:
            Plot.bar(None, [1, 2, 3, 4, 5], 'alphabets', 'counts',
                     'alphabets-count', self.TEST_PLOT_FILE_PATH,
                     self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid data_list1' in str(context.exception))

        # Invalid data_list2
        with self.assertRaises(PreconditionException) as context:
            Plot.bar(['a', 'e', 'i', 'o', 'u'], None, 'alphabets', 'counts',
                     'alphabets-count', self.TEST_PLOT_FILE_PATH,
                     self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid data_list2' in str(context.exception))

        # Invalid x_label
        with self.assertRaises(PreconditionException) as context:
            Plot.bar(['a', 'e', 'i', 'o', 'u'], [1, 2, 3, 4, 5], None,
                     'counts', 'alphabets-count', self.TEST_PLOT_FILE_PATH,
                     self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid x_label' in str(context.exception))

        # Invalid y_label
        with self.assertRaises(PreconditionException) as context:
            Plot.bar(['a', 'e', 'i', 'o', 'u'], [1, 2, 3, 4, 5], 'alphabets',
                     None, 'alphabets-count', self.TEST_PLOT_FILE_PATH,
                     self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid y_label' in str(context.exception))

        # Invalid title
        with self.assertRaises(PreconditionException) as context:
            Plot.bar(['a', 'e', 'i', 'o', 'u'], [1, 2, 3, 4, 5], 'alphabets',
                     'counts', None, self.TEST_PLOT_FILE_PATH,
                     self.TEST_SHOULD_SHOW_PLOT)

        self.assertTrue('Invalid title' in str(context.exception))
Esempio n. 12
0
 def plot(self):
     Plot.plot(self.asset_array, 'name')