Example #1
0
def make_binder(path):

    src_path = os.path.abspath(path)

    sim_paths_list = find_sim_dirs(src_path)

    for path in sim_paths_list:
        sim_name = os.path.split(path)[1]
        make_notebook(path, sim_name)
        if len(sim_paths_list) == 1 and sim_paths_list[0] == src_path:
            files = os.listdir(src_path)
            files = [os.path.join(src_path, f) for f in files]
            mkdir(os.path.join(src_path, sim_name))
            could_not_copy = []
            for f in files:
                try:
                    copy(f, os.path.join(src_path, sim_name))
                except BaseException as exc:
                    could_not_copy.append([f, exc])
                    continue
                os.remove(f)
            if len(could_not_copy) != 0:
                print("Could not copy the following files:\n")
                for f in could_not_copy:
                    print('file: ', f[0])
                    print('error: ', f[1], '\n')

    _write_readme_requrements(src_path)
Example #2
0
    def write_vtk(self, array_name, props):
        # ceck if it is possible
        if not TVTK:
            raise RuntimeError("Cannot generate VTK output!")

        # check if the array is legal
        if array_name not in self.array_dict.keys():
            raise RuntimeError("Array %s not defined" % array_name)

        # create a list of props
        if type(props) != list:
            props = [props]

        # create an output folder for the vtk files
        dirname = path.join(self.dirname, "vtk")
        utils.mkdir(dirname)

        array = self.array_dict[array_name]
        num_particles = array.num_real_particles

        # save the points
        points = np.zeros(shape=(num_particles, 3))
        points[:, 0] = array.z
        points[:, 1] = array.y
        points[:, 2] = array.x

        mesh = tvtk.PolyData(points=points)

        # add the scalar props
        for prop in props:
            if prop == "vmag":
                u, v, w = array.get("u", "v", "w")
                numpy_array = np.sqrt(u ** 2 + v ** 2 + w ** 2)
            else:
                numpy_array = array.get(prop)

            vtkarray = array2vtk(numpy_array)
            vtkarray.SetName(prop)

            # add the array as point data
            mesh.point_data.add_array(vtkarray)

        # set the last prop as the active scalar
        mesh.point_data.set_active_scalars(props[-1])

        # spit it out
        if self.fileno is None:
            _fname = "%s" % (array_name)
        else:
            _fname = "%s_%03d" % (array_name, self.fileno)

        self._write_vtk_snapshot(mesh, dirname, _fname)
Example #3
0
    def write_vtk(self, array_name, props):
        # ceck if it is possible
        if not TVTK:
            raise RuntimeError('Cannot generate VTK output!')

        # check if the array is legal
        if array_name not in list(self.array_dict.keys()):
            raise RuntimeError('Array %s not defined' % array_name)

        # create a list of props
        if type(props) != list:
            props = [props]

        # create an output folder for the vtk files
        dirname = path.join(self.dirname, 'vtk')
        utils.mkdir(dirname)

        array = self.array_dict[array_name]
        num_particles = array.num_real_particles

        # save the points
        points = np.zeros(shape=(num_particles, 3))
        points[:, 0] = array.z
        points[:, 1] = array.y
        points[:, 2] = array.x

        mesh = tvtk.PolyData(points=points)

        # add the scalar props
        for prop in props:
            if prop == 'vmag':
                u, v, w = array.get('u', 'v', 'w')
                numpy_array = np.sqrt(u**2 + v**2 + w**2)
            else:
                numpy_array = array.get(prop)

            vtkarray = array2vtk(numpy_array)
            vtkarray.SetName(prop)

            # add the array as point data
            mesh.point_data.add_array(vtkarray)

        # set the last prop as the active scalar
        mesh.point_data.set_active_scalars(props[-1])

        # spit it out
        if self.fileno is None:
            _fname = '%s' % (array_name)
        else:
            _fname = '%s_%03d' % (array_name, self.fileno)

        self._write_vtk_snapshot(mesh, dirname, _fname)
Example #4
0
    def write_vtk(self, array_name, props):
        if not TVTK:
            return

        # create a list of props
        if type(props) != list:
            props = [props]

        # create an output folder for the vtk files
        dirname = path.join(self.dirname, "vtk")
        utils.mkdir(dirname)

        nfiles = self.nfiles
        for i in range(self.start, nfiles):
            f = self.files[i]
            data = utils.load(f)

            array = data["arrays"][array_name]
            num_particles = array.num_real_particles

            # save the points
            points = np.zeros(shape=(num_particles, 3))
            points[:, 0] = array.z
            points[:, 1] = array.y
            points[:, 2] = array.x

            mesh = tvtk.PolyData(points=points)

            # add the scalar props
            for prop in props:
                if prop == "vmag":
                    u, v, w = array.get("u", "v", "w")
                    numpy_array = np.sqrt(u ** 2 + v ** 2 + w ** 2)
                else:
                    numpy_array = array.get(prop)

                vtkarray = array2vtk(numpy_array)
                vtkarray.SetName(prop)

                # add the array as point data
                mesh.point_data.add_array(vtkarray)

            # set the last prop as the active scalar
            mesh.point_data.set_active_scalars(props[-1])

            # spit it out
            fileno = data["solver_data"]["count"]
            _fname = self.fname + "_%s_%s" % (array_name, fileno)

            self._write_vtk_snapshot(mesh, dirname, _fname)
