Skip to content

Commit

Permalink
Packaging improvements; update to config system; docs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mperrin committed Sep 4, 2014
1 parent e60e490 commit c0a117f
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 180 deletions.
331 changes: 331 additions & 0 deletions WebbPSF_tutorial.ipynb

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions cextern/README.rst

This file was deleted.

19 changes: 0 additions & 19 deletions dev_utils/README-DEVEL.txt

This file was deleted.

13 changes: 0 additions & 13 deletions dev_utils/README_RELEASE.txt

This file was deleted.

2 changes: 1 addition & 1 deletion dev_utils/make-data-sdist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cat filters.txt | grep -v FND > webbpsf-data/filters.txt
\rm -r webbpsf-data/MIRI/filters
ln -s tophat_filters webbpsf-data/MIRI/filters
# create public distributable tar file
$TAR -cvz -L --exclude .svn --exclude OPD_RevT --exclude TFI --exclude .DS_Store --exclude sources --exclude "*FND*" --exclude "*_filters" -f webbpsf/dist/webbpsf-data-public-$VER.tar.gz webbpsf-data
$TAR -cvz -L --exclude .svn --exclude OPD_RevT --exclude TFI --exclude .DS_Store --exclude sources --exclude "*FND*" --exclude "*_filters" --exclude "*py" --exclude "_Obsolete" -f webbpsf/dist/webbpsf-data-public-$VER.tar.gz webbpsf-data


# Make a copy with more real data, for internal or CoroWG use
Expand Down
7 changes: 0 additions & 7 deletions scripts/script_example

This file was deleted.

58 changes: 17 additions & 41 deletions webbpsf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,20 @@ class Conf(_config.ConfigNamespace):
logging_filename = _config.ConfigItem("none", "Desired filename to save log messages to.")
last_version_ran = _config.ConfigItem('0.0', 'Most recently used version of WebbPSF on this computer. This is used for detecting new or upgraded installations and providing some additional information to users.')

conf = Conf()

def _save_config():
""" Save package configuration variables using the Astropy.config system
NOTE: The functionality for saving config was was deprecated as of astropy v0.4
See http://astropy.readthedocs.org/en/latest/config/config_0_4_transition.html
#def _apply_settings_to_poppy():
# """Use webbpsf's settings to override any of the
# same settings in poppy. This is admittedly perhaps overbuilt to have identical
# settings in both packages, but the intent is to shield typical users of webbpsf
# from having to think about the existence of the underlying library. They can
# just deal with one set of settings.
# """
#
# import poppy
#
# poppy.conf.use_multiprocessing = conf.use_multiprocessing
# poppy.conf.n_processes = conf.n_processes
# poppy.conf.use_fftw = conf.use_fftw
# poppy.conf.default_image_display_fov = conf.default_fov_arcsec

