Example #1
0
    def load_i1(self):

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

        # Inform the user
        log.info("Loading the IRAC 3.6 micron image ...")

        # Determine the path to the truncated 3.6 micron image
        #path = fs.join(truncation_path, "IRAC I1.fits")

        path = fs.join(self.prep_path, "IRAC I1", "result.fits")
        frame = Frame.from_file(path)

        # Convert the frame to Jy/pix
        conversion_factor = 1.0
        conversion_factor *= 1e6

        # Convert the 3.6 micron image from Jy / sr to Jy / pixel
        pixelscale = frame.average_pixelscale
        pixel_factor = (1.0/pixelscale**2).to("pix2/sr").value
        conversion_factor /= pixel_factor
        frame *= conversion_factor
        frame.unit = "Jy"

        # Set the frame
        self.i1_jy = frame
Example #2
0
    def load_i1(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the IRAC 3.6 micron image ...")

        # Determine the path to the truncated 3.6 micron image
        #path = fs.join(truncation_path, "IRAC I1.fits")

        path = fs.join(self.prep_path, "IRAC I1", "result.fits")
        frame = Frame.from_file(path)

        # Convert the frame to Jy/pix
        conversion_factor = 1.0
        conversion_factor *= 1e6

        # Convert the 3.6 micron image from Jy / sr to Jy / pixel
        pixelscale = frame.average_pixelscale
        pixel_factor = (1.0 / pixelscale**2).to("pix2/sr").value
        conversion_factor /= pixel_factor
        frame *= conversion_factor
        frame.unit = "Jy"

        # Set the frame
        self.i1_jy = frame
Example #3
0
File: test.py Project: rag9704/PTS
    def get_map(self, name):
        """
        This function ...
        :param name:
        :return:
        """

        # Determine path
        path = fs.join(self.maps_path, name)
        return Frame.from_file(path)
Example #4
0
    def young_stars_map(self):
        """
        This function ...
        :return:
        """

        # young stars

        young_map = Frame.from_file(young_map_path)
        young_map.wcs = self.wcs
        return young_map
Example #5
0
    def dust_map(self):
        """
        This function ...
        :return:
        """

        # Dust

        dust_map = Frame.from_file(dust_map_path)
        dust_map.wcs = self.wcs
        return dust_map
Example #6
0
    def ionizing_stars_map(self):
        """
        This function ....
        :return:
        """

        # Ionizing stars

        ionizing_map = Frame.from_file(ionizing_map_path)
        ionizing_map.wcs = self.wcs
        return ionizing_map
Example #7
0
File: test.py Project: SKIRT/PTS
    def get_map(self, name):

        """
        This function ...
        :param name:
        :return:
        """

        # Determine path
        path = fs.join(self.maps_path, name)
        return Frame.from_file(path)
Example #8
0
    def old_stars_map(self):
        """
        This function ...
        :return:
        """

        # Old stars

        old_map = Frame.from_file(old_map_path)
        old_map.wcs = self.wcs
        return old_map
Example #9
0
File: base.py Project: SKIRT/PTS
    def load_maps(self):

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

        # Inform the user
        log.info("Loading the input maps ...")

        # Determine path to maps directory
        maps_path = fs.join(m81_data_path, "maps")

        # Determine the path to the header file
        header_path = fs.join(maps_path, "header.txt")
        header = Header.fromtextfile(header_path)
        wcs = CoordinateSystem(header=header)

        # Old stars
        old_map_path = fs.join(maps_path, old_filename)
        old_map = Frame.from_file(old_map_path)
        old_map.wcs = wcs
        self.maps["old"] = old_map

        # young stars
        young_map_path = fs.join(maps_path, young_filename)
        young_map = Frame.from_file(young_map_path)
        young_map.wcs = wcs
        self.maps["young"] = young_map

        # Ionizing stars
        ionizing_map_path = fs.join(maps_path, ionizing_filename)
        ionizing_map = Frame.from_file(ionizing_map_path)
        ionizing_map.wcs = wcs
        self.maps["ionizing"] = ionizing_map

        # Dust
        dust_map_path = fs.join(maps_path, dust_filename)
        dust_map = Frame.from_file(dust_map_path)
        dust_map.wcs = wcs
        self.maps["dust"] = dust_map
Example #10
0
File: data.py Project: SKIRT/PTS
    def dust_map(self):

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

        # Dust

        dust_map = Frame.from_file(dust_map_path)
        dust_map.wcs = self.wcs
        return dust_map
Example #11
0
    def load_disk(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the disk image ...")

        # Determine the path to the disk image
        path = fs.join(self.components_images_path, "disk.fits")
        self.disk_jy = Frame.from_file(path)
Example #12
0
    def load_model(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the model image ...")

        # Determine the path to the truncated model image
        path = fs.join(self.components_images_path, "model.fits")
        self.model_jy = Frame.from_file(path)
Example #13
0
File: data.py Project: SKIRT/PTS
    def ionizing_stars_map(self):

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

        # Ionizing stars

        ionizing_map = Frame.from_file(ionizing_map_path)
        ionizing_map.wcs = self.wcs
        return ionizing_map
Example #14
0
File: data.py Project: SKIRT/PTS
    def young_stars_map(self):

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

        # young stars

        young_map = Frame.from_file(young_map_path)
        young_map.wcs = self.wcs
        return young_map
Example #15
0
File: data.py Project: SKIRT/PTS
    def old_stars_map(self):

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

        # Old stars

        old_map = Frame.from_file(old_map_path)
        old_map.wcs = self.wcs
        return old_map
Example #16
0
    def load_bulge2d(self):
        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Loading the bulge 2D image ...")

        # Determine the path to the bulge 2D image
        path = fs.join(self.components_images_path, "bulge2D.fits")
        self.bulge2d_jy = Frame.from_file(path)
Example #17
0
File: test.py Project: rag9704/PTS
    def load_images(self):
        """
        This function ...
        :return:
        """

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

        # The common wcs of the images
        wcs = None

        # Loop over the images in the data directory
        for path, filename in fs.files_in_path(self.data_path,
                                               extension="fits",
                                               returns=["path", "name"]):

            # Load the frame
            frame = Frame.from_file(path)

            # Set filter
            previous_filter = frame.filter
            frame.filter = parse_filter(filename.split("_norm")[0])
            if previous_filter != frame.filter: frame.save()

            # Check filter
            if str(frame.filter) not in [
                    str(fltr) for fltr in self.config.fitting_filters
            ]:
                continue

            # Determine name
            name = str(frame.filter)

            # Check wcs
            if wcs is None: wcs = frame.wcs
            elif wcs == frame.wcs: pass
            else:
                raise IOError("The coordinate system of image '" + filename +
                              "' does not match that of other images")

            # Debugging
            log.debug("Adding frame '" + filename + "' ...")

            # Add to dictionary
            self.images[name] = frame

            # Set original path
            self.image_paths[name] = path

        # Set the wcs
        self.wcs = wcs
Example #18
0
    def load_bulge2d(self):

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

        # Inform the user
        log.info("Loading the bulge 2D image ...")

        # Determine the path to the bulge 2D image
        path = fs.join(self.components_images_path, "bulge2D.fits")
        self.bulge2d_jy = Frame.from_file(path)
Example #19
0
    def load_model(self):

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

        # Inform the user
        log.info("Loading the model image ...")

        # Determine the path to the truncated model image
        path = fs.join(self.components_images_path, "model.fits")
        self.model_jy = Frame.from_file(path)
Example #20
0
    def load_disk(self):

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

        # Inform the user
        log.info("Loading the disk image ...")

        # Determine the path to the disk image
        path = fs.join(self.components_images_path, "disk.fits")
        self.disk_jy = Frame.from_file(path)
Example #21
0
    #continue

    # Loop over the images
    for step in paths:

        # Get the path
        path = paths[step]

        # Check whether the correction has already been performed
        backup_filepath = fs.appended_filepath(path, "_backup")
        if fs.is_file(path):  # local

            if fs.is_file(backup_filepath):  # already corrected

                # Check
                corrected = Frame.from_file(path)
                backup = Frame.from_file(backup_filepath)

                ratio = corrected / backup
                ratios = ratio[np.isfinite(ratio)]
                if not np.all(np.isclose(ratios, factor)):
                    raise RuntimeError("Correction was not OK for " +
                                       prep_name + " after the " + step +
                                       " step: mean ratio of " +
                                       str(np.mean(ratios)))

                log.success("The " + prep_name + " image after the " + step +
                            " step has already been corrected (locally)")
                continue

            else:
Example #22
0
    if np.isclose(factor, config.factor, rtol=0.01):
        the_image_path = image_path
        break

# Check
if the_image_path is None:
    raise ValueError("Could not find the truncated " + filter_name +
                     " image with a truncation factor of " +
                     str(config.factor))

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

# Download the image to a temporary path
filename = time.unique_name("truncated_" + filter_name + "_" +
                            str(config.factor))
filepath = remote.download_file_to(the_image_path,
                                   pts_temp_dir,
                                   new_name=filename)

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

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

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

# Plot the truncated image
plotting.plot_box(frame)

# -----------------------------------------------------------------
Example #23
0
# Create the command-line parser
parser = argparse.ArgumentParser()
parser.add_argument("region", type=str, help="the name of the region file")
parser.add_argument("image", type=str, help="the name of the image file")
parser.add_argument("value", type=float, nargs='?', help="the fill value", default='nan')
parser.add_argument("--data", action="store_true", help="use the original data for pixels that are not masked")
parser.add_argument('--invert', action="store_true", help="invert the mask so that mask covers outside regions")

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

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

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

# Load the region
region_name = os.path.splitext(os.path.basename(arguments.region))[0]
region = load_as_pixel_region_list(arguments.region, frame.wcs)

# Create the mask
mask = region.to_mask(x_size=frame.xsize, y_size=frame.ysize)

# Calculate the inverse, if requested
if arguments.invert: mask = mask.inverse()

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

if arguments.data:
    
Example #24
0
    the_image_path = None

    # Find the image corresponding to the specified factor
    for image_path, image_name in fs.files_in_path(lowres_path,
                                                   extension="fits",
                                                   returns=["path", "name"]):

        # Determine the factor
        factor = real(image_name)

        # If the factor corresponds to the specified factor, take this image
        if np.isclose(factor, config.factor, rtol=0.01):
            the_image_path = image_path
            break

    # Check
    if the_image_path is None:
        raise ValueError("No truncated " + filter_name +
                         " image found for a factor of " + str(config.factor))

    # Add the image
    frame = Frame.from_file(the_image_path)
    plotter.add_image(frame, filter_name)

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

# Run the plotter
plotter.run()

# -----------------------------------------------------------------
Example #25
0
definition.add_optional("alpha", "string", "alpha method", default_alpha_method, suggestions=alpha_methods)
definition.add_flag("no_alpha", "no alpha", False)
definition.add_optional("output", "string", "output filepath", letter="o")
definition.add_optional("peak_alpha", "real", "alpha of peak value", 1.)
definition.add_optional("max_npixels", "positive_integer", "maximum number of pixels")
definition.add_optional("downsample", "positive_real", "downsample with this factor")
definition.add_flag("show", "show after creating", False)
config = parse_arguments("fits_to_png", definition)

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

# Inform the user
log.info("Loading the FITS file ...")

# Load the FITS file
frame = Frame.from_file(config.filename)

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

if config.output is not None: filepath = fs.absolute_or_in(config.output, fs.cwd())
else:

    # Determine the path
    name = fs.strip_extension(fs.name(config.filename))
    filepath = fs.absolute_path(name + ".png")

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

# Max npixels
if config.max_npixels is not None:
Example #26
0
    name = fs.strip_extension(fs.name(filepath))

    # Get header
    header = get_header(filepath)

    # Get the filter
    fltr = get_filter(name, header=header)

    # Check whether the filter is in the list of filters to be plotted
    if fltr not in config.filters: continue

    # Get the index for this filter
    index = config.filters.index(fltr)

    # Load the image
    frame = Frame.from_file(filepath)

    # Replace zeroes and negatives
    frame.replace_zeroes_by_nans()
    frame.replace_negatives_by_nans()

    # Set the image
    mock_images[index] = frame

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

# Get the observed images
observed_images = []
for fltr in config.filters:

    # Check
Example #27
0
paths = fs.files_in_path(galex_images_path, extension="fits", contains="poisson") + fs.files_in_path(sdss_images_path, extension="fits", contains="poisson")

# Loop over the GALEX poisson frames
for path in paths:

    # Image name
    name = fs.strip_extension(fs.name(path))

    # Get instrument and band
    galaxy_name, instrument, band, _ = name.split("_")

    # Create the filter
    fltr = BroadBandFilter.from_instrument_and_band(instrument, band)

    # Load the frame
    poisson = Frame.from_file(path)

    # Get the attenuation
    att = attenuation.extinction_for_filter(fltr)

    # CORRECT FOR GALACTIC EXTINCTION
    poisson *= 10**(0.4 * att)

    # CONVERT UNIT to MJy/sr
    poisson *= 1e-6
    poisson /= poisson.pixelarea.to("sr").value
    poisson.unit = "MJy/sr"

    # Make frame remote
    remote_frame = RemoteFrame.from_local(poisson, remote_host_id)
Example #28
0
modeling_path = config.path

galaxy_name = fs.name(modeling_path)

fit_best_images_path = fs.join(modeling_path, "fit", "best", "images", "test")

simulated = dict()

for path, name in fs.files_in_path(fit_best_images_path,
                                   extension="fits",
                                   returns=["path", "name"]):

    if name == galaxy_name + "_earth_total": continue

    frame = Frame.from_file(path)

    if "2MASS" in str(frame.filter): continue
    if "I4" in str(frame.filter): continue
    if "W3" in str(frame.filter): continue

    if frame.filter is None: raise ValueError("No filter for " + name)

    simulated[str(frame.filter)] = frame

trunc_path = fs.join(modeling_path, "truncated")

observed = dict()

for path, name in fs.files_in_path(trunc_path,
                                   extension="fits",
Example #29
0
    # return the MSE, the lower the error, the more "similar"
    # the two images are
    return err


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

# Loop over the different kinds of maps
for which_map in config.maps:

    # Get the map path
    path = map_paths[which_map]

    # Load the map
    the_map = Frame.from_file(path)

    # Set psf filter
    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()
Example #30
0
plotter.config.max_nrows = 3
plotter.config.ngrids = 4

# Write data
plotter.config.write = config.write_data

# Crop to
plotter.crop_to = environment.truncation_box

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

# Loop over the frames in the current working directory
for path, name in fs.files_in_cwd(extension="fits", returns=["path", "name"]):

    # Load the frame
    frame = Frame.from_file(path)

    # Get the filter
    fltr = frame.filter
    filter_name = str(fltr)

    # Do we have a photometry image for this filter
    if not environment.has_photometry_for_filter(fltr): continue

    # Get the photometry image
    reference_path = environment.photometry_image_paths_for_filters[fltr]
    reference = Frame.from_file(reference_path)

    # Add row
    plotter.add_row(reference, frame, filter_name)
Example #31
0
#finder.config.point_sources_catalog = ...

# Set the output directory
finder.config.output = output_find_name

# Set options for extended sources, point sources and other sources
# For extended source options: see 'definition' in pts.magic.config.find_extended.py
# For point source options: see 'definition' in pts.magic.config.find_point.py
# For other source options: see 'definition' in pts.magic.config.find_other.py
#finder.config.extended. .. = ...
#finder.config.point. ... = ...
#finder.config.other. ... = ...

## Add your image frame(s)
# Output path can be specified seperately for each frame
frame = Frame.from_file("testIm-i.fits")

#finder.add_frame(frame="J000002.00+051717.0_1237678777941229794-g.fits", name=name, output_path='output/')
#finder.add_frame(...)
#...

## Start the source finder:
# various kinds of input can be passed here:
# - frames: a FrameList instance
# - dataset: a DataSet instance
# - output_paths: a dictionary of output paths for each frame
# - star_finder_settings: different settings for each frame
# - ignore: ignore images (list of names)
# - ignore_stars: ignore stars for these images (list of names)
# - ignore_other_sources: ignore other sources for these images (list of names)
# - extended_source_catalog: object of ExtendedSourceCatalog class
Example #32
0
                    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)

# Create the list of stars
for i in range(len(catalog)):
Example #33
0
definition.add_optional("colours", "string", "colour or colour scale", "red")
definition.add_optional("alpha", "string", "alpha method", default_alpha_method, suggestions=alpha_methods)
definition.add_optional("output", "string", "output filepath", letter="o")
definition.add_optional("peak_alpha", "real", "alpha of peak value", 1.)
definition.add_optional("max_npixels", "positive_integer", "maximum number of pixels")
definition.add_optional("downsample", "positive_real", "downsample with this factor")
definition.add_flag("show", "show after creating", False)
config = parse_arguments("fits_to_png", definition)

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

# Inform the user
log.info("Loading the FITS file ...")

# Load the FITS file
frame = Frame.from_file(config.filename)

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

if config.output is not None: filepath = fs.absolute_or_in(config.output, fs.cwd())
else:

    # Determine the path
    name = fs.strip_extension(fs.name(config.filename))
    filepath = fs.absolute_path(name + ".png")

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

# Max npixels
if config.max_npixels is not None:
Example #34
0
prep_names_column = []
names = ["Image name", "Image path", "Preparation name"]

# Loop over all subdirectories of the data directory
for path, name in fs.directories_in_path(fs.join(config.path, "data"),
                                         not_contains="bad",
                                         returns=["path", "name"]):

    # Loop over all FITS files found in the current subdirectory
    for image_path, image_name in fs.files_in_path(path,
                                                   extension="fits",
                                                   not_contains="_Error",
                                                   returns=["path", "name"]):

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

        # Determine the preparation name
        if frame.filter is not None: prep_name = str(frame.filter)
        else: prep_name = image_name

        # Set the row entries
        names_column.append(image_name)
        paths_column.append(image_path)
        prep_names_column.append(prep_name)

# Create the table
data = [names_column, paths_column, prep_names_column]
table = tables.new(data, names)

# Check whether the preparation directory exists
Example #35
0
trunc_path = fs.join(modeling_path, "truncated")
prep_path = fs.join(modeling_path, "prep")

observed = dict()

# Loop over the directories in the preparation directory
for path, name in fs.directories_in_path(prep_path, returns=["path", "name"]):

    # Skip Halpha
    if "Halpha" in name: continue

    # Determine the path to the prepared image
    result_path = fs.join(path, "result.fits")

    # Load the frame
    frame = Frame.from_file(result_path)
    if frame.filter is None: raise ValueError("No filter for " + name)

    observed[str(frame.filter)] = frame

# Sort the filter names on wavelength
sorted_filter_names = sorted(observed.keys(), key=lambda key: observed[key].filter.pivotwavelength())

sorted_filter_names = sorted_filter_names[0:6]

##### CAN BE REMOVED ########
"""
plt.figure()

x = []
y = []
Example #36
0
data_images_path = get_data_images_path(modeling_path)

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

shapes = dict()

# Loop over the images
for image_path, image_name in fs.files_in_path(data_images_path,
                                               extension="fits",
                                               not_contains="poisson",
                                               returns=["path", "name"],
                                               recursive=True,
                                               recursion_level=1):

    # Load the image
    frame = Frame.from_file(image_path, silent=True)

    # Determine filter name
    filter_name = frame.filter_name

    # Set pixel shape
    shapes[filter_name] = frame.shape

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

# Sort on shape
sorted_filter_names = sorted(shapes.keys(), key=lambda name: shapes[name])

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

print("")
Example #37
0
    fltr = parse_filter(name)
    filter_name = str(fltr)

    # Initializ variable
    the_image_path = None

    # Find the image corresponding to the specified factor
    for image_path, image_name in fs.files_in_path(lowres_path, extension="fits", returns=["path", "name"]):

        # Determine the factor
        factor = real(image_name)

        # If the factor corresponds to the specified factor, take this image
        if np.isclose(factor, config.factor, rtol=0.01):
            the_image_path = image_path
            break

    # Check
    if the_image_path is None: raise ValueError("No truncated " + filter_name + " image found for a factor of " + str(config.factor))

    # Add the image
    frame = Frame.from_file(the_image_path)
    plotter.add_image(frame, filter_name)

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

# Run the plotter
plotter.run()

# -----------------------------------------------------------------
log.start("Starting decomposition_residuals ...")

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

components_path = fs.join(config.path, "components")
truncation_path = fs.join(config.path, "truncated")
residuals_path = fs.join(config.path, "residuals")

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

# Inform the user
log.info("Loading the IRAC 3.6 micron image ...")

# Determine the path to the truncated 3.6 micron image
path = fs.join(truncation_path, "IRAC I1.fits")
frame = Frame.from_file(path)

# Convert the frame to Jy/pix
conversion_factor = 1.0
conversion_factor *= 1e6

# Convert the 3.6 micron image from Jy / sr to Jy / pixel
pixelscale = frame.average_pixelscale
pixel_factor = (1.0/pixelscale**2).to("pix2/sr").value
conversion_factor /= pixel_factor
frame *= conversion_factor
frame.unit = "Jy"

frame.save(fs.join(residuals_path, "i1_jy.fits"))

# Inform the user
# -----------------------------------------------------------------

names_column = []
paths_column = []
prep_names_column = []
names = ["Image name", "Image path", "Preparation name"]

# Loop over all subdirectories of the data directory
for path, name in fs.directories_in_path(fs.join(config.path, "data"), not_contains="bad", returns=["path", "name"]):

    # Loop over all FITS files found in the current subdirectory
    for image_path, image_name in fs.files_in_path(path, extension="fits", not_contains="_Error", returns=["path", "name"]):

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

        # Determine the preparation name
        if frame.filter is not None: prep_name = str(frame.filter)
        else: prep_name = image_name

        # Set the row entries
        names_column.append(image_name)
        paths_column.append(image_path)
        prep_names_column.append(prep_name)

# Create the table
data = [names_column, paths_column, prep_names_column]
table = tables.new(data, names)

# Check whether the preparation directory exists