Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        """
        This function ...
        :param kwargs:
        """

        # Call the constructor of the base class
        super(GalaxyTest, self).__init__(*args, **kwargs)

        # Free parameters for fitting
        self.free_parameters = Map()

        # Path to the ski file for the reference simulation
        self.reference_ski_path = None
        self.simulation_output_path = None

        # The reference ski file
        self.ski = None

        # Galaxy properties
        self.properties = None

        # Galaxy properties
        self.wcs = None

        # Configurables
        self.launcher = None
        self.flux_calculator = None
        self.image_maker = None
Esempio n. 2
0
File: test.py Progetto: rag9704/PTS
    def __init__(self, *args, **kwargs):
        """
        The constructor ...
        :param kwargs:
        """

        # Call the constructor of the base class
        super(SkyTest, self).__init__(*args, **kwargs)

        # FRAME COMPONENTS

        # The sources map
        self.sources = None

        # The noise map
        self.noise = None

        # The galaxy
        self.galaxy = None

        # Real sky frames
        self.constant_sky = None
        self.gradient_sky = None

        # TABLES
        self.source_table = None

        # MASKS

        # The sources mask
        self.sources_mask = None

        # The rotation mask
        self.rotation_mask = None

        # The galaxy
        self.galaxy_region = None

        # SKY ESTIMATION

        # Photutils Background2D object
        self.photutils_bkg = None

        # Sky reference estimation
        self.reference_sky = None

        # Path
        self.subtraction_path = None

        # The sky subtractor
        self.subtractor = None

        # STATISTICS

        # The statistics
        self.statistics = Map()
