Exemplo n.º 1
0
Arquivo: test.py Projeto: rag9704/PTS
    def test_dust_mass(self):
        """
        This function ...
        :return: 
        """

        # Inform the user
        log.info("Testing the dust mass ...")

        ndigits = 4

        nbits = numbers.binary_digits_for_significant_figures(ndigits)

        print(str(nbits) + " bits for " + str(ndigits) + " digits")

        mass_range = parsing.quantity_range(
            "1500000.0 Msun > 300000000.0 Msun")

        unit = "Msun"

        minimum = mass_range.min
        maximum = mass_range.max

        low = minimum.to(unit).value
        high = maximum.to(unit).value

        value = parse_quantity("1.5e7 Msun").to(unit).value

        # Test : ROUNDING IN TEST BUT NOT IN BETWEEN CONVERSION!!
        if light_test_from_number_rounding(value, low, high, ndigits):
            log.success("Test succeeded")
        else:
            log.error("Test failed")
Exemplo n.º 2
0
Arquivo: test.py Projeto: SKIRT/PTS
    def test_dust_mass(self):

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

        # Inform the user
        log.info("Testing the dust mass ...")

        ndigits = 4

        nbits = numbers.binary_digits_for_significant_figures(ndigits)

        print(str(nbits) + " bits for " + str(ndigits) + " digits")

        mass_range = parsing.quantity_range("1500000.0 Msun > 300000000.0 Msun")

        unit = "Msun"

        minimum = mass_range.min
        maximum = mass_range.max

        low = minimum.to(unit).value
        high = maximum.to(unit).value

        value = parse_quantity("1.5e7 Msun").to(unit).value

        # Test : ROUNDING IN TEST BUT NOT IN BETWEEN CONVERSION!!
        if light_test_from_number_rounding(value, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")
Exemplo n.º 3
0
Arquivo: test.py Projeto: rag9704/PTS
    def test_dust_mass_second(self):
        """
        This function ...
        :return: 
        """

        # Inform the user
        log.info("Second dust mass test ...")

        ndigits = 4

        genome = [1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0]
        check = [1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        nbits = len(genome)

        print(nbits)

        unit = "Msun"

        mass_range = parsing.quantity_range(
            "1500000.0 Msun > 300000000.0 Msun")

        minimum = mass_range.min
        maximum = mass_range.max

        low = minimum.to(unit).value
        high = maximum.to(unit).value

        if test_from_binary_string_rounding(genome, low, high, ndigits):
            log.success("Test succeeded")
        else:
            log.error("Test failed")

        if test_from_binary_string_rounding(check, low, high, ndigits):
            log.success("Test succeeded")
        else:
            log.error("Test failed")

        genome_mass = numbers.binary_string_to_float(genome, low, high, nbits)

        rounded_genome_mass = numbers.round_to_n_significant_digits(
            genome_mass, ndigits)

        genome_mass_to_binary = numbers.float_to_binary_string(
            genome_mass, low, high, nbits)
        rounded_genome_mass_to_binary = numbers.float_to_binary_string(
            rounded_genome_mass, low, high, nbits)

        print("original:", genome_mass)
        print("rounded:", rounded_genome_mass)
        print("genome:", genome)
        print("original to binary:", genome_mass_to_binary)
        print("rounded to binary: ", rounded_genome_mass_to_binary)
        print("check:             ", check)
Exemplo n.º 4
0
Arquivo: test.py Projeto: rag9704/PTS
    def test_gray_conversion_dynamic(self):
        """
        This function ...
        :return: 
        """

        # Inform the user
        log.info("Testing the Gray code conversions (dynamic nbits) ...")

        max_number = 15

        if check_gray_conversion(max_number): log.success("Test succeeded")
        else: log.error("Test failed")
Exemplo n.º 5
0
Arquivo: test.py Projeto: rag9704/PTS
    def test_dust_mass_with_rounding(self):
        """
        This fucntion ...
        :return: 
        """

        # Inform the user
        log.info("Testing dust mass with rounding ...")

        ndigits = 4

        nbits = numbers.binary_digits_for_significant_figures(ndigits)

        #print(str(nbits) + " bits for " + str(ndigits) + " digits")

        mass_range = parsing.quantity_range(
            "1500000.0 Msun > 300000000.0 Msun")

        unit = "Msun"

        minimum = mass_range.min
        maximum = mass_range.max

        low = minimum.to(unit).value
        high = maximum.to(unit).value

        # (FROM ERROR RESULTS IN MODELING:)

        # WITH ROUNDING:

        binary_string_a = [1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1]
        binary_string_b = [1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0]

        if test_from_binary_string_rounding(binary_string_a, low, high,
                                            ndigits):
            log.success("Test succeeded")
        else:
            log.error("Test failed")

        if test_from_binary_string_rounding(binary_string_b, low, high,
                                            ndigits):
            log.success("Test succeeded")
        else:
            log.error("Test failed")

        # Convert to numbers
        number_a = numbers.binary_string_to_float(binary_string_a, low, high,
                                                  nbits)
        number_b = numbers.binary_string_to_float(binary_string_b, low, high,
                                                  nbits)

        if test_from_number_rounding(number_a, low, high, ndigits):
            log.success("Test succeeded")
        else:
            log.error("Test failed")

        if test_from_number_rounding(number_b, low, high, ndigits):
            log.success("Test succeeded")
        else:
            log.error("Test failed")
Exemplo n.º 6
0
Arquivo: test.py Projeto: SKIRT/PTS
    def test_gray_conversion_dynamic(self):

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

        # Inform the user
        log.info("Testing the Gray code conversions (dynamic nbits) ...")

        max_number = 15

        if check_gray_conversion(max_number): log.success("Test succeeded")
        else: log.error("Test failed")
Exemplo n.º 7
0
Arquivo: test.py Projeto: rag9704/PTS
    def test_gray_generation(self):
        """
        This function ...
        :return: 
        """

        #n = int(raw_input())

        # Inform the user
        log.info("Testing the generation of Gray code ...")

        n = 14

        if check_gray_generation(n): log.success("Test succeeded")
        else: log.error("Test failed")
Exemplo n.º 8
0
Arquivo: test.py Projeto: SKIRT/PTS
    def test_dust_mass_second(self):

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

        # Inform the user
        log.info("Second dust mass test ...")

        ndigits = 4

        genome = [1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0]
        check = [1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        nbits = len(genome)

        print(nbits)

        unit = "Msun"

        mass_range = parsing.quantity_range("1500000.0 Msun > 300000000.0 Msun")

        minimum = mass_range.min
        maximum = mass_range.max

        low = minimum.to(unit).value
        high = maximum.to(unit).value

        if test_from_binary_string_rounding(genome, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")

        if test_from_binary_string_rounding(check, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")

        genome_mass = numbers.binary_string_to_float(genome, low, high, nbits)

        rounded_genome_mass = numbers.round_to_n_significant_digits(genome_mass, ndigits)

        genome_mass_to_binary = numbers.float_to_binary_string(genome_mass, low, high, nbits)
        rounded_genome_mass_to_binary = numbers.float_to_binary_string(rounded_genome_mass, low, high, nbits)

        print("original:", genome_mass)
        print("rounded:", rounded_genome_mass)
        print("genome:", genome)
        print("original to binary:", genome_mass_to_binary)
        print("rounded to binary: ", rounded_genome_mass_to_binary)
        print("check:             ", check)
Exemplo n.º 9
0
Arquivo: test.py Projeto: SKIRT/PTS
    def test_gray_conversion_fixed(self):

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

        # Inform the user
        log.info("Testing the Gray code conversions (fixed nbits) ...")

        max_number = 15

        nbits = numbers.nbits_for_integer(max_number)

        if check_gray_conversion(max_number, nbits): log.success("Test succeeded")
        else: log.error("Test failed")
Exemplo n.º 10
0
Arquivo: test.py Projeto: SKIRT/PTS
    def test_gray_generation(self):

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

        #n = int(raw_input())

        # Inform the user
        log.info("Testing the generation of Gray code ...")

        n = 14

        if check_gray_generation(n): log.success("Test succeeded")
        else: log.error("Test failed")
Exemplo n.º 11
0
Arquivo: test.py Projeto: rag9704/PTS
    def test_speed_of_light_experimental(self):
        """
        This function ...
        :return: 
        """

        # Inform the user
        log.info("Testing speed of light ...")

        ndigits = 3

        #nbits = numbers.nbits_for_ndigits(ndigits)

        minimum = 0.01 * speed_of_light
        maximum = speed_of_light

        unit = "km/s"

        # Convert value to binary
        value = (0.333 * speed_of_light).to(unit).value

        low = minimum.to(unit).value
        high = maximum.to(unit).value

        nbits = numbers.nbits_for_ndigits_experimental(ndigits, low, high)

        print(str(nbits) + " bits for " + str(ndigits) + " digits")

        # Test without rounding IN CONVERSION, BUT FOR COMPARISON THERE IS ROUNDING
        if light_test_from_number_rounding(value,
                                           low,
                                           high,
                                           ndigits,
                                           experimental=True):
            log.success("Test succeeded")
        else:
            log.error("Test failed")

        # With rounding
        if test_from_number_rounding(value,
                                     low,
                                     high,
                                     ndigits,
                                     experimental=True):
            log.success("Test succeeded")
        else:
            log.error("Test failed")
Exemplo n.º 12
0
Arquivo: test.py Projeto: rag9704/PTS
    def test_gray_conversion_fixed(self):
        """
        This function ...
        :return: 
        """

        # Inform the user
        log.info("Testing the Gray code conversions (fixed nbits) ...")

        max_number = 15

        nbits = numbers.nbits_for_integer(max_number)

        if check_gray_conversion(max_number, nbits):
            log.success("Test succeeded")
        else:
            log.error("Test failed")
Exemplo n.º 13
0
Arquivo: test.py Projeto: SKIRT/PTS
    def test_speed_of_light(self):

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

        # Inform the user
        log.info("Testing speed of light ...")

        ndigits = 3

        nbits = numbers.nbits_for_ndigits(ndigits)

        print(str(nbits) + " bits for " + str(ndigits) + " digits")

        minimum = 0.01 * speed_of_light
        maximum = speed_of_light

        unit = "km/s"

        # Convert value to binary
        value = (0.333 * speed_of_light).to(unit).value

        low = minimum.to(unit).value
        high = maximum.to(unit).value

        #print(value)
        #print(low)
        #print(high)

        # Test without rounding IN CONVERSION, BUT FOR COMPARISON THERE IS ROUNDING
        if light_test_from_number_rounding(value, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")

        # With rounding
        if test_from_number_rounding(value, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")
Exemplo n.º 14
0
Arquivo: test.py Projeto: SKIRT/PTS
    def test_dust_mass_with_rounding(self):

        """
        This fucntion ...
        :return: 
        """

        # Inform the user
        log.info("Testing dust mass with rounding ...")

        ndigits = 4

        nbits = numbers.binary_digits_for_significant_figures(ndigits)

        #print(str(nbits) + " bits for " + str(ndigits) + " digits")

        mass_range = parsing.quantity_range("1500000.0 Msun > 300000000.0 Msun")

        unit = "Msun"

        minimum = mass_range.min
        maximum = mass_range.max

        low = minimum.to(unit).value
        high = maximum.to(unit).value

        # (FROM ERROR RESULTS IN MODELING:)

        # WITH ROUNDING:

        binary_string_a = [1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1]
        binary_string_b = [1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0]

        if test_from_binary_string_rounding(binary_string_a, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")

        if test_from_binary_string_rounding(binary_string_b, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")

        # Convert to numbers
        number_a = numbers.binary_string_to_float(binary_string_a, low, high, nbits)
        number_b = numbers.binary_string_to_float(binary_string_b, low, high, nbits)

        if test_from_number_rounding(number_a, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")

        if test_from_number_rounding(number_b, low, high, ndigits): log.success("Test succeeded")
        else: log.error("Test failed")
Exemplo n.º 15
0
        local_version = None

    # Check present and version remotely
    if dependency in remote_packages:
        remotely_present = True
        remote_version = remote_packages[dependency]
    else:
        # Check again for present by importing
        remotely_present = remote_python.is_present_package(dependency)
        remote_version = None

    # If present both locally and remotely
    if locally_present and remotely_present:

        if config.versions:

            if local_version is None and remote_version is not None: log.warning(dependency + ": local version unknown")
            elif remote_version is None and local_version is not None: log.warning(dependency + ": remote version unknown")
            elif remote_version is None and local_version is None: log.warning(dependency + ": local and remote version unknown")
            elif local_version == remote_version: log.success(dependency + ": OK")
            else: log.warning(dependency + ": version " + local_version + " locally and version " + remote_version + " remotely")

        else: log.success(dependency + ": OK")

    # Not present on at least one system
    elif remotely_present and not locally_present: log.error(dependency + ": not present on this system")
    elif locally_present and not remotely_present: log.error(dependency + ": not present on remote '" + config.remote + "'")
    else: log.error(dependency + ": not present on either this sytem or remote '" + config.remote + "'")

# -----------------------------------------------------------------
Exemplo n.º 16
0
    the_map.psf_filter = "Pacs red"

    # Loop over the maps
    if which_map == "dust": maps = collection.get_dust_maps(flatten=True)
    elif which_map == "old": maps = collection.get_old_maps(flatten=True)
    elif which_map == "young": maps = collection.get_young_maps(flatten=True)
    elif which_map == "ionizing":
        maps = collection.get_ionizing_maps(flatten=True)
    else:
        raise ValueError("Invalid map type: '" + which_map + "'")

    similarities = dict()

    # No maps
    if len(maps) == 0:
        log.error("No " + which_map + " maps (yet)")
        continue

    # Loop over the maps
    for name in maps:

        # Get the map
        comparison_map = maps[name]

        #print(comparison_map.wcs.is_celestial)
        #print(comparison_map.wcs.has_celestial)

        if not comparison_map.wcs.is_celestial:
            log.warning("The " + name + " " + which_map +
                        " dust map doesn't have a celestial WCS: skipping ...")
            continue
Exemplo n.º 17
0
definition.add_required("remote", "string", "remote host ID", choices=find_host_ids())
definition.add_flag("private", "install SKIRT from private (development) repository")

# Create the configuration
config = parse_arguments("installation_commands", definition)

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

installation_commands = defaultdict(list)

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

# Create the remote
remote = Remote()
if not remote.setup(config.remote):
    log.error("The remote host is not available")
    exit()

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

# Check the modules
modules = Modules(remote)

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

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

    # Get the version
    version = modules.versions["qt"]
Exemplo n.º 18
0
definition = ConfigurationDefinition()
definition.add_required("parsing_type", "string", "parsing type")
definition.add_required("string", "string", "string to be parsed")

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

# Get config
config = parse_arguments("parse", definition)

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

# Get parsing function
parsing_function = getattr(parsing, config.parsing_type)

# Parse
try:

    result = parsing_function(config.string)

    # Show result
    if isinstance(result, collections.Iterable):
        for item in result:
            print(str(item))
    else:
        print(str(result))

except ValueError:
    log.error("The string could not be parsed into this property")

    # -----------------------------------------------------------------
Exemplo n.º 19
0
Arquivo: open.py Projeto: rag9704/PTS
# -----------------------------------------------------------------

# Connect to remote
remote = Remote()
remote.setup(config.remote)

# Determine the absolute file path
filepath = remote.absolute_path(config.filename)

# Determine the file path relative to the home directory
relative_filepath = remote.relative_to_home(filepath)

# Check if the file exists; otherwise don't bother mounting
if not remote.is_file(filepath):
    log.error("The file does not exist")
    exit()

# Disconnect the remote
remote.logout()

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

# Create the mounter
mounter = RemoteMounter()

# Mount and get the mount path
mount_path = mounter.mount(config.remote)

# Determine the local file path
filepath = fs.join(mount_path, relative_filepath)
Exemplo n.º 20
0
Arquivo: parse.py Projeto: SKIRT/PTS
definition = ConfigurationDefinition()
definition.add_required("parsing_type", "string", "parsing type")
definition.add_required("string", "string", "string to be parsed")

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

# Get config
config = parse_arguments("parse", definition)

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

# Get parsing function
parsing_function = getattr(parsing, config.parsing_type)

# Parse
try:

    result = parsing_function(config.string)

    # Show result
    if isinstance(result, collections.Iterable):
        for item in result: print(str(item))
    else: print(str(result))

except ValueError as e:
    log.error("The string could not be parsed into this property")
    log.error(e.message)

# -----------------------------------------------------------------
Exemplo n.º 21
0
# Import the relevant PTS classes and modules
# (the appropriate module for performing the requested stage is imported conditionally below)
from pts.core.basics.log import log
from pts.eagle import performer

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

# Get appropriate callback for given stage
if stage == "extract":
    from pts.eagle.extractor import extract as callback
    chunksize = 20
if stage == "simulate":
    from pts.eagle.simulator import simulate as callback
    chunksize = 1
if stage == "observe":
    from pts.eagle.observer import observe as callback
    chunksize = 20
if stage == "store":
    log.error("Sorry - the store stage is not yet implemented")
    exit()

# Perform according to requested mode
log.info("Performing {} in {} mode ...".format(stage, mode))
if mode == "loop":
    performer.loop(callback, stage, float(eval(argum)), chunksize)
if mode == "force":
    performer.force(callback, stage, argum)
log.info("Finished performing.")

# -----------------------------------------------------------------
Exemplo n.º 22
0
        if config.versions:

            if local_version is None and remote_version is not None:
                log.warning(dependency + ": local version unknown")
            elif remote_version is None and local_version is not None:
                log.warning(dependency + ": remote version unknown")
            elif remote_version is None and local_version is None:
                log.warning(dependency + ": local and remote version unknown")
            elif local_version == remote_version:
                log.success(dependency + ": OK")
            else:
                log.warning(dependency + ": version " + local_version +
                            " locally and version " + remote_version +
                            " remotely")

        else:
            log.success(dependency + ": OK")

    # Not present on at least one system
    elif remotely_present and not locally_present:
        log.error(dependency + ": not present on this system")
    elif locally_present and not remotely_present:
        log.error(dependency + ": not present on remote '" + config.remote +
                  "'")
    else:
        log.error(dependency +
                  ": not present on either this sytem or remote '" +
                  config.remote + "'")

# -----------------------------------------------------------------
Exemplo n.º 23
0
Arquivo: open.py Projeto: SKIRT/PTS
# -----------------------------------------------------------------

# Connect to remote
remote = Remote()
remote.setup(config.remote)

# Determine the absolute file path
filepath = remote.absolute_path(config.filename)

# Determine the file path relative to the home directory
relative_filepath = remote.relative_to_home(filepath)

# Check if the file exists; otherwise don't bother mounting
if not remote.is_file(filepath):
    log.error("The file does not exist")
    exit()

# Disconnect the remote
remote.logout()

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

# Create the mounter
mounter = RemoteMounter()

# Mount and get the mount path
mount_path = mounter.mount(config.remote)

# Determine the local file path
filepath = fs.join(mount_path, relative_filepath)