示例#1
0
    def launch_reference(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Launching the reference simulation ...")

        # Settings
        settings_launch = dict()
        settings_launch["ski"] = self.reference_ski_path
        settings_launch["input"] = self.simulation_input_path
        settings_launch["output"] = self.simulation_output_path
        settings_launch["create_output"] = True
        settings_launch["remote"] = self.moderator.host_id_for_single(
            "reference")
        settings_launch["attached"] = self.config.attached
        settings_launch["progress_bar"] = True

        # Create the analysis options
        analysis = AnalysisOptions()
        analysis.extraction.path = self.simulation_extract_path
        analysis.plotting.path = self.simulation_plot_path
        analysis.misc.path = self.simulation_misc_path
        analysis.extraction.progress = True
        analysis.extraction.timeline = True
        analysis.extraction.memory = True
        analysis.plotting.progress = True
        analysis.plotting.timeline = True
        analysis.plotting.memory = True
        analysis.plotting.seds = True
        analysis.plotting.grids = True
        analysis.plotting.reference_seds = fs.files_in_path(seds_path)
        analysis.misc.fluxes = True
        analysis.misc.images = False
        analysis.misc.observation_filters = fitting_filter_names
        analysis.misc.observation_instruments = [instrument_name]
        analysis.misc.spectral_convolution = self.config.spectral_convolution

        # Set flux error bars
        dustpedia_sed = ObservedSED.from_file(dustpedia_sed_path)
        filter_names = dustpedia_sed.filter_names()
        errors = dustpedia_sed.errors()
        flux_errors = sequences.zip_into_dict(filter_names,
                                              [str(error) for error in errors])
        analysis.misc.flux_errors = flux_errors

        # Input
        input_launch = dict()
        # input_launch["memory"] = MemoryRequirement(serial_memory, parallel_memory)
        input_launch["analysis_options"] = analysis

        # Launch command
        launch = Command("launch_simulation",
                         "launch the reference simulation",
                         settings_launch,
                         input_launch,
                         cwd=".")
        self.launcher = self.run_command(launch)
示例#2
0
    def create_sed(self):
        """
        This function ...
        :return:
        """

        # Create simulation
        #prefix = name = "spiral"
        output_path = simulation_output_path
        #simulation = SkirtSimulation(prefix, outpath=output_path, ski_path=ski_path, name=name)

        # Settings
        settings_sed = dict()
        settings_sed["spectral_convolution"] = False

        # Input
        input_sed = dict()
        input_sed["simulation_output_path"] = simulation_output_path
        input_sed["output_path"] = "."

        # Construct the command
        create_sed = Command("observed_fluxes",
                             "create the mock SED",
                             settings_sed,
                             input_sed,
                             cwd=".")

        # Add the command
        #commands.append(create_sed)

        calculator = self.run_command(create_sed)

        # Determine the path to the mock SED
        mock_sed_path = "spiral_earth_fluxes.dat"
示例#3
0
    def launch_reference(self):
        """
        This function ...
        :return:
        """

        # Determine the simulation output path
        simulation_output_path = "./ref"

        # Settings
        settings_launch = dict()
        settings_launch["ski"] = ski_path
        settings_launch["output"] = simulation_output_path
        settings_launch["create_output"] = True

        # Input
        input_launch = dict()

        # Construct the command
        launch = Command("launch_simulation",
                         "launch the reference simulation",
                         settings_launch,
                         input_launch,
                         cwd=".")

        # Add the command
        #commands.append(launch)

        launcher = self.run_command(launch)
示例#4
0
    def setup_modelling(self):
        """
        This function ...
        :return:
        """

        # -----------------------------------------------------------------
        # SETUP THE MODELLING
        # -----------------------------------------------------------------

        # Settings
        settings_setup = dict()
        settings_setup["type"] = "sed"
        settings_setup["name"] = "Spiral"
        settings_setup["fitting_host_ids"] = None

        # Create object config
        object_config = dict()
        object_config["ski"] = ski_path

        # Create input dict for setup
        input_setup = dict()
        input_setup["object_config"] = object_config
        input_setup["sed"] = mock_sed_path

        # Construct the command
        stp = Command("setup",
                      "setup the modeling",
                      settings_setup,
                      input_setup,
                      cwd=".")

        # Add the command
        commands.append(stp)
示例#5
0
文件: test.py 项目: rag9704/PTS
    def setup_modelling(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Setting up the modeling ...")

        # Settings
        settings_setup = dict()
        settings_setup["type"] = "images"
        settings_setup["name"] = "NGC4013"
        settings_setup["fitting_host_ids"] = None

        # Create object config
        object_config = dict()
        ski_path = fs.join(this_dir_path, "NGC4013.ski")
        object_config["ski"] = ski_path

        object_config["images"] = self.image_paths.values()

        # Create input dict for setup
        input_setup = dict()
        input_setup["object_config"] = object_config

        # Construct the command
        setup_command = Command("setup", "setup the modelling", settings_setup,
                                input_setup, ".")

        # Run the command
        tool = self.run_command(setup_command)
示例#6
0
文件: test.py 项目: rag9704/PTS
    def launch_fitskirt(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Launching FitSKIRT ...")

        # Create configuration
        config = dict()

        # The path to the ski file and fski file
        config["ski"] = self.reference_ski_path
        config["fski"] = self.reference_fski_path

        config["input"] = self.data_path
        config["output"] = self.reference_output_path

        # Input
        input_dict = dict()

        # Construct the command
        command = Command("fitskirt",
                          "run the reference fitting with FitSKIRT",
                          config,
                          input_dict,
                          cwd=".")

        # Run the command
        self.launcher = self.run_command(command)
示例#7
0
    def make_sed(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Creating the observed mock SED ...")

        # Settings
        settings_sed = dict()
        settings_sed["spectral_convolution"] = False

        # Input
        input_sed = dict()
        input_sed["simulation_output_path"] = self.simulation_output_path
        input_sed["output_path"] = "."

        # Construct the command
        #create_sed = Command("observed_fluxes", "create the mock SED", settings_sed, input_sed, cwd=".")

        # Add the command
        #commands.append(create_sed)

        # Launch command
        calculate = Command("observed_fluxes",
                            "create the mock SED",
                            settings_sed,
                            input_sed,
                            cwd=".")
        self.flux_calculator = self.run_command(calculate)

        # Determine the path to the mock SED
        mock_sed_path = "spiral_earth_fluxes.dat"
示例#8
0
    def launch_reference(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Launching the reference simulation ...")

        # Settings
        settings_launch = dict()
        settings_launch["ski"] = self.reference_ski_path
        settings_launch["output"] = self.simulation_output_path
        settings_launch["create_output"] = True

        # Input
        input_launch = dict()

        # Launch command
        launch = Command("launch_simulation",
                         "launch the reference simulation",
                         settings_launch,
                         input_launch,
                         cwd=".")
        self.launcher = self.run_command(launch)
示例#9
0
文件: test.py 项目: rag9704/PTS
    def optimize(self):

        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Optimizing ...")

        # Construct the command
        command = Command("optimize_continuous", "finding the maximum of the function defined by Charbonneau (1995)",
                           settings_optimize, input_optimize, cwd=".")

        # Add the command
        #commands.append(optimize)

        self.optimizer = self.run_command(command)
示例#10
0
    def setup_modelling(self):
        """
        This fucntion ...
        :return:
        """

        # Inform the user
        log.info("Setting up the modelling ...")

        # Settings
        settings_setup = dict()
        settings_setup["type"] = "sed"
        settings_setup["name"] = self.modeling_name
        settings_setup[
            "fitting_host_ids"] = self.moderator.host_ids_for_ensemble(
                "fitting", none_if_none=True)

        # Create input dict for setup
        input_setup = dict()
        input_setup["sed"] = self.observed_sed
        input_setup["ski"] = self.ski_template
        #input_setup["ski_input"] = self.required_input_files
        input_setup[
            "ski_input"] = self.all_input_files  # Important so that the fittinginitializer can choose the number
        #  of wavelengths for the fitting based on what the user used as a wavelength grid file for the ski file

        # Create object config
        object_config = dict()
        # object_config["ski"] = ski_path
        input_setup["object_config"] = object_config

        # Construct the command
        stp = Command("setup",
                      "setup the modeling",
                      settings_setup,
                      input_setup,
                      cwd=".")

        # Call the command
        tool = self.run_command(stp)
示例#11
0
文件: test.py 项目: rag9704/PTS
    def model(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Performing the modelling ...")

        # Settings
        settings_model = dict()
        settings_model["ngenerations"] = self.config.ngenerations

        # -----------------------------------------------------------------

        # Create input dict for model
        input_model = dict()
        #input_model["parameters_config"] = Configuration(free_parameters=free_parameter_names)
        #input_model["descriptions_config"] = Configuration(descriptions=descriptions)
        #input_model["types_config"] = Configuration(types=types)
        #input_model["units_config"] = Configuration(units=units)
        #input_model["ranges_config"] = Configuration(luminosity_range=luminosity_range, dustmass_range=dustmass_range, grainsize_range=grainsize_range, fsil_range=fsil_range)
        #input_model["filters_config"] = Configuration(filters=filter_names)

        # Fitting initializer config
        #input_model["initialize_config"] = Configuration(npackages=1e4)

        # Construct the command
        model_command = Command("model",
                                "perform the modelling",
                                settings_model,
                                input_model,
                                cwd="./NGC4013")

        # Run the command
        self.modeler = self.run_command(model_command)
示例#12
0
文件: test.py 项目: rag9704/PTS
    def model(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Performing the modelling ...")

        # Settings
        settings_model = dict()
        settings_model["ngenerations"] = 4
        settings_model["nsimulations"] = 20
        settings_model["fitting_settings"] = {"spectral_convolution": False}

        # -----------------------------------------------------------------

        # Input

        # Get free parameter names
        ski = LabeledSkiFile(ski_path)
        free_parameter_names = ski.labels

        # Get fitting filter names
        filter_names = sed.filter_names()

        # Set descriptions
        descriptions = Map()
        descriptions["luminosity"] = "total luminosity of the SN"
        descriptions["dustmass"] = "total dust mass"
        descriptions["grainsize"] = "dust grain size"
        descriptions["fsil"] = "dust silicate fraction"

        # Set types
        types = Map()
        types["luminosity"] = "luminosity"
        types["dustmas"] = "mass"
        types["grainsize"] = "grainsize"
        types["fsil"] = "dimless"

        # Set units
        units = Map()
        units["luminosity"] = u("Lsun")
        units["dustmass"] = u("Msun")
        units["grainsize"] = u("micron")
        units["fsil"] = None

        # Set ranges
        luminosity_range = QuantityRange(100, 1000, "Lsun")
        dustmass_range = QuantityRange(0.3, 5, "Msun")
        grainsize_range = QuantityRange(0.1, 5, "micron")
        fsil_range = RealRange(0.1, 100)

        # Create input dict for model
        input_model = dict()
        input_model["parameters_config"] = Configuration(
            free_parameters=free_parameter_names)
        input_model["descriptions_config"] = Configuration(
            descriptions=descriptions)
        input_model["types_config"] = Configuration(types=types)
        input_model["units_config"] = Configuration(units=units)
        input_model["ranges_config"] = Configuration(
            luminosity_range=luminosity_range,
            dustmass_range=dustmass_range,
            grainsize_range=grainsize_range,
            fsil_range=fsil_range)
        input_model["filters_config"] = Configuration(filters=filter_names)

        # Fitting initializer config
        input_model["initialize_config"] = Configuration(npackages=1e4)

        # Construct the command
        model_command = Command("model", "perform the modelling",
                                settings_model, input_model, "./SN1987A")

        # Add the command
        #commands.append(model_command)

        self.modeler = self.run_command(model_command)
示例#13
0
    def model(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Performing the modelling ...")

        # Settings
        settings_model = dict()
        settings_model["ngenerations"] = self.config.ngenerations
        settings_model["nsimulations"] = self.config.nsimulations
        settings_model["fitting_settings"] = {"spectral_convolution": False}

        # For remote execution
        settings_model["attached"] = self.config.attached
        settings_model["fitting_attached"] = self.config.attached

        # Set the random seed
        #settings_model["seed"] = self.config.seed

        # RECURRENCE SETTINGS
        settings_model["check_recurrence"] = self.config.check_recurrence
        settings_model["recurrence_rtol"] = self.config.recurrence_rtol
        settings_model["recurrence_atol"] = self.config.recurrence_atol

        # Input
        input_model = dict()

        # Set galaxy properties
        input_model["properties"] = self.properties

        # Set SEDs
        #input_model["seds"] = dict()

        # Create free parameters config

        # Create descriptions config
        descriptions_config = Map(descriptions=free_parameter_descriptions)
        input_model["descriptions_config"] = descriptions_config

        # Create types config
        types_config = Map(types=free_parameter_types)
        input_model["types_config"] = types_config

        # Create units config
        units_config = Map(units=free_parameter_units)
        input_model["units_config"] = units_config

        # Create the ndigits config
        ndigits_config = Map(ndigits=parameter_ndigits)
        input_model["ndigits_config"] = ndigits_config

        # Create filters config
        filters_config = Map(filters=fitting_filter_names)
        input_model["filters_config"] = filters_config

        # Create genetic config
        input_model["genetic_config"] = Map(genetic=self.config.genetic)

        # Create grid config ??
        #input_model["grid_config"] = Map(grid=self.config.grid)

        # Create ranges config
        ranges_config = Map()
        for parameter_name in self.config.free_parameters:  # Define range
            ranges_config[
                parameter_name +
                "_range"] = self.config.relative_range_fitting * self.real_parameter_values[
                    parameter_name]
        input_model["ranges_config"] = ranges_config

        # If we're cheating
        if self.config.cheat:
            fixed_parameter_values = defaultdict(list)
            for label in self.config.free_parameters:
                fixed_parameter_values[label].append(
                    self.real_parameter_values[label])
            input_model["fixed_initial_parameters"] = fixed_parameter_values

        # Create initialize config
        initialize_config = Map()
        initialize_config.npackages = self.config.npackages_fitting
        initialize_config.selfabsorption = self.config.selfabsorption
        initialize_config.transient_heating = self.config.transient_heating
        input_model["initialize_config"] = initialize_config

        # Other input
        input_model["fitting_method"] = self.config.fitting_method
        input_model["parameter_grid_scales"] = self.parameter_grid_scales
        input_model["parameter_grid_weights"] = None

        # Construct the command
        command = Command("model",
                          "perform the modelling",
                          settings_model,
                          input_model,
                          cwd=self.modeling_path)

        # Run the command
        self.modeler = self.run_command(command)
示例#14
0
    def model(self):
        """
        This function ...
        :return:
        """

        # Settings
        settings_model = dict()
        settings_model["ngenerations"] = 4
        settings_model["nsimulations"] = 20
        settings_model["fitting_settings"] = {"spectral_convolution": False}

        # Input

        # Get free parameter names
        ski = LabeledSkiFile(ski_path)
        free_parameter_names = ski.labels

        # Get fitting filter names
        #filter_names = sed.filter_names()

        # Set descriptions
        descriptions = Map()
        descriptions[
            "exp_dustmass"] = "dust mass of the exponential disk with spiral structure"

        # Set types
        types = Map()
        types["exp_dustmass"] = "dust mass"

        # Set units
        units = Map()
        units["exp_dustmass"] = u("Msun")

        # Set the range of the dust mass
        dustmass_range = QuantityRange(0.1 * dust_mass, 100 * dust_mass)

        # Create input dict for model
        input_model = dict()
        input_model["parameters_config"] = Configuration(
            free_parameters=free_parameter_names)
        input_model["descriptions_config"] = Configuration(
            descriptions=descriptions)
        input_model["types_config"] = Configuration(types=types)
        input_model["units_config"] = Configuration(units=units)
        input_model["ranges_config"] = Configuration(
            exp_dustmass_range=dustmass_range)
        #input_model["filters_config"] = Configuration(filters=filter_names)

        # Fitting initializer config
        input_model["initialize_config"] = Configuration(npackages=1e4)

        # Add dict of input for 'model' command to the list
        #input_dicts.append(input_model)

        # Construct the command
        command = Command("model", "perform the modelling", settings_model,
                          input_model, "./Spiral")

        # Add the command
        #commands.append(command)

        modeler = self.run_command(command)
示例#15
0
    def make_images(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Creating the observed mock images ...")

        # Create Aniano kernels object
        aniano = AnianoKernels()

        # Set the paths to the kernel for each image
        kernel_paths = dict()
        for filter_name in fitting_filter_names:
            kernel_paths[filter_name] = aniano.get_psf_path(
                parse_filter(filter_name))

        # Settings
        settings_images = dict()
        settings_images["spectral_convolution"] = False
        # No output path is specified, so images won't be written out

        # Input
        input_images = dict()
        input_images["simulation_output_path"] = self.simulation_output_path
        input_images["output_path"] = "."
        input_images["filter_names"] = fitting_filter_names
        input_images["instrument_names"] = ["earth"]
        # input_images["wcs_path"] =
        input_images["wcs"] = self.wcs
        input_images["kernel_paths"] = kernel_paths
        input_images["unit"] = "Jy/pix"
        # input_images["host_id"] = "nancy"

        # Construct the command
        #create_images = Command("observed_images", "create the mock images", settings_images, input_images, cwd=".",
        #                        finish=make_data)

        # Add the command
        #commands.append(create_images)

        make = Command("observed_images",
                       "create the mock images",
                       settings_images,
                       input_images,
                       cwd=".")
        self.image_maker = self.run_command(make)

        # MAKE DATA:

        # Create directory for the images
        ref_path = fs.create_directory_in(self.path, "ref")
        images_path = fs.create_directory_in(ref_path, "images")

        # Determine the name of the datacube
        datacube_names = self.image_maker.images.keys()
        if len(datacube_names) > 1:
            raise RuntimeError("Unexpected number of datacubes")
        datacube_name = datacube_names[0]

        # Loop over the images
        for filter_name in self.image_maker.images[datacube_name]:

            # Get the image
            image = self.image_maker.images[datacube_name][filter_name]

            # Save the image
            image_path = fs.join(images_path, filter_name + ".fits")
            image.saveto(image_path)