Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc updates #96

Merged
merged 11 commits into from
Jul 30, 2018
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ env:
matrix:
# Make sure that egg_info works without dependencies
- PYTHON_VERSION=2.7 SETUP_CMD='egg_info'
- PYTHON_VERSION=3.4 SETUP_CMD='egg_info'
- PYTHON_VERSION=3.5 SETUP_CMD='egg_info'
- PYTHON_VERSION=3.6 SETUP_CMD='egg_info'

Expand Down Expand Up @@ -86,17 +85,15 @@ matrix:
- os: linux
env: ASTROPY_VERSION=lts

# Try all python versions and Numpy versions. Since we can assume that
# Try various python and numpy combinations. Since we can assume that
# the Numpy developers have taken care of testing Numpy with different
# versions of Python, we can vary Python and Numpy versions at the same
# time.

- os: linux
env: PYTHON_VERSION=3.5 NUMPY_VERSION=1.10
env: PYTHON_VERSION=3.5 NUMPY_VERSION=1.13
- os: linux
env: PYTHON_VERSION=3.5 NUMPY_VERSION=1.11
- os: linux
env: NUMPY_VERSION=1.12
env: PYTHON_VERSION=3.5 NUMPY_VERSION=1.14

# Try numpy pre-release
- os: linux
Expand Down
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ specsim Change Log
0.13 (unreleased)
-----------------

