Пример #1
0
def get_rootdir():
    # use the environment variable if set
    data_dir = os.environ.get('SNCOSMO_DATA_DIR')

    # otherwise, use config file value if set.
    if data_dir is None:
        data_dir = conf.data_dir

    # if still None, use astropy cache dir (and create if necessary!)
    if data_dir is None:
        data_dir = join(get_cache_dir(), "sncosmo")
        if not os.path.isdir(data_dir):
            if os.path.exists(data_dir):
                raise RuntimeError("{0} not a directory".format(data_dir))
            os.mkdir(data_dir)

    return data_dir
Пример #2
0
def get_rootdir():
    # use the environment variable if set
    data_dir = os.environ.get('SNCOSMO_DATA_DIR')

    # otherwise, use config file value if set.
    if data_dir is None:
        data_dir = conf.data_dir

    # if still None, use astropy cache dir (and create if necessary!)
    if data_dir is None:
        data_dir = join(get_cache_dir(), "sncosmo")
        if not os.path.isdir(data_dir):
            if os.path.exists(data_dir):
                raise RuntimeError("{0} not a directory".format(data_dir))
            os.mkdir(data_dir)

    return data_dir
Пример #3
0
def get_conf_paths():
    # Get configuration information from setup.cfg
    conf_path = os.path.join(os.path.dirname(__file__), 'conf.json')
    with open(conf_path, 'r') as confstream:
        confparse = json.load(confstream)
    data_root_cfg = confparse.get("data_root")
    ref_lib_cfg = confparse.get("ref_lib_data")

    if len(data_root_cfg) == 0 and len(ref_lib_cfg) == 0:
        cache_dir = os.path.join(astropyconfig.get_cache_dir(), '.pipe-cheops')
        DATA_ROOT = os.path.join(cache_dir, 'data_root')
        REF_LIB_PATH = os.path.join(cache_dir, 'ref_lib_data')
    else:
        DATA_ROOT = data_root_cfg
        REF_LIB_PATH = ref_lib_cfg

    return DATA_ROOT, REF_LIB_PATH
Пример #4
0
def get_image_index():
    cache = get_cache_dir()
    ast_data = os.path.dirname(_solve_field)
    ast_data = os.path.dirname(ast_data)
    ast_data = os.path.join(ast_data, 'data')
    os.makedirs(ast_data, exist_ok=True)
    index = 'index-4107.fits'  # index-4202-28.fits'
    d = 'http://broiler.astrometry.net/~dstn/4100/' + index
    f = os.path.join(ast_data, index)
    if not os.path.isfile(f):
        request.urlretrieve(d, f)  # nosec
    name = os.path.join(cache, 'm20_dss.fits')
    if not os.path.isfile(name):
        s = SkyView.get_images('M20',
                               radius=Angle('60arcmin'),
                               pixels=2048,
                               survey='DSS')
        s[0][0].writeto(name)
    return name, f
Пример #5
0
    def __init__(self, data_dir=None, database_url=None, remote_timeout=None):

        self.config_file = __config_file__

        with open(self.config_file) as f:
            self.meta = yaml.safe_load(f)
            self.data_dir = self.meta["data_dir"]
            self.database_url = self.meta["database_url"]
            self.remote_timeout = self.meta["remote_timeout"]
            self.default_data_dir = os.path.join(get_cache_dir(), self.meta["default_data_dir"])

        if data_dir is not None:
            self._set_param("data_dir", data_dir)

        if database_url is not None:
            self._set_param("database_url", database_url)

        if remote_timeout is not None:
            self._set_param("remote_timeout", remote_timeout)
Пример #6
0
def get_data_dir():
    """Return the full path to the data directory, ensuring that it exists.

    If the 'data_dir' configuration parameter is set, checks that it exists
    and returns it (doesn't automatically create it).

    Otherwise, uses `(astropy cache dir)/sncosmo` (automatically created if
    it doesn't exist)."""

    global CHECKED_DATA_DIR

    # use a global to avoid checking if the directory exists every time
    if CHECKED_DATA_DIR is not None:
        return CHECKED_DATA_DIR

    # use the environment variable if set
    data_dir = os.environ.get("SNCOSMO_DATA_DIR")

    # otherwise, use config file value if set.
    if data_dir is None:
        data_dir = conf.data_dir

    # if either of the above, check existance
    if data_dir is not None:
        if not os.path.isdir(data_dir):
            raise RuntimeError("data directory {0!r} not an existing directory".format(conf.data_dir))

    # if still None, use astropy cache dir and create if necessary
    if data_dir is None:
        data_dir = join(get_cache_dir(), "sncosmo")
        if not os.path.isdir(data_dir):
            if os.path.exists(data_dir):
                raise RuntimeError("{0} not a directory".format(data_dir))
            os.mkdir(data_dir)

    CHECKED_DATA_DIR = data_dir

    return data_dir
Пример #7
0
def get_data_dir():
    """Return the full path to the data directory, ensuring that it exists.

    If the 'data_dir' configuration parameter is set, checks that it exists
    and returns it (doesn't automatically create it).

    Otherwise, uses `(astropy cache dir)/sncosmo` (automatically created if
    it doesn't exist)."""
    if conf.data_dir is not None:
        if os.path.isdir(conf.data_dir):
            return conf.data_dir
        else:
            raise RuntimeError(
                "data directory {0!r} not an existing directory"
                .format(conf.data_dir))
    else:
        data_dir = join(get_cache_dir(), "sncosmo")
        if not os.path.isdir(data_dir):
            if os.path.exists(data_dir):
                raise RuntimeError("{0} not a directory".format(data_dir))
            else:
                os.mkdir(data_dir)
        return data_dir
Пример #8
0
def get_data_dir():
    """Return the full path to the data directory, ensuring that it exists.

    If the 'data_dir' configuration parameter is set, checks that it exists
    and returns it (doesn't automatically create it).

    Otherwise, uses `(astropy cache dir)/sncosmo` (automatically created if
    it doesn't exist)."""
    if conf.data_dir is not None:
        if os.path.isdir(conf.data_dir):
            return conf.data_dir
        else:
            raise RuntimeError(
                "data directory {0!r} not an existing directory".format(
                    conf.data_dir))
    else:
        data_dir = join(get_cache_dir(), "sncosmo")
        if not os.path.isdir(data_dir):
            if os.path.exists(data_dir):
                raise RuntimeError("{0} not a directory".format(data_dir))
            else:
                os.mkdir(data_dir)
        return data_dir
Пример #9
0
def cache_dir():
    return astropyconfig.get_cache_dir()
Пример #10
0
import argparse
import astropy.config as astropy_config
from configparser import ConfigParser
from datetime import datetime
from dateutil import parser
import glob
import numpy as np
import os
import shutil
import sys
import traceback

# Wrapper script for the photometry, post-processing, and detrending scripts.

# Clear the astroquery cache to ensure up-to-date values are grabbed from SIMBAD
if os.path.exists(astropy_config.get_cache_dir()+'/astroquery/'):
    # First delete the astropy cache for astroquery; otherwise the data might be out of date!
    shutil.rmtree(astropy_config.get_cache_dir()+'/astroquery/')
    
# Then import astropy, astroquery, and other modules in this code
from astropy import units as u
from astropy.time import Time
from astroquery import simbad

from constants import log
from get_photometry_eden import get_photometry
import PhotUtils
from transit_photometry import post_processing
from eden_GPDetrend import eden_GPDetrend