Exemplo n.º 1
0
Arquivo: single.py Projeto: SKIRT/PTS
    def filename(self):

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

        return fs.strip_extension(fs.name(self.config.image))
Exemplo n.º 2
0
from pts.core.basics.rgbimage import invert_colors
from pts.core.tools import filesystem as fs

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

# Create the command-line parser
parser = argparse.ArgumentParser()

# Basic options
parser.add_argument("filename", type=str, help="the name of the input image file")

# Parse the command line arguments
arguments = parser.parse_args()

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

# Open the original image
image = imageio.imread(arguments.filename)

# Invert the colours
invert_colors(image)

# Determine output name
name = fs.strip_extension(fs.name(arguments.filename))
newname = name + "_inverted.png"

# Write the inverted image
imageio.imwrite(newname, image)

# -----------------------------------------------------------------
Exemplo n.º 3
0
# -----------------------------------------------------------------

single_command = matches.keys()[0]
log.debug("The matching command is '" + single_command + "'")
if len(matches[single_command]) == 0: raise RuntimeError("Something went wrong")

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

# Get latest
latest_time = None
latest_filepath = None

# Loop over the files
for filepath in matches[single_command]:

    name = fs.strip_extension(fs.name(filepath))
    command_name, datetime = time.get_name_and_time_from_unique_name(name)

    #print(name, command_name, datetime)

    if latest_time is None or latest_time < datetime:
        latest_time = datetime
        latest_filepath = filepath

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

log.info("Showing log from '" + single_command + "' command at " + str(latest_time))

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

# Loop over the lines
Exemplo n.º 4
0
# -----------------------------------------------------------------

# Create the command-line parser
parser = argparse.ArgumentParser()

# Basic options
parser.add_argument("filename",
                    type=str,
                    help="the name of the input image file")

# Parse the command line arguments
arguments = parser.parse_args()

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

# Open the original image
image = imageio.imread(arguments.filename)

# Invert the colours
invert_colors(image)

# Determine output name
name = fs.strip_extension(fs.name(arguments.filename))
newname = name + "_inverted.png"

# Write the inverted image
imageio.imwrite(newname, image)

# -----------------------------------------------------------------
Exemplo n.º 5
0
# -*- coding: utf8 -*-
# *****************************************************************
# **       PTS -- Python Toolkit for working with SKIRT          **
# **       © Astronomical Observatory, Ghent University          **
# *****************************************************************

## \package pts.do.magic.show_image_info Show basic info of a FITS image.

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

# Import the relevant PTS classes and modules
from pts.core.basics.configuration import ConfigurationDefinition, parse_arguments
from pts.magic.tools.info import get_image_info_strings_from_header_file
from pts.core.tools import filesystem as fs

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

# Create the definition
definition = ConfigurationDefinition()
definition.add_required("file_path", "file_path", "name of the input image file")

# Parse the command line arguments
config = parse_arguments("show_image_info", definition)

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

filename = fs.strip_extension(fs.name(config.file_path))
for line in get_image_info_strings_from_header_file(filename, config.file_path, name=False): print(line)

# -----------------------------------------------------------------
Exemplo n.º 6
0
    # User-specified color
    elif "," in config.color: red, blue, green = map(int, config.color.split(","))

    # Invalid
    else: raise ValueError("Invalid input")

    # Check dimensions
    if image.shape[2] == 3:
        shape = list(image.shape)
        old_image = image
        shape[2] = 4
        shape = tuple(shape)
        image = np.ones(shape) * 255
        image[:, :, :3] = old_image

    # Set transparent
    if config.gradient: set_transparency_gradient(image, (red, blue, green,), config.scale)
    else: set_transparent_color(image, (red, blue, green,), tolerance=config.tolerance)

    # Determine output name
    name = fs.strip_extension(fs.name(filename))
    #extension = fs.get_extension(filename)
    extension = "png" # because transparancy has to be supported
    newname = name + "_transparent." + extension

    # Write the inverted image
    imageio.imwrite(newname, image)

# -----------------------------------------------------------------
Exemplo n.º 7
0
    # Load the wavelength grid
    grid = fitting_run.get_wavelength_grid_data_grid(name)

    # Determine the new path
    path = fitting_run.get_wavelength_grid_path(name)

    # Save
    grid.to_skirt_input(path)

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

# Grid path is given
if config.grid_path is not None:

    # Set wavelength grid
    grid_name = fs.strip_extension(fs.name(config.grid_path))

    # Load the grid
    if config.skirt: wavelength_grid = WavelengthGrid.from_skirt_input(config.grid_path)
    else: wavelength_grid = WavelengthGrid.from_file(config.grid_path)

# Grid name is given
else:

    # Set wavelength grid name
    grid_name = config.name

    # Load the wavelength grid
    if config.name not in fitting_run.wavelength_grid_names: raise ValueError("Wavelength grid '" + config.name + "' does not exist")
    wavelength_grid = fitting_run.get_wavelength_grid(config.name)
Exemplo n.º 8
0
# -----------------------------------------------------------------

# Create the configuration definition
definition = ConfigurationDefinition()
definition.add_required("files", "filepath_list",
                        "list of the data file paths")
definition.add_flag("loglog", "use log-log scale", False)

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

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

