예제 #1
0
    def __init__(self, config=None, optable_args=None, dashboard_args=None):
        super(Star, self).__init__()
        self.log = logging.getLogger(__name__)
        self.data_log = logging.getLogger("data")
        self.telem_log = logging.getLogger("telemetry")
        self.telem_log.propagate = False
        self._call_count = 0
        self._warning_count = {"Neg": 0}
        self.name = current_process().name

        self._config = DottedConfiguration(config)
        self._config.dn = DottedConfiguration

        self._integrator_name = self.config.get("System.Integrator.Method",
                                                "scipy")
        self._max_warnings = self.config["System.Integrator"].get(
            "Warnings", 100)
        self._integrator = getattr(self, self._integrator_name)
        self._logmode = self.config.get("System.Integrator.LogScale", True)
        self._plotting = self.config.get("System.Integrator.LivePlot", True)
        np.set_printoptions(**self.config["System.Numpy.PrintOptions"])

        if optable_args is None:
            self.log.debug("Starting Opacity Table from Scratch")
            self._opacity = ObjectThread(
                OpacityTable,
                ikwargs=dict(fkey=self._config["Data.Opacity.Config"],
                             X=self.X,
                             Y=self.Y,
                             snap=self._config["System.Opacity.Snap"],
                             error=self._config["System.Opacity.Error"],
                             wmax=self._config["System.Opacity.Warnings"],
                             efkey=self._config.get(
                                 "System.Opacity.ExtendedKey", None)),
                locking=True,
                timeout=self._config["System.Opacity.Timeout"])
            self.opacity.start()
            self.log.debug("Started Opacity Table From Scratch")
        else:
            self.log.debug("Starting Opacity Table from Arguments")
            self._opacity = ObjectManager(**optable_args)
            self.log.debug("Started Opacity Table from Arguments")

        if dashboard_args is not None:
            self._dashboard = ObjectManager(**dashboard_args)

        from astropysics.constants import Rs, Lsun, Ms
        self.Pc_Guess = float(self._config["Star.Initial.Pc"])
        self.Tc_Guess = float(self._config["Star.Initial.Tc"])
        self.R_Guess = float(self._config["Star.Initial.Rs"]) * Rs
        self.L_Guess = float(self._config["Star.Initial.Ls"]) * Lsun
        self.dm_Guess = float(self._config["Star.Initial.dm"]) * Ms
        self.fp = float(self._config["Star.Integration.fp"]) * self.M

        self._update_frequency = self.config["System.Dashboard.Update"]
        self._save_frequency = self.config["System.Outputs.Update"]
예제 #2
0
    def __init__(self,
                 fkey,
                 load=True,
                 filename="OPAL.yml",
                 X=None,
                 Y=None,
                 snap=False,
                 error=True,
                 wmax=100,
                 efkey=None):
        super(OpacityTable, self).__init__()

        # Initialize our attribute values

        # Compositional Values
        self._X = None
        self._Y = None
        self._dXc = None
        self._dXo = None

        self._interpolator = None  # Object for the interpolator
        self._snap = snap  # Snap out-of-bounds objects to the grid.
        self._error = error  # Use python errors, or return np.nan
        self._warnings = {"NaNs": 0}
        self._warnings_max = wmax

        # Logging Values:
        self.log = logging.getLogger(__name__)

        # Set up the configuration
        self.fkey = fkey
        self.cfg = DottedConfiguration({})
        self.cfg.load(filename, silent=False)
        self.cfg.dn = DottedConfiguration
        self.table_type = self.cfg[self.fkey].get('type', 'single')
        self.table_comp = (X, Y)

        # Load the tables (from cached .npy files if appropriate)
        self.log.debug("Loading Tables...")
        if load:
            try:
                self.load()
            except IOError:
                self.read()
                self.save()
        else:
            self.read()
        self.log.debug("Tables Loaded: %s", repr(self._tbls.shape))

        # Make ourselves a nearest-neighbor composition interpolator
        self._composition_interpolator()

        # If we have a composition, we should use it.
        if X is not None and Y is not None:
            self.composition(X, Y)

        if efkey is not None:
            self.log.debug("Loading extension tables")
            if self.cfg[efkey].get('type', 'single') == 'single':
                e_comp, e_tbls = read_table_opal(efkey, cfg=self.cfg)
                self.log.debug("Read Opacity Tables from %(filename)s" %
                               self.cfg[efkey])
            elif self.cfg[efkey].get('type', 'single') == 'split':
                e_comp, e_tbls = read_standalone_opal(self.X,
                                                      self.Z,
                                                      efkey,
                                                      cfg=self.cfg)
                self.log.debug("Read Opacity Tables from %(filename)s" %
                               self.cfg[efkey])
            self._tbls = merge_tables(self._comp, e_comp, self._tbls, e_tbls)
            self.log.debug("Read Extension Opacity Tables from %(filename)s" %
                           self.cfg[efkey])
            self._temperature_density_interpolator()

        self.log.debug("Opacity Interpolator Initialzied")