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

        # 2 different ways should be the same:
        # fluxdensity_ = fluxdensity_jy.to("W / (m2 * micron)", equivalencies=spectral_density(wavelength))
        #fluxdensity = fluxdensity_jy.to("W / (m2 * Hz)").value * spectral_factor_hz_to_micron(wavelength) * u("W / (m2 * micron)")
        # print(fluxdensity_, fluxdensity) # IS OK!
        #fluxdensities.append(fluxdensity.to("W / (m2 * micron)").value)

        wavelengths = self.model_sed_1.wavelengths("micron",
                                                   asarray=True)  # in micron
        fluxes = self.model_sed_1.photometry(
            "W/m2", asarray=True
        )  #self.model_sed_1["Photometry"] # in W/m2 (lambda * F_Lambda)

        #print("wavelengths", wavelengths)
        #print("fluxes", fluxes)

        fluxes = fluxes / wavelengths  # in W / (m2 * micron)
        fluxes = [
            flux / spectral_factor_hz_to_micron(wavelength * u("micron"))
            for flux, wavelength in zip(fluxes, wavelengths)
        ]  # in W / (m2 * Hz)
        fluxes = [flux * si_to_jansky for flux in fluxes]

        self.model_sed_3 = SED.from_arrays(wavelengths,
                                           fluxes,
                                           wavelength_unit="micron",
                                           photometry_unit="Jy")
Ejemplo n.º 2
0
Archivo: test.py Proyecto: SKIRT/PTS
    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 = SkiFile(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)
Ejemplo n.º 3
0
Archivo: test.py Proyecto: rag9704/PTS
def spectral_factor_hz_to_meter(wavelength):
    """
    This function ...
    :return:
    """

    wavelength_unit = "m"
    frequency_unit = "Hz"

    # Convert string units to Unit objects
    if types.is_string_type(wavelength_unit):
        wavelength_unit = u(wavelength_unit)
    if types.is_string_type(frequency_unit): frequency_unit = u(frequency_unit)

    conversion_factor_unit = wavelength_unit / frequency_unit

    # Calculate the conversion factor
    factor = (wavelength**2 / speed_of_light).to(conversion_factor_unit).value
    return 1. / factor
Ejemplo n.º 4
0
Archivo: test.py Proyecto: SKIRT/PTS
def spectral_factor_hz_to_meter(wavelength):

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

    wavelength_unit = "m"
    frequency_unit = "Hz"

    # Convert string units to Unit objects
    if types.is_string_type(wavelength_unit): wavelength_unit = u(wavelength_unit)
    if types.is_string_type(frequency_unit): frequency_unit = u(frequency_unit)

    conversion_factor_unit = wavelength_unit / frequency_unit

    # Calculate the conversion factor
    factor = (wavelength ** 2 / speed_of_light).to(conversion_factor_unit).value
    return 1./factor
Ejemplo n.º 5
0
Archivo: test.py Proyecto: rag9704/PTS
    def test_fluxes(self):
        """
        This function ...
        :return:
        """

        # Create a quantity that is 1 W/m2 at 200 micron

        wavelength = parse_quantity("200 micron")

        frequency = wavelength.to("Hz", equivalencies=spectral())

        print("")
        print("wavelength:", wavelength)
        print("frequency:", frequency)
        print("")

        flux = parse_quantity("1 W/m2", density=True)  # neutral flux density

        print("neutral flux density:", flux)
        print("wavelength flux density:", flux / wavelength)
        print("frequency flux density:", flux / frequency)
        print("")

        converted = flux.value / wavelength.value  # to W / (m2 * micron)
        converted = converted / spectral_factor_hz_to_micron(wavelength)
        converted = converted * si_to_jansky * u("Jy")  # in Jy

        converted3 = flux.value / frequency.value * si_to_jansky * u(
            "Jy")  # first to W / [m2 * Hz] and then to Jy

        converted_auto = flux.to("Jy", wavelength=wavelength)

        print("")
        print("flux density in Jy:", converted)
        print("flux density in Jy (other way):", converted3)
        print("automatically converted flux density in Jy:", converted_auto)
        print("")

        print("conversion factor:", converted.value / flux.value)
        print("automatically determined conversion factor:",
              converted_auto.value / flux.value)
        print("")
