Skip to content

Commit

Permalink
Merge 3a31029 into 5901d17
Browse files Browse the repository at this point in the history
  • Loading branch information
Pica4x6 committed Oct 9, 2015
2 parents 5901d17 + 3a31029 commit c94d403
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 368 deletions.
88 changes: 33 additions & 55 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,47 @@
language:
# - objective-c # Used for OSX tests
- python # Used for linux tests
# - c

os:
- linux
# - osx

env:
- python=2.7
- python=3.4

#matrix:
#
# # Don't wait for allowed failures
# fast_finish: true
#
# include:
#
# # Try MacOS X
# - os: osx
# env: PYTHON_VERSION=2.7 SETUP_CMD='test' OPTIONAL_DEPS=true
#
# - os: linux
# env: PYTHON_VERSION=2.7 SETUP_CMD='test --open-files'
# - os: linux
# env: PYTHON_VERSION=3.4 SETUP_CMD='test --open-files'


language: python
sudo: false

matrix:
include:
- python: "2.7"
env: DEPS="numpy=1.9 scipy=0.15 astropy=1.0" COVERAGE=true
- python: "3.4"
env: DEPS="numpy=1.9 scipy=0.15 astropy=1.0"

cache:
apt: true
pip: true
directories:
- $HOME/.cache/pip
- $HOME/.local

before_install:
- echo $TRAVIS_OS_NAME
- echo ${TRAVIS_PYTHON_VERSION:0:1}
- echo $TRAVIS_PYTHON_VERSION
- echo $python
# - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update; fi
# - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install libsdl1.2-dev; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then if [ $python == "2.7" ]; then wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; else wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; fi ; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then chmod +x miniconda.sh; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then ./miniconda.sh -b -p /home/travis/mc; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then export PATH=/home/travis/mc/bin:$PATH; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then if [ $python == "2.7" ]; then wget http://repo.continuum.io/miniconda/Miniconda-latest-MacOSX-x86_64.sh -O miniconda.sh; else wget http://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh; fi ; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then chmod +x miniconda.sh; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then ./miniconda.sh -b; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then if [ $python == "2.7" ]; then export PATH=/Users/travis/miniconda/bin:$PATH; else export PATH=/Users/travis/miniconda3/bin:$PATH; fi ; fi
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then wget http://repo.continuum.io/miniconda/Miniconda-3.5.5-Linux-x86_64.sh -O miniconda.sh; else wget http://repo.continuum.io/miniconda/Miniconda3-3.5.5-Linux-x86_64.sh -O miniconda.sh; fi
- chmod +x miniconda.sh
- ./miniconda.sh -b -p /home/travis/mc
- export PATH=/home/travis/mc/bin:$PATH


install:
# See:
# https://groups.google.com/a/continuum.io/forum/#!topic/conda/RSFENqovnro
# - conda update --yes --no-deps conda
# OK, this used to *fix* the build, but now it *breaks* the build.
# If you're reading this, good luck out there. I'm not sure what to tell you.
- conda update --yes conda
- conda list
- conda install --yes numpy
- conda create -n testenv --yes --file requirements.txt
- conda list
- source activate testenv
- pip install pytest-benchmark pytest-cov
- pip install setuptools
- pip install -e git+git://github.com/guaix-ucm/numina.git#egg=numina
- echo $PATH
- which python
- conda info
- conda list
- python setup.py install
- if [[ $COVERAGE == true ]]; then pip install coveralls; fi
# Build in place so we can run tests
- python setup.py build_ext --inplace
- pwd


script:
- py.test -s -v megaradrp
- py.test -s -v megaradrp
- if [[ $COVERAGE == true ]]; then py.test megaradrp --cov=megaradrp; fi

after_success:
- if [[ $COVERAGE == true ]]; then coveralls; fi
7 changes: 1 addition & 6 deletions megaradrp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
from astropy.io import fits
import numpy as np

