def screenlog_path(self): """ This function ... :return: """ if self.output_path is None: return None the_index = 0 the_path = None # Find screenlog file for path in self.remote.files_in_path(self.output_path): name = fs.name(path) if name.startswith("screenlog"): index = int(name.split(".")[1]) if the_path is None: the_path = path the_index = index elif index > the_index: the_path = path the_index = index # Return the path return the_path
def set_reference_images(self): """ This function ... :return: """ # Inform the user log.info("Setting the reference images ...") # Remove reference images self.fski.remove_all_reference_images() # Set reference images for name in self.image_paths: # Get filename path = self.image_paths[name] filename = fs.name(path) # Set FWHM if "u" in filename: kernel_fwhm = 1.7 elif "g" in filename: kernel_fwhm = 1.6 else: raise NotImplementedError("Not implemented") # Ranges (for both stellar components) luminosity_range = RealRange(min_luminosity, max_luminosity) luminosity_ranges = [luminosity_range, luminosity_range] # Add reference image self.fski.add_reference_image(filename, luminosity_ranges, kernel_fwhm, self.config.kernel_type, self.config.kernel_dimension)
def image_name(self): """ This function ... :return: """ return fs.name(self.config.image)
def filename(self): """ This function ... :return: """ return fs.strip_extension(fs.name(self.config.image))
def adjust_fski(self): """ This function ... :return: """ # Inform the user log.info("Creating the fski file ...") # Set ski name self.fski.set_ski_name(fs.name(self.reference_ski_path)) # Set the parameter ranges self.set_parameter_ranges() # Set the reference images self.set_reference_images() # Set the genetic options self.set_genetic_options()
# 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)
# ----------------------------------------------------------------- # 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() # -----------------------------------------------------------------
# Required definition.add_required("local_path", "string", "path or name of the file or directory to send") definition.add_required("remote", "string", "the remote host to send to", choices=find_host_ids()) # Remote path definition.add_positional_optional("remote_path", "string", "path of the remote directory to send to") # Create configuration config = parse_arguments("send", definition, "Send a file or directory to a remote host") # ----------------------------------------------------------------- # Create remote remote = Remote(host_id=config.remote) # ----------------------------------------------------------------- # Set full path of origin origin = fs.absolute_or_in_cwd(config.local_path) name = fs.name(origin) # Set full path to the destination if config.remote_path is None: destination = fs.join(remote.home_directory, name) else: destination = remote.absolute_path(config.remote_path) # Upload remote.upload(origin, destination) # -----------------------------------------------------------------
remote.setup(config.remote) # Remove specification of the remote arguments_no_remote = arguments[:-2] # Make a new temporary directory remotely remote_path = fs.join(remote.home_directory, temp_name) remote.create_directory(remote_path) remote.change_cwd(remote_path) # Send the appropriate command remote.launch_pts_command("get_poisson_errors", arguments_no_remote) # Retrieve the remote directory remote.download(remote_path, fs.cwd(), show_output=True) local_path = fs.join(fs.cwd(), fs.name(remote_path)) # Remove the temporary remote directory remote.remove_directory(remote_path) # Locally else: # Make a local directory local_path = fs.join(fs.cwd(), temp_name) fs.create_directory(local_path) # Create the DustPedia data processing instance dpdp = DustPediaDataProcessing() # GALEX
# 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())
definition = ConfigurationDefinition() definition.add_required("local_path", "string", "path or name of the file or directory to send") definition.add_required("remote", "string", "the remote host to send to", choices=find_host_ids()) definition.add_optional("remote_path", "string", "path of the remote directory to send to") config = parse_arguments("send", definition) # ----------------------------------------------------------------- # Create remote remote = Remote(host_id=config.remote) # ----------------------------------------------------------------- # Set full path of origin origin = fs.absolute_or_in_cwd(config.local_path) name = fs.name(origin) # Set full path to the destination if config.path is not None: destination = fs.join(remote.home_directory, name) else: destination = remote.absolute_path(config.remote_path) # Upload remote.upload(origin, destination) # -----------------------------------------------------------------
# ----------------------------------------------------------------- # 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) # -----------------------------------------------------------------
prep_path = fs.join(modeling_path, "prep") # ----------------------------------------------------------------- progress = defaultdict(dict) # ----------------------------------------------------------------- # Loop over all images of the initial dataset #for path in fs.files_in_path(prep_path, recursive=True, exact_name="initialized"): for directory_path in fs.directories_in_path(prep_path): # Directory path #directory_path = fs.directory_of(path) image_name = fs.name(directory_path) # Determine filter fltr = parse_filter(image_name) # Sort label, filepath = sort_image(image_name, directory_path, read_only=True) category = fltr.instrument if fltr.instrument is not None else "other" # Add to progress data progress[category][fltr.band] = label # ----------------------------------------------------------------- print("")
# ----------------------------------------------------------------- # Loop over the generations for generation_name in config.generations: # Loop over the simulations for simulation in get_simulations(modeling_path, generation_name): # Inform the user log.info("Plotting SED for simulation '" + simulation.name + "' of generation '" + generation_name + "' ...") # Determine plot path plot_dir_path = fs.join(simulation.base_path, "plot") plot_path = fs.join(plot_dir_path, "sed.pdf") # Create SED plotter plotter = SEDPlotter() # Add observed sed plotter.add_sed(observed_sed, "observation") # Add simulated sed(s) for path in simulation.seddatpaths(): sed = SED.from_skirt(path) plotter.add_sed(sed, fs.name(path)) # Run the plotter plotter.run(output=plot_path) # -----------------------------------------------------------------
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
# ----------------------------------------------------------------- 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)
# ----------------------------------------------------------------- # 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
if not remote.is_directory( remote_prep_path) or not remote.is_directory( remote_image_directory_path) or not remote.is_file( remote_initialized_path): log.warning("The initialized '" + name + "' image is not found, skipping ...") continue # Cache # Create directory for the image # Get the path path = paths[name] # Get filename filename = fs.strip_extension(fs.name(path)) #print(filename) # Determine origin from filename #origin = instrument_to_origin(filename.split("_")[1]) # Other way origin = fs.name(fs.directory_of(path)) # CHeck #if origin != origin_alt: raise ValueError(origin + " != " + origin_alt) # Create remote directory remote_image_directory = fs.join(remote_data_path, origin) if not remote.is_directory(remote_image_directory):
# Loop over the generations for generation_name in config.generations: # Loop over the simulations for simulation in get_simulations(modeling_path, generation_name): # Inform the user log.info("Plotting SED for simulation '" + simulation.name + "' of generation '" + generation_name + "' ...") # Determine plot path plot_dir_path = fs.join(simulation.base_path, "plot") plot_path = fs.join(plot_dir_path, "sed.pdf") # Create SED plotter plotter = SEDPlotter() # Add observed sed plotter.add_sed(observed_sed, "observation") # Add simulated sed(s) for path in simulation.seddatpaths(): sed = SED.from_skirt(path) plotter.add_sed(sed, fs.name(path)) # Run the plotter plotter.run(output=plot_path) # -----------------------------------------------------------------
# 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) # -----------------------------------------------------------------
# -*- 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) # -----------------------------------------------------------------
# Create configuration definition = ConfigurationDefinition(write_config=False) #definition.add_required("filename", "file_path", "table file") definition.add_required("columns", "string_list", "names of columns") definition.add_optional("method", "string", "table reading method", "lines") config = parse_arguments("remove_columns", definition) # ----------------------------------------------------------------- # Find table files filepaths = fs.files_in_cwd(extension="dat", recursive=True) for filepath in filepaths: #print(filepath) directory_name = fs.name(fs.directory_of(filepath)) filename = fs.name(filepath) # Get column names column_names = fs.get_column_names(filepath) if not sequences.contains_any(column_names, config.columns): continue print(directory_name, filename, column_names) # ----------------------------------------------------------------- # Load the table table = SmartTable.from_file(filepath, method=config.method) # -----------------------------------------------------------------
from pts.core.plot.sed import SEDPlotter # ----------------------------------------------------------------- # Set the log level level = "DEBUG" # Initialize the logger log = logging.setup_log(level=level) log.start("Starting compare_sed ...") # ----------------------------------------------------------------- fit_path = fs.absolute_path("../../../../../") modeling_path = fs.directory_of(fit_path) galaxy_name = fs.name(modeling_path) # ----------------------------------------------------------------- # Create the plotter plotter = SEDPlotter() # Add the SEDs filename = galaxy_name + "_earth_sed.dat" sed = SED.from_skirt(filename) # Load the reference SED reference_sed_path = fs.join(modeling_path, "sed.dat") reference_sed = ObservedSED.from_file(reference_sed_path) plotter.add_sed(sed, "simulation")
#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") # ----------------------------------------------------------------- # -----------------------------------------------------------------
definition.add_required("match", "string", "(partial) command name") # Get configuration config = parse_arguments("previous_config", definition) # ----------------------------------------------------------------- matches = defaultdict(list) # ----------------------------------------------------------------- # Loop over the filepaths for filepath in filepaths: # Get the modeling command filename = fs.name(filepath) command = filename.split("__")[0] # Skip other commands if not command.startswith(config.match): continue # Add filepath matches[command].append(filepath) # ----------------------------------------------------------------- if len(matches) > 1: raise ValueError("Ambigious command: matches are " + ", ".join(matches.keys())) # ----------------------------------------------------------------- single_command = matches.keys()[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) # -----------------------------------------------------------------
#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") # ----------------------------------------------------------------- # -----------------------------------------------------------------