Пример #1
0
    def visualise(project_id=str(),
                  max_distance=False,
                  critical_concentration=None,
                  heatmap=False,
                  simulation_number=str(),
                  concentration=False):

        if max_distance:
            maximal_distances = json.load(
                open(
                    'Dataset/Maximal_distances/' + str(project_id) + '/' +
                    str(critical_concentration), 'r'))
            Visualiser.plot_scatter_2d(x=numpy.arange(
                len(maximal_distances['concentrated'])),
                                       y=maximal_distances['concentrated'],
                                       project_id=project_id,
                                       info=str(critical_concentration))

        if heatmap:
            info = json.load(open(project_id, 'r'))
            lattice = Lattice.load(project_id=project_id,
                                   simulation_number=simulation_number)
            print(lattice.cells)
            # critical_concentration = str(critical_concentration)

            if critical_concentration:
                Visualiser.concentration_heatmap(
                    lattice=lattice,
                    simulation_number=simulation_number,
                    critical_concentration=critical_concentration)
            else:
                Visualiser.concentration_heatmap(
                    lattice=lattice, simulation_number=simulation_number)
        if concentration:
            data = []
            # for simulation_number in [50, 100, 150, 300, 400, 450, 499]:
            # for simulation_number in [50, 100, 150, 200, 250, 300, 350, 400, 450, 499]:
            info = json.load(open(project_id, 'r')),
            lattice = Lattice.load(project_id=project_id,
                                   simulation_number=str(300))

            # lattice.critical_concentration = 3500
            # lattice.update_critical()

            val = dict()
            for cell in lattice.cells.values():
                val[cell.index.x_axis] = cell.get_concentration()
            od = OrderedDict(sorted(val.items()))
            x = []
            y = []
            for key, val in od.items():
                x.append(key)
                y.append(val)
            # if x or y:
            #     x.insert(0,x[0])
            #     y.insert(0,0)
            #     x.append(x[-1])
            #     y.append(0)
            data.append([x, y, simulation_number])
            Visualiser.plot_scatter_2d(data=data, project_id=project_id)
Пример #2
0
    def inspect_lattice(self, project_id=str(), critical_concentration=None):

        info = dict()
        info = json.load(open(project_id, 'r'))

        lattice = Lattice()
        lattice.critical_concentration = int(1e5) * critical_concentration

        i = 0
        while True:
            if os.path.exists('Dataset/Lattices/' + project_id + '/' + str(i)):
                print(str(i))

                # loading state
                lattice.cells = Lattice.load(cells_only=True,
                                             project_id=project_id,
                                             simulation_number=i)

                # inspecting loaded state
                lattice.update_critical()

                lattice.sort_critical()
                lattice.update_maximal_distances(dimension=info['dimension'])

                i += 1

            else:
                break

        json.dump(
            lattice.maximal_distances,
            open(
                'Dataset/Maximal_distances/' + info['project_id'] + '/' +
                str(critical_concentration), 'w'))
Пример #3
0
    def inspect_lattice(self, critical_concentration):
        info = dict()
        info = json.load(open(str(self.id) + self.sub_id + 'info', 'r'))

        lattice = Lattice()
        lattice.critical_concentration = critical_concentration

        i = 0
        while True:
            if os.path.exists(self.id + self.sub_id + 'Lattices/' + str(i)):
                print(str(i))

                lattice.cells = Lattice.load(cells_only=True,
                                             project_id=self.id,
                                             sub_id=self.sub_id,
                                             simulation_number=i,
                                             implementation=True)

                lattice.update_critical()

                lattice.update_maximal_distances(dimension=info['dimension'],
                                                 check_area=False)

                i += 1

            else:
                break

        json.dump(
            lattice.maximal_distances['concentrated'],
            open(
                self.id + self.sub_id + 'Maximal_distances/' +
                str(critical_concentration) + 'n2', 'w'))
