def main(args):
    if args.verbose:
        logger.setLevel('DEBUG')
    logger.debug(args)

    schema = database_schema()

    tables = {}
    for table_name in schema:
        query = raw_create_table(table_name, schema)
        tables[table_name] = query

    with connect_to_database_from_args(args) as cursor:
        for table_name, query in tables.items():
            cursor.execute('drop table if exists {table_name}'.format(
                table_name=table_name))
            logger.debug('Executing query `%s`', query)
            cursor.execute(query)
Example #2
0
from __future__ import division, print_function, absolute_import
from astropy.io import fits
from collections import namedtuple
import tempfile
import subprocess as sp
import numpy as np
from scipy.spatial import KDTree

from ngts_transmission.logs import logger
from ngts_transmission.utils import open_fits
from ngts_transmission.db import database_schema, connect_to_database

schema = database_schema()['transmission_sources']

TransmissionCatalogueEntry = namedtuple('TransmissionCatalogueEntry',
                                        [key for key in schema if key != 'id'])


def image_has_prescan(fname):
    return fits.getdata(fname).shape == (2048, 2088)


def source_detect(fname, n_pixels, threshold, fwhmfilt, aperture_radius):
    logger.info('Running source detect')
    logger.debug('n_pixels: %s, threshold: %s', n_pixels, threshold)
    with tempfile.NamedTemporaryFile(suffix='.fits') as tfile:
        cmd = ['imcore', fname, 'noconf', tfile.name, n_pixels, threshold,
               '--noell', '--filtfwhm', fwhmfilt, '--rcore', aperture_radius]
        str_cmd = list(map(str, cmd))
        logger.debug('Running command [%s]', ' '.join(str_cmd))
        sp.check_call(str_cmd)
from collections import namedtuple
import photutils as ph
from astropy.io import fits
import numpy as np

from ngts_transmission.logs import logger
from ngts_transmission.utils import open_fits
from ngts_transmission.db import database_schema

schema = database_schema()['transmission_log']
TransmissionEntryBase = namedtuple('TransmissionEntryBase', schema.keys())


def mad(data, median=None):
    median = median if median is not None else np.median(data)
    return np.median(np.abs(data - median))


def std_from_mad(mad):
    '''
    Source: https://en.wikipedia.org/wiki/Median_absolute_deviation#Relation_to_standard_deviation
    '''
    return 1.4826 * mad


def standard_error(flux):
    # Only 1d arrays allowed
    assert len(flux.shape) == 1
    return std_from_mad(mad(flux)) / np.sqrt(flux.size)