Beispiel #1
0
from pts.core.basics.configuration import ConfigurationDefinition, parse_arguments

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

definition = ConfigurationDefinition(write_config=False)
definition.add_required("path_a", "file_path", "path of the first table")
definition.add_required("path_b", "file_path", "path of the second table")

config = parse_arguments("compare_tables", definition, add_logging=False, add_cwd=False)

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

format_a = "ascii." + fs.get_extension(config.path_a)
format_b = "ascii." + fs.get_extension(config.path_b)

table_a = tables.from_file(config.path_a, format=format_a)
table_b = tables.from_file(config.path_b, format=format_b)

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

print("")

print(fmt.underlined + fmt.green + "Table a" + fmt.reset + " [" + config.path_a + "]:")
print("")
print(" - length: " + str(len(table_a)))
print(" - number of columns: " + str(len(table_a.colnames)))
#print(" - columns: " + stringify.stringify(table_a.colnames)[1])

print("")

print(fmt.underlined + fmt.green + "Table b" + fmt.reset + " [" + config.path_b + "]:")
Beispiel #2
0
                    help="the FWHM of the stars (in pixels)")
parser.add_argument("sigma_level",
                    type=float,
                    nargs='?',
                    help="the sigma level",
                    default=3.0)
parser.add_argument("--color", type=str, help="the color", default="blue")

# Parse the command line arguments
arguments = parser.parse_args()

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

# Load the catalog
catalog_name = os.path.splitext(os.path.basename(arguments.catalog))[0]
catalog = tables.from_file(arguments.catalog)

# Open the frame
frame = Frame.from_file(arguments.image)

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

# Determine the path to the region file
path = os.path.join(os.getcwd(), catalog_name + ".reg")

# Create a file
f = open(path, 'w')

# Initialize the region string
print("# Region file format: DS9 version 4.1", file=f)
Beispiel #3
0
# Check whether the generation is scored
if not fs.is_file(chi_squared_path): raise RuntimeError("The last generation has not been scored yet!")

# Path to the random state
random_path = fs.join(generation_path, "rndstate.pickle")

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

# Load the random state
load_state(random_path)

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

# Load the parameters table
parameters = tables.from_file(parameters_path, format="ascii.ecsv")

# Load the chi squared table
chi_squared = tables.from_file(chi_squared_path, format="ascii.ecsv")

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

# Load the GA
ga = GAEngine.from_file(path)

# Check whether the chi-squared and parameter tables match
for i in range(len(parameters)):
    assert parameters["Unique name"][i] == chi_squared["Unique name"][i]

# Get the scores
scores = chi_squared["Chi-squared"]
Beispiel #4
0
                    default="stars.dat")
parser.add_argument("--debug", type=str, help="debug mode")

# Parse the command line arguments
arguments = parser.parse_args()

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

directory_path = fs.cwd()

# Determine the full paths to the galaxy and star catalog
galactic_catalog_path = fs.join(directory_path, arguments.galaxies)
stellar_catalog_path = fs.join(directory_path, arguments.stars)

# Open the galactic catalog (to get the name of the principal galaxy)
galactic_catalog = tables.from_file(galactic_catalog_path)

galaxy_name = None

# Loop over the entries of the galactic catalog
for i in range(len(galactic_catalog)):

    if galactic_catalog["Principal"][i]:

        galaxy_name = galactic_catalog["Name"][i]
        break

# If the galaxy name is still None, something is wrong with the galaxy catalog (principal not defined)
if galaxy_name is None:
    raise RuntimeError(
        "The galactic catalog is invalid: principal galaxy not defined")
Beispiel #5
0
# Check whether the generation is scored
if not fs.is_file(chi_squared_path):
    raise RuntimeError("The last generation has not been scored yet!")

# Path to the random state
random_path = fs.join(generation_path, "rndstate.pickle")

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

# Load the random state
load_state(random_path)

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

# Load the parameters table
parameters = tables.from_file(parameters_path, format="ascii.ecsv")

