def write_in_file(self, directory: Union[str, Path] = None) -> Setup: """Write Phantom 'in' file. Optional parameters ------------------- directory The path to a directory to write the file. Default is current working directory. """ if directory is None: directory = pathlib.Path().cwd() directory = pathlib.Path(directory).expanduser().resolve() if not directory.exists(): directory.mkdir(parents=True) if self.prefix is None: raise ValueError('No prefix set') else: filename = f'{self.prefix}.in' phantomconfig.read_dict(self.infile).write_phantom(directory / filename) return self
def test_read_dict_nested(): """Test reading nested Python dictionaries.""" conf = pc.read_dict(test_dict_nested, dtype='nested') assert conf.config == test_data.config assert conf.header == test_data.header assert conf.datetime == test_data._datetime
# ------------------------------------------------ # options controlling photoevaporation 'options controlling photoevaporation': { 'mu_cgs': (1.26, 'Mean molecular weight'), 'recombrate_cgs': (2.6e-13, 'Recombination rate (alpha)'), 'ionflux_cgs': (1.0e41, 'Stellar EUV flux rate'), }, # ------------------------------------------------ # options for injecting particles # TODO # ------------------------------------------------ # options controlling non-ideal MHD # TODO } RUN_OPTIONS = phantomconfig.read_dict(_RUN_OPTIONS, 'nested') _RUN_OPTIONS = dict(zip(RUN_OPTIONS.variables, RUN_OPTIONS.values)) HEADER = { 'Bextx': 0.0, 'Bexty': 0.0, 'Bextz': 0.0, 'C_cour': _RUN_OPTIONS['C_cour'], 'C_force': _RUN_OPTIONS['C_force'], 'RK2': 1.5, 'alpha': _RUN_OPTIONS['alpha'], 'alphaB': _RUN_OPTIONS['alphaB'], 'alphau': _RUN_OPTIONS['alphau'], 'angtot_in': 0.0, 'dtmax': _RUN_OPTIONS['dtmax'],
def test_read_dict_flat(): """Test reading flat Python dictionaries.""" conf = pc.read_dict(test_dict_flat, dtype='flat') assert conf.config == test_data.config assert conf.header == test_data.header assert conf.datetime == test_data._datetime