예제 #1
0
파일: test.py 프로젝트: rag9704/PTS
    def make_animation(self):

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

        # Inform the user
        log.info("Making animation ...")

        # Get the best
        best = self.optimizer.best

        # Determine path
        temp_path = self.optimizer.config.path
        filepath = fs.join(temp_path, "best.png")

        # Make plot of best

        # Create animated gif
        animation = Animation()

        # Open the images present in the directory
        for path in fs.files_in_path(temp_path, extension="png", exact_not_name="best"):
            # Add frame to the animation
            animation.add_frame_from_file(path)

        # Save the animation
        animation_path = fs.join(temp_path, "animation.gif")
        animation.saveto(animation_path)
예제 #2
0
파일: test.py 프로젝트: SKIRT/PTS
    def make_animation(self):

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

        # Inform the user
        log.info("Making animation ...")

        # Get the best
        best = self.optimizer.best

        # Determine path
        temp_path = self.optimizer.config.path
        filepath = fs.join(temp_path, "best.png")

        # Make plot of best

        # Create animated gif
        animation = Animation()

        # Open the images present in the directory
        for path in fs.files_in_path(temp_path, extension="png", exact_not_name="best"):
            # Add frame to the animation
            animation.add_frame_from_file(path)

        # Save the animation
        animation_path = fs.join(temp_path, "animation.gif")
        animation.saveto(animation_path)
예제 #3
0
파일: base.py 프로젝트: SKIRT/PTS
    def setup(self, **kwargs):

        """
        This function ...
        :param kwargs:
        :return:
        """

        # Call the setup function of the base class
        super(M81TestBase, self).setup(**kwargs)

        # Reference base path
        self.reference_path = fs.create_directory_in(self.path, "ref")

        # Reference wcs path
        self.reference_wcs_path = fs.join(self.reference_path, "wcs.txt")

        # Reference ski path
        self.reference_ski_path = fs.join(self.reference_path, "M81.ski")

        # Determine the simulation input and output path
        self.simulation_input_path = fs.create_directory_in(self.reference_path, "in")
        self.simulation_output_path = fs.create_directory_in(self.reference_path, "out")
        self.simulation_extract_path = fs.create_directory_in(self.reference_path, "extr")
        self.simulation_plot_path = fs.create_directory_in(self.reference_path, "plot")
        self.simulation_misc_path = fs.create_directory_in(self.reference_path, "misc")

        # Determine the path to the wavelength grid file
        self.wavelength_grid_path = fs.join(self.simulation_input_path, reference_wavelength_grid_filename)

        # Create the plot path
        self.plot_path = fs.create_directory_in(self.path, "plot")

        # Set the execution platforms
        self.set_platforms()
예제 #4
0
    def create_dataset(self, masks=None):

        """
        This function ...
        :param masks:
        :return:
        """

        # Inform the user
        log.info("Creating the dataset ...")

        # Initialize
        self.dataset = DataSet()

        # Add the frames
        for fltr in self.frames:

            # Determine name for the image
            name = str(fltr)

            # Determine path for this frame
            path = fs.join(self.data_frames_path, name + ".fits")

            # Debugging
            log.debug("Saving the frame ...")

            # Save the frame
            self.frames[fltr].saveto(path)

            # Debugging
            log.debug("Adding the '" + name + "' image to the dataset ...")

            # Add the frame to the dataset
            self.dataset.add_path(name, path)

            # Determine the path for the mask
            mask_path = fs.join(self.data_masks_path, name + ".fits")

            # Mask
            if masks is not None and fltr in masks:

                # Debugging
                log.debug("Saving the mask ...")

                # Save
                masks[fltr].saveto(mask_path)

                # Debugging
                log.debug("Adding mask ...")

                # Add the mask
                self.dataset.add_mask_path(name, mask_path)

        # Determine database path
        path = fs.join(self.path, "database.dat")

        # Write the dataset
        self.dataset.saveto(path)