Example #5
0
    def write_vtk(self, array_name, props):
        if not TVTK:
            return

        # create a list of props
        if type(props) != list:
            props = [props]

        # create an output folder for the vtk files
        dirname = path.join(self.dirname, 'vtk')
        utils.mkdir(dirname)

        nfiles = self.nfiles
        for i in range(self.start, nfiles):
            f = self.files[i]
            data = utils.load(f)

            array = data['arrays'][array_name]
            num_particles = array.num_real_particles

            # save the points
            points = np.zeros(shape=(num_particles, 3))
            points[:, 0] = array.z
            points[:, 1] = array.y
            points[:, 2] = array.x

            mesh = tvtk.PolyData(points=points)

            # add the scalar props
            for prop in props:
                if prop == 'vmag':
                    u, v, w = array.get('u', 'v', 'w')
                    numpy_array = np.sqrt(u**2 + v**2 + w**2)
                else:
                    numpy_array = array.get(prop)

                vtkarray = array2vtk(numpy_array)
                vtkarray.SetName(prop)

                # add the array as point data
                mesh.point_data.add_array(vtkarray)

            # set the last prop as the active scalar
            mesh.point_data.set_active_scalars(props[-1])

            # spit it out
            fileno = data['solver_data']['count']
            _fname = self.fname + '_%s_%s' % (array_name, fileno)

            self._write_vtk_snapshot(mesh, dirname, _fname)
Example #6
0
def make_binder(path):

    src_path = os.path.abspath(path)

    sim_paths_list = find_sim_dirs(src_path)

    for path in sim_paths_list:
        sim_name = os.path.split(path)[1]
        make_notebook(path, sim_name)
        if len(sim_paths_list) == 1 and sim_paths_list[0] == src_path:
            files = os.listdir(src_path)
            files = [os.path.join(src_path, f) for f in files]
            mkdir(os.path.join(src_path, sim_name))
            could_not_copy = []
            for f in files:
                try:
                    copy(f, os.path.join(src_path, sim_name))
                except BaseException as exc:
                    could_not_copy.append([f, exc])
                    continue
                os.remove(f)
            if len(could_not_copy) != 0:
                print("Could not copy the following files:\n")
                for f in could_not_copy:
                    print('file: ', f[0])
                    print('error: ', f[1], '\n')

    with open(os.path.join(src_path, 'requirements.txt'), 'w') as file:
        file.write(
            "ipympl\n" +
            "matplotlib\n" +
            "ipyvolume\n" +
            "numpy\n" +
            "pytools\n" +
            "-e git+https://github.com/pypr/compyle#egg=compyle\n" +
            "-e git+https://github.com/pypr/pysph#egg=pysph"
        )

    with open(os.path.join(src_path, 'README.md'), 'w') as file:
        file.write(
            "# Title\n" +
            "[![Binder](https://mybinder.org/badge_logo.svg)]" +
            "(https://mybinder.org/v2/gh/user_name/repo_name/branch_name)" +
            "\n" +
            "[comment]: # (The above link is for repositories hosted " +
            "on GitHub. For links corresponding to other hosting services, " +
            "please visit https://mybinder.readthedocs.io)"
        )
Example #7
0
    def _save_all_plots_handler(self, change):

        import ipyvolume as p3
        if change['new'] is True:
            mkdir('all_plots')
            self._widgets.play_button.disabled = True
            self._widgets.delay_box.disabled = True
            self._widgets.save_figure.disabled = True
            self._widgets.save_all_plots.disabled = True

            for array_name in self._widgets.particles.keys():
                pa_widgets = self._widgets.particles[array_name]
                pa_widgets.scalar.disabled = True
                pa_widgets.scalar_cmap.disabled = True
                pa_widgets.velocity_vectors.disabled = True
                pa_widgets.vector_size.disabled = True
                pa_widgets.scalar_size.disabled = True

            change = {}  # dummy dictionary to be used in 'self._frame.handler'
            file_count = len(self.paths_list) - 1

            for i in np.arange(0, file_count + 1):
                self._widgets.frame.value = i
                self._frame_handler(change)
                p3.savefig('all_plots/frame_%s.png' % i,
                           width=1000,
                           height=1000,
                           fig=self.plot)

            print("Saved the plots in the folder 'all_plots'" +
                  " in the present working directory")

            self._widgets.play_button.disabled = False
            self._widgets.delay_box.disabled = False
            self._widgets.save_figure.disabled = False
            self._widgets.save_all_plots.disabled = False
            self._widgets.save_all_plots.value = False

            for array_name in self._widgets.particles.keys():
                pa_widgets = self._widgets.particles[array_name]
                pa_widgets.scalar.disabled = True
                pa_widgets.scalar_cmap.disabled = True
                pa_widgets.velocity_vectors.disabled = True
                pa_widgets.vector_size.disabled = True
                pa_widgets.scalar_size.disabled = True