Ejemplo n.º 1
0
def get_data_dir():

    config = get_internal_configuration()
    data_dir = config.get("data_dir", None)
    if data_dir is None:
        config_fpath = os.path.join(
            get_config_dir(), "tardis_internal_config.yml"
        )
        logging.critical(
            "\n{line_stars}\n\nTARDIS will download different kinds of data (e.g. atomic) to its data directory {default_data_dir}\n\n"
            "TARDIS DATA DIRECTORY not specified in {config_file}:\n\n"
            "ASSUMING DEFAULT DATA DIRECTORY {default_data_dir}\n "
            "YOU CAN CHANGE THIS AT ANY TIME IN {config_file} \n\n"
            "{line_stars} \n\n".format(
                line_stars="*" * 80,
                config_file=config_fpath,
                default_data_dir=DEFAULT_DATA_DIR,
            )
        )
        if not os.path.exists(DEFAULT_DATA_DIR):
            os.makedirs(DEFAULT_DATA_DIR)
        config["data_dir"] = DEFAULT_DATA_DIR
        yaml.dump(config, open(config_fpath, "w"), default_flow_style=False)
        data_dir = DEFAULT_DATA_DIR

    if not os.path.exists(data_dir):
        raise IOError(
            "Data directory specified in {0} does not exist".format(data_dir)
        )

    return data_dir
Ejemplo n.º 2
0
def get_configuration():

    config_fpath  = os.path.join(get_config_dir(), 'wsynphot_config.yml')
    if not os.path.exists(config_fpath):
        logger.warning("Configuration File {0} does not exist - creating new one from default".format(config_fpath))
        shutil.copy(DEFAULT_CONFIG_PATH, config_fpath)
    return yaml.load(open(config_fpath))
Ejemplo n.º 3
0
def get_configuration():

    config_fpath  = os.path.join(get_config_dir(), 'wsynphot_config.yml')
    if not os.path.exists(config_fpath):
        logger.warning("Configuration File {0} does not exist - creating new one from default".format(config_fpath))
        shutil.copy(DEFAULT_CONFIG_PATH, config_fpath)
    return yaml.load(open(config_fpath),Loader=yaml.SafeLoader)
Ejemplo n.º 4
0
def get_configuration():

    config_fpath = os.path.join(get_config_dir(), 'tardisnuclear_config.yml')
    if not os.path.exists(config_fpath):
        logger.warning(f"Configuration File {config_fpath} does not exist - "
                       f"creating new one from default")
        shutil.copy(DEFAULT_CONFIG_PATH, config_fpath)
    return yaml.load(open(config_fpath), Loader=yaml.FullLoader)
Ejemplo n.º 5
0
def get_internal_configuration():

    config_fpath = os.path.join(get_config_dir(), "tardis_internal_config.yml")
    if not os.path.exists(config_fpath):
        logger.warning(
            f"Configuration File {config_fpath} does not exist - creating new one from default"
        )
        shutil.copy(DEFAULT_CONFIG_PATH, config_fpath)
    with open(config_fpath) as config_fh:
        return yaml.load(config_fh, Loader=yaml.CLoader)
Ejemplo n.º 6
0
def fftw_load_wisdom(filename=None):
    """ Read accumulated FFTW wisdom previously saved in previously saved in a file 

    By default this file will be in the user's astropy configuration directory.
    (Another location could be chosen - this is simple and works easily cross-platform.)
    
    Parameters
    ------------
    filename : string, optional
        Filename to use (instead of the default, poppy_fftw_wisdom.txt)
    """
 
    import os
    from astropy import config
    try:
        import pyfftw
    except:
        return # FFTW is not present, therefore this is a null op

    if filename is None:
        filename=os.path.join( config.get_config_dir(), "poppy_fftw_wisdom.txt")
 
    if not os.path.exists(filename): return # gracefully ignore the case of lacking wisdom yet.

    _log.debug("Trying to reload wisdom from file "+filename)
    try:
        lines = open(filename,'r').readlines()
        # the first four lines are comments and should be ignored.
        wisdom = [lines[i].replace(r'\n', '\n') for i in [4,5,6]]
        wisdom = tuple(wisdom)
    except:
        _log.debug("ERROR - wisdom tuple could not be loaded from file :"+filename)
        return False

    success = pyfftw.import_wisdom(wisdom)
    _log.debug("Reloaded double precision wisdom: "+str(success[0]))
    _log.debug("Reloaded single precision wisdom: "+str(success[1]))
    _log.debug("Reloaded longdouble precision wisdom: "+str(success[2]))
    
    return True
