Ejemplo n.º 1
0
Archivo: test.py Proyecto: rag9704/PTS
    def show(self):
        """
        This function ...
        :return:
        """

        print("")
        print("Best parameter values:")
        print("")
        for label in self.best_parameter_values:
            print(" - " + label + ": " +
                  stringify.stringify(self.best_parameter_values[label])[1])
        print("")

        print("Best luminosities:")
        print("")
        for filter_name in self.best_luminosities:
            print("  " + filter_name + ":")
            print("")
            for index in range(len(self.best_luminosities)):
                print("   - component #" + str(index) + ": " +
                      stringify.stringify(self.best_luminosities[filter_name]
                                          [index])[1])
            print("")
Ejemplo n.º 2
0
    def set_fwhms(self):

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

        # Inform the user
        log.info("Setting the FWHMs ...")

        # Loop over the filters
        for fltr in self.frames:

            # Get the fwhm
            if has_variable_fwhm(fltr): fwhm = fwhms[str(fltr)]
            else: fwhm = get_fwhm(fltr)

            # Debugging
            log.debug("The FWHM of the '" + str(fltr) + "' image is " + stringify.stringify(fwhm)[1])

            # Set
            self.real_fwhms[fltr] = fwhm
Ejemplo n.º 3
0
Archivo: test.py Proyecto: rag9704/PTS
    def make_rotation_masks(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Making rotation masks ...")

        # Loop over the filters
        for fltr in self.frames:

            # Debugging
            log.info("Making rotation mask for the '" + str(fltr) +
                     "' image ...")

            # Get the frame
            frame = self.frames[fltr]

            # Rotate
            if self.config.rotate:

                # Choose a random rotation angle
                angle = Angle(np.random.uniform(-90, 90), "deg")

                # Debugging
                log.debug("The random rotation angle is '" +
                          stringify.stringify(angle)[1] + "'")

                # Create mask
                mask = frame.rotation_mask(angle)

            # Don't rotate
            else:
                mask = Mask.empty_like(frame)

            # Set the mask
            self.rotation_masks[fltr] = mask
Ejemplo n.º 4
0
Archivo: test.py Proyecto: SKIRT/PTS
    def make_rotation_masks(self):

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

        # Inform the user
        log.info("Making rotation masks ...")

        # Loop over the filters
        for fltr in self.frames:

            # Debugging
            log.info("Making rotation mask for the '" + str(fltr) + "' image ...")

            # Get the frame
            frame = self.frames[fltr]

            # Rotate
            if self.config.rotate:

                # Choose a random rotation angle
                angle = Angle(np.random.uniform(-90, 90), "deg")

                # Debugging
                log.debug("The random rotation angle is '" + stringify.stringify(angle)[1] + "'")

                # Create mask
                mask = frame.rotation_mask(angle)

            # Don't rotate
            else: mask = Mask.empty_like(frame)

            # Set the mask
            self.rotation_masks[fltr] = mask
Ejemplo n.º 5
0
        # Show the properties
        for prop_name in properties:

            description = properties[prop_name].description
            ptype = properties[prop_name].ptype
            min_value = properties[prop_name].min
            max_value = properties[prop_name].max
            default = properties[prop_name].default
            choices = properties[prop_name].choices
            item = properties[prop_name].item

            string = fmt.blue + prop_name + fmt.reset

            string += " [type: " + ptype + "]"
            if min_value is not None: string += " [min: " + stringify.stringify_not_list(min_value)[1] + "]"
            if max_value is not None: string += " [max: " + stringify.stringify_not_list(max_value)[1] + "]"
            if default is not None: string += " [default: " + stringify.stringify_not_list(default)[1] + "]"
            if choices is not None: string += " [choices: " + stringify.stringify(choices.keys())[1] + "]"

            string += " " + fmt.darkgray + stringify.stringify_string_fancy(description, lines_prefix="    ")[1] + fmt.reset

            if item: string += fmt.red + " [SIMULATION ITEM] " + fmt.reset

            print(" -  " + string)
            print("")

    #print("")

# -----------------------------------------------------------------
Ejemplo n.º 6
0
    def make_point_sources_fixed_fwhm(self, masks=None):

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

        # Inform the user
        log.info("Making point sources with a fixed FWHM in each band ...")

        # Loop over the 'star' filters
        for fltr in self.star_filters:

            # Debugging
            log.debug("Making point sources for the '" + str(fltr) + "' image ...")

            # Get pixelscale
            pixelscale = self.frames[fltr].average_pixelscale

            # Debugging
            log.debug("The pixelscale of the image is " + stringify.stringify(pixelscale)[1])

            # Determine the FWHM in pixel coordinates
            fwhm_pix = self.real_fwhms[fltr].to("arcsec").value / pixelscale.to("arcsec").value

            # Determine sigma
            sigma = statistics.fwhm_to_sigma * fwhm_pix

            # Only 'render' the Gaussian locally
            origin = PixelCoordinate(0.0, 0.0)
            amplitude = 1.
            min_x, max_x, min_y, max_y, rel_center = determine_patch_for_psf(origin, amplitude, sigma, keep_in_frame=False)

            # Make the model
            model = create_model(self.config.psf_model, amplitude, rel_center, sigma)

            # Evalute the model
            y, x = np.indices((max_y - min_y, max_x - min_x))
            data = model(x, y)

            # Keep track of the number of sources
            counter = 0

            # Loop over the coordinates in the point sources catalog
            for coordinate in self.point_source_catalog.coordinates():

                counter += 1

                # Debugging
                log.debug("Adding source " + str(counter) + " of " + str(len(self.point_source_catalog)) + " ...")

                # Check whether it falls in the frame
                if not self.frames[fltr].contains(coordinate): continue

                # Convert into pixel coordinate
                pixel_coordinate = coordinate.to_pixel(self.frames[fltr].wcs)

                # Get the corresponding pixel
                pixel = Pixel.for_coordinate(pixel_coordinate)

                # Check whether not masked
                if masks is not None and fltr in masks and masks[fltr][pixel.y, pixel.x]: continue

                # Generate a random amplitude (from 100 till 100 000)
                amplitude_exponent = np.random.uniform(2., 5.)
                amplitude = 10 ** amplitude_exponent

                # Calculate absolute minima and maxima
                source_min_x = min_x + pixel.x
                source_max_x = max_x + pixel.x
                source_min_y = min_y + pixel.y
                source_max_y = max_y + pixel.y

                source_xsize = source_max_x - source_min_x
                source_ysize = source_max_y - source_min_y

                # Correct
                if source_min_x < 0:
                    cut_x_min = - source_min_x
                    source_min_x = 0
                else: cut_x_min = 0

                if source_max_x >= self.frames[fltr].xsize:
                    cut_x_max = source_xsize - (source_max_x - self.frames[fltr].xsize)
                    source_max_x = self.frames[fltr].xsize
                else: cut_x_max = source_xsize

                if source_min_y < 0:
                    cut_y_min = - source_min_y
                    source_min_y = 0
                else: cut_y_min = 0

                if source_max_y >= self.frames[fltr].ysize:
                    cut_y_max = source_ysize - (source_max_y - self.frames[fltr].ysize)
                    source_max_y = self.frames[fltr].ysize
                else: cut_y_max = source_ysize

                # Create the final data for this source
                source_data = data[cut_y_min:cut_y_max, cut_x_min:cut_x_max] * amplitude

                # Add the data
                self.frames[fltr][source_min_y:source_max_y, source_min_x:source_max_x] += source_data
Ejemplo n.º 7
0
    def make_point_sources_variable_fwhm(self, masks=None):

        """
        THis function ...
        :param masks:
        :return:
        """

        # Inform the user
        log.info("Making point sources with a variable FWHM in each band ...")

        # Loop over the 'star' filters
        for fltr in self.star_filters:

            # Debugging
            log.debug("Making point sources for the '" + str(fltr) + "' image ...")

            # Get y and x
            if not self.config.only_local:
                y, x = np.indices(self.frames[fltr].shape)
            else: y = x = None

            # Get pixelscale
            pixelscale = self.frames[fltr].average_pixelscale

            # Debugging
            log.debug("The pixelscale of the image is " + stringify.stringify(pixelscale)[1])

            # Determine the FWHM in pixel coordinates
            fwhm_pix = self.real_fwhms[fltr].to("arcsec").value / pixelscale.to("arcsec").value

            counter = 0

            # Loop over the coordinates in the point sources catalog
            for coordinate in self.point_source_catalog.coordinates():

                counter += 1

                # Debugging
                log.debug("Adding point source " + str(counter) + " of " + str(len(self.point_source_catalog)) + " ...")

                # Check whether it falls in the frame
                if not self.frames[fltr].contains(coordinate): continue

                # Convert into pixel coordinate
                pixel_coordinate = coordinate.to_pixel(self.frames[fltr].wcs)

                # Get the corresponding pixel
                pixel = Pixel.for_coordinate(pixel_coordinate)

                # Check whether not masked
                if masks is not None and fltr in masks and masks[fltr][pixel.y, pixel.x]: continue

                # Generate random deviation
                x_deviation = np.random.normal(0.0, 1.)
                y_deviation = np.random.normal(0.0, 1.)

                # Debugging
                log.debug("Random pixel position deviation is (" + str(x_deviation) + ", " + str(y_deviation) + ")")

                # Alter pixel coordinate
                pixel_coordinate.x += x_deviation
                pixel_coordinate.y += y_deviation

                # Generate random deviation from FWHM
                fwhm_deviation = np.random.normal(0.0, 0.05 * fwhm_pix)

                # Debugging
                log.debug("Random FWHM deviation (on a FWHM of " + str(fwhm_pix) + ") is " + str(fwhm_deviation))

                # Add the deviation
                fwhm_pix += fwhm_deviation

                # Generate a random amplitude (from 100 till 100 000)
                amplitude_exponent = np.random.uniform(2., 5.)
                amplitude = 10**amplitude_exponent

                # Determine sigma
                sigma = statistics.fwhm_to_sigma * fwhm_pix

                # Only 'render' the Gaussian locally
                if self.config.only_local: min_x, max_x, min_y, max_y, rel_center = determine_patch_for_psf(pixel_coordinate, amplitude, sigma, max_x_pixel=self.frames[fltr].xsize-1, max_y_pixel=self.frames[fltr].ysize-1, keep_in_frame=True)

                # Render each Gaussian over the entire frame
                else:
                    min_x = max_x = min_y = max_y = None
                    rel_center = pixel_coordinate

                # Make the model
                model = create_model(self.config.psf_model, amplitude, rel_center, sigma)

                # Evaluate the model
                if self.config.only_local: y, x = np.indices((max_y - min_y, max_x - min_x))
                data = model(x, y)

                # Add the data
                if self.config.only_local: self.frames[fltr][min_y:max_y, min_x:max_x] += data
                else: self.frames[fltr] += data
Ejemplo n.º 8
0
Archivo: python.py Proyecto: SKIRT/PTS
    def load_dictionary(self, dictionary_name, dictionary, local_temp_path, remote_temp_path=None):

        """
        This function ...
        :param dictionary_name:
        :param dictionary:
        :param local_temp_path:
        :param remote_temp_path:
        :return:
        """

        # Set temp paths
        temp_path = local_temp_path

        # Check if remote temp path is defined
        if remote_temp_path is None: remote_temp_path = self.session_temp_directory

        # Import the parsing module remotely
        self.import_package("parsing", from_name="pts.core.tools", show_output=log.is_debug)

        # Paths to input files that have to be uploaded
        local_input_filepaths = []

        # Depending paths
        depending_filepaths = dict()

        # Strings
        input_strings = dict()

        # E.G.
        # dictionary = {"a": OBJECT_A, "b": OBJECT_B}

        # Loop over the names of the input objects
        for name in dictionary:

            # name = "a"

            # Get the value
            value = dictionary[name]

            # value = OBJECT_A

            # Check whether extension is defined
            if hasattr(value, "default_extension"):

                # Determine filepath
                path = fs.join(temp_path, name + "." + value.default_extension)
                # path = .../a.ext

                # Save
                dictionary[name].saveto(path)

                # Add the filepath
                local_input_filepaths.append(path)

                # Check whether this object has depending paths
                if hasattr(value, "get_depending_paths"):

                    # Get the local depending filepaths
                    local_depending_filepaths = value.get_depending_paths() # = dictionary

                    # Set the depending filepaths for this input object
                    depending_filepaths[name] = local_depending_filepaths

            # Extension is not defined
            else:

                # Try to convert the object to a string
                ptype, string = stringify(value)

                # Add to dictinoary
                input_strings[name] = (ptype, string)

        #### UPLOAD THE INPUT :

        # Upload the input files
        self.remote.upload_retry(local_input_filepaths, remote_temp_path, show_output=log.is_debug)

        # UPLOAD DEPENDING FILEPATHS

        remote_depending_filepaths = dict()
        for name in depending_filepaths:

            # name = "a"

            # Create remote directory for this input object
            dirname = name + "_depending"
            dirpath = fs.join(remote_temp_path, dirname)
            self.create_directory(dirpath)

            # Initialize
            remote_depending_filepaths[name] = dict()

            # Upload all depending
            index = 0
            for label in depending_filepaths[name]:

                # Get the local filepath
                local_depending_filepath = depending_filepaths[name][label]

                # Determine new name for the file
                extension = fs.get_extension(local_depending_filepath)
                new_name = str(index) + "." + extension

                # Upload the file, giving it a new name
                remote_depending_filepath = self.remote.upload_file_to(local_depending_filepath, dirpath, new_name=new_name, show_output=log.is_debug)

                # Set the remote path
                remote_depending_filepaths[name][label] = remote_depending_filepath

                # Increment the counter
                index += 1

        ### LOAD THE INPUT DICT REMOTELY

        # Initialize the remote input dictionary
        self.send_line(dictionary_name + " = dict()", show_output=log.is_debug)

        # Add the stuff
        for name in dictionary:

            # Get the value
            value = dictionary[name]

            # Check whether extension is defined
            if hasattr(value, "default_extension"):

                # Determine the remote filepath
                remote_filepath = fs.join(remote_temp_path, name + "." + value.default_extension)

                # Import the class of the filetype remotely
                classpath = str(type(value)).split("'")[1].split("'")[0]
                modulepath, classname = classpath.rsplit(".", 1)
                self.send_line("input_module = importlib.import_module('" + modulepath + "')", show_output=log.is_debug)  # get the module of the class
                self.send_line("input_cls = getattr(input_module, '" + classname + "')", show_output=log.is_debug)  # get the class

                # Open the input file
                if name in depending_filepaths: self.send_line("input_dict['" + name + "'] = input_cls.from_file('" + remote_filepath + "', check=False)", show_output=True)
                else: self.send_line("input_dict['" + name + "'] = input_cls.from_file('" + remote_filepath + "')", show_output=True)

                # Check whether depending paths have to be adjusted
                if name in depending_filepaths:

                    # Loop over each label
                    for label in depending_filepaths[name]:

                        # Get the remote filepath
                        depending_filepath = remote_depending_filepaths[name][label]

                        # Set the depending path
                        self.send_line("input_dict['" + name + "'].set_depending_path('" + label + "', '" + depending_filepath + "')", show_output=True)

            # Extension is not defined
            else:

                # Get the parsing type and the string
                ptype, string = input_strings[name]

                # Get the parsing function remotely
                self.send_line("parsing_function = getattr(parsing, '" + ptype + "')")

                # Parse the input object
                self.send_line("input_dict['" + name + "'] = parsing_function('" + string + "')")
Ejemplo n.º 9
0
print(" - position: " + str(sample.get_position(name)))
print(" - D25: " + str(sample.get_d25(name)))
print(" - R25: " + str(sample.get_r25(name)))
print("")
print(" - stage: " + str(info["Hubble Stage"][0]))
print(" - V: " + str(info["V"][0]))
print(" - inclination: " + str(info["Inclination"][0]))

print("")
print(fmt.red + fmt.underlined + "Images:" + fmt.reset)
print("")

#for name in image_names: print(" - " + name)
#print("")

print("   " + "\n     ".join(wrap(stringify.stringify(image_filters)[1], 100)))
print("")

#urls = database.get_image_urls(name, error_maps=False)
#print(urls)

#database.reset(username, password)

# Open the cutouts file
fs.open_file(path)

# Create the photometry
photometry = DustPediaPhotometry()

# Get the aperture
aperture = photometry.get_aperture(name)
Ejemplo n.º 10
0
from pts.core.basics.configuration import ConfigurationDefinition, parse_arguments

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

# Create the configuration
definition = ConfigurationDefinition()
definition.add_positional_optional(
    "match", "string",
    "only show quantities with names that contain this string")

# Parse
config = parse_arguments("skirt_quantities", definition)

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

# Create the SKIRT smile schema
smile = SKIRTSmileSchema()

print("")
for quantity in smile.quantities:

    units = smile.units_for_quantity(quantity)
    print(fmt.green + fmt.underlined + quantity + fmt.reset + ": " +
          stringify.stringify(units)[1].replace(" ", "").replace(",", ", ") +
          " [PTS: " + skirt_quantities_to_pts_quantities[quantity] + "]")
    print("")

#print("")

# -----------------------------------------------------------------
Ejemplo n.º 11
0
print(" - position: " + str(sample.get_position(name)))
print(" - D25: " + str(sample.get_d25(name)))
print(" - R25: " + str(sample.get_r25(name)))
print("")
print(" - stage: " + str(info["Hubble Stage"][0]))
print(" - V: " + str(info["V"][0]))
print(" - inclination: " + str(info["Inclination"][0]))

print("")
print(fmt.red + fmt.underlined + "Images:" + fmt.reset)
print("")

#for name in image_names: print(" - " + name)
#print("")

print("   " + "\n     ".join(wrap(stringify.stringify(image_filters)[1], 100)))
print("")

#urls = database.get_image_urls(name, error_maps=False)
#print(urls)

#database.reset(username, password)

# Open the cutouts file
fs.open_file(path)

# Create the photometry
photometry = DustPediaPhotometry()

# Get the aperture
aperture = photometry.get_aperture(name)