def write(self, filename=None, compression=True, copy=True,
              absolute_paths=False, wall_dtype=float,
              physics_dtype=float, overwrite=True):

        # If no filename has been specified, use the model name to construct
        # one. If neither have been specified, raise an exception.
        if filename is None:
            if self.name is not None:
                filename = self.name + '.rtin'
            else:
                raise ValueError("filename= has not been specified and model "
                                 "has no name")

        # Remove previous file if it exists
        if overwrite and os.path.exists(filename):
            os.remove(filename)

        # Check that grid has been set up
        if self.grid is None:
            raise Exception("No coordinate grid has been set up")

        # Check that containing directory exists to give a more understandable
        # message than 'File does not exist', since this might confuse users
        # (it is the output directory that does not exist)
        if not os.path.dirname(filename) == "":
            if not os.path.exists(os.path.dirname(filename)):
                raise IOError("Directory %s does not exist" %
                              os.path.dirname(filename))

        # Create output file
        delete_file(filename)
        root = h5py.File(filename, 'w')

        # Add Python version
        root.attrs['python_version'] = np.string_(__version__.encode('utf-8'))

        # Create all the necessary groups and sub-groups
        g_sources = root.create_group('Sources')
        g_output = root.create_group('Output')
        g_peeled = g_output.create_group('Peeled')
        g_binned = g_output.create_group('Binned')

        # Output sources
        for i, source in enumerate(self.sources):
            if isinstance(source, MapSource):
                source.write(g_sources, 'source_%05i' % (i + 1), self.grid,
                             compression=compression, map_dtype=physics_dtype)
            else:
                source.write(g_sources, 'source_%05i' % (i + 1))

        # Output configuration for peeled images/SEDs
        for i, peel in enumerate(self.peeled_output):
            if not self._frequencies is None:
                if not peel._monochromatic:
                    raise Exception("Peeled images need to be set to monochromatic mode")
            peel.write(g_peeled.create_group('group_%05i' % (i + 1)))

        # Output configuration for binned images/SEDs
        if self.binned_output is not None:
            if self.forced_first_scattering:
                raise Exception("can't use binned images with forced first scattering - use set_forced_first_scattering(False) to disable")
            self.binned_output.write(g_binned.create_group('group_00001'))

        # Write monochromatic configuration
        self._write_monochromatic(root, compression=compression)

        # Write run-time and output configuration
        self.write_run_conf(root)
        self.conf.output.write(g_output)

        if isinstance(self.grid, GridOnDisk):

            g_grid = link_or_copy(root, 'Grid', self.grid.link, copy=copy, absolute_paths=absolute_paths)

        else:

            # Create group
            g_grid = root.create_group('Grid')

            # Check self-consistency of grid
            self.grid._check_array_dimensions()

            # Write the geometry and physical quantity arrays to the input file
            self.grid.write(g_grid, copy=copy, absolute_paths=absolute_paths, compression=compression, physics_dtype=physics_dtype)

        if 'density' in self.grid:

            # Check if dust types are specified for each
            if self.dust is None:
                raise Exception("No dust properties specified")

            if isinstance(self.dust, h5py.ExternalLink):

                link_or_copy(root, 'Dust', self.dust, copy, absolute_paths=absolute_paths)

            elif isinstance(self.dust, h5py.Group):

                root.copy(self.dust, 'Dust')

            elif type(self.dust) == list:

                g_dust = root.create_group('Dust')

                if self.grid['density'].n_dust != len(self.dust):
                    raise Exception("Number of density grids should match number of dust types")

                # Output dust file, avoiding writing the same dust file multiple times
                present = {}
                for i, dust in enumerate(self.dust):

                    short_name = 'dust_%03i' % (i + 1)

                    if copy:

                        if isinstance(dust, basestring):
                            dust = SphericalDust(dust)

                        if dust.hash() in present:
                            g_dust[short_name] = h5py.SoftLink(present[dust.hash()])
                        else:
                            dust.write(g_dust.create_group(short_name))
                            present[dust.hash()] = short_name

                    else:

                        if type(dust) != str:
                            if dust._file is None:
                                raise ValueError("Dust properties are not located in a file, so cannot link. Use copy=True or write the dust properties to a file first")
                            else:
                                # Check that has still matches file
                                if dust.hash() != dust._file[1]:
                                    raise ValueError("Dust properties have been modified since "
                                                     "being read in, so cannot link to dust file "
                                                     "on disk. You can solve this by writing out "
                                                     "the dust properties to a new file, or by "
                                                     "using copy=True.")
                                dust = dust._file[0]

                        if absolute_paths:
                            path = os.path.abspath(dust)
                        else:
                            # Relative path should be relative to input file, not current directory.
                            path = os.path.relpath(dust, os.path.dirname(filename))

                        g_dust[short_name] = h5py.ExternalLink(path, '/')

            else:
                raise ValueError("Unknown type for dust attribute: %s" % type(self.dust))

            _n_dust = len(root['Dust'])

            # Write minimum specific energy
            if self._minimum_temperature is not None:

                if np.isscalar(self._minimum_temperature):
                    _minimum_temperature = [self._minimum_temperature for i in range(_n_dust)]
                elif len(self._minimum_temperature) != _n_dust:
                    raise Exception("Number of minimum_temperature values should match number of dust types")
                else:
                    _minimum_temperature = self._minimum_temperature

                _minimum_specific_energy = []
                for i, dust in enumerate(root['Dust']):
                    d = SphericalDust(root['Dust'][dust])
                    _minimum_specific_energy.append(d.temperature2specific_energy(_minimum_temperature[i]))

            elif self._minimum_specific_energy is not None:

                if np.isscalar(self._minimum_specific_energy):
                    _minimum_specific_energy = [self._minimum_specific_energy for i in range(_n_dust)]
                elif len(self._minimum_specific_energy) != _n_dust:
                    raise Exception("Number of minimum_specific_energy values should match number of dust types")
                else:
                    _minimum_specific_energy = self._minimum_specific_energy

            else:

                _minimum_specific_energy = None

            if isinstance(self.grid, GridOnDisk):
                if _minimum_specific_energy is not None:
                    raise ValueError("Cannot set minimum specific energy or temperature when using grid from disk")
            elif _minimum_specific_energy is not None:
                g_grid['Quantities'].attrs["minimum_specific_energy"] = [float(x) for x in _minimum_specific_energy]

        else:

            root.create_group('Dust')

        root.close()

        self.filename = filename
Generate a suitable ASCII alpha salt.
dataset/ETHPy150Open hyperion-rt/hyperion/hyperion/model/model.py/Model.write--crossover with--dataset/ETHPy150Open timvideos/streaming-system/website/tracker/views.py/generate_salt