Ejemplo n.º 7
0
def fftw_load_wisdom(filename=None):
    """ Read accumulated FFTW wisdom previously saved in previously saved in a file 

    By default this file will be in the user's astropy configuration directory.
    (Another location could be chosen - this is simple and works easily cross-platform.)
    
    Parameters
    ------------
    filename : string, optional
        Filename to use (instead of the default, poppy_fftw_wisdom.txt)
    """
 
    import os
    from astropy import config
    try:
        import pyfftw
    except:
        return # FFTW is not present, therefore this is a null op

    if filename is None:
        filename=os.path.join( config.get_config_dir(), "poppy_fftw_wisdom.txt")
 
    if not os.path.exists(filename): return # gracefully ignore the case of lacking wisdom yet.

    _log.debug("Trying to reload wisdom from file "+filename)
    try:
        lines = open(filename,'r').readlines()
        # the first four lines are comments and should be ignored.
        wisdom = [lines[i].replace(r'\n', '\n') for i in [4,5,6]]
        wisdom = tuple(wisdom)
    except:
        _log.debug("ERROR - wisdom tuple could not be loaded from file :"+filename)
        return False

    success = pyfftw.import_wisdom(wisdom)
    _log.debug("Reloaded double precision wisdom: "+str(success[0]))
    _log.debug("Reloaded single precision wisdom: "+str(success[1]))
    _log.debug("Reloaded longdouble precision wisdom: "+str(success[2]))
    
    return True
Ejemplo n.º 8
0
    def setUp(self):
        """
        Setup tests
        SN_blank: A SNObject with no MW extinction
        """

        mydir = get_config_dir()
        print('===============================')
        print('===============================')
        print(mydir)
        print('===============================')
        print('===============================')
        # A range of wavelengths in Ang
        self.wave = np.arange(3000., 12000., 50.)
        # Equivalent wavelenths in nm
        self.wavenm = self.wave / 10.
        # Time to be used as Peak
        self.mjdobs = 571190

        # Check that we can set up a SED
        # with no extinction
        self.SN_blank = SNObject()
        self.SN_blank.setCoords(ra=30., dec=-60.)
        self.SN_blank.set(z=0.96, t0=571181, x1=2.66, c=0.353, x0=1.796e-6)
        self.SN_blank.set_MWebv(0.)

        self.SN_extincted = SNObject(ra=30., dec=-60.)
        self.SN_extincted.set(z=0.96,
                              t0=571181,
                              x1=2.66,
                              c=0.353,
                              x0=1.796112e-06)

        self.SNCosmoModel = self.SN_extincted.equivalentSNCosmoModel()
        self.rectify_photParams = PhotometricParameters()
        self.lsstBandPass = BandpassDict.loadTotalBandpassesFromFiles()
        self.SNCosmoBP = sncosmo.Bandpass(wave=self.lsstBandPass['r'].wavelen,
                                          trans=self.lsstBandPass['r'].sb,
                                          wave_unit=astropy.units.Unit('nm'),
                                          name='lsst_r')
Ejemplo n.º 9
0
    def setUp(self):
        """
        Setup tests
        SN_blank: A SNObject with no MW extinction
        """

        from astropy.config import get_config_dir

        mydir = get_config_dir()
        print '==============================='
        print '==============================='
        print (mydir)
        print '==============================='
        print '==============================='
        # A range of wavelengths in Ang
        self.wave = np.arange(3000., 12000., 50.)
        # Equivalent wavelenths in nm
        self.wavenm = self.wave / 10.
        # Time to be used as Peak
        self.mjdobs = 571190

        # Check that we can set up a SED
        # with no extinction
        self.SN_blank = SNObject()
        self.SN_blank.setCoords(ra=30., dec=-60.)
        self.SN_blank.set(z=0.96, t0=571181, x1=2.66, c=0.353, x0=1.796e-6)
        self.SN_blank.set_MWebv(0.)

        self.SN_extincted = SNObject(ra=30., dec=-60.)
        self.SN_extincted.set(z=0.96, t0=571181, x1=2.66, c=0.353,
                              x0=1.796112e-06)

        self.SNCosmoModel = self.SN_extincted.equivalentSNCosmoModel()

        self.lsstBandPass = BandpassDict.loadTotalBandpassesFromFiles()
        self.SNCosmoBP = sncosmo.Bandpass(wave=self.lsstBandPass['r'].wavelen,
                                          trans=self.lsstBandPass['r'].sb,
                                          wave_unit=astropy.units.Unit('nm'),
                                          name='lsst_r')