# Load the chi squared table
chi_squared = tables.from_file(chi_squared_path, format="ascii.ecsv")

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

# Load the GA
ga = GAEngine.from_file(path)

# Check whether the chi-squared and parameter tables match
for i in range(len(parameters)):
    assert parameters["Unique name"][i] == chi_squared["Unique name"][i]

# Get the scores
scores = chi_squared["Chi-squared"]
# Create the command-line parser
parser = argparse.ArgumentParser()
parser.add_argument("catalog", type=str, help="the name of the region file")
parser.add_argument("image", type=str, help="the name of the image file for which to create the region")
parser.add_argument("fwhm", type=float, help="the FWHM of the stars (in pixels)")
parser.add_argument("sigma_level", type=float, nargs='?', help="the sigma level", default=3.0)
parser.add_argument("--color", type=str, help="the color", default="blue")

# Parse the command line arguments
arguments = parser.parse_args()

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

# Load the catalog
catalog_name = os.path.splitext(os.path.basename(arguments.catalog))[0]
catalog = tables.from_file(arguments.catalog)

# Open the frame
frame = Frame.from_file(arguments.image)

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

# Determine the path to the region file
path = os.path.join(os.getcwd(), catalog_name + ".reg")

# Create a file
f = open(path, 'w')

# Initialize the region string
print("# Region file format: DS9 version 4.1", file=f)
Beispiel #7
0
parser.add_argument("stars", type=str, help="the name of the file containing the stellar catalog", nargs='?', default="stars.dat")
parser.add_argument("--debug", type=str, help="debug mode")

# Parse the command line arguments
arguments = parser.parse_args()

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

directory_path = fs.cwd()

# Determine the full paths to the galaxy and star catalog
galactic_catalog_path = fs.join(directory_path, arguments.galaxies)
stellar_catalog_path = fs.join(directory_path, arguments.stars)

# Open the galactic catalog (to get the name of the principal galaxy)
galactic_catalog = tables.from_file(galactic_catalog_path)

galaxy_name = None

# Loop over the entries of the galactic catalog
for i in range(len(galactic_catalog)):

    if galactic_catalog["Principal"][i]:

        galaxy_name = galactic_catalog["Name"][i]
        break

# If the galaxy name is still None, something is wrong with the galaxy catalog (principal not defined)
if galaxy_name is None: raise RuntimeError("The galactic catalog is invalid: principal galaxy not defined")

# Determine the path to the user catalogs directory
Beispiel #8
0
else:
    generation_path = fs.join(fs.cwd(), "Generation " + str(last_generation))
    print("Current generation: " + str(last_generation))

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

# Path to the current GA object
path = fs.join(generation_path, "ga.pickle")

# Path to the parameters table
parameters_path = fs.join(generation_path, "parameters.dat")

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

# Load the parameters table
table = tables.from_file(parameters_path, format="ascii.ecsv")

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

names = []
scores = []

lowest_score = None
index_lowest = None

for index in range(len(table)):

    # Get the parameter values
    parameter_a_tab = table["Parameter a"][index]
    parameter_b_tab = table["Parameter b"][index]
Beispiel #9
0
definition = ConfigurationDefinition(write_config=False)
definition.add_required("path_a", "file_path", "path of the first table")
definition.add_required("path_b", "file_path", "path of the second table")

config = parse_arguments("compare_tables",
                         definition,
                         add_logging=False,
                         add_cwd=False)

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

format_a = "ascii." + fs.get_extension(config.path_a)
format_b = "ascii." + fs.get_extension(config.path_b)

table_a = tables.from_file(config.path_a, format=format_a)
table_b = tables.from_file(config.path_b, format=format_b)

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

print("")

print(fmt.underlined + fmt.green + "Table a" + fmt.reset + " [" +
      config.path_a + "]:")
print("")
print(" - length: " + str(len(table_a)))
print(" - number of columns: " + str(len(table_a.colnames)))
#print(" - columns: " + stringify.stringify(table_a.colnames)[1])

print("")