curves = dict()
for filepath in config.files:
    name = fs.strip_extension(fs.name(filepath))
    curves[name] = Curve.from_data_file(filepath)

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

plot = MPLPlot()
for name in curves:
    plot.add_curve(curves[name], name)

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

if config.loglog:
    plot.set_x_log_scale()
    plot.set_y_log_scale()

# -----------------------------------------------------------------
Exemplo n.º 9
0
Arquivo: view.py Projeto: rag9704/PTS
# Create config
config = parse_arguments("view", definition)

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

stylesheet_url = "https://users.ugent.be/~sjversto/stylesheet.css"
background_color = "white"
page_style = "ugentstyle"

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

# Create CSS for the page width
css = html.make_page_width(config.page_width)

# Get name
name = fs.strip_extension(fs.name(config.image))
title = name

# Create list of css scripts
css_paths = css_scripts[:]
css_paths.append(stylesheet_url)

# Create the page
page = html.HTMLPage(title,
                     css=css,
                     body_settings=body_settings,
                     style=page_style,
                     css_path=css_paths,
                     javascript_path=javascripts,
                     footing=html.updated_footing())
Exemplo n.º 10
0
#parser.add_argument("fwhm", type=float, help="the FWHM of the stars (in pixels)")
#parser.add_argument("sigma_level", type=float, nargs='?', help="the sigma level", default=3.0)
#parser.add_argument("--color", type=str, help="the color", default="blue")

config = parse_arguments("catalog_to_regions", definition)

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

# Load the catalog
#catalog_name = os.path.splitext(os.path.basename(arguments.catalog))[0]
#catalog = tables.from_file(arguments.catalog)

# Open the frame
#frame = Frame.from_file(arguments.image)

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

catalog_name = fs.strip_extension(fs.name(config.path))

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

# Load the catalog
if config.type == "extended": catalog = ExtendedSourceCatalog.from_file(config.path)
elif config.type == "point": catalog = PointSourceCatalog.from_file(config.path)
else: raise ValueError("Invalid catalog type")

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



# -----------------------------------------------------------------
Exemplo n.º 11
0
# -----------------------------------------------------------------

remote_host_id = "nancy"
session = AttachedPythonSession.from_host_id(remote_host_id)

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

# Paths
paths = fs.files_in_path(galex_images_path, extension="fits", contains="poisson") + fs.files_in_path(sdss_images_path, extension="fits", contains="poisson")

# Loop over the GALEX poisson frames
for path in paths:

    # Image name
    name = fs.strip_extension(fs.name(path))

    # Get instrument and band
    galaxy_name, instrument, band, _ = name.split("_")

    # Create the filter
    fltr = BroadBandFilter.from_instrument_and_band(instrument, band)

    # Load the frame
    poisson = Frame.from_file(path)

    # Get the attenuation
    att = attenuation.extinction_for_filter(fltr)

    # CORRECT FOR GALACTIC EXTINCTION
    poisson *= 10**(0.4 * att)
Exemplo n.º 12
0
definition.add_optional("not_columns", "string_list", "don't use these columns")

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

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

# Load the tables
tables = []
for filepath in config.files:
    table = SmartTable.from_file(filepath)
    tables.append(table)

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

filenames = [fs.strip_extension(fs.name(filepath)) for filepath in config.files]

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

table = merge_tables(*tables, column_name=config.column, labels=filenames, differences=config.differences,
                     rel_differences=config.rel_differences, percentual=config.percentual, columns=config.columns, not_columns=config.not_columns)

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

# Show the table
if config.show: print(table)

# Write the table
if config.write:

    # Determine path
Exemplo n.º 13
0
# -----------------------------------------------------------------

# Inform the user
log.info("Loading the FITS file ...")

# Load the FITS file
frame = Frame.from_file(config.filename)

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

if config.output is not None: filepath = fs.absolute_or_in(config.output, fs.cwd())
else:

    # Determine the path
    name = fs.strip_extension(fs.name(config.filename))
    filepath = fs.absolute_path(name + ".png")

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

# Max npixels
if config.max_npixels is not None:

    # Determine downsample factor
    if frame.xsize > config.max_npixels or frame.ysize > config.max_npixels:

        factor = max(frame.xsize, frame.ysize) / float(config.max_npixels)
        # Make integer
        #numbers.round_up_to_int(factor)
        #if factor < 2.: factor = 2
        config.downsample = factor
Exemplo n.º 14
0
#parser.add_argument("sigma_level", type=float, nargs='?', help="the sigma level", default=3.0)
#parser.add_argument("--color", type=str, help="the color", default="blue")

config = parse_arguments("catalog_to_regions", definition)

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

# Load the catalog
#catalog_name = os.path.splitext(os.path.basename(arguments.catalog))[0]
#catalog = tables.from_file(arguments.catalog)

# Open the frame
#frame = Frame.from_file(arguments.image)

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

catalog_name = fs.strip_extension(fs.name(config.path))

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

# Load the catalog
if config.type == "extended":
    catalog = ExtendedSourceCatalog.from_file(config.path)
elif config.type == "point":
    catalog = PointSourceCatalog.from_file(config.path)
else:
    raise ValueError("Invalid catalog type")

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

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