Пример #1
0
def migrate_image_files(connection, image_bucket_name, file_bucket_name, s3helper):
    for file_name in glob.glob('/home/ec2-user/galaxyImages/*/*'):
        (name, version, extension) = get_name_version(file_name)

        # Only migrate the images in the original galaxy is still in the database
        galaxy = connection.execute(select([GALAXY]).where(and_(GALAXY.c.name == name, GALAXY.c.version_number == version))).first()
        if galaxy is not None:
            if extension == '.fits':
                add_file_to_bucket1(file_bucket_name, get_key_fits(galaxy[GALAXY.c.name], galaxy[GALAXY.c.run_id], galaxy[GALAXY.c.galaxy_id]), file_name, s3helper)
            else:
                galaxy_key = get_galaxy_file_name(galaxy[GALAXY.c.name], galaxy[GALAXY.c.run_id], galaxy[GALAXY.c.galaxy_id])
                if file_name.endswith('_tn_colour_1.png'):
                    add_file_to_bucket1(image_bucket_name, get_thumbnail_colour_image_key(galaxy_key, 1), file_name, s3helper)
                elif file_name.endswith('_colour_1.png'):
                    add_file_to_bucket1(image_bucket_name, get_colour_image_key(galaxy_key, 1), file_name, s3helper)
                elif file_name.endswith('_colour_2.png'):
                    add_file_to_bucket1(image_bucket_name, get_colour_image_key(galaxy_key, 2), file_name, s3helper)
                elif file_name.endswith('_colour_3.png'):
                    add_file_to_bucket1(image_bucket_name, get_colour_image_key(galaxy_key, 3), file_name, s3helper)
                elif file_name.endswith('_colour_4.png'):
                    add_file_to_bucket1(image_bucket_name, get_colour_image_key(galaxy_key, 4), file_name, s3helper)
                elif file_name.endswith('_mu.png'):
                    add_file_to_bucket1(image_bucket_name, get_build_png_name(galaxy_key, 'mu'), file_name, s3helper)
                elif file_name.endswith('_m.png'):
                    add_file_to_bucket1(image_bucket_name, get_build_png_name(galaxy_key, 'm'), file_name, s3helper)
                elif file_name.endswith('_ldust.png'):
                    add_file_to_bucket1(image_bucket_name, get_build_png_name(galaxy_key, 'ldust'), file_name, s3helper)
                elif file_name.endswith('_sfr.png'):
                    add_file_to_bucket1(image_bucket_name, get_build_png_name(galaxy_key, 'sfr'), file_name, s3helper)
Пример #2
0
    def _build_image_asinh(self, fits_file_name, galaxy_key_stub, centre,
                           galaxy_id, bucket_name):
        """
        Build Three Colour Images using the asinh() function.
        :param fits_file_name:
        :param galaxy_key_stub:
        :param centre:
        :param galaxy_id:
        :param bucket_name:
        """
        hdulist = pyfits.open(fits_file_name, memmap=True)

        hdu = hdulist[0]
        width = hdu.header['NAXIS1']
        height = hdu.header['NAXIS2']

        (image1_filters, image2_filters, image3_filters,
         image4_filters) = self._get_image_filters(hdulist)

        # Create Three Colour Images
        image1 = ImageBuilder(bucket_name, 1,
                              get_colour_image_key(galaxy_key_stub, 1),
                              get_thumbnail_colour_image_key(
                                  galaxy_key_stub,
                                  1), image1_filters[0], image1_filters[1],
                              image1_filters[2], width, height, centre,
                              self._connection, galaxy_id)  # i, r, g
        image2 = ImageBuilder(bucket_name, 2,
                              get_colour_image_key(galaxy_key_stub, 2), None,
                              image2_filters[0], image2_filters[1],
                              image2_filters[2], width, height, centre,
                              self._connection, galaxy_id)  # r, g, NUV
        image3 = ImageBuilder(bucket_name, 3,
                              get_colour_image_key(galaxy_key_stub, 3), None,
                              image3_filters[0], image3_filters[1],
                              image3_filters[2], width, height, centre,
                              self._connection, galaxy_id)  # 3.6, g, NUV
        image4 = ImageBuilder(bucket_name, 4,
                              get_colour_image_key(galaxy_key_stub, 4), None,
                              image4_filters[0], image4_filters[1],
                              image4_filters[2], width, height, centre,
                              self._connection, galaxy_id)  # 22, r, NUV
        images = [image1, image2, image3, image4]

        for hdu in hdulist:
            filter_band = hdu.header['MAGPHYSI']
            for image in images:
                image.set_data(filter_band, hdu.data)

        s3helper = S3Helper()
        for image in images:
            if image.is_valid():
                image.save_image(s3helper)
            else:
                print 'not valid'

        hdulist.close()
Пример #3
0
    def _build_Image_Asinh(self, fits_file_name, galaxy_key_stub, centre, galaxy_id, bucket_name):
        """
        Build Three Colour Images using the asinh() function.
        :param fits_file_name:
        :param galaxy_key_stub:
        :param centre:
        :param galaxy_id:
        :param bucket:
        """
        hdulist = pyfits.open(fits_file_name, memmap=True)

        hdu = hdulist[0]
        width = hdu.header['NAXIS1']
        height = hdu.header['NAXIS2']

        (image1_filters, image2_filters, image3_filters, image4_filters) = self._get_image_filters(hdulist)

        # Create Three Colour Images
        image1 = ImageBuilder(bucket_name,
                              1,
                              get_colour_image_key(galaxy_key_stub, 1),
                              get_thumbnail_colour_image_key(galaxy_key_stub, 1),
                              image1_filters[0],
                              image1_filters[1],
                              image1_filters[2],
                              width,
                              height,
                              centre,
                              self._connection,
                              galaxy_id)  # i, r, g
        image2 = ImageBuilder(bucket_name,
                              2,
                              get_colour_image_key(galaxy_key_stub, 2),
                              None,
                              image2_filters[0],
                              image2_filters[1],
                              image2_filters[2],
                              width,
                              height,
                              centre,
                              self._connection,
                              galaxy_id)  # r, g, NUV
        image3 = ImageBuilder(bucket_name,
                              3,
                              get_colour_image_key(galaxy_key_stub, 3),
                              None,
                              image3_filters[0],
                              image3_filters[1],
                              image3_filters[2],
                              width,
                              height,
                              centre,
                              self._connection,
                              galaxy_id)  # 3.6, g, NUV
        image4 = ImageBuilder(bucket_name,
                              4,
                              get_colour_image_key(galaxy_key_stub, 4),
                              None,
                              image4_filters[0],
                              image4_filters[1],
                              image4_filters[2],
                              width,
                              height,
                              centre,
                              self._connection,
                              galaxy_id)  # 22, r, NUV
        images = [image1, image2, image3, image4]

        for hdu in hdulist:
            filter_band = hdu.header['MAGPHYSI']
            for image in images:
                image.set_data(filter_band, hdu.data)

        s3helper = S3Helper()
        for image in images:
            if image.is_valid():
                image.save_image(s3helper)
            else:
                print 'not valid'

        hdulist.close()