Esempio n. 3
0
File: test.py Progetto: rag9704/PTS
    def reference(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Estimating background with photutils ...")

        # Plot total mask
        if self.config.plot:
            plotting.plot_mask(self.total_mask, title="total mask")

        integer_aperture_radius = int(math.ceil(self.aperture_radius))
        box_shape = (integer_aperture_radius, integer_aperture_radius)
        filter_size = (3, 3)

        # Estimate the background
        sigma_clip = SigmaClip(sigma=3., iters=10)
        #bkg_estimator = MedianBackground()
        bkg_estimator = SExtractorBackground()

        bkg = Background2D(self.frame.data,
                           box_shape,
                           filter_size=filter_size,
                           sigma_clip=sigma_clip,
                           bkg_estimator=bkg_estimator,
                           mask=self.total_mask.data)

        # Statistics
        #print("median background", bkg.background_median)
        #print("rms background", bkg.background_rms_median)

        self.statistics.reference = Map()
        self.statistics.reference.median = bkg.background_median
        self.statistics.reference.rms = bkg.background_rms_median

        # Plot
        if self.config.plot:
            plotting.plot_box(bkg.background,
                              title="background from photutils")

        # Set the sky
        self.reference_sky = Frame(bkg.background)

        # Set bkg object
        self.photutils_bkg = bkg

        # Plot
        if self.config.plot:
            plotting.plot_box(self.reference_sky, title="reference sky")
Esempio n. 4
0
File: test.py Progetto: rag9704/PTS
    def create_tables(self):
        """
        This function ...
        :return: 
        """

        table = GenerationsTable(parameters=["a"], units={"a": "m"})

        info = GenerationInfo()

        table.add_entry(info, {"a": Map(min=None, max=None)})

        #print(tab)

        #print(type(table["Generation index"][0]))

        self.tables["generations"] = table
Esempio n. 5
0
File: test.py Progetto: rag9704/PTS
    def calculate_statistics_clipping(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Sigma-clipping ...")

        # Sigma clip
        mean, median, std = sigma_clipped_stats(self.sources_with_noise.data,
                                                sigma=3.0,
                                                iters=5,
                                                mask=self.rotation_mask)

        #print("sigma-clip mean:", mean)
        #print("sigma-clip median:", median)
        #print("sigma-clip std:", std)

        self.statistics.clipping = Map()
        self.statistics.clipping.mean = mean
        self.statistics.clipping.median = median
        self.statistics.clipping.std = std
Esempio n. 6
0
File: test.py Progetto: rag9704/PTS
    def calculate_statistics_masked(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Calculating statistics with sources masked ...")

        # Statistics
        mean, median, std = sigma_clipped_stats(self.sources_with_noise.data,
                                                sigma=3.0,
                                                mask=self.total_mask.data,
                                                iters=5)

        #print("sigma-clip mean after source masking:", mean)
        #print("sigma-clip median after source masking:", median)
        #print("sigma_clip std after source masking:", std)

        # Set the statistics
        self.statistics.masked = Map()
        self.statistics.masked.mean = mean
        self.statistics.masked.median = median
        self.statistics.masked.std = std
Esempio n. 7
0
File: test.py Progetto: rag9704/PTS
    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

        # Get free parameter names
        ski = LabeledSkiFile(ski_path)
        free_parameter_names = ski.labels

        # Get fitting filter names
        filter_names = sed.filter_names()

        # Set descriptions
        descriptions = Map()
        descriptions["luminosity"] = "total luminosity of the SN"
        descriptions["dustmass"] = "total dust mass"
        descriptions["grainsize"] = "dust grain size"
        descriptions["fsil"] = "dust silicate fraction"

        # Set types
        types = Map()
        types["luminosity"] = "luminosity"
        types["dustmas"] = "mass"
        types["grainsize"] = "grainsize"
        types["fsil"] = "dimless"

        # Set units
        units = Map()
        units["luminosity"] = u("Lsun")
        units["dustmass"] = u("Msun")
        units["grainsize"] = u("micron")
        units["fsil"] = None

        # Set ranges
        luminosity_range = QuantityRange(100, 1000, "Lsun")
        dustmass_range = QuantityRange(0.3, 5, "Msun")
        grainsize_range = QuantityRange(0.1, 5, "micron")
        fsil_range = RealRange(0.1, 100)

        # Create input dict for model
        input_model = dict()
        input_model["parameters_config"] = Configuration(
            free_parameters=free_parameter_names)
        input_model["descriptions_config"] = Configuration(
            descriptions=descriptions)
        input_model["types_config"] = Configuration(types=types)
        input_model["units_config"] = Configuration(units=units)
        input_model["ranges_config"] = Configuration(
            luminosity_range=luminosity_range,
            dustmass_range=dustmass_range,
            grainsize_range=grainsize_range,
            fsil_range=fsil_range)
        input_model["filters_config"] = Configuration(filters=filter_names)

        # Fitting initializer config
        input_model["initialize_config"] = Configuration(npackages=1e4)

        # Construct the command
        model_command = Command("model", "perform the modelling",
                                settings_model, input_model, "./SN1987A")

        # Add the command
        #commands.append(model_command)

        self.modeler = self.run_command(model_command)
Esempio n. 8
0
    def model(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Performing the modelling ...")

        # Settings
        settings_model = dict()
        settings_model["ngenerations"] = self.config.ngenerations
        settings_model["nsimulations"] = self.config.nsimulations
        settings_model["fitting_settings"] = {"spectral_convolution": False}

        # For remote execution
        settings_model["attached"] = self.config.attached
        settings_model["fitting_attached"] = self.config.attached

        # Set the random seed
        #settings_model["seed"] = self.config.seed

        # RECURRENCE SETTINGS
        settings_model["check_recurrence"] = self.config.check_recurrence
        settings_model["recurrence_rtol"] = self.config.recurrence_rtol
        settings_model["recurrence_atol"] = self.config.recurrence_atol

        # Input
        input_model = dict()

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

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

        # Create free parameters config

        # Create descriptions config
        descriptions_config = Map(descriptions=free_parameter_descriptions)
        input_model["descriptions_config"] = descriptions_config

        # Create types config
        types_config = Map(types=free_parameter_types)
        input_model["types_config"] = types_config

        # Create units config
        units_config = Map(units=free_parameter_units)
        input_model["units_config"] = units_config

        # Create the ndigits config
        ndigits_config = Map(ndigits=parameter_ndigits)
        input_model["ndigits_config"] = ndigits_config

        # Create filters config
        filters_config = Map(filters=fitting_filter_names)
        input_model["filters_config"] = filters_config

        # Create genetic config
        input_model["genetic_config"] = Map(genetic=self.config.genetic)

        # Create grid config ??
        #input_model["grid_config"] = Map(grid=self.config.grid)

        # Create ranges config
        ranges_config = Map()
        for parameter_name in self.config.free_parameters:  # Define range
            ranges_config[
                parameter_name +
                "_range"] = self.config.relative_range_fitting * self.real_parameter_values[
                    parameter_name]
        input_model["ranges_config"] = ranges_config

        # If we're cheating
        if self.config.cheat:
            fixed_parameter_values = defaultdict(list)
            for label in self.config.free_parameters:
                fixed_parameter_values[label].append(
                    self.real_parameter_values[label])
            input_model["fixed_initial_parameters"] = fixed_parameter_values

        # Create initialize config
        initialize_config = Map()
        initialize_config.npackages = self.config.npackages_fitting
        initialize_config.selfabsorption = self.config.selfabsorption
        initialize_config.transient_heating = self.config.transient_heating
        input_model["initialize_config"] = initialize_config

        # Other input
        input_model["fitting_method"] = self.config.fitting_method
        input_model["parameter_grid_scales"] = self.parameter_grid_scales
        input_model["parameter_grid_weights"] = None

        # Construct the command
        command = Command("model",
                          "perform the modelling",
                          settings_model,
                          input_model,
                          cwd=self.modeling_path)

        # Run the command
        self.modeler = self.run_command(command)
Esempio n. 9
0
# -----------------------------------------------------------------

# Check the modules
modules = Modules(remote)

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

# Qt is present
if modules.paths["qt"] is not None:

    # Get the version
    version = modules.versions["qt"]

    # Check if module has to be loaded
    if modules.names["qt"] is not None:
        installation_commands["qt"].append(Map(line="module load " + modules.names["qt"], comment="Load qt module (" + version + ")"))

    installation_commands["qt"].append(Map(comment="Qmake is present (" + version + "), no installation required"))

else:

    installation_commands["qt"].append(Map(comment="Installation of Qt"))

    #temp_path = remote.home_directory
    #path = fs.join(temp_path, "qt.tar.gz")

    filepath = "~/qt.tar.gz"
    download_command = "wget " + qt_url + " -O " + filepath

    installation_commands["qt"].append(Map(line=download_command, comment="Download the installer"))
Esempio n. 10
0
    def model(self):
        """
        This function ...
        :return:
        """

        # Settings
        settings_model = dict()
        settings_model["ngenerations"] = 4
        settings_model["nsimulations"] = 20
        settings_model["fitting_settings"] = {"spectral_convolution": False}

        # Input

        # Get free parameter names
        ski = LabeledSkiFile(ski_path)
        free_parameter_names = ski.labels

        # Get fitting filter names
        #filter_names = sed.filter_names()

        # Set descriptions
        descriptions = Map()
        descriptions[
            "exp_dustmass"] = "dust mass of the exponential disk with spiral structure"

        # Set types
        types = Map()
        types["exp_dustmass"] = "dust mass"

        # Set units
        units = Map()
        units["exp_dustmass"] = u("Msun")

        # Set the range of the dust mass
        dustmass_range = QuantityRange(0.1 * dust_mass, 100 * dust_mass)

        # Create input dict for model
        input_model = dict()
        input_model["parameters_config"] = Configuration(
            free_parameters=free_parameter_names)
        input_model["descriptions_config"] = Configuration(
            descriptions=descriptions)
        input_model["types_config"] = Configuration(types=types)
        input_model["units_config"] = Configuration(units=units)
        input_model["ranges_config"] = Configuration(
            exp_dustmass_range=dustmass_range)
        #input_model["filters_config"] = Configuration(filters=filter_names)

        # Fitting initializer config
        input_model["initialize_config"] = Configuration(npackages=1e4)

        # Add dict of input for 'model' command to the list
        #input_dicts.append(input_model)

        # Construct the command
        command = Command("model", "perform the modelling", settings_model,
                          input_model, "./Spiral")

        # Add the command
        #commands.append(command)

        modeler = self.run_command(command)
Esempio n. 11
0
# -----------------------------------------------------------------

fuv_filter = BroadBandFilter("FUV")
fuv_wavelength = fuv_filter.pivot

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

# Modeling path
modeling_path = verify_modeling_cwd()

# Path to the fixed parameters file
fixed_path = fs.join(modeling_path, "fit", "fixed.dat")

# Load the fixed parameters map
fixed = Map()
with open(fixed_path, 'r') as f:
    load_mapping(f, fixed)

# Get parameters
metallicity = fixed["metallicity"]
compactness = fixed["sfr_compactness"]
pressure = fixed["sfr_pressure"]
covering_factor = fixed["sfr_covering"]

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

test_path = fs.create_directory_in(modeling_path, "test")

# -----------------------------------------------------------------
Esempio n. 12
0
File: test.py Progetto: SKIRT/PTS
    def model(self):

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

        # Inform the user
        log.info("Performing the modelling ...")

        # Settings
        settings_model = dict()
        settings_model["ngenerations"] = self.config.ngenerations
        settings_model["nsimulations"] = self.config.nsimulations
        settings_model["fitting_settings"] = {"spectral_convolution": False}

        # For remote execution
        settings_model["attached"] = self.config.attached
        settings_model["fitting_attached"] = self.config.attached

        # Set the random seed
        #settings_model["seed"] = self.config.seed

        # RECURRENCE SETTINGS
        settings_model["check_recurrence"] = self.config.check_recurrence
        settings_model["recurrence_rtol"] = self.config.recurrence_rtol
        settings_model["recurrence_atol"] = self.config.recurrence_atol

        # Input
        input_model = dict()

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

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

        # Create free parameters config

        # Create descriptions config
        descriptions_config = Map(descriptions=free_parameter_descriptions)
        input_model["descriptions_config"] = descriptions_config

        # Create types config
        types_config = Map(types=free_parameter_types)
        input_model["types_config"] = types_config

        # Create units config
        units_config = Map(units=free_parameter_units)
        input_model["units_config"] = units_config

        # Create the ndigits config
        ndigits_config = Map(ndigits=parameter_ndigits)
        input_model["ndigits_config"] = ndigits_config

        # Create filters config
        filters_config = Map(filters=fitting_filter_names)
        input_model["filters_config"] = filters_config

        # Create genetic config
        input_model["genetic_config"] = Map(genetic=self.config.genetic)

        # Create grid config ??
        #input_model["grid_config"] = Map(grid=self.config.grid)

        # Create ranges config
        ranges_config = Map()
        for parameter_name in self.config.free_parameters: # Define range
            ranges_config[parameter_name + "_range"] = self.config.relative_range_fitting * self.real_parameter_values[parameter_name]
        input_model["ranges_config"] = ranges_config

        # If we're cheating
        if self.config.cheat:
            fixed_parameter_values = defaultdict(list)
            for label in self.config.free_parameters:
                fixed_parameter_values[label].append(self.real_parameter_values[label])
            input_model["fixed_initial_parameters"] = fixed_parameter_values

        # Create initialize config
        initialize_config = Map()
        initialize_config.npackages = self.config.npackages_fitting
        initialize_config.selfabsorption = self.config.selfabsorption
        initialize_config.transient_heating = self.config.transient_heating
        input_model["initialize_config"] = initialize_config

        # Other input
        input_model["fitting_method"] = self.config.fitting_method
        input_model["parameter_grid_scales"] = self.parameter_grid_scales
        input_model["parameter_grid_weights"] = None

        # Construct the command
        command = Command("model", "perform the modelling", settings_model, input_model, cwd=self.modeling_path)

        # Run the command
        self.modeler = self.run_command(command)
Esempio n. 13
0
# -----------------------------------------------------------------

description = "fitting a mock spiral galaxy"

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

# Determine a name for this galaxy
fake_name = "GALAXY X"

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

# Dictionary with the parameters for the spiral disks for different components
spiral_parameters = dict()

# Young stars
young_parameters = Map()
young_parameters.radial_scale = parse_quantity("2600 pc")
young_parameters.axial_scale = parse_quantity("260 pc")
young_parameters.radial_truncation = parse_quantity("2e4 pc")
young_parameters.axial_truncation = parse_quantity("1e4 pc")
young_parameters.inner_radius = parse_quantity("0 pc")
young_parameters.arms = 2
young_parameters.pitch = parse_angle("18 deg")
young_parameters.radius = parse_quantity("500 pc")
young_parameters.phase = parse_angle("0 deg")
young_parameters.perturbation_weight = 0.3
young_parameters.index = 1
spiral_parameters["young"] = young_parameters

# Ionizing stars
ionizing_parameters = Map()