Пример #4
0
 def get_data(self, simulation_number=int()):
     data = np.zeros((int(self.y_max-self.y_min), int(self.x_max-self.x_min)))
     cells = Lattice.load(project_id=self.project_id, simulation_number=simulation_number, cells_only=True)
     for cell in cells.values():
         if cell.get_concentration() > self.critical_c:
             if cell.position(1).x_axis > self.x_min and cell.position(1).x_axis < self.x_max:
                 if cell.position(1).y_axis > self.y_min and cell.position(1).y_axis < self.y_max:
                     data[int((cell.index.y_axis-self.y_min)), int((cell.index.x_axis-self.x_min))] = cell.counter
     return data
Пример #5
0
    def visualise(self,
                  heatmap=False,
                  max_distance=False,
                  critical_concentration=float(),
                  simulation_number=None):

        if heatmap:
            x_max = 60
            x_min = -60
            y_max = 60
            y_min = -60

            y_size = int((y_max - y_min)) + 1
            x_size = int((x_max - x_min)) + 1
            data = np.zeros((y_size, x_size))
            plot_data = []
            for i in range(10, 700, 50):
                lattice = Lattice.load(project_id=self.id,
                                       sub_id=self.sub_id,
                                       simulation_number=i,
                                       implementation=True)

                for cell in lattice.cells.values():
                    if cell.get_concentration() > critical_concentration:
                        if cell.position(1).x_axis > x_min and cell.position(
                                1).x_axis < x_max:
                            if cell.position(
                                    1).y_axis > y_min and cell.position(
                                        1).y_axis < y_max:
                                data[int((cell.index.y_axis - y_min)),
                                     int((cell.index.x_axis -
                                          x_min))] = cell.counter

                graph_x_axis = list(
                    range(int(x_min * lattice.density),
                          int(x_max * lattice.density)))
                graph_y_axis = list(
                    range(int(y_min * lattice.density),
                          int(y_max * lattice.density)))
                trace = go.Heatmap(z=data, x=graph_x_axis, y=graph_y_axis)
                plot_data.append(trace)

            fig = tools.make_subplots(rows=4, cols=4)
            for i in range(len(plot_data)):
                print(plot_data[i]['z'])
                # fig.append_trace(plot_data[i], i//4+1, i%4+1)
            # plotly.offline.plot(fig, filename='H' + str(simulation_number) + '.html',
            #                     image_filename='2D-h' + str(simulation_number) ,
            #                     image_width=800, image_height=800, image='png', auto_open=True)
            # Visualiser.concentration_heatmap(lattice=lattice, simulation_number=simulation_number, critical_concentration=critical_concentration)

        if max_distance:
            maximal_distances = json.load(
                open(
                    str(self.id) + self.sub_id + 'Maximal_distances/' +
                    str(critical_concentration) + 'n2', 'r'))
            print(maximal_distances)
            trace = go.Scatter(
                x=np.arange(len(maximal_distances)),
                y=maximal_distances,
                mode='markers',
            )
            data = [trace]
            layout = go.Layout(
                title='',
                xaxis=dict(title='Počet iteračných krokov',
                           titlefont=dict(family='Courier New, monospace',
                                          size=14,
                                          color='#7f7f7f')),
                yaxis=dict(title='Polomer oblasti s kritickou koncentráciou',
                           titlefont=dict(family='Courier New, monospace',
                                          size=14,
                                          color='#7f7f7f')))
            fig = go.Figure(data=data, layout=layout)
            plotly.offline.plot(fig,
                                filename='impl2-2D-1e5-R(n)' +
                                str(critical_concentration) + 'n2' + '.html')
