예제 #1
0
    def _store_fits_header(self):
        """
        Store the FITS headers we need to remember
        """
        insert = FITS_HEADER.insert()
        header = self._hdu_list[0].header
        index = 0
        ctype1 = None
        ctype2 = None
        for keyword in header:
            # The new version of PyFits supports comments
            value = header[index]
            comment = header.comments[index]
            self._connection.execute(insert.values(galaxy_id=self._galaxy_id, keyword=keyword, value=value, comment=comment))

            # Record the ctype so we can get the RA and DEC
            if keyword == 'CTYPE1':
                ctype1 = value
            elif keyword == 'CTYPE2':
                ctype2 = value

            # Record the RA and DEC if we can
            if keyword == 'RA_CENT' or (ctype1 == 'RA---TAN' and keyword == 'CRVAL1'):
                self._connection.execute(GALAXY.update().where(GALAXY.c.galaxy_id == self._galaxy_id).values(ra_cent=float(value)))
            elif keyword == 'DEC_CENT' or (ctype2 == 'DEC--TAN' and keyword == 'CRVAL2'):
                self._connection.execute(GALAXY.update().where(GALAXY.c.galaxy_id == self._galaxy_id).values(dec_cent=float(value)))

            index += 1
예제 #2
0
def remove_database_entries(connection, galaxy_id):
    connection.execute(
        PIXEL_RESULT.delete().where(PIXEL_RESULT.c.galaxy_id == galaxy_id))
    connection.execute(IMAGE_FILTERS_USED.delete().where(
        IMAGE_FILTERS_USED.c.galaxy_id == galaxy_id))
    connection.execute(AREA.delete().where(AREA.c.galaxy_id == galaxy_id))
    connection.execute(
        FITS_HEADER.delete().where(FITS_HEADER.c.galaxy_id == galaxy_id))
    connection.execute(GALAXY.delete().where(GALAXY.c.galaxy_id == galaxy_id))
예제 #3
0
def delete_galaxy(connection, galaxy_ids):
    for galaxy_id in galaxy_ids:
        transaction = connection.begin()
        galaxy = connection.execute(select([GALAXY]).where(GALAXY.c.galaxy_id == galaxy_id)).first()
        if galaxy is None:
            LOG.info('Error: Galaxy with galaxy_id of %d was not found', galaxy_id)
        else:
            LOG.info('Deleting Galaxy with galaxy_id of %d - %s', galaxy_id, galaxy[GALAXY.c.name])
            area_count = connection.execute(select([func.count(AREA.c.area_id)]).where(AREA.c.galaxy_id == galaxy[GALAXY.c.galaxy_id])).first()[0]
            counter = 1

            for area_id1 in connection.execute(select([AREA.c.area_id]).where(AREA.c.galaxy_id == galaxy[GALAXY.c.galaxy_id]).order_by(AREA.c.area_id)):
                LOG.info("Deleting galaxy {0} area {1}. {2} of {3}".format(galaxy_id, area_id1[0], counter, area_count))
                connection.execute(PIXEL_RESULT.delete().where(PIXEL_RESULT.c.area_id == area_id1[0]))

                # Give the rest of the world a chance to access the database
                time.sleep(0.1)
                counter += 1

                if shutdown() is True:
                    transaction.rollback()
                    raise SystemExit

            LOG.info("Deleting FITS headers for galaxy {0}".format(galaxy_id))
            connection.execute(FITS_HEADER.delete().where(FITS_HEADER.c.galaxy_id == galaxy[GALAXY.c.galaxy_id]))

            # Now empty the bucket of the sed files
            s3helper = S3Helper()
            bucket = s3helper.get_bucket(get_sed_files_bucket())
            galaxy_file_name = get_galaxy_file_name(galaxy[GALAXY.c.name], galaxy[GALAXY.c.run_id], galaxy[GALAXY.c.galaxy_id])
            for key in bucket.list(prefix='{0}/'.format(galaxy_file_name)):
                # Ignore the key
                if key.key.endswith('/'):
                    continue

                bucket.delete_key(key)

                if shutdown() is True:
                    transaction.rollback()
                    raise SystemExit

            # Now the folder
            key = Key(bucket)
            key.key = '{0}/'.format(galaxy_file_name)
            bucket.delete_key(key)

        LOG.info('Galaxy with galaxy_id of %d was deleted', galaxy_id)
        connection.execute(GALAXY.update().where(GALAXY.c.galaxy_id == galaxy_id).values(status_id=DELETED, status_time=datetime.datetime.now()))

        if shutdown() is True:
            transaction.rollback()
            raise SystemExit

        transaction.commit()
def delete_galaxy(connection, galaxy_id):
    if DRY_RUN:
        LOG.info('DRY_RUN: deleting galaxy_id: {0}'.format(galaxy_id))
    else:
        transaction = connection.begin()
        for area_id1 in connection.execute(select([AREA.c.area_id]).where(AREA.c.galaxy_id == galaxy_id).order_by(AREA.c.area_id)):
            connection.execute(PIXEL_RESULT.delete().where(PIXEL_RESULT.c.area_id == area_id1[0]))
            connection.execute(AREA_USER.delete().where(AREA_USER.c.area_id == area_id1[0]))

        connection.execute(AREA.delete().where(AREA.c.galaxy_id == galaxy_id))
        connection.execute(FITS_HEADER.delete().where(FITS_HEADER.c.galaxy_id == galaxy_id))
        connection.execute(IMAGE_FILTERS_USED.delete().where(IMAGE_FILTERS_USED.c.galaxy_id == galaxy_id))
        connection.execute(GALAXY.delete().where(GALAXY.c.galaxy_id == galaxy_id))

        LOG.info('Galaxy with galaxy_id of %d was deleted', galaxy_id)
        transaction.commit()