Ejemplo n.º 6
0
    def set_galaxy_properties(self):
        """
        This function ..
        :return:
        """

        # Inform the user
        log.info("Setting galaxy properties ...")

        # Galaxy poperties
        galaxy_distance = parse_quantity("3.63 Mpc")
        galaxy_inclination = Angle(59, "deg")
        galaxy_pa = Angle(67, "deg")

        # Generate a random coordinate for the center of the galaxy
        ra_random = np.random.rand() * 360.0 * u("deg")
        dec_random = (np.random.rand() * 180.0 - 90.0) * u("deg")
        galaxy_center = SkyCoordinate(ra=ra_random, dec=dec_random)

        # Determine the galaxy size, convert to
        galaxy_size = parse_quantity("100000 lyr")
        galaxy_radius = 0.5 * galaxy_size.to("pc")
        galaxy_radius_arcsec = (galaxy_radius / galaxy_distance).to(
            "arcsec", equivalencies=dimensionless_angles())

        # Determine ellipticity
        ellipticity = 0.5

        # Set the properties
        self.properties = GalaxyProperties(name=fake_name,
                                           ngc_name=fake_name,
                                           hyperleda_name=fake_name,
                                           galaxy_type=None,
                                           center=galaxy_center,
                                           major=galaxy_radius,
                                           major_arcsec=galaxy_radius_arcsec,
                                           ellipticity=ellipticity,
                                           position_angle=galaxy_pa,
                                           distance=galaxy_distance,
                                           distance_error=None,
                                           inclination=galaxy_inclination,
                                           redshift=None,
                                           common_name=fake_name)
Ejemplo n.º 7
0
Archivo: test.py Proyecto: SKIRT/PTS
    def test_fluxes(self):

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

        # Create a quantity that is 1 W/m2 at 200 micron

        wavelength = parse_quantity("200 micron")

        frequency = wavelength.to("Hz", equivalencies=spectral())

        print("")
        print("wavelength:", wavelength)
        print("frequency:", frequency)
        print("")

        flux = parse_quantity("1 W/m2", density=True) # neutral flux density

        print("neutral flux density:", flux)
        print("wavelength flux density:", flux / wavelength)
        print("frequency flux density:", flux / frequency)
        print("")

        converted = flux.value / wavelength.value # to W / (m2 * micron)
        converted = converted / spectral_factor_hz_to_micron(wavelength)
        converted = converted * si_to_jansky * u("Jy") # in Jy

        converted3 = flux.value / frequency.value * si_to_jansky * u("Jy")  # first to W / [m2 * Hz] and then to Jy

        converted_auto = flux.to("Jy", wavelength=wavelength)

        print("")
        print("flux density in Jy:", converted)
        print("flux density in Jy (other way):", converted3)
        print("automatically converted flux density in Jy:", converted_auto)
        print("")

        print("conversion factor:", converted.value / flux.value)
        print("automatically determined conversion factor:", converted_auto.value / flux.value)
        print("")
Ejemplo n.º 8
0
Archivo: test.py Proyecto: SKIRT/PTS
    def test_brightness(self):

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

        # Inform the user
        log.info("Testing surface brightness units ...")

        units = [u("Jy"), u("W/micron"), u("Lsun"), u("erg/s/Hz"), u("W/sr"), u("Lsun/pc2", brightness=True), u("W/m2/micron")]

        print("")
        for unit in units:

            print(str(unit))
            print("")
            print(" - symbol: " + unit.symbol)
            print(" - physical type: " + unit.physical_type)
            print(" - base physical type: " + unit.base_physical_type)
            print(" - base unit: " + str(unit.base_unit))
            print(" - density: " + str(unit.density))
            print(" - brightness: " + str(unit.brightness))

            angular_area_unit = unit.corresponding_angular_area_unit
            #print(angular_area_unit)
            intrinsic_area_unit = unit.corresponding_intrinsic_area_unit

            print(" - corresponding angular area unit: " + str(angular_area_unit))
            print(" - corresponding intrinsic area unit: " + str(intrinsic_area_unit))
            print("")
Ejemplo n.º 9
0
Archivo: test.py Proyecto: rag9704/PTS
    def setup(self, **kwargs):
        """
        This function ...
        :param kwargs: 
        :return: 
        """

        # Call the setup function of the base class
        super(HomogenizeTest, self).setup(**kwargs)

        # Set galaxy name
        #sample = DustPediaSample()
        #self.galaxy_name = sample.get_name(self.config.galaxy)

        # Connect to the database
        #self.database = DustPediaDatabase()
        #username, password = get_account()
        #self.database.login(username, password)

        # Set distance
        self.distance = 10. * u("Mpc")