conf = Conf()
This code is an undocumented workaround as advised by mdboom for the specific
purpose of saving webbpsf GUI state, logging state, and related.
"""

from astropy.config import configuration
configuration._save_config("webbpsf")


from poppy import (display_PSF, display_PSF_difference, display_EE, display_profiles, radial_profile,
Expand All @@ -102,13 +97,14 @@ class Conf(_config.ConfigNamespace):
from .utils import setup_logging #, _system_diagnostic, _check_for_new_install, _restart_logging

if not _ASTROPY_SETUP_:
#try:
# utils.check_for_new_install() # display informative message if so.
#except:
# pass

utils.check_for_new_install() # display informative message if so.

# this should display a warning to the user if they don't have WEBBPSF_PATH
# defined in either the environment or in webbpsf.cfg
_data_path = utils.get_webbpsf_data_path()


utils.restart_logging() # restart logging based on saved settings.


Expand Down Expand Up @@ -158,24 +154,4 @@ def gui(preferred='wx'):



# this should display a warning to the user if they don't have WEBBPSF_PATH
# defined in either the environment or in webbpsf.cfg
data_path = utils.get_webbpsf_data_path()


#def test( verbose=False ) :
# import os, pytest
#
# # find the directory where the test package lives
# from . import tests
# dir = os.path.dirname( tests.__file__ )
#
# # assemble the py.test args
# args = [ dir ]
#
# # run py.test
# try :
# return pytest.main( args )
# except SystemExit as e :
# return e.code
#

56 changes: 0 additions & 56 deletions webbpsf/config.py

This file was deleted.

25 changes: 14 additions & 11 deletions webbpsf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import ConfigParser


#from astropy.config import ConfigurationItem, get_config_dir, save_config

from . import conf

Expand All @@ -29,7 +28,7 @@ def restart_logging(verbose=True):
lev = logging.__dict__[level] # obtain one of the DEBUG, INFO, WARN, or ERROR constants
if verbose: print "WebbPSF log messages of level {0} and above will be shown.".format(level)
else:
print "Invalid logging level: "+level
raise ValueError("Invalid logging level: "+level)
return

for name in lognames:
Expand All @@ -41,7 +40,7 @@ def restart_logging(verbose=True):

# set up file logging
filename = conf.logging_filename
if filename.strip().lower() != 'none':
if filename is None or filename.strip().lower() != 'none':
hdlr = logging.FileHandler(filename)

formatter = logging.Formatter('%(asctime)s %(name)-10s: %(levelname)-8s %(message)s')
Expand Down Expand Up @@ -105,11 +104,12 @@ def setup_logging(level='INFO', filename=None):

level = str(level).upper()


# The astropy config system will enforce the limited set of values for the logging_level parameter
# by raising a TypeError on this next line if we feed in an invalid string.
conf.logging_level = level


if filename is None: filename='none' # must be a string to write into the config system
if filename is None: filename='none' # must be a string to store into the config system
conf.logging_filename = filename

#conf.logging_level.save()
Expand Down Expand Up @@ -137,7 +137,7 @@ def get_webbpsf_data_path():
#(path == 'unknown') or (path == 'from_environment_variable'):
_log.critical("Fatal error: Unable to find required WebbPSF data files!")
print """
********* WARNING ****** WARNING ****** WARNING ****** WARNING *************
********* ERROR ****** ERROR ****** ERROR ****** ERROR *************
* *
* WebbPSF requires several data files to operate. *
* These files could not be located automatically at this *
Expand All @@ -152,6 +152,7 @@ def get_webbpsf_data_path():
* *
****************************************************************************
"""
raise IOError('Missing or invalid WEBBPSF_PATH to required data files')

return path

Expand All @@ -164,11 +165,12 @@ def check_for_new_install(force=False):

from .version import version as __version__
if conf.last_version_ran == '0.0' or force:
from astropy.config import save_config, get_config_dir

from . import _save_config
import astropy.config

conf.last_version_ran = __version__
from .config import save_config
save_config()
_save_config()
#conf.last_version_ran.save()
#save_config('webbpsf') # save default values to text file

Expand All @@ -191,16 +193,17 @@ def check_for_new_install(force=False):
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
{0}/webbpsf.{1}.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())
See the WebbPSF documentation for more detail. """.format(astropy.config.get_config_dir(), __version__)

# check for data dir?
path_from_env_var = os.getenv('WEBBPSF_PATH')

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)
Expand Down
27 changes: 2 additions & 25 deletions webbpsf/webbpsf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ def Instrument(name):
if name == 'tfi': return TFI()
if name == 'fgs': return FGS()
else: raise ValueError("Incorrect instrument name "+name)
Instrument.list = ['nircam', 'nirspec', 'tfi', 'miri'] # useful list for iteration
Instrument.list = ['nircam', 'nirspec', 'niriss', 'miri'] # useful list for iteration


def calc_or_load_PSF(filename, inst, clobber=False, **kwargs):
Expand Down Expand Up @@ -1893,27 +1893,4 @@ def pix2angle(self, xpix, ypix):
#########################3


if __name__ == "__main__":

logging.basicConfig(level=logging.INFO,format='%(name)-10s: %(levelname)-8s %(message)s')

#
# nc = NIRCam()
# nc.filter = 'F460M'
# nc.image_mask = 'MASK430R'
# nc.pupil_mask = 'CIRCLYOT'
# #nc.calcPSF('test_nircam.fits', mono=False)
#
miri=MIRI()
miri.image_mask = 'LYOT2300'
miri.pupil_mask = 'MASKLYOT'
miri.filter='F2300C'
plt.clf()
miri.display()
#
# #miri.display()
# nircam=NIRCam()
# tfi = TFI()
# tfi.image_mask = "CORON058"
# tfi.pupil_mask = 'MASKC66N'
# nirspec = NIRSpec()

0 comments on commit c0a117f

Please sign in to comment.