Ejemplo n.º 10
0
def get_data_dir():

    config = get_configuration()
    data_dir = config.get('data_dir', None)
    if data_dir is None:
        config_fpath = os.path.join(get_config_dir(), 'wsynphot_config.yml')
        logging.critical('\n{line_stars}\n\nWYSNPHOT will download filters to its data directory {default_data_dir}\n\n'
                         'WSYNPHOT DATA DIRECTORY not specified in {config_file}:\n\n'
                         'ASSUMING DEFAULT DATA DIRECTORY {default_data_dir}\n '
                         'YOU CAN CHANGE THIS AT ANY TIME IN {config_file} \n\n'
                         '{line_stars} \n\n'.format(line_stars='*'*80, config_file=config_fpath,
                                                     default_data_dir=DEFAULT_DATA_DIR))
        if not os.path.exists(DEFAULT_DATA_DIR):
            os.makedirs(DEFAULT_DATA_DIR)
        config['data_dir'] = DEFAULT_DATA_DIR
        yaml.dump(config, open(config_fpath, 'w'), default_flow_style=False)
        data_dir = DEFAULT_DATA_DIR

    if not os.path.exists(data_dir):
        raise IOError('Data directory specified in {0} does not exist'.format(data_dir))

    return data_dir
Ejemplo n.º 11
0
def get_data_dir():

    config = get_configuration()
    data_dir = config.get('data_dir', None)
    if data_dir is None:
        config_fpath = os.path.join(get_config_dir(), 'wsynphot_config.yml')
        logging.critical('\n{line_stars}\n\nWYSNPHOT will download filters to its data directory {default_data_dir}\n\n'
                         'WSYNPHOT DATA DIRECTORY not specified in {config_file}:\n\n'
                         'ASSUMING DEFAULT DATA DIRECTORY {default_data_dir}\n '
                         'YOU CAN CHANGE THIS AT ANY TIME IN {config_file} \n\n'
                         '{line_stars} \n\n'.format(line_stars='*'*80, config_file=config_fpath,
                                                     default_data_dir=DEFAULT_DATA_DIR))
        if not os.path.exist(DEFAULT_DATA_DIR):
            os.makedirs(DEFAULT_DATA_DIR)
        config['data_dir'] = DEFAULT_DATA_DIR
        yaml.dump(config, open(config_fpath, 'w'), default_flow_style=False)
        data_dir = DEFAULT_DATA_DIR

    if not os.path.exists(data_dir):
        raise IOError('Data directory specified in {0} does not exist'.format(data_dir))

    return data_dir
Ejemplo n.º 12
0
def get_data_dir():
    config = get_configuration()
    data_dir = config.get('data_dir', None)
    if data_dir is None:
        config_fpath = os.path.join(get_config_dir(),
                                    'tardisnuclear_config.yml')
        logging.critical(
            '\n{line_stars}\n\nTARDISNUCLEAR will download nuclear data to its data directory {default_data_dir}\n\n'
            'TARDISNUCLEAR DATA DIRECTORY not specified in {config_file}:\n\n'
            'ASSUMING DEFAULT DATA DIRECTORY {default_data_dir}\n '
            'YOU CAN CHANGE THIS AT ANY TIME IN {config_file} \n\n'
            '{line_stars} \n\n'.format(line_stars='*' * 80,
                                       config_file=config_fpath,
                                       default_data_dir=DEFAULT_DATA_DIR))
        if not os.path.exists(DEFAULT_DATA_DIR):
            os.makedirs(DEFAULT_DATA_DIR)
        config['data_dir'] = DEFAULT_DATA_DIR
        yaml.dump(config, open(config_fpath, 'w'), default_flow_style=False)
        data_dir = DEFAULT_DATA_DIR

    if not os.path.exists(data_dir):
        raise IOError(f'Data directory specified in {data_dir} does not exist')
    logger.info(f"Using TARDISNuclear Data directory {data_dir}")
    return data_dir
Ejemplo n.º 13
0
from wsynphot import __path__ as WSYNPHOT_PATH
import os, logging, shutil
import yaml
from datetime import datetime

from astropy.config import get_config_dir

WSYNPHOT_PATH = WSYNPHOT_PATH[0]
DEFAULT_CONFIG_PATH = os.path.join(WSYNPHOT_PATH, 'data',
                                   'default_wsynphot_config.yml')
DEFAULT_DATA_DIR = os.path.join(os.path.expanduser('~'), 'Downloads',
                                'wsynphot')
CONFIG_FPATH = os.path.join(get_config_dir(), 'wsynphot_config.yml')
logger = logging.getLogger(__name__)