Ejemplo n.º 10
0
Archivo: base.py Proyecto: SKIRT/PTS
    def create_dust_grid(self):

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

        # Inform the user
        log.info("Creating the dust grid ...")

        # Create the dust grid generator
        generator = DustGridGenerator()

        # Determine truncation ellipse
        disk_ellipse_path = fs.join(m81_data_path, "components", "disk.reg")
        disk_ellipse = SkyRegionList.from_file(disk_ellipse_path)[0]
        truncation_ellipse = self.config.physical_domain_disk_ellipse_factor * disk_ellipse

        # Determine the radius of the galaxy
        semimajor_angular = truncation_ellipse.semimajor  # semimajor axis length of the sky ellipse
        radius_physical = (semimajor_angular * self.galaxy_distance).to("pc", equivalencies=dimensionless_angles())

        # Set properties
        generator.grid_type = "bintree"  # set grid type
        generator.x_radius = radius_physical
        generator.y_radius = radius_physical
        generator.z_radius = 2. * u("kpc")

        # Set input
        input_dict = dict()
        input_dict["ngrids"] = 1
        input_dict["scale"] = self.config.dust_grid_relative_scale * self.deprojections["dust"].pixelscale # in pc
        input_dict["level"] = self.config.dust_grid_min_level
        input_dict["mass_fraction"] = self.config.dust_grid_max_mass_fraction

        # Generate the grid
        generator.run(**input_dict)

        # Set the dust grid
        self.dust_grid = generator.single_grid
Ejemplo n.º 11
0
Archivo: test.py Proyecto: SKIRT/PTS
    def setup(self, **kwargs):

        """
        This function ...
        :param kwargs: 
        :return: 
        """

        # Call the setup function of the base class
        super(HomogenizeTest, self).setup(**kwargs)

        # Set galaxy name
        #sample = DustPediaSample()
        #self.galaxy_name = sample.get_name(self.config.galaxy)

        # Connect to the database
        #self.database = DustPediaDatabase()
        #username, password = get_account()
        #self.database.login(username, password)

        # Set distance
        self.distance = 10. * u("Mpc")
Ejemplo n.º 12
0
Archivo: test.py Proyecto: rag9704/PTS
    def test_brightness(self):
        """
        This function ...
        :return: 
        """

        # Inform the user
        log.info("Testing surface brightness units ...")

        units = [
            u("Jy"),
            u("W/micron"),
            u("Lsun"),
            u("erg/s/Hz"),
            u("W/sr"),
            u("Lsun/pc2", brightness=True),
            u("W/m2/micron")
        ]

        print("")
        for unit in units:

            print(str(unit))
            print("")
            print(" - symbol: " + unit.symbol)
            print(" - physical type: " + unit.physical_type)
            print(" - base physical type: " + unit.base_physical_type)
            print(" - base unit: " + str(unit.base_unit))
            print(" - density: " + str(unit.density))
            print(" - brightness: " + str(unit.brightness))

            angular_area_unit = unit.corresponding_angular_area_unit
            #print(angular_area_unit)
            intrinsic_area_unit = unit.corresponding_intrinsic_area_unit

            print(" - corresponding angular area unit: " +
                  str(angular_area_unit))
            print(" - corresponding intrinsic area unit: " +
                  str(intrinsic_area_unit))
            print("")
Ejemplo n.º 13
0
Archivo: test.py Proyecto: SKIRT/PTS
    def convert_sed_manual(self):

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

        # 2 different ways should be the same:
        # fluxdensity_ = fluxdensity_jy.to("W / (m2 * micron)", equivalencies=spectral_density(wavelength))
        #fluxdensity = fluxdensity_jy.to("W / (m2 * Hz)").value * spectral_factor_hz_to_micron(wavelength) * u("W / (m2 * micron)")
        # print(fluxdensity_, fluxdensity) # IS OK!
        #fluxdensities.append(fluxdensity.to("W / (m2 * micron)").value)

        wavelengths = self.model_sed_1.wavelengths("micron", asarray=True) # in micron
        fluxes = self.model_sed_1.photometry("W/m2", asarray=True) #self.model_sed_1["Photometry"] # in W/m2 (lambda * F_Lambda)

        #print("wavelengths", wavelengths)
        #print("fluxes", fluxes)

        fluxes = fluxes / wavelengths # in W / (m2 * micron)
        fluxes = [flux / spectral_factor_hz_to_micron(wavelength * u("micron")) for flux, wavelength in zip(fluxes, wavelengths)] # in W / (m2 * Hz)
        fluxes = [flux * si_to_jansky for flux in fluxes]

        self.model_sed_3 = SED.from_arrays(wavelengths, fluxes, wavelength_unit="micron", photometry_unit="Jy")