Пример #6
0
    def visualise(self,
                  heatmap=False,
                  max_distance=False,
                  critical_concentration=float(),
                  simulation_number=None):

        if heatmap:
            lattice = Lattice.load(project_id=self.id,
                                   sub_id=self.sub_id,
                                   simulation_number=simulation_number,
                                   implementation=True)
            print(lattice.dictionary())
            Visualiser.concentration_heatmap(
                lattice=lattice,
                simulation_number=simulation_number,
                critical_concentration=critical_concentration)

        # if heatmap:
        #     x_max = 80
        #     x_min = -80
        #     y_max = 0
        #     y_min = 0
        #
        #     fig = tools.make_subplots(rows=7, cols=1, print_grid=False)
        #
        #     y_size = int((y_max - y_min)) + 1
        #     x_size = int((x_max - x_min)) + 1
        #     data = np.zeros((y_size, x_size))
        #
        #     for i in range(50,700,100):
        #         lattice = Lattice.load(project_id=self.id, sub_id=self.sub_id, simulation_number=i, implementation=True)
        #
        #         for cell in lattice.cells.values():
        #             if cell.get_concentration() > critical_concentration:
        #                 if cell.position(1).x_axis > x_min and cell.position(1).x_axis < x_max:
        #                     data[int((cell.index.y_axis - y_min)), int((cell.index.x_axis - x_min))] = cell.counter
        #
        #         graph_x_axis = list(range(int(x_min * lattice.density), int(x_max * lattice.density)))
        #         graph_y_axis = list(range(int(y_min * lattice.density), int(y_max * lattice.density)))
        #
        #     # colorscale = [
        #     #     [0, 'rgb(0, 0, 0)'],
        #     #     [0.1, 'rgb(0, 0, 0)'],
        #     #     [0.1, 'rgb(20, 20, 20)'],
        #     #     [0.2, 'rgb(20, 20, 20)'],
        #     #     [0.2, 'rgb(40, 40, 40)'],
        #     #     [0.3, 'rgb(40, 40, 40)'],
        #     #
        #     #     [0.3, 'rgb(60, 60, 60)'],
        #     #     [0.4, 'rgb(60, 60, 60)'],
        #     #
        #     #     [0.4, 'rgb(80, 80, 80)'],
        #     #     [0.5, 'rgb(80, 80, 80)'],
        #     #
        #     #     [0.5, 'rgb(100, 100, 100)'],
        #     #     [0.6, 'rgb(100, 100, 100)'],
        #     #
        #     #     [0.6, 'rgb(120, 120, 120)'],
        #     #     [0.7, 'rgb(120, 120, 120)'],
        #     #
        #     #     [0.7, 'rgb(140, 140, 140)'],
        #     #     [0.8, 'rgb(140, 140, 140)'],
        #     #
        #     #     [0.8, 'rgb(160, 160, 160)'],
        #     #     [0.9, 'rgb(160, 160, 160)'],
        #     #
        #     #     [0.9, 'rgb(180, 180, 180)'],
        #     #     [1.0, 'rgb(180, 180, 180)']]
        #         trace = go.Heatmap(z=data, x=graph_x_axis, y=graph_y_axis)
        #         fig.append_trace(trace, int(i/100+0.5), 1)
        #         # , colorscale=colorscale)
        #
        #     layout = go.Layout(title='Rozloženie koncentrácie pre 1D prípad',
        #                        xaxis=dict(title='Priestorová súradnica x'),
        #                                   # titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f')),
        #                        yaxis=dict(title='y = 0'),)
        #                                   # titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f')))
        #
        #
        #     fig['layout'].update(height=1000, width=1000, title='Multiple Subplots')
        #     # fig = go.Figure(data=plot_data, layout=layout)
        #     plotly.offline.plot(fig, filename='H'+str(simulation_number)+'.html',
        #                     image_filename='h'+str(simulation_number), image_width=800, image_height=800, image='png',
        #                     auto_open=True)
        #     # Visualiser.concentration_heatmap(lattice=lattice, simulation_number=simulation_number, critical_concentration=critical_concentration)

        if max_distance:
            maximal_distances = json.load(
                open(
                    str(self.id) + self.sub_id + '/Maximal_distances/' +
                    str(critical_concentration) + 'n2A', 'r'))
            print(maximal_distances)
            trace = go.Scatter(
                x=np.arange(len(maximal_distances)),
                y=maximal_distances,
                mode='lines+markers',
            )
            data = [trace]
            layout = go.Layout(
                title='',
                xaxis=dict(title='Počet iteračných krokov',
                           titlefont=dict(family='Courier New, monospace',
                                          size=14,
                                          color='#7f7f7f')),
                yaxis=dict(title='Polomer oblasti s kritickou koncentráciou',
                           titlefont=dict(family='Courier New, monospace',
                                          size=14,
                                          color='#7f7f7f')))
            fig = go.Figure(data=data, layout=layout)
            plotly.offline.plot(fig,
                                filename='impl1-2D-1e5-R(n)' +
                                str(critical_concentration) + 'n2A' + '.html')