예제 #5
0
파일: python.py 프로젝트: SKIRT/PTS
    def import_package_update(self, name, as_name=None, from_name=None, show_output=False):

        """
        Thins function ...
        :param name:
        :param as_name:
        :param from_name:
        :param show_output:
        :return:
        """

        # Try to import
        success, module_name, import_statement = self.import_package(name, as_name=as_name, from_name=from_name, show_output=show_output, return_false_if_fail=True, return_failed_module=True)

        # Not succesful, try updating the module on which it failed
        if not success:

            # No problem module, show import statement
            if module_name is None: raise RuntimeError("Unsolvable import error occured at: '" + import_statement + "'")

            # Debugging
            log.debug("Import of '" + name + "' was unsuccesful: trying updating the '" + module_name + "' package ...")

            from ..prep.update import update_pts_dependencies_remote

            # Find conda
            conda_installation_path, conda_main_executable_path = self.remote.find_conda()

            # Determine the conda environment for PTS
            env_name = self.remote.conda_environment_for_pts
            if env_name is None: raise Exception("Cannot determine the conda environment used for pts")
            conda_environment = env_name

            environment_bin_path = fs.join(conda_installation_path, "envs", conda_environment, "bin")
            if not self.remote.is_directory(environment_bin_path): raise RuntimeError("The environment directory is not present")
            conda_executable_path = fs.join(environment_bin_path, "conda")

            # Set ...
            conda_pip_path = fs.join(environment_bin_path, "pip")
            conda_python_path = fs.join(environment_bin_path, "python")
            conda_easy_install_path = fs.join(environment_bin_path, "easy_install")

            # Update the module
            packages = [module_name]
            update_pts_dependencies_remote(self.remote, packages, conda_executable_path,
                                           conda_environment, conda_python_path, conda_pip_path,
                                           conda_easy_install_path)

            # Try again
            success, module_name, import_statement = self.import_package(name, as_name=as_name, from_name=from_name,
                                                       show_output=show_output, return_false_if_fail=True,
                                                       return_failed_module=True)

            # Not succesful again
            if not success: raise ImportError("The import statement '" + import_statement + "' failed on remote host '" + self.host_id + "'")
예제 #6
0
파일: residuals.py 프로젝트: SKIRT/PTS
    def old(self):

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

        exit()

        # FWHM of all the images
        fwhm = 11.18 * u("arcsec")
        fwhm_pix = (fwhm / frame.average_pixelscale).to("pix").value
        sigma = fwhm_pix * statistics.fwhm_to_sigma

        # Get the center pixel of the galaxy
        parameters_path = fs.join(components_path, "parameters.dat")
        parameters = load_parameters(parameters_path)
        center = parameters.center.to_pixel(frame.wcs)

        # Create a source around the galaxy center
        ellipse = PixelEllipseRegion(center, 20.0*sigma)
        source = Source.from_ellipse(model_residual, ellipse, 1.5)

        source.estimate_background("polynomial")

        source.plot()

        position = source.center
        model = source.subtracted.fit_model(position, "Gaussian")

        rel_center = center - Extent(source.x_min, source.y_min)
        rel_model = fitting.shifted_model(model, -source.cutout.x_min, -source.cutout.y_min)
        plotting.plot_peak_model(source.cutout, rel_center.x, rel_center.y, rel_model)

        model_fwhm_pix = fitting.fwhm(model)
        model_fwhm = (model_fwhm_pix * frame.average_pixelscale).to("arcsec")

        print("Model FWHM: ", model_fwhm)

        evaluated_model = source.cutout.evaluate_model(model)

        all_residual = Frame(np.copy(model_residual))
        all_residual[source.y_slice, source.x_slice] -= evaluated_model
        all_residual.saveto(fs.join(residuals_path, "all_residual.fits"))

        model = Gaussian2D(amplitude=0.0087509425805, x_mean=center.x, y_mean=center.y, x_stddev=sigma, y_stddev=sigma)
        rel_model = fitting.shifted_model(model, -source.cutout.x_min, -source.cutout.y_min)
        plotting.plot_peak_model(source.cutout, rel_center.x, rel_center.y, rel_model)

        evaluated_model = source.cutout.evaluate_model(model)

        all_residual2 = Frame(np.copy(model_residual))
        all_residual2[source.y_slice, source.x_slice] -= evaluated_model
        all_residual2.saveto(fs.join(residuals_path, "all_residual2.fits"))
예제 #7
0
    def setup(self, **kwargs):
        """
        This function ...
        :param kwargs:
        :return:
        """

        # Call the
        super(GalaxyTest, self).setup(**kwargs)

        # Reference ski path
        self.reference_ski_path = fs.join(self.path, "galaxy_clumpy.ski")

        # Determine the simulation output path
        self.simulation_output_path = fs.join(self.path, "ref")