Ejemplo n.º 14
0
Archivo: test.py Proyecto: SKIRT/PTS
from pts.core.basics.log import log
from pts.core.units.unit import PhotometricUnit
from pts.core.units.parsing import parse_unit as u
from pts.core.tools import numbers
from pts.core.units.parsing import parse_quantity
from pts.core.tools import parsing
from pts.core.tools.stringify import tostr

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

description = "testing binary real conversions"

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

speed_of_light = constants.c
solar_luminosity = 3.846e26 * u("W") # 3.828×10^26 W

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

class BinaryTest(TestImplementation):

    """
    This class ...
    """

    def __init__(self, *args, **kwargs):

        """
        This function ...
        :param kwargs:
        """
Ejemplo n.º 15
0
from pts.dustpedia.core.properties import DustPediaProperties
from pts.modeling.core.environment import verify_modeling_cwd

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

modeling_path = verify_modeling_cwd()

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

data_images_path = get_data_images_path(modeling_path)

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

fwhms = dict()

default_fwhm = 2.0 * u("arcsec")

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

# Get the DustPedia properties instance
properties = DustPediaProperties()

# Get FWHMs
official_fwhms = properties.fwhms

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

# Loop over the images
for image_path, image_name in fs.files_in_path(data_images_path,
                                               extension="fits",
                                               not_contains="poisson",
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
    # 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)

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

# # Set spectral convolution flag
spectral_convolution = "refined" in grid_name or "highres" in grid_name

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

# Get the wavelengths as an array
wavelength_unit = u("micron")
wavelengths = wavelength_grid.wavelengths(wavelength_unit, asarray=True)

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

def check_grid_convolution():

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

    # Wavelengths used for each filter
    wavelengths_for_filters = OrderedDict()

    print("")
Ejemplo n.º 18
0
for filter_name in images:

    frame = images[filter_name]

    # Get the wavelength
    wavelength = frame.filter.pivot

    # Determine the conversion factor
    conversion_factor = 1.0

    # From W / (m2 * arcsec2 * micron) to W / (m2 * arcsec2 * Hz)
    conversion_factor *= (wavelength ** 2 / speed_of_light).to("micron/Hz").value

    # From W / (m2 * arcsec2 * Hz) to MJy / sr
    # conversion_factor *= (u("W/(m2 * arcsec2 * Hz)") / u("MJy/sr")).to("")
    conversion_factor *= 1e26 * 1e-6 * (u("sr") / u("arcsec2")).to("")

    # Multiply the frame with the conversion factor
    frame *= conversion_factor

    # Set the new unit
    frame.unit = "MJy/sr"

    #print(frame.unit)
    #print(frame.remote.get_python_string("str(" + frame.label + ".filter)"))
    #print(frame.filter)

# Save the frames
for filter_name in images:

    # The frame
Ejemplo n.º 19
0
Archivo: data.py Proyecto: SKIRT/PTS
disk_metallicity = 0.03

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

# Young stellar disk
young_template = "BruzualCharlot"
young_age = 0.1
# young_metallicity = 0.02
young_metallicity = 0.03

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

# Ionizing stellar disk
ionizing_metallicity = 0.03  # XU KONG et al. 2000
ionizing_compactness = 6.
ionizing_pressure = 1e12 * u("K/m3")
ionizing_covering_factor = 0.2

# Convert the SFR into a FUV luminosity
sfr = 0.8  # The star formation rate # see Perez-Gonzalez 2006 (mentions Devereux et al 1995)

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

# fuv_young:6.0068695608165e+36 W/micron
# fuv_ionizing:2.4590756925069244e+33 W/micron]
# 15450820.890962543 Msun

fuv_young = PhotometricQuantity(1e36, "W/micron")
fuv_ionizing = PhotometricQuantity(2.5e33, "W/micron")
dust_mass = parse_quantity("1.5e7 Msun")
Ejemplo n.º 20
0
# -----------------------------------------------------------------

sed = mappings_initial.sed
wavelengths = sed.wavelengths(unit="micron")
luminosities = sed.photometry(unit="W/micron")

fluxes = []

# Convert the spectral luminosities from W / micron to W / Hz
for i in range(len(wavelengths)):

    wavelength = wavelengths[i]
    luminosity = luminosities[i]

    new_luminosity = luminosity.to(
        "W/micron").value / spectral_factor_hz_to_micron(wavelength) * u(
            "W/Hz")

    #new_luminosities.append(new_luminosity)

    # Calculate flux density in Jansky
    flux = (new_luminosity / denominator).to("Jy")

    # Add flux density
    fluxes.append(flux)

# Create an SED
flux_sed = SED(photometry_unit="Jy")

for i in range(len(wavelengths)):

    flux_sed.add_point(wavelengths[i], fluxes[i])
Ejemplo n.º 21
0
Archivo: test.py Proyecto: SKIRT/PTS
    def setup_modelling(self):

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

        # Inform the user
        log.info("Setting up the modeling ...")

        # Settings
        settings_setup = dict()
        settings_setup["type"] = "sed"
        settings_setup["name"] = "SN1987A"
        settings_setup["fitting_host_ids"] = None

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

        # Input

        # Construct the observed SED
        sed = ObservedSED(photometry_unit="Jy")
        sed.add_point("Pacs 70", 0.0455 * u("Jy"), 0.0034 * u("Jy"))
        sed.add_point("Pacs 100", 0.0824 * u("Jy"), 0.0045 * u("Jy"))
        sed.add_point("Pacs 160", 0.1530 * u("Jy"), 0.0090 * u("Jy"))
        sed.add_point("SPIRE 250", 0.1107 * u("Jy"), 0.0252 * u("Jy"))
        sed.add_point("SPIRE 350", 0.0693 * u("Jy"), 0.0228 * u("Jy"))
        sed.add_point("ALMA 440um", 0.0500 * u("Jy"), 0.0150 * u("Jy"))
        sed.add_point("ALMA 870um", 0.0050 * u("Jy"), 0.0010 * u("Jy"))

        # Create object config
        object_config = dict()
        ski_path = fs.join(this_dir_path, "SN1987A.ski")
        object_config["ski"] = ski_path

        # Create input dict for setup
        input_setup = dict()
        input_setup["object_config"] = object_config
        input_setup["sed"] = sed

        # Construct the command
        setup_command = Command("setup", "setup the modelling", settings_setup, input_setup, cwd=".")

        # Add the command
        #commands.append(setup_command)

        tool = self.run_command(setup_command)
Ejemplo n.º 22
0
Archivo: test.py Proyecto: rag9704/PTS
from pts.core.basics.log import log
from pts.core.units.unit import PhotometricUnit
from pts.core.units.parsing import parse_unit as u
from pts.core.tools import numbers
from pts.core.units.parsing import parse_quantity
from pts.core.tools import parsing
from pts.core.tools.stringify import tostr

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

description = "testing binary real conversions"

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

speed_of_light = constants.c
solar_luminosity = 3.846e26 * u("W")  # 3.828×10^26 W

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


class BinaryTest(TestImplementation):
    """
    This class ...
    """
    def __init__(self, *args, **kwargs):
        """
        This function ...
        :param kwargs:
        """

        # Call the constructor of the base class
Ejemplo n.º 23
0
Archivo: test.py Proyecto: rag9704/PTS
    def test_solar_bolometric(self):
        """
        This function ...
        :return: 
        """

        # Inform the user
        #log.info("Loading the frames ...")

        # Get the galaxy distance
        #distance = self.galaxy_properties.distance
        distance = 10. * u("Mpc")

        # Load all the frames and error maps
        #for name in names:

        #frame = self.dataset.get_frame(name)
        #errors = self.dataset.get_errormap(name)

        ## CONVERT TO LSUN

        # Get pixelscale and wavelength
        pixelscale = 1.5 * u("arcsec")
        wavelength = 70. * u("micron")

        ##

        # Get a quantity
        quantity = 1 * u("MJy/sr")

        # Conversion from MJy / sr to Jy / sr
        conversion_factor = 1e6

        # Conversion from Jy / sr to Jy / pix(2)
        conversion_factor *= (pixelscale**2).to("sr").value

        # Conversion from Jy / pix to W / (m2 * Hz) (per pixel)
        conversion_factor *= 1e-26

        # Conversion from W / (m2 * Hz) (per pixel) to W / (m2 * m) (per pixel)
        conversion_factor *= (speed_of_light / wavelength**2).to("Hz/m").value

        # Conversion from W / (m2 * m) (per pixel) [SPECTRAL FLUX] to W / m [SPECTRAL LUMINOSITY]
        conversion_factor *= (4. * np.pi * distance**2).to("m2").value

        # Conversion from W / m [SPECTRAL LUMINOSITY] to W [NEUTRAL SPECTRAL LUMINOSITY]
        conversion_factor *= wavelength.to("m").value

        # Conversion from W to Lsun
        conversion_factor *= 1. / solar_luminosity.to("W").value

        ## CONVERT

        #frame *= conversion_factor
        #frame.unit = "Lsun"
        quantity_manual = quantity * conversion_factor
        quantity_manual.unit = "Lsun"

        print(quantity_manual)

        quantity_automatic = quantity.to("Lsun",
                                         density=True,
                                         distance=distance,
                                         wavelength=wavelength,
                                         pixelscale=pixelscale)

        print(quantity_automatic)

        if np.isclose(quantity_manual.value, quantity_automatic.value
                      ) and quantity_manual.unit == quantity_automatic.unit:
            print("SOLAR: OK")
        else:
            print("SOLAR: FAIL!")
Ejemplo n.º 24
0
    :return:
    """

    if parsing_types_for_parameter_types[parameter_type] == "photometric_quantity":
        if is_photometric_density(parameter_type): ptype = "photometric_density_unit"
        else: ptype = "photometric_unit"
    else: ptype = "unit"

    return ptype

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

# Default units for different parameter types
default_units = dict()
default_units[dimless_name] = None
default_units[mass_name] = u("Msun")
default_units[grainsize_name] = u("micron")
default_units[length_name] = u("pc")
default_units[angle_name] = u("deg")
default_units[posangle_name] = u("deg")
default_units[luminosity_name] = u("Lsun") # bolometric luminosity
default_units[spectral_luminosity_density_name] = u("W/micron", density=True) # spectral luminosity density
default_units[flux_name] = u("W/m2", density=True) # bolometric flux
default_units[spectral_flux_density_name] = u("Jy", density=True) # spectral flux density
default_units[intensity_name] = u("W/sr") # bolometric intensity
default_units[spectral_intensity_density_name] = u("W/sr/micron", density=True) # spectral intensity density
default_units[surface_brightness_name] = u("W/m2/sr") # bolometric surface brightness
default_units[spectral_surface_brightness_density_name] = u("W/m2/sr/micron", density=True) # spectral surface brightness density
default_units[pressure_name] = u("K/m3")

# -----------------------------------------------------------------
Ejemplo n.º 25
0
from pts.core.launch.options import AnalysisOptions
from pts.modeling.tests.base import M81TestBase, m81_data_path, fitting_filter_names, instrument_name
from pts.modeling.tests.base import seds_path, dustpedia_sed_path
from pts.core.data.sed import ObservedSED
from pts.core.tools import sequences
from pts.modeling.core.environment import GalaxyModelingEnvironment

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

description = "creating the best model of the M81 galaxy based on mock observations"

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

# Rough estimates
# memory requirement: 3.16 GB
serial_memory = 2.0 * u("GB")
parallel_memory = 2.0 * u("GB")

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

class M81Test(M81TestBase):

    """
    This class runs the test on M81
    """

    def __init__(self, *args, **kwargs):

        """
        This function ...
        :param kwargs:
Ejemplo n.º 26
0
Archivo: test.py Proyecto: rag9704/PTS
    def setup_modelling(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Setting up the modeling ...")

        # Settings
        settings_setup = dict()
        settings_setup["type"] = "sed"
        settings_setup["name"] = "SN1987A"
        settings_setup["fitting_host_ids"] = None

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

        # Input

        # Construct the observed SED
        sed = ObservedSED(photometry_unit="Jy")
        sed.add_point("Pacs 70", 0.0455 * u("Jy"), 0.0034 * u("Jy"))
        sed.add_point("Pacs 100", 0.0824 * u("Jy"), 0.0045 * u("Jy"))
        sed.add_point("Pacs 160", 0.1530 * u("Jy"), 0.0090 * u("Jy"))
        sed.add_point("SPIRE 250", 0.1107 * u("Jy"), 0.0252 * u("Jy"))
        sed.add_point("SPIRE 350", 0.0693 * u("Jy"), 0.0228 * u("Jy"))
        sed.add_point("ALMA 440um", 0.0500 * u("Jy"), 0.0150 * u("Jy"))
        sed.add_point("ALMA 870um", 0.0050 * u("Jy"), 0.0010 * u("Jy"))

        # Create object config
        object_config = dict()
        ski_path = fs.join(this_dir_path, "SN1987A.ski")
        object_config["ski"] = ski_path

        # Create input dict for setup
        input_setup = dict()
        input_setup["object_config"] = object_config
        input_setup["sed"] = sed

        # Construct the command
        setup_command = Command("setup",
                                "setup the modelling",
                                settings_setup,
                                input_setup,
                                cwd=".")

        # Add the command
        #commands.append(setup_command)

        tool = self.run_command(setup_command)
Ejemplo n.º 27
0
# -----------------------------------------------------------------

# Create definition
definition = ConfigurationDefinition()

# Filter
definition.add_required("filter", "filter", "filter in which to calculate the luminosity")

# SFR
definition.add_positional_optional("sfr", "quantity", "star formation rate", "1. Msun/yr", convert_default=True)

# MAPPINGS parameters
definition.add_optional("metallicity", "positive_real", "metallicity", 0.02)
definition.add_optional("compactness", "positive_real", "compactness", 6)
definition.add_optional("pressure", "quantity", "pressure", 1e12 * u("K/m3"))
definition.add_optional("covering_factor", "positive_real", "covering factor", 0.2) # fPDR

# Flags
definition.add_flag("plot", "plot the SEDs", False)
definition.add_flag("skirt", "use SKIRT", True)
definition.add_flag("pts", "use PTS", True)
definition.add_flag("sampled", "use SKIRT luminosities already sampled on a wavelength grid", True)
definition.add_flag("only_skirt", "only SKIRT", False)
definition.add_flag("only_pts", "only PTS", False)
definition.add_flag("only_sampled", "only sampled", False)

# Output path
definition.add_optional("output", "directory_path", "output path")

# Get the configuration
Ejemplo n.º 28
0
        if is_photometric_density(parameter_type):
            ptype = "photometric_density_unit"
        else:
            ptype = "photometric_unit"
    else:
        ptype = "unit"

    return ptype


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

# Default units for different parameter types
default_units = dict()
default_units["dimless"] = None
default_units["mass"] = u("Msun")
default_units["grainsize"] = u("micron")
default_units["length"] = u("pc")
default_units["angle"] = u("deg")
default_units["posangle"] = u("deg")
default_units["luminosity"] = u("Lsun")  # bolometric luminosity
default_units["spectral luminosity density"] = u(
    "W/micron", density=True)  # spectral luminosity density
default_units["flux"] = u("W/m2", density=True)  # bolometric flux
default_units["spectral flux density"] = u(
    "Jy", density=True)  # spectral flux density
default_units["intensity"] = u("W/sr")  # bolometric intensity
default_units["spectral intensity density"] = u(
    "W/sr/micron", density=True)  # spectral intensity density
default_units["surface brightness"] = u(
    "W/m2/sr")  # bolometric surface brightness
Ejemplo n.º 29
0
Archivo: test.py Proyecto: 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)
Ejemplo n.º 30
0
Archivo: test.py Proyecto: SKIRT/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 = SkiFile(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)
Ejemplo n.º 31
0
Archivo: test.py Proyecto: SKIRT/PTS
from pts.modeling.tests.base import M81TestBase, m81_data_path, fitting_filter_names, instrument_name
from pts.modeling.tests.base import seds_path, dustpedia_sed_path
from pts.core.data.sed import ObservedSED
from pts.core.tools import sequences
from pts.modeling.core.environment import GalaxyModelingEnvironment
from pts.core.tools.utils import lazyproperty

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

description = "creating the best model of the M81 galaxy based on mock observations"

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

# Rough estimates
# memory requirement: 3.16 GB
serial_memory = 2.0 * u("GB")
parallel_memory = 2.0 * u("GB")

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

class M81Test(M81TestBase):

    """
    This class runs the test on M81
    """

    def __init__(self, *args, **kwargs):

        """
        This function ...
        :param kwargs:
Ejemplo n.º 32
0
Archivo: test.py Proyecto: SKIRT/PTS
    def test_solar_bolometric(self):

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

        # Inform the user
        #log.info("Loading the frames ...")

        # Get the galaxy distance
        #distance = self.galaxy_properties.distance
        distance = 10. * u("Mpc")

        # Load all the frames and error maps
        #for name in names:

        #frame = self.dataset.get_frame(name)
        #errors = self.dataset.get_errormap(name)

        ## CONVERT TO LSUN

        # Get pixelscale and wavelength
        pixelscale = 1.5 * u("arcsec")
        wavelength = 70. * u("micron")

        ##

        # Get a quantity
        quantity = 1 * u("MJy/sr")

        # Conversion from MJy / sr to Jy / sr
        conversion_factor = 1e6

        # Conversion from Jy / sr to Jy / pix(2)
        conversion_factor *= (pixelscale ** 2).to("sr").value

        # Conversion from Jy / pix to W / (m2 * Hz) (per pixel)
        conversion_factor *= 1e-26

        # Conversion from W / (m2 * Hz) (per pixel) to W / (m2 * m) (per pixel)
        conversion_factor *= (speed_of_light / wavelength ** 2).to("Hz/m").value

        # Conversion from W / (m2 * m) (per pixel) [SPECTRAL FLUX] to W / m [SPECTRAL LUMINOSITY]
        conversion_factor *= (4. * np.pi * distance ** 2).to("m2").value

        # Conversion from W / m [SPECTRAL LUMINOSITY] to W [NEUTRAL SPECTRAL LUMINOSITY]
        conversion_factor *= wavelength.to("m").value

        # Conversion from W to Lsun
        conversion_factor *= 1. / solar_luminosity.to("W").value

        ## CONVERT

        #frame *= conversion_factor
        #frame.unit = "Lsun"
        quantity_manual = quantity * conversion_factor
        quantity_manual.unit = "Lsun"

        print(quantity_manual)

        quantity_automatic = quantity.to("Lsun", density=True, distance=distance, wavelength=wavelength, pixelscale=pixelscale)

        print(quantity_automatic)

        if np.isclose(quantity_manual.value, quantity_automatic.value) and quantity_manual.unit == quantity_automatic.unit: print("SOLAR: OK")
        else: print("SOLAR: FAIL!")
Ejemplo n.º 33
0
from pts.core.tools import stringify
from pts.magic.tools import wavelengths
from pts.magic.tools import fitting, statistics
from pts.magic.convolution.kernels import has_variable_fwhm, get_fwhm
from pts.magic.basics.vector import Pixel
from pts.magic.basics.coordinate import PixelCoordinate
from pts.magic.core.list import CoordinateSystemList

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

description = "Test the source detection and extraction"

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

# For M81
fwhms = {"2MASS H": 4.640929858306589 * u("arcsec"),
          "2MASS J": 4.580828087551186 * u("arcsec"),
          "2MASS Ks": 4.662813601376219 * u("arcsec"),
          "SDSS g": 2.015917936060279 * u("arcsec"),
          "SDSS i": 1.85631074608032 * u("arcsec"),
          "SDSS r": 2.026862297071852 * u("arcsec"),
          "SDSS u": 2.327165667182196 * u("arcsec"),
          "SDSS z": 1.841443699129355 * u("arcsec")}

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

# Determine the path to the headers directory
headers_path = fs.join(m81_data_path, "headers")

# -----------------------------------------------------------------
Ejemplo n.º 34
0
disk_metallicity = 0.03

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

# Young stellar disk
young_template = "BruzualCharlot"
young_age = 0.1
# young_metallicity = 0.02
young_metallicity = 0.03

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

# Ionizing stellar disk
ionizing_metallicity = 0.03  # XU KONG et al. 2000
ionizing_compactness = 6.
ionizing_pressure = 1e12 * u("K/m3")
ionizing_covering_factor = 0.2

# Convert the SFR into a FUV luminosity
sfr = 0.8  # The star formation rate # see Perez-Gonzalez 2006 (mentions Devereux et al 1995)

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

# fuv_young:6.0068695608165e+36 W/micron
# fuv_ionizing:2.4590756925069244e+33 W/micron]
# 15450820.890962543 Msun

fuv_young = PhotometricQuantity(1e36, "W/micron")
fuv_ionizing = PhotometricQuantity(2.5e33, "W/micron")
dust_mass = parse_quantity("1.5e7 Msun")