def from_config(cls, config, **kwargs): """ Create a new Simulation instance from a Configuration object. Parameters ---------- config : tardis.io.config_reader.Configuration **kwargs Allow overriding some structures, such as model, plasma, atomic data and the runner, instead of creating them from the configuration object. Returns ------- Simulation """ # Allow overriding some config structures. This is useful in some # unit tests, and could be extended in all the from_config classmethods. if 'model' in kwargs: model = kwargs['model'] else: model = Radial1DModel.from_config(config) if 'plasma' in kwargs: plasma = kwargs['plasma'] else: plasma = assemble_plasma(config, model, atom_data=kwargs.get('atom_data', None)) if 'runner' in kwargs: runner = kwargs['runner'] else: runner = MontecarloRunner.from_config(config) luminosity_nu_start = config.supernova.luminosity_wavelength_end.to( u.Hz, u.spectral()) try: luminosity_nu_end = config.supernova.luminosity_wavelength_start.to( u.Hz, u.spectral()) except ZeroDivisionError: luminosity_nu_end = np.inf * u.Hz last_no_of_packets = config.montecarlo.last_no_of_packets if last_no_of_packets is None or last_no_of_packets < 0: last_no_of_packets = config.montecarlo.no_of_packets last_no_of_packets = int(last_no_of_packets) return cls(iterations=config.montecarlo.iterations, model=model, plasma=plasma, runner=runner, no_of_packets=int(config.montecarlo.no_of_packets), no_of_virtual_packets=int( config.montecarlo.no_of_virtual_packets), luminosity_nu_start=luminosity_nu_start, luminosity_nu_end=luminosity_nu_end, last_no_of_packets=last_no_of_packets, luminosity_requested=config.supernova.luminosity_requested.cgs, convergence_strategy=config.montecarlo.convergence_strategy, nthreads=config.montecarlo.nthreads)
def from_config(cls, config, packet_source=None, virtual_packet_logging=False, **kwargs): """ Create a new Simulation instance from a Configuration object. Parameters ---------- config : tardis.io.config_reader.Configuration **kwargs Allow overriding some structures, such as model, plasma, atomic data and the runner, instead of creating them from the configuration object. Returns ------- Simulation """ # Allow overriding some config structures. This is useful in some # unit tests, and could be extended in all the from_config classmethods. if "model" in kwargs: model = kwargs["model"] else: if hasattr(config, "csvy_model"): model = Radial1DModel.from_csvy(config) else: model = Radial1DModel.from_config(config) if "plasma" in kwargs: plasma = kwargs["plasma"] else: plasma = assemble_plasma(config, model, atom_data=kwargs.get("atom_data", None)) if "runner" in kwargs: if packet_source is not None: raise ConfigurationError( "Cannot specify packet_source and runner at the same time." ) runner = kwargs["runner"] else: runner = MontecarloRunner.from_config( config, packet_source=packet_source, virtual_packet_logging=virtual_packet_logging, ) luminosity_nu_start = config.supernova.luminosity_wavelength_end.to( u.Hz, u.spectral()) if u.isclose(config.supernova.luminosity_wavelength_start, 0 * u.angstrom): luminosity_nu_end = np.inf * u.Hz else: luminosity_nu_end = ( const.c / config.supernova.luminosity_wavelength_start).to( u.Hz) last_no_of_packets = config.montecarlo.last_no_of_packets if last_no_of_packets is None or last_no_of_packets < 0: last_no_of_packets = config.montecarlo.no_of_packets last_no_of_packets = int(last_no_of_packets) return cls( iterations=config.montecarlo.iterations, model=model, plasma=plasma, runner=runner, no_of_packets=int(config.montecarlo.no_of_packets), no_of_virtual_packets=int(config.montecarlo.no_of_virtual_packets), luminosity_nu_start=luminosity_nu_start, luminosity_nu_end=luminosity_nu_end, last_no_of_packets=last_no_of_packets, luminosity_requested=config.supernova.luminosity_requested.cgs, convergence_strategy=config.montecarlo.convergence_strategy, nthreads=config.montecarlo.nthreads, )