예제 #8
0
    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
        input_model = dict()

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

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

        # Set images dictionary
        images = dict()
        for filter_name in fitting_filter_names:
            images[filter_name] = fs.join("../ref/images",
                                          filter_name + ".fits")
        input_model["images"] = images
예제 #9
0
파일: uninstaller.py 프로젝트: rag9704/PTS
    def uninstall_conda_remote(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info(
            "Uninstalling the Conda python distribution on the remote host ..."
        )

        # Determine path of miniconda installation
        installation_path = fs.join(self.remote.home_directory, "miniconda")
        if not self.remote.is_directory(installation_path):
            log.warning("Conda was not found on the remote host")
            return

        # Debugging
        log.debug("Removing the Conda directory ...")

        # Remove the directory
        self.remote.remove_directory(installation_path)

        # Debugging
        log.debug("Removing lines from shell configuration ...")

        # Remove lines from shell configuration file
        comment = "For Conda, added by PTS (Python Toolkit for SKIRT)"
        self.remote.remove_aliases_and_variables_with_comment(comment)
        self.remote.remove_from_path_variable_containing("miniconda/bin")
예제 #10
0
    def create_ski(self):
        """
        This function ...
        """

        # Inform the user
        log.info("Creating ski file ...")

        fraction = 0.5
        count = 1000
        radius = parse_quantity("10 pc")
        cutoff = False
        kernel_type = "uniform"

        # Determine the ski path
        ski_path = fs.join(this_dir_path, "galaxy.ski")

        # Create clumpy ski file
        self.ski = LabeledSkiFile(ski_path)

        # Set instrument
        self.set_instrument()

        # Set stellar components
        self.set_stellar_components()

        # Set dust components
        self.set_dust_components()

        # Save as new ski file
        self.ski.saveto(self.reference_ski_path)
예제 #11
0
파일: run.py 프로젝트: SKIRT/PTS
def run_script(matches, args):

    """
    This function ...
    :param matches:
    :param args:
    :return:
    """

    if args.remote is not None: raise ValueError("This do command cannot be executed remotely")

    match = matches[0]

    # Execute the matching script, after adjusting the command line arguments so that it appears that the script was executed directly
    target = fs.join(introspection.pts_do_dir, match[0], match[1])
    sys.argv[0] = target
    del sys.argv[1]
    print("Executing: " + match[0] + "/" + match[1] + " " + " ".join(sys.argv[1:]))

    #command_name = match[1]

    # Set target
    #def start(): exec open(target)

    # Start # DOESN'T WORK WHEN THE SCRIPT FILE DEFINES A FUNCTION
    #start_target(command_name, start)
    exec open(target)
예제 #12
0
def run_script(matches, args):
    """
    This function ...
    :param matches:
    :param args:
    :return:
    """

    if args.remote is not None:
        raise ValueError("This do command cannot be executed remotely")

    match = matches[0]

    # Execute the matching script, after adjusting the command line arguments so that it appears that the script was executed directly
    target = fs.join(introspection.pts_do_dir, match[0], match[1])
    sys.argv[0] = target
    del sys.argv[1]
    print("Executing: " + match[0] + "/" + match[1] + " " +
          " ".join(sys.argv[1:]))

    #command_name = match[1]

    # Set target
    #def start(): exec open(target)

    # Start # DOESN'T WORK WHEN THE SCRIPT FILE DEFINES A FUNCTION
    #start_target(command_name, start)
    exec open(target)
예제 #13
0
파일: uninstaller.py 프로젝트: SKIRT/PTS
    def uninstall_conda_remote(self):

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

        # Inform the user
        log.info("Uninstalling the Conda python distribution on the remote host ...")

        # Determine path of miniconda installation
        installation_path = fs.join(self.remote.home_directory, "miniconda")
        if not self.remote.is_directory(installation_path):
            log.warning("Conda was not found on the remote host")
            return

        # Debugging
        log.debug("Removing the Conda directory ...")

        # Remove the directory
        self.remote.remove_directory(installation_path)

        # Debugging
        log.debug("Removing lines from shell configuration ...")

        # Remove lines from shell configuration file
        comment = "For Conda, added by PTS (Python Toolkit for SKIRT)"
        self.remote.remove_aliases_and_variables_with_comment(comment)
        self.remote.remove_from_path_variable_containing("miniconda/bin")
예제 #14
0
파일: residuals.py 프로젝트: SKIRT/PTS
    def load_i1(self):

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

        # Inform the user
        log.info("Loading the IRAC 3.6 micron image ...")

        # Determine the path to the truncated 3.6 micron image
        #path = fs.join(truncation_path, "IRAC I1.fits")

        path = fs.join(self.prep_path, "IRAC I1", "result.fits")
        frame = Frame.from_file(path)

        # Convert the frame to Jy/pix
        conversion_factor = 1.0
        conversion_factor *= 1e6

        # Convert the 3.6 micron image from Jy / sr to Jy / pixel
        pixelscale = frame.average_pixelscale
        pixel_factor = (1.0/pixelscale**2).to("pix2/sr").value
        conversion_factor /= pixel_factor
        frame *= conversion_factor
        frame.unit = "Jy"

        # Set the frame
        self.i1_jy = frame
예제 #15
0
파일: test.py 프로젝트: rag9704/PTS
    def check_reference_data(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Checking the reference data ...")

        # Determine simulation directory
        if self.config.reference_path is not None:
            data_path = self.config.reference_path
        elif self.config.reference_test is not None:
            data_path = fs.join(introspection.pts_tests_dir,
                                self.config.reference_test, "data")
        else:
            raise ValueError(
                "Reference path and reference test settings are None")

        # Check whether directory exist and not empty
        if not fs.is_directory(data_path):
            raise ValueError("Directory does not exist: " + data_path)
        if fs.is_empty(data_path):
            raise ValueError("Empty directory: " + data_path)

        # Remove data directory for this test
        fs.remove_directory(self.data_path)

        # Set data path
        self.data_path = data_path
예제 #16
0
파일: uninstaller.py 프로젝트: SKIRT/PTS
    def uninstall_conda_local(self):

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

        # Inform the user
        log.info("Uninstalling the Conda python distribution locally ...")

        # Check installation
        installation_path = fs.join(fs.home, "miniconda")
        if not fs.is_directory(installation_path):
            log.warning("Conda was not found locally")
            return

        # Debugging
        log.debug("Removing the Conda directory ...")

        # Remove the directory
        fs.remove_directory(installation_path)

        # Debugging
        log.debug("Removing lines from shell configuration ...")

        # Remove lines from shell configuration file
        comment = "For Conda, added by PTS (Python Toolkit for SKIRT)"
        terminal.remove_aliases_and_variables_with_comment(comment)
        terminal.remove_from_path_variable_containing("miniconda/bin")
예제 #17
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_chi_squared(self):

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

        # Inform the user
        log.info("Restoring the chi squared tables ...")

        # Loop over the generations
        for generation_name in self.generation_names:

            # Has generation?
            if not self.has_generation(generation_name): continue

            # Debugging
            log.debug("Creating backup of chi squared table for generation '" + generation_name + "' ...")

            # Get the generation
            generation = self.generations[generation_name]

            # Get the generation path
            generation_path = self.get_generation_restore_path(generation_name)

            # Determine the filepath
            filepath = fs.join(generation_path, "chi_squared.dat")

            # Copy the file
            fs.copy_file(filepath, generation.chi_squared_table_path)
예제 #18
0
파일: test.py 프로젝트: rag9704/PTS
    def make_young_stars_maps(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Making maps of young stars ...")

        # Get input
        fuv = self.get_frame("FUV")
        fuv_attenuation = self.get_map(fuv_attenuation_filename)
        old_disk = self.get_map(old_disk_filename)
        factor = 0.25  # to be determined for each galaxy

        # Make the map of young stars
        young_stars = make_young_stellar_map(
            self.get_frame("FUV"), self.get_map(fuv_attenuation_filename),
            old_disk, factor)

        # Determine the path
        path = fs.join(self.maps_path, young_stars_filename)

        # Save the map
        young_stars.saveto(path)
예제 #19
0
파일: test.py 프로젝트: SKIRT/PTS
    def create_wcs(self):

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

        # Inform the user
        log.info("Creating the WCS ...")

        min_pixelscale = None

        # Determine the path to the headers directory
        headers_path = fs.join(m81_data_path, "headers")

        # Loop over the header files
        for path, name in fs.files_in_path(headers_path, extension="txt", returns=["path", "name"]):

            # Get the filter
            fltr = parse_filter(name)
            filter_name = str(fltr)

            # Set the path of the file for the filter name
            self.wcs_paths[filter_name] = path

            # Get WCS
            wcs = CoordinateSystem.from_header_file(path)

            # Adjust the pixelscale
            if min_pixelscale is None:
                min_pixelscale = wcs.pixelscale
                self.wcs = wcs
            elif min_pixelscale > wcs.pixelscale:
                min_pixelscale = wcs.pixelscale
                self.wcs = wcs
예제 #20
0
    def create_wcs(self):

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

        # Inform the user
        log.info("Creating the WCS ...")

        min_pixelscale = None

        # Determine the path to the headers directory
        headers_path = fs.join(m81_data_path, "headers")

        # Loop over the header files
        for path, name in fs.files_in_path(headers_path, extension="txt", returns=["path", "name"]):

            # Get the filter
            fltr = parse_filter(name)
            filter_name = str(fltr)

            # Set the path of the file for the filter name
            self.wcs_paths[filter_name] = path

            # Get WCS
            wcs = CoordinateSystem.from_header_file(path)

            # Adjust the pixelscale
            if min_pixelscale is None:
                min_pixelscale = wcs.pixelscale
                self.wcs = wcs
            elif min_pixelscale > wcs.pixelscale:
                min_pixelscale = wcs.pixelscale
                self.wcs = wcs
예제 #21
0
파일: uninstaller.py 프로젝트: rag9704/PTS
    def uninstall_conda_local(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Uninstalling the Conda python distribution locally ...")

        # Check installation
        installation_path = fs.join(fs.home(), "miniconda")
        if not fs.is_directory(installation_path):
            log.warning("Conda was not found locally")
            return

        # Debugging
        log.debug("Removing the Conda directory ...")

        # Remove the directory
        fs.remove_directory(installation_path)

        # Debugging
        log.debug("Removing lines from shell configuration ...")

        # Remove lines from shell configuration file
        comment = "For Conda, added by PTS (Python Toolkit for SKIRT)"
        terminal.remove_aliases_and_variables_with_comment(comment)
        terminal.remove_from_path_variable_containing("miniconda/bin")
예제 #22
0
    def load_i1(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the IRAC 3.6 micron image ...")

        # Determine the path to the truncated 3.6 micron image
        #path = fs.join(truncation_path, "IRAC I1.fits")

        path = fs.join(self.prep_path, "IRAC I1", "result.fits")
        frame = Frame.from_file(path)

        # Convert the frame to Jy/pix
        conversion_factor = 1.0
        conversion_factor *= 1e6

        # Convert the 3.6 micron image from Jy / sr to Jy / pixel
        pixelscale = frame.average_pixelscale
        pixel_factor = (1.0 / pixelscale**2).to("pix2/sr").value
        conversion_factor /= pixel_factor
        frame *= conversion_factor
        frame.unit = "Jy"

        # Set the frame
        self.i1_jy = frame
예제 #23
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)
예제 #24
0
    def load_reference(self):
        """
        This function ...
        :return: 
        """

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

        # Determine simulation directory
        if self.config.reference_path is not None:
            simulation_path = self.config.reference_path
        elif self.config.reference_test is not None:
            simulation_path = fs.join(introspection.pts_tests_dir,
                                      self.config.reference_test, "ref")
        else:
            raise ValueError(
                "Reference path and reference test settings are None")

        # Check whether present
        if not fs.is_directory(simulation_path):
            raise ValueError(
                "The reference simulation path could not be found")

        # Look for simulation
        prefix, ski_path, in_path, out_path = find_one_simulation_in_path(
            simulation_path)

        # Load the ski file
        self.ski = LabeledSkiFile(ski_path)

        # Other paths
        extr_path = fs.join(simulation_path, "extr")
        plot_path = fs.join(simulation_path, "plot")
        misc_path = fs.join(simulation_path, "misc")

        # Check existence
        if not fs.is_directory(extr_path):
            raise IOError("Extraction directory not found")
        if not fs.is_directory(plot_path):
            raise IOError("Plotting directory not found")
        if not fs.is_directory(misc_path):
            raise IOError("Misc directory not found")

        # Copy
        self.copy_reference(ski_path, in_path, out_path, extr_path, plot_path,
                            misc_path)
예제 #25
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_configuration_path(self):

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

        return fs.join(self.restore_path, "configuration.cfg")
예제 #26
0
파일: base.py 프로젝트: SKIRT/PTS
    def modeling_path(self):

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

        return fs.join(self.path, self.modeling_name)
예제 #27
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_prob_path(self):

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

        return fs.join(self.restore_path, "prob")
예제 #28
0
    def write_mask(self):
        """
        Thisfunction ...
        :return:
        """

        path = fs.join(output_path, "mask.fits")
        mask.saveto(path, header=header)
예제 #29
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_weights_path(self):

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

        return fs.join(self.restore_path, "weights.dat")
예제 #30
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_generations_path(self):

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

        return fs.join(self.restore_path, "generations")
예제 #31
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_best_parameters_path(self):

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

        return fs.join(self.restore_path, "best_parameters.dat")
예제 #32
0
파일: plot.py 프로젝트: rag9704/PTS
    def write_tour_to_img(self, tour):

        """
        The function to plot the graph
        :param tour:
        """

        padding = 20
        coords = [(x+padding,y+padding) for (x,y) in self.coordinates]
        maxx, maxy = 0, 0

        for x, y in coords:

          maxx = max(x, maxx)
          maxy = max(y, maxy)

        maxx += padding
        maxy += padding

        img = Image.new("RGB",(int(maxx),int(maxy)),color=(255,255,255))

        font = ImageFont.load_default()
        d = ImageDraw.Draw(img)
        num_cities = len(tour)

        # Loop over the cities
        for i in range(num_cities):

          j = (i+1) % num_cities
          city_i = tour[i]
          city_j = tour[j]
          x1,y1 = coords[city_i]
          x2,y2 = coords[city_j]

          d.line((int(x1),int(y1),int(x2),int(y2)),fill=(0,0,0))
          d.text((int(x1)+7,int(y1)-5),str(i),font=font,fill=(32,32,32))

        for x, y in coords:

          x, y = int(x),int(y)
          d.ellipse((x-5,y-5,x+5,y+5),outline=(0,0,0),fill=(196,196,196))

        del d

        # Save
        if self.output_path is not None:

            # Determine the plot path
            path = fs.join(self.output_path, str(self.counter) + ".png")

            # Debugging
            log.debug("Saving the plot to '" + path + "' ...")

            # Save
            img.save(path, "PNG")

        else: raise RuntimeError("Cannot show the plot, specify an output path")
예제 #33
0
파일: base.py 프로젝트: SKIRT/PTS
    def elitism_table_path_for_generation(self, generation_name):

        """
        This function ...
        :param generation_name: 
        :return: 
        """

        return fs.join(self.fitting_run.generations_path, generation_name, "elitism.dat")
예제 #34
0
파일: restore.py 프로젝트: SKIRT/PTS
    def get_generation_restore_path(self, generation_name):

        """
        This function ...
        :param generation_name:
        :return:
        """

        return fs.join(self.restore_generations_path, generation_name)
예제 #35
0
파일: base.py 프로젝트: SKIRT/PTS
    def write_input(self):

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

        # Inform the user
        log.info("Writing the simulation input ...")

        # Write wavelength grid
        self.wavelength_grid.to_skirt_input(self.wavelength_grid_path)

        # Write maps
        self.maps["old"].saveto(fs.join(self.simulation_input_path, old_filename))
        self.maps["young"].saveto(fs.join(self.simulation_input_path, young_filename))
        self.maps["ionizing"].saveto(fs.join(self.simulation_input_path, ionizing_filename))
        self.maps["dust"].saveto(fs.join(self.simulation_input_path, dust_filename))
예제 #36
0
파일: test.py 프로젝트: rag9704/PTS
    def load_seds(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the SEDs ...")

        observed_sed_path = fs.join(this_dir_path, "DustPedia.dat")
        sim_sed_path_1 = fs.join(this_dir_path, "M81_earth_sed1.dat")
        sim_sed_path_2 = fs.join(this_dir_path, "M81_earth_sed2.dat")
        mock_sed_path = fs.join(this_dir_path, "M81_earth_fluxes.dat")

        self.observed_sed = ObservedSED.from_file(observed_sed_path)
        self.model_sed_1 = SED.from_skirt(sim_sed_path_1)
        self.model_sed_2 = SED.from_skirt(sim_sed_path_2)
        self.mock_sed = ObservedSED.from_file(mock_sed_path)
예제 #37
0
파일: test.py 프로젝트: SKIRT/PTS
    def load_seds(self):

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

        # Inform the user
        log.info("Loading the SEDs ...")

        observed_sed_path = fs.join(this_dir_path, "DustPedia.dat")
        sim_sed_path_1 = fs.join(this_dir_path, "M81_earth_sed1.dat")
        sim_sed_path_2 = fs.join(this_dir_path, "M81_earth_sed2.dat")
        mock_sed_path = fs.join(this_dir_path, "M81_earth_fluxes.dat")

        self.observed_sed = ObservedSED.from_file(observed_sed_path)
        self.model_sed_1 = SED.from_skirt(sim_sed_path_1)
        self.model_sed_2 = SED.from_skirt(sim_sed_path_2)
        self.mock_sed = ObservedSED.from_file(mock_sed_path)
예제 #38
0
파일: test.py 프로젝트: rag9704/PTS
    def get_map(self, name):
        """
        This function ...
        :param name:
        :return:
        """

        # Determine path
        path = fs.join(self.maps_path, name)
        return Frame.from_file(path)
예제 #39
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_path(self):

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

        path = fs.join(self.fitting_run.refitting_path, self.config.name)
        if not fs.is_directory(path): raise ValueError("'" + self.config.name + "' is not a backup of a fit")
        return path
예제 #40
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_fluxes_plots(self):

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

        # Inform the user
        log.info("Making a backup of the mock fluxes plots ...")

        # Loop over the generations
        for generation_name in self.generation_names:

            # Has generation?
            if not self.has_generation(generation_name): continue

            # Debugging
            log.debug("Creating backups for generation '" + generation_name + "' ...")

            # Get the generation
            generation = self.generations[generation_name]

            # Get restore path
            generation_path = self.get_generation_restore_path(generation_name)

            # Loop over the simulations
            for simulation_name in generation.simulation_names:

                # Set simulation path
                simulation_path = fs.join(generation_path, simulation_name)

                # Check whether fluxes are present
                filepath = fs.join(simulation_path, "earth_fluxes.pdf")
                if not fs.is_file(filepath):
                    log.warning("No mock SED plot for simulation '" + simulation_name + "' of generation '" + generation_name + "'")
                    continue

                # Debugging
                log.debug("Restoring fluxes plot for simulation '" + simulation_name + "' ...")

                # Copy the plot file
                fs.copy_file(filepath, generation.get_mock_sed_plot_path(simulation_name))
예제 #41
0
파일: restore.py 프로젝트: SKIRT/PTS
    def restore_differences(self):

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

        # Inform the user
        log.info("Making a backup of the flux differences ...")

        # Loop over the generations
        for generation_name in self.generation_names:

            # Has generation?
            if not self.has_generation(generation_name): continue

            # Debugging
            log.debug("Creating backups for generation '" + generation_name + "' ...")

            # Get the generation
            generation = self.generations[generation_name]

            # Get restore path
            generation_path = self.get_generation_restore_path(generation_name)

            # Loop over the simulations
            for simulation_name in generation.simulation_names:

                # Set simulation path
                simulation_path = fs.join(generation_path, simulation_name)

                # Check whether the simulation has differences
                filepath = fs.join(simulation_path, "differences.dat")
                if not fs.is_file(filepath):
                    log.warning("No differences table for simulation '" + simulation_name + "' of generation '" + generation_name + "'")
                    continue

                # Debugging
                log.debug("Restoring differences table for simulation '" + simulation_name + "' ...")

                # Copy the file
                fs.copy_file(filepath, generation.get_simulation_sed_differences_path(simulation_name))
예제 #42
0
파일: test.py 프로젝트: SKIRT/PTS
    def get_map(self, name):

        """
        This function ...
        :param name:
        :return:
        """

        # Determine path
        path = fs.join(self.maps_path, name)
        return Frame.from_file(path)
예제 #43
0
파일: base.py 프로젝트: SKIRT/PTS
    def load_components(self):

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

        # Inform the user
        log.info("Loading the components ...")

        # Determine paths
        path = fs.join(m81_data_path, "components")
        bulge_path = fs.join(path, "bulge.mod")
        disk_path = fs.join(path, "disk.mod")

        # Load bulge model
        self.bulge = load_3d_model(bulge_path)

        # Load disk model
        self.disk = load_3d_model(disk_path)
예제 #44
0
    def write_residuals(self):
        """
        This function ...
        :return:
        """

        # Bulge residual
        path = fs.join(self.components_residuals_path, "bulge.fits")
        self.bulge_residual.saveto(path)

        # Bulge2D residual
        path = fs.join(self.components_residuals_path, "bulge2D.fits")
        self.bulge2d_residual.saveto(path)

        # Disk residual
        path = fs.join(self.components_residuals_path, "disk.fits")
        self.disk_residual.saveto(path)

        # Calculate the model residual frame
        path = fs.join(self.components_residuals_path, "model.fits")
        self.model_residual.saveto(path)
예제 #45
0
    def load_model(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the model image ...")

        # Determine the path to the truncated model image
        path = fs.join(self.components_images_path, "model.fits")
        self.model_jy = Frame.from_file(path)
예제 #46
0
    def load_disk(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the disk image ...")

        # Determine the path to the disk image
        path = fs.join(self.components_images_path, "disk.fits")
        self.disk_jy = Frame.from_file(path)
예제 #47
0
    def load_bulge2d(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the bulge 2D image ...")

        # Determine the path to the bulge 2D image
        path = fs.join(self.components_images_path, "bulge2D.fits")
        self.bulge2d_jy = Frame.from_file(path)
예제 #48
0
파일: residuals.py 프로젝트: SKIRT/PTS
    def load_model(self):

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

        # Inform the user
        log.info("Loading the model image ...")

        # Determine the path to the truncated model image
        path = fs.join(self.components_images_path, "model.fits")
        self.model_jy = Frame.from_file(path)
예제 #49
0
파일: residuals.py 프로젝트: SKIRT/PTS
    def write_residuals(self):

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

        # Bulge residual
        path = fs.join(self.components_residuals_path, "bulge.fits")
        self.bulge_residual.saveto(path)

        # Bulge2D residual
        path = fs.join(self.components_residuals_path, "bulge2D.fits")
        self.bulge2d_residual.saveto(path)

        # Disk residual
        path = fs.join(self.components_residuals_path, "disk.fits")
        self.disk_residual.saveto(path)

        # Calculate the model residual frame
        path = fs.join(self.components_residuals_path, "model.fits")
        self.model_residual.saveto(path)
예제 #50
0
파일: residuals.py 프로젝트: SKIRT/PTS
    def load_disk(self):

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

        # Inform the user
        log.info("Loading the disk image ...")

        # Determine the path to the disk image
        path = fs.join(self.components_images_path, "disk.fits")
        self.disk_jy = Frame.from_file(path)
예제 #51
0
파일: test.py 프로젝트: rag9704/PTS
    def write_sources(self):
        """
        THis function ...
        :return:
        """

        # Inform the user
        log.info("Writing the sources frame with noise ...")

        # Determine the path
        path = fs.join(self.path, "sources_noise.fits")

        # Save the frame
        self.sources_with_noise.saveto(path)
예제 #52
0
파일: test.py 프로젝트: rag9704/PTS
    def write_residual(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Writing the residual map ...")

        # Determine the path
        path = fs.join(self.path, "residual.fits")

        # Save
        self.sky_residual.saveto(path)
예제 #53
0
파일: test.py 프로젝트: rag9704/PTS
    def write_statistics(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Writing the statistics ...")

        # Determine the path
        path = fs.join(self.path, "statistics.dat")

        # Write
        save_mapping(path, self.statistics)
예제 #54
0
파일: test.py 프로젝트: rag9704/PTS
    def write_frame(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Writing the frame ...")

        # Determine the path
        path = fs.join(self.path, "frame.fits")

        # SAve the frame
        self.frame.saveto(path)
예제 #55
0
파일: test.py 프로젝트: rag9704/PTS
    def write_subtracted(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Writing the sky-subtracted frame ...")

        # Determine the path
        path = fs.join(self.path, "subtracted.fits")

        # Save
        self.subtracted.saveto(path)
예제 #56
0
파일: test.py 프로젝트: rag9704/PTS
    def write_estimated_sky(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Writing the estimated sky map ...")

        # Determine the path
        path = fs.join(self.path, "estimated_sky.fits")

        # Save
        self.estimated_sky.saveto(path)
예제 #57
0
파일: test.py 프로젝트: rag9704/PTS
    def write_reference_sky(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Writing the reference sky map ...")

        # Determine the path
        path = fs.join(self.path, "reference_sky.fits")

        # Save
        self.reference_sky.saveto(path)
예제 #58
0
파일: test.py 프로젝트: rag9704/PTS
    def write_galaxy_mask(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Writing the galaxy mask ...")

        # Determine the path
        path = fs.join(self.path, "galaxy_mask.fits")

        # Save
        self.galaxy_mask.saveto(path)