- No changes yet.
- Changes to SimulationExamples notebook:
- Change median LRG minor/major axis ratio from 0.16 to 0.5.
- Add quantitative comparison of galsim and fastsim fiberloss modes.
- Streamline array indexing for downsampling and convolution operations.
- Do not require fastsim file to be present (fixes #90).
- Update to astropy_helpers v2.0.6 (merges #85).
- Remove python 3.4 from travis test matrix and update "old" numpy versions used (fixes #93).

0.12 (2018-07-26)
-----------------
Expand Down
2 changes: 1 addition & 1 deletion astropy_helpers
Submodule astropy_helpers updated 35 files
+12 −17 .travis.yml
+0 −66 CHANGES.rst
+2 −2 README.rst
+13 −55 ah_bootstrap.py
+4 −1 appveyor.yml
+1 −4 astropy_helpers/commands/build_sphinx.py
+0 −51 astropy_helpers/conftest.py
+1 −1 astropy_helpers/extern/automodapi/__init__.py
+9 −21 astropy_helpers/extern/automodapi/automodsumm.py
+0 −2 astropy_helpers/extern/numpydoc/__init__.py
+20 −38 astropy_helpers/extern/numpydoc/docscrape.py
+24 −49 astropy_helpers/extern/numpydoc/docscrape_sphinx.py
+83 −0 astropy_helpers/extern/numpydoc/linkcode.py
+29 −95 astropy_helpers/extern/numpydoc/numpydoc.py
+0 −16 astropy_helpers/extern/numpydoc/templates/numpydoc_docstring.rst
+1 −1 astropy_helpers/extern/setup_package.py
+4 −9 astropy_helpers/git_helpers.py
+0 −107 astropy_helpers/openmp_helpers.py
+2 −32 astropy_helpers/setup_helpers.py
+11 −2 astropy_helpers/sphinx/conf.py
+0 −4 astropy_helpers/sphinx/ext/changelog_links.py
+0 −18 astropy_helpers/sphinx/ext/doctest.py
+0 −4 astropy_helpers/sphinx/ext/edit_on_github.py
+0 −4 astropy_helpers/sphinx/ext/tocdepthfix.py
+32 −41 astropy_helpers/tests/__init__.py
+0 −1 astropy_helpers/tests/coveragerc
+83 −106 astropy_helpers/tests/test_ah_bootstrap.py
+3 −26 astropy_helpers/tests/test_git_helpers.py
+0 −38 astropy_helpers/tests/test_openmp_helpers.py
+39 −110 astropy_helpers/tests/test_setup_helpers.py
+3 −3 astropy_helpers/utils.py
+2 −6 astropy_helpers/version_helpers.py
+0 −28 licenses/LICENSE_ASTROSCRAPPY.rst
+3 −5 setup.py
+19 −0 tox.ini
15 changes: 13 additions & 2 deletions docs/fiberloss.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ methods selected by the value of ``instrument.fiberloss.method``:
atmospheric models. This mode is the most flexible and slowest, and uses
all of the relevant configuration parameters.
* The ``fastsim`` method is based on an interpolation of fiber acceptance values
pre-computed with ``galsim`` using the script ``fitgalsim``.
The interpolation parameters/axis are source profile (point source, exponential disk, De Vaucouleurs bulge), sigma (atmosphere+telescope blur, in um on focal surface), fiber offset from source (in um on focal surface), and half light radius (in arcsec) from extended source. This interpolation is performed with the class ``fastfiberacceptance.FastFiberAcceptance``. The accuracy is about 1 percent, which is sufficient for simulations.
pre-computed with ``galsim`` using the script ``fitgalsim``, which assumes
a fixed axis ratio of 0.7 (for extended objects), a fixed Moffat PSF
model with beta=3.5 (but variable FWHM) for the atmosphere, and a fixed
fiber diameter of 107um.
The interpolation parameters/axis are source profile (point source,
exponential disk, De Vaucouleurs bulge), sigma (atmosphere+telescope blur,
in um on focal surface), fiber offset from source (in um on focal surface),
and half light radius (in arcsec) from extended source. This interpolation
is performed with the class ``fastfiberacceptance.FastFiberAcceptance``.
The accuracy is about 1 percent when the assumptions above are valid.

Refer to the comments in the sample configuration files for more information
about the available parameters.
Expand All @@ -58,6 +66,9 @@ GalSim Dependency
-----------------

The GalSim package is only required when the ``galsim`` method is selected.
As of GalSim version 2.0, this package can be easily install using either
conda or pip.

Fiberloss arrays calculated with GalSim can be saved for later table-based
simulations. For example, first run the :ref:`quickspecsim` script to
use GalSim to calculate and save the fiberloss for a specific configuration
Expand Down
279 changes: 217 additions & 62 deletions docs/nb/SimulationExamples.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions specsim/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ def downsample(self, data, method=np.sum):
if not self.allow_convolution:
raise RuntimeError('Camera created with allow_convolution False.')
data = np.asanyarray(data)
if data.shape[-1] != len(self._wavelength):
if data.shape[0] != len(self._wavelength):
raise ValueError(
'Invalid data shape for downsampling: {0}.'.format(data.shape))

output = data[..., self._output_slice]
new_shape = output.shape[:-1] + self._downsampled_shape
return method(output.reshape(new_shape), axis=-1)
output = data[self._output_slice]
new_shape = self._downsampled_shape + output.shape[1:]
return method(output.reshape(new_shape), axis=1)

def apply_resolution(self, flux):
"""
Expand All @@ -357,8 +357,8 @@ def apply_resolution(self, flux):
flux = np.asarray(flux)
dispersed = np.zeros_like(flux)

dispersed[..., self.ccd_slice] = self._resolution_matrix.dot(
flux[..., self.response_slice].T).T
dispersed[self.ccd_slice] = self._resolution_matrix.dot(
flux[self.response_slice])

return dispersed

Expand Down
9 changes: 6 additions & 3 deletions specsim/data/config/desi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ instrument:
columns:
wavelength: { index: 0, unit: Angstrom }
fiber_acceptance: { index: 1 }
# Fits file of precomputed galsim fiber acceptance
# the fits file is created with specsim/fitgalsim.py
# the fits file is read with specsim/fastfiberacceptance.py
# Fits file of precomputed galsim fiber acceptances.
# Ignored unless method is fastsim.
# The fits file is created with specsim/fitgalsim.py
# and used by specsim/fastfiberacceptance.py
# Comment out this line to disable the "fastsim" mode (e.g., if
# this file is not available or describes a different config).
fast_fiber_acceptance_path: throughput/galsim-fiber-acceptance.fits
blur:
# Read RMS blur values tabulated as a function of field angle and
Expand Down
11 changes: 10 additions & 1 deletion specsim/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Instrument(object):
Dictionary of fiber acceptance fractions tabulated for different
source models, with keys corresponding to source model names.
Ignored when fiberloss_method is "galsim".
fast_fiber_acceptance : specsim.fastfiberacceptance.FastFiberAcceptance or None
Initialized instance to use when fiberloss_method is "fastsim".
Ignored for other values of fiberloss_method.
fiberloss_num_wlen : int
Number of wavelengths where the fiberloss fraction should be tabulated
for interpolation. Ignored when fiberloss_method is not "galsim".
Expand Down Expand Up @@ -103,6 +106,8 @@ def __init__(self, name, wavelength, fiberloss_method,
self._wavelength = wavelength
self.fiber_acceptance_dict = fiber_acceptance_dict
self.fast_fiber_acceptance = fast_fiber_acceptance
# Both fiber_acceptance_dict and fast_fiber_acceptance must be initialized
# before assigning to fiberloss_method (since its setter checks their values).
self.fiberloss_method = fiberloss_method
self.fiberloss_num_wlen = fiberloss_num_wlen
self.fiberloss_num_pixels = fiberloss_num_pixels
Expand Down Expand Up @@ -186,9 +191,13 @@ def fiberloss_method(self, fiberloss_method):
Must be one of "table" or "galsim" or "fastsim".
"""
if fiberloss_method not in ('table', 'galsim', 'fastsim' ):
raise ValueError('fiberloss_method must be "table" or "galsim" or "fastsim".')
raise ValueError(
'fiberloss_method must be "table" or "galsim" or "fastsim".')
if fiberloss_method == 'table' and self.fiber_acceptance_dict is None:
raise ValueError('Missing required instrument.fiberloss.table.')
if fiberloss_method == 'fastsim' and self.fast_fiber_acceptance is None:
raise ValueError(
'Missing required instrument.fiberloss.fast_fiber_acceptance_path.')
if fiberloss_method == 'galsim':
try:
import galsim
Expand Down
2 changes: 1 addition & 1 deletion specsim/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def initialize(config):
print('Adjusted by {0:+.3f} for HA {1}.'
.format(dt.to(u.hour), hour_angle))
cond = obs.observing_model
print('Conditions: pressure {0:.1f}, temperature {1:.1f}, RH {2:.3f}.'
print('Conditions: pressure {0:.1f}, temperature {1:.1f}, RH {2}.'
.format(cond.pressure, cond.temperature, cond.relative_humidity))
altaz = obs.boresight_altaz
print('Boresight (alt, az) = ({0:.1f}, {1:.1f}).'
Expand Down
14 changes: 7 additions & 7 deletions specsim/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,19 @@ def simulate(self, sky_positions=None, focal_positions=None,
# Apply resolution to the source and sky detected electrons on
# the high-resolution grid.
num_source_electrons[:] = camera.apply_resolution(
num_source_electrons.T).T
num_source_electrons)
num_sky_electrons[:] = camera.apply_resolution(
num_sky_electrons.T).T
num_sky_electrons)

# Calculate the corresponding downsampled output quantities.
output['num_source_electrons'][:] = (
camera.downsample(num_source_electrons.T)).T
camera.downsample(num_source_electrons))
output['num_sky_electrons'][:] = (
camera.downsample(num_sky_electrons.T)).T
camera.downsample(num_sky_electrons))
output['num_dark_electrons'][:] = (
camera.downsample(num_dark_electrons.T)).T
camera.downsample(num_dark_electrons))
output['read_noise_electrons'][:] = np.sqrt(
camera.downsample(read_noise_electrons.T ** 2)).T
camera.downsample(read_noise_electrons ** 2))
output['variance_electrons'][:] = (
output['num_source_electrons'] +
output['num_sky_electrons'] +
Expand All @@ -548,7 +548,7 @@ def simulate(self, sky_positions=None, focal_positions=None,
# source flux above the atmosphere, downsampled to output pixels.
output['flux_calibration'][:] = 1.0 / camera.downsample(
camera.apply_resolution(
source_flux_to_photons.T * camera.throughput)).T
source_flux_to_photons * camera.throughput.reshape(-1, 1)))

# Calculate the calibrated flux in this camera.
output['observed_flux'][:] = (
Expand Down