def get_configuration():

    if not os.path.exists(CONFIG_FPATH):
        logger.warning(
            "Configuration File {0} does not exist - creating new one from default"
            .format(CONFIG_FPATH))
        shutil.copy(DEFAULT_CONFIG_PATH, CONFIG_FPATH)
    return yaml.load(open(CONFIG_FPATH), Loader=yaml.SafeLoader)


def get_data_dir():

    config = get_configuration()
    data_dir = config.get('data_dir', None)
    if data_dir is None:
Ejemplo n.º 14
0
from lsst.sims.catUtils.exampleCatalogDefinitions import (
    PhoSimCatalogSersic2D, PhoSimCatalogPoint, PhoSimCatalogZPoint,
    PhoSimCatalogSSM, PhoSimCatalogSN)
from lsst.sims.catUtils.utils import makePhoSimTestDB

# 2016 November 22
# For some reason, the Jenkins nodes used for continuous integration
# cannot properly load the astropy config directories used by sncosmo.
# To prevent this from crashing every build, we will test whether
# the directories can be accessed and, if they cannot, use unittest.skipIf()
# to skip all of the unit tests in this file.
from astropy.config import get_config_dir

_skip_sn_tests = False
try:
    get_config_dir()
except:
    _skip_sn_tests = True

ROOT = os.path.abspath(os.path.dirname(__file__))


def createTestSNDB():
    """
    Create a CatalogDBObject-like database that contains everything needed to create
    a supernova catalog.  Return the CatalogDBObject and an ObservationMetaData pointing
    to its center.

    Note: the OpsimMetaData for the returned ObservationMetaData will be inconsistent.
    It is just there so that PhoSim InstanceCatalog classes can write out a header.
    """
Ejemplo n.º 15
0
# Routines Being Tested
from lsst.sims.catUtils.supernovae import SNObject
from lsst.sims.catUtils.mixins import SNIaCatalog
from lsst.sims.catUtils.utils import SNIaLightCurveGenerator

# 2016 July 28
# For some reason, the Jenkins slaves used for continuous integration
# cannot properly load the astropy config directories used by sncosmo.
# To prevent this from crashing every build, we will test whether
# the directories can be accessed and, if they cannot, use unittest.skipIf()
# to skip all of the unit tests in this file.
from astropy.config import get_config_dir

_skip_sn_tests = False
try:
    get_config_dir()
except:
    _skip_sn_tests = True

ROOT = os.path.abspath(os.path.dirname(__file__))


def setup_module(module):
    lsst.utils.tests.init()


@unittest.skipIf(_skip_sn_tests, "cannot properly load astropy config dir")
class SNObject_tests(unittest.TestCase):

    @classmethod
    def tearDownClass(cls):
Ejemplo n.º 16
0
def _check_for_new_install(force=False):
    """ Check for a new installation, and if so
    print a hopefully helpful explanatory message.
    """

    from ._version import __version__
    if LAST_VERSION_RAN() == '0.0' or force:
        from astropy.config import save_config, get_config_dir

        LAST_VERSION_RAN.set(__version__)
        LAST_VERSION_RAN.save()
        save_config('webbpsf') # save default values to text file

        print """
  ***************************************************
  *           WebbPSF Initialization & Setup         *
  ****************************************************

    This appears to be the first time you have used WebbPSF. 
    
    Just so you know, there is a mailing list for users of
    webbpsf to keep you informed about any announcements of
    updates or enhancements to this software. If you would like
    to subscribe, please email 
        [email protected]
    with the message 
        subscribe webbpsf-users

    
    WebbPSF has some options that can be set using a 
    configuration file. An example configuration file with
    default values has been created in 
            {0}/webbpsf.cfg
    (unless such a config file was already present there)
    You can examine that file and change settings if desired.
    See the WebbPSF documentation for more detail. """.format(get_config_dir())

        # check for data dir?
        path_from_env_var = os.getenv('WEBBPSF_PATH') 
        WEBBPSF_PATH = ConfigurationItem('webbpsf_data_path','unknown','Directory path to data files required for WebbPSF calculations, such as OPDs and filter transmissions.', module='webbpsf.webbpsf_core')

        if path_from_env_var is not None:
            print """
    WebbPSF's required data files appear to be 
    installed at a path given by $WEBBPSF_PATH :
    {0} """.format(path_from_env_var)
        else:
            # the following will automatically print an error message if
            # the path is unknown in the config file.
            path_from_config = WEBBPSF_PATH()

            if path_from_config != 'unknown':
                print """
    WebbPSF's required data files appear to be 
    installed at a path given in the config file:
    {0} """.format(path_from_config)


        print """

    This message will not be displayed again.
    Press [Enter] to continue
    """
        any_key = raw_input()