from numina.core import BaseRecipeAutoQC as MegaraBaseRecipe # @UnusedImport
from megaradrp.products import TraceMap
from megaradrp.trace.peakdetection import peakdet
from numina.core import BaseRecipeAutoQC as MegaraBaseRecipe
from numina.array.trace.extract import extract_simple_rss
from numina.array.utils import wc_to_pix_1d as wcs_to_pix_1d

Expand Down Expand Up @@ -153,7 +151,6 @@ def trim_and_o_array(array, direction='normal', bins='11'):
nc2 = H_X_DIM * 2 / bng[1]

nr = H_Y_DIM / bng[0]
nc = H_X_DIM / bng[1]

oscan2 = OSCANW / bng[0]
psc1 = PSCANW / bng[0]
Expand Down Expand Up @@ -228,8 +225,6 @@ def apextract_tracemap(data, tracemap):
pix_12 = 2 * pix_1 - pix_01
borders.append((pix_01, pix_12))

rss = np.empty((len(pols), data.shape[1]))

rss = extract_simple_rss(data, borders)


Expand Down
59 changes: 19 additions & 40 deletions megaradrp/recipes/calibration/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import numpy
from astropy.io import fits

from numina.core import Product
from numina.core import Requirement, Product, Parameter
from numina.core import DataFrameType
from numina.core.products import ArrayType
Expand All @@ -40,15 +39,16 @@
from numina.core.products import LinesCatalog
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt
from numina.array.wavecal.arccalibration import arccalibration_direct, fit_solution, gen_triplets_master
from numina.array.wavecal.arccalibration import arccalibration_direct
from numina.array.wavecal.arccalibration import fit_solution
from numina.array.wavecal.arccalibration import gen_triplets_master
from numina.array.wavecal.statsummary import sigmaG
from numina.array.wavecal.findpeaks1D import findPeaks_spectrum, refinePeaks_spectrum
from numina.array.peaks.findpeaks1D import findPeaks_spectrum
from numina.array.peaks.findpeaks1D import refinePeaks_spectrum

from megaradrp.core import MegaraBaseRecipe
from megaradrp.processing import OverscanCorrector, TrimImage
# from numina.logger import log_to_history

from megaradrp.products import MasterFiberFlat
from megaradrp.products import TraceMap
from megaradrp.requirements import MasterBiasRequirement

Expand All @@ -65,7 +65,7 @@ class ArcCalibrationRecipe(MegaraBaseRecipe):
master_bias = MasterBiasRequirement()
tracemap = Requirement(TraceMap, 'Trace information of the Apertures')
lines_catalog = Requirement(LinesCatalog, 'Catalog of lines')
polynomial_degree = Parameter(2, 'Polynomial degree of the arc calibration')
polynomial_degree = Parameter(2, 'Polynomial degree of arc calibration')
# Products
arc_image = Product(DataFrameType)
arc_rss = Product(DataFrameType)
Expand All @@ -86,7 +86,8 @@ def run(self, rinput):
rss = fits.HDUList([rsshdu])

# Skip any other inputs for the moment
coeff_table = self.calibrate_wl(rssdata, rinput.lines_catalog, rinput.polynomial_degree)
coeff_table = self.calibrate_wl(rssdata, rinput.lines_catalog,
rinput.polynomial_degree)

