# Import the relevant PTS classes and modules from pts.core.tools import filesystem as fs from pts.do.commandline import Command from pts.evolve.core import reference from pts.evolve.optimize.optimizer import show_best from pts.evolve.core.crossovers import G1DListCrossoverOX from pts.evolve.core.mutators import G1DListMutatorSwap from pts.core.basics.animation import Animation from pts.core.basics.range import RealRange from pts.core.test.implementation import TestImplementation from pts.core.basics.log import log # ----------------------------------------------------------------- this_path = fs.absolute_path(inspect.stack()[0][1]) this_dir_path = fs.directory_of(this_path) # ----------------------------------------------------------------- description = "finding the maximum of the function defined by Charbonneau (1995)" # ----------------------------------------------------------------- # Define properties #nparameters = 20 nparameters = 2 nindividuals = 80 parameter_range = RealRange(0., 1.) #best_raw_score = float('inf') best_raw_score = 100 #round_decimal = None
import inspect import numpy as np from matplotlib import pyplot as plt # Import the relevant PTS classes and modules from pts.core.tools import filesystem as fs from pts.do.commandline import Command from pts.core.basics.range import RealRange from pts.evolve.core import reference from pts.evolve.optimize.optimizer import show_best from pts.core.test.implementation import TestImplementation # ----------------------------------------------------------------- this_path = fs.absolute_path(inspect.stack()[0][1]) this_dir_path = fs.directory_of(this_path) # ----------------------------------------------------------------- description = "optimizing the Rastrigin function, a deceptive function" # ----------------------------------------------------------------- # Define properties #nparameters = 20 nparameters = 2 nindividuals = 80 parameter_range = RealRange(-5.2, 5.30) best_raw_score = 0.0 round_decimal = None #ngenerations = 800
lum_neutral = lum.to("W", density=True, wavelength=fltr_wavelength) lum_solar = lum.to("Lsun", density=True, wavelength=fltr_wavelength) # Neutral and solar log.info("Luminosity in spectral solar units: " + tostr(lum_spectral_solar) + " Lsun_" + fltr.band) log.info("Luminosity in neutral units: " + tostr(lum_neutral)) log.info("Luminosity in solar units: " + tostr(lum_solar)) # ----------------------------------------------------------------- # Calculate from file with sampled luminosituies if config.sampled: # Determine the path to this directory this_filepath = fs.absolute_or_in_cwd(inspect.getfile(inspect.currentframe())) directory_path = fs.directory_of(this_filepath) # Determine the filepath filepath = fs.join(directory_path, "MappingsTemplate.dat") # Get wavelength grid, calculate luminosities in W wg = WavelengthGrid.from_text_file(filepath, "m") deltas = wg.deltas(asarray=True, unit="m") lums = np.loadtxt(filepath, skiprows=0, unpack=True, usecols=(1)) lums *= sfr_scalar # CORRECT FOR SFR # Construct the SED spectrallums = lums / deltas sampled_sed = SED.from_arrays(wg.wavelengths(asarray=True, unit="m"), spectrallums, "m", "W/m") print("FROM SAMPLED LUMINOSITIES:")
from pts.core.data.sed import SED, ObservedSED 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)
# 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): remote.create_directory(remote_image_directory) # Check whether the file exists if not fs.is_file(path): # Check whether already cached to the remote remote_image_path = fs.join(remote_image_directory, fs.name(path))
from pts.core.data.sed import SED, ObservedSED 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)
# 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) # -----------------------------------------------------------------