#NEWLINE# def write( self , filename = None , compression = True , copy = True , absolute_paths = False , wall_dtype = float , physics_dtype = float , overwrite = True ) : #NEWLINE# #INDENT# '\n        Write the model input parameters to an HDF5 file\n\n        Parameters\n        ----------\n        filename : str\n            The name of the input file to write. If no name is specified, the\n            filename is constructed from the model name.\n        compression : bool\n            Whether to compress the datasets inside the HDF5 file.\n        copy : bool\n            Whether to copy all external content into the input file, or\n            whether to just link to external content.\n        absolute_paths : bool\n            If copy=False, then if absolute_paths is True, absolute filenames\n            are used in the link, otherwise the path relative to the input\n            file is used.\n        wall_dtype : type\n            Numerical type to use for wall positions.\n        physics_dtype : type\n            Numerical type to use for physical grids.\n        overwrite : bool\n            Whether to overwrite any pre-existing file\n        ' #NEWLINE# if ( filename is None ) : #NEWLINE# #INDENT# if ( self . name is not None ) : #NEWLINE# #INDENT# filename = ( self . name + '.rtin' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'filename= has not been specified and model has no name' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( overwrite and os . path . exists ( filename ) ) : #NEWLINE# #INDENT# os . remove ( filename ) #NEWLINE# #UNINDENT# if ( self . grid is None ) : #NEWLINE# #INDENT# raise Exception ( 'No coordinate grid has been set up' ) #NEWLINE# #UNINDENT# if ( not ( os . path . dirname ( filename ) == '' ) ) : #NEWLINE# #INDENT# if ( not os . path . exists ( os . path . dirname ( filename ) ) ) : #NEWLINE# #INDENT# raise IOError ( ( 'Directory %s does not exist' % os . path . dirname ( filename ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# delete_file ( filename ) #NEWLINE# root = h5py . File ( filename , 'w' ) #NEWLINE# root . attrs [ 'python_version' ] = np . string_ ( __version__ . encode ( 'utf-8' ) ) #NEWLINE# g_sources = root . create_group ( 'Sources' ) #NEWLINE# g_output = root . create_group ( 'Output' ) #NEWLINE# g_peeled = g_output . create_group ( 'Peeled' ) #NEWLINE# g_binned = g_output . create_group ( 'Binned' ) #NEWLINE# for ( i , source ) in enumerate ( self . sources ) : #NEWLINE# #INDENT# if isinstance ( source , MapSource ) : #NEWLINE# #INDENT# source . write ( g_sources , ( 'source_%05i' % ( i + 1 ) ) , self . grid , compression = compression , map_dtype = physics_dtype ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# source . write ( g_sources , ( 'source_%05i' % ( i + 1 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# for ( i , peel ) in enumerate ( self . peeled_output ) : #NEWLINE# #INDENT# if ( not ( self . _frequencies is None ) ) : #NEWLINE# #INDENT# if ( not peel . _monochromatic ) : #NEWLINE# #INDENT# raise Exception ( 'Peeled images need to be set to monochromatic mode' ) #NEWLINE# #UNINDENT# #UNINDENT# peel . write ( g_peeled . create_group ( ( 'group_%05i' % ( i + 1 ) ) ) ) #NEWLINE# #UNINDENT# if ( self . binned_output is not None ) : #NEWLINE# #INDENT# if self . forced_first_scattering : #NEWLINE# #INDENT# raise Exception ( "can't use binned images with forced first scattering - use set_forced_first_scattering(False) to disable" ) #NEWLINE# #UNINDENT# self . binned_output . write ( g_binned . create_group ( 'group_00001' ) ) #NEWLINE# #UNINDENT# self . _write_monochromatic ( root , compression = compression ) #NEWLINE# self . write_run_conf ( root ) #NEWLINE# self . conf . output . write ( g_output ) #NEWLINE# if isinstance ( self . grid , GridOnDisk ) : #NEWLINE# #INDENT# g_grid = link_or_copy ( root , 'Grid' , self . grid . link , copy = copy , absolute_paths = absolute_paths ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# g_grid = root . create_group ( 'Grid' ) #NEWLINE# self . grid . _check_array_dimensions ( ) #NEWLINE# self . grid . write ( g_grid , copy = copy , absolute_paths = absolute_paths , compression = compression , physics_dtype = physics_dtype ) #NEWLINE# #UNINDENT# if ( 'density' in self . grid ) : #NEWLINE# #INDENT# if ( self . dust is None ) : #NEWLINE# #INDENT# raise Exception ( 'No dust properties specified' ) #NEWLINE# #UNINDENT# if isinstance ( self . dust , h5py . ExternalLink ) : #NEWLINE# #INDENT# link_or_copy ( root , 'Dust' , self . dust , copy , absolute_paths = absolute_paths ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( self . dust , h5py . Group ) : #NEWLINE# #INDENT# root . copy ( self . dust , 'Dust' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( self . dust ) == list ) : #NEWLINE# #INDENT# g_dust = root . create_group ( 'Dust' ) #NEWLINE# if ( self . grid [ 'density' ] . n_dust != len ( self . dust ) ) : #NEWLINE# #INDENT# raise Exception ( 'Number of density grids should match number of dust types' ) #NEWLINE# #UNINDENT# present = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( i , dust ) in enumerate ( self . dust ) : #NEWLINE# #INDENT# short_name = ( 'dust_%03i' % ( i + 1 ) ) #NEWLINE# if copy : #NEWLINE# #INDENT# if isinstance ( dust , basestring ) : #NEWLINE# #INDENT# dust = SphericalDust ( dust ) #NEWLINE# #UNINDENT# if ( dust . hash ( ) in present ) : #NEWLINE# #INDENT# g_dust [ short_name ] = h5py . SoftLink ( present [ dust . hash ( ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dust . write ( g_dust . create_group ( short_name ) ) #NEWLINE# present [ dust . hash ( ) ] = short_name #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( dust ) != str ) : #NEWLINE# #INDENT# if ( dust . _file is None ) : #NEWLINE# #INDENT# 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' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dust . hash ( ) != dust . _file [ 1 ] ) : #NEWLINE# #INDENT# 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.' ) #NEWLINE# #UNINDENT# dust = dust . _file [ 0 ] #NEWLINE# #UNINDENT# #UNINDENT# if absolute_paths : #NEWLINE# #INDENT# path = os . path . abspath ( dust ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# path = os . path . relpath ( dust , os . path . dirname ( filename ) ) #NEWLINE# #UNINDENT# g_dust [ short_name ] = h5py . ExternalLink ( path , '/' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Unknown type for dust attribute: %s' % type ( self . dust ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# _n_dust = len ( root [ 'Dust' ] ) #NEWLINE# if ( self . _minimum_temperature is not None ) : #NEWLINE# #INDENT# if np . isscalar ( self . _minimum_temperature ) : #NEWLINE# #INDENT# _minimum_temperature = [ self . _minimum_temperature for i in range ( _n_dust ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( self . _minimum_temperature ) != _n_dust ) : #NEWLINE# #INDENT# raise Exception ( 'Number of minimum_temperature values should match number of dust types' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _minimum_temperature = self . _minimum_temperature #NEWLINE# #UNINDENT# #UNINDENT# _minimum_specific_energy = [ ] #NEWLINE# for ( i , dust ) in enumerate ( root [ 'Dust' ] ) : #NEWLINE# #INDENT# d = SphericalDust ( root [ 'Dust' ] [ dust ] ) #NEWLINE# _minimum_specific_energy . append ( d . temperature2specific_energy ( _minimum_temperature [ i ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . _minimum_specific_energy is not None ) : #NEWLINE# #INDENT# if np . isscalar ( self . _minimum_specific_energy ) : #NEWLINE# #INDENT# _minimum_specific_energy = [ self . _minimum_specific_energy for i in range ( _n_dust ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( self . _minimum_specific_energy ) != _n_dust ) : #NEWLINE# #INDENT# raise Exception ( 'Number of minimum_specific_energy values should match number of dust types' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _minimum_specific_energy = self . _minimum_specific_energy #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# _minimum_specific_energy = None #NEWLINE# #UNINDENT# #UNINDENT# if isinstance ( self . grid , GridOnDisk ) : #NEWLINE# #INDENT# if ( _minimum_specific_energy is not None ) : #NEWLINE# #INDENT# raise ValueError ( 'Cannot set minimum specific energy or temperature when using grid from disk' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( _minimum_specific_energy is not None ) : #NEWLINE# #INDENT# g_grid [ 'Quantities' ] . attrs [ 'minimum_specific_energy' ] = [ float ( x ) for x in _minimum_specific_energy ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# root . create_group ( 'Dust' ) #NEWLINE# #UNINDENT# root . close ( ) #NEWLINE# self . filename = filename