# WL calibration goes here
return self.create_result(arc_image=reduced, arc_rss=rss,
Expand All @@ -98,7 +99,7 @@ def calibrate_wl(self, rss, lines_catalog, poldeg, times_sigma=50.0):
# all the slits) for the wavelength calibration
wv_master = lines_catalog[:,0]
ntriplets_master, ratios_master_sorted, triplets_master_sorted_list = \
gen_triplets_master(wv_master, LDEBUG=True)
gen_triplets_master(wv_master)
# FIXME: this depends on the spectral and dispersion axes
nspec = rss.shape[0]
coeff_table = numpy.zeros((nspec, poldeg + 1))
Expand All @@ -109,12 +110,11 @@ def calibrate_wl(self, rss, lines_catalog, poldeg, times_sigma=50.0):
# find peaks (initial search providing integer numbers)
threshold = numpy.median(row)+times_sigma*sigmaG(row)
ipeaks_int = findPeaks_spectrum(row, nwinwidth=nwinwidth,
data_threshold=threshold,
LDEBUG=False, LPLOT=False)
data_threshold=threshold)
# refine peaks fitting an appropriate function (providing float
# numbers)
ipeaks_float = refinePeaks_spectrum(row, ipeaks_int, nwinwidth,
method=2, LDEBUG=False)
method=2)


# define interpolation function and interpolate the refined peak
Expand All @@ -132,24 +132,7 @@ def calibrate_wl(self, rss, lines_catalog, poldeg, times_sigma=50.0):
finterp_channel = interp1d(range(xchannel.size), xchannel,
kind='linear')
xpeaks_refined = finterp_channel(ipeaks_float)

if False: # TBR (to be removed in the future)
# plot extracted spectrum
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('row %d' % idx)
ax.set_xlim([1,naxis1])
ax.plot(xchannel,row,'k-')
ax.plot(xchannel[ipeaks_int], row[ipeaks_int], 'ro')
ax.plot([1,naxis1],[threshold, threshold], linestyle='dashed')
ylim = ax.get_ylim()
for xdum in zip(xpeaks_refined,xpeaks_refined):
ax.plot(xdum, ylim, linestyle='dotted', color='magenta')
plt.show()
#plt.show(block=False)
#input('press <RETURN> to continue...')

# wavelength calibration

try:
solution = arccalibration_direct(wv_master,
ntriplets_master,
Expand All @@ -162,25 +145,21 @@ def calibrate_wl(self, rss, lines_catalog, poldeg, times_sigma=50.0):
error_xpos_arc=2.0,
times_sigma_r=3.0,
frac_triplets_for_sum=0.50,
times_sigma_TheilSen=10.0,
poly_degree=2,
times_sigma_theil_sen=10.0,
poly_degree_wfit=2,
times_sigma_polfilt=10.0,
times_sigma_inclusion=5.0,
LDEBUG=False,
LPLOT=False)
times_sigma_inclusion=5.0)
_logger.info('Solution for row %d completed', idx)
_logger.info('Fitting solution for row %d', idx)
numpy_array_with_coeff, crval1_approx, cdelt1_approx = \
fit_solution(wv_master,
xpeaks_refined,
solution,
naxis1,
poly_degree=2,
weighted=False,
LDEBUG=False,
LPLOT=False)
poly_degree_wfit=2,
weighted=False)

_logger.info('approximate crval1, cdelt1: %f %f',crval1_approx,cdelt1_approx)
_logger.info('approximate crval1, cdelt1: %f %f',
crval1_approx,cdelt1_approx)
_logger.info('fitted coefficients %s',numpy_array_with_coeff)
coeff_table[idx] = numpy_array_with_coeff
except TypeError as error:
Expand Down
1 change: 0 additions & 1 deletion megaradrp/recipes/calibration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from megaradrp.core import MegaraBaseRecipe
from megaradrp.processing import OverscanCorrector, TrimImage
from megaradrp.processing import ApertureExtractor, FiberFlatCorrector
from megaradrp.core import peakdet
# from numina.logger import log_to_history
from megaradrp.requirements import MasterBiasRequirement
from megaradrp.requirements import MasterFiberFlatRequirement
Expand Down
2 changes: 1 addition & 1 deletion megaradrp/recipes/calibration/tests/test_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ def test_mode_arc_calibration_set0(drpmocker):
drpmocker.add_drp('MEGARA', megara_drp_load)
load_cli_storage()

run_recipe()
run_recipe()
Loading

0 comments on commit c94d403

Please sign in to comment.