예제 #5
0
def delete_galaxy(connection, galaxy_id):
    if DRY_RUN:
        LOG.info('DRY_RUN: deleting galaxy_id: {0}'.format(galaxy_id))
    else:
        transaction = connection.begin()
        for area_id1 in connection.execute(
                select([AREA.c.area_id
                        ]).where(AREA.c.galaxy_id == galaxy_id).order_by(
                            AREA.c.area_id)):
            connection.execute(PIXEL_RESULT.delete().where(
                PIXEL_RESULT.c.area_id == area_id1[0]))
            connection.execute(
                AREA_USER.delete().where(AREA_USER.c.area_id == area_id1[0]))

        connection.execute(AREA.delete().where(AREA.c.galaxy_id == galaxy_id))
        connection.execute(
            FITS_HEADER.delete().where(FITS_HEADER.c.galaxy_id == galaxy_id))
        connection.execute(IMAGE_FILTERS_USED.delete().where(
            IMAGE_FILTERS_USED.c.galaxy_id == galaxy_id))
        connection.execute(
            GALAXY.delete().where(GALAXY.c.galaxy_id == galaxy_id))

        LOG.info('Galaxy with galaxy_id of %d was deleted', galaxy_id)
        transaction.commit()
예제 #6
0
def delete_galaxy(connection, galaxy_ids):
    for galaxy_id in galaxy_ids:
        transaction = connection.begin()
        galaxy = connection.execute(
            select([GALAXY]).where(GALAXY.c.galaxy_id == galaxy_id)).first()
        if galaxy is None:
            LOG.info('Error: Galaxy with galaxy_id of %d was not found',
                     galaxy_id)
        else:
            LOG.info('Deleting Galaxy with galaxy_id of %d - %s', galaxy_id,
                     galaxy[GALAXY.c.name])
            area_count = connection.execute(
                select([func.count(AREA.c.area_id)]).where(
                    AREA.c.galaxy_id == galaxy[GALAXY.c.galaxy_id])).first()[0]
            counter = 1

            for area_id1 in connection.execute(
                    select([AREA.c.area_id]).where(AREA.c.galaxy_id == galaxy[
                        GALAXY.c.galaxy_id]).order_by(AREA.c.area_id)):
                LOG.info("Deleting galaxy {0} area {1}. {2} of {3}".format(
                    galaxy_id, area_id1[0], counter, area_count))
                connection.execute(PIXEL_RESULT.delete().where(
                    PIXEL_RESULT.c.area_id == area_id1[0]))

                # Give the rest of the world a chance to access the database
                time.sleep(0.1)
                counter += 1

                if shutdown() is True:
                    transaction.rollback()
                    raise SystemExit

            LOG.info("Deleting FITS headers for galaxy {0}".format(galaxy_id))
            connection.execute(FITS_HEADER.delete().where(
                FITS_HEADER.c.galaxy_id == galaxy[GALAXY.c.galaxy_id]))

            # Now empty the bucket of the sed files
            s3helper = S3Helper()
            bucket = s3helper.get_bucket(get_sed_files_bucket())
            galaxy_file_name = get_galaxy_file_name(galaxy[GALAXY.c.name],
                                                    galaxy[GALAXY.c.run_id],
                                                    galaxy[GALAXY.c.galaxy_id])
            for key in bucket.list(prefix='{0}/'.format(galaxy_file_name)):
                # Ignore the key
                if key.key.endswith('/'):
                    continue

                bucket.delete_key(key)

                if shutdown() is True:
                    transaction.rollback()
                    raise SystemExit

            # Now the folder
            key = Key(bucket)
            key.key = '{0}/'.format(galaxy_file_name)
            bucket.delete_key(key)

        LOG.info('Galaxy with galaxy_id of %d was deleted', galaxy_id)
        connection.execute(
            GALAXY.update().where(GALAXY.c.galaxy_id == galaxy_id).values(
                status_id=DELETED, status_time=datetime.datetime.now()))

        if shutdown() is True:
            transaction.rollback()
            raise SystemExit

        transaction.commit()
예제 #7
0
def remove_database_entries(connection, galaxy_id):
    connection.execute(PIXEL_RESULT.delete().where(PIXEL_RESULT.c.galaxy_id == galaxy_id))
    connection.execute(IMAGE_FILTERS_USED.delete().where(IMAGE_FILTERS_USED.c.galaxy_id == galaxy_id))
    connection.execute(AREA.delete().where(AREA.c.galaxy_id == galaxy_id))
    connection.execute(FITS_HEADER.delete().where(FITS_HEADER.c.galaxy_id == galaxy_id))
    connection.execute(GALAXY.delete().where(GALAXY.c.galaxy_id == galaxy_id))