Skip to content

Commit

Permalink
Merge 4742062 into f063bb1
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-neal committed Aug 24, 2018
2 parents f063bb1 + 4742062 commit 54fbb99
Show file tree
Hide file tree
Showing 37 changed files with 1,315 additions and 1,256 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ source=pystart
branch=True
omit =
# Omit large plotting function.
eniric/plotting_functions.py
eniric/obsolete/plotting_functions.py
eniric/obsolete/*
data/*
plots/*
precision/*
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ data/atmmodel/Average_TAPAS_2014_visible.txt
data/atmmodel/Average_TAPAS_2014*.txt
data/test_data/*

.joblib
docs/Notebooks/.joblib

# updated_files data
eniric/updated_code/resampled_cont/*
# White list one file
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ install:
- cmd: "move tests\\config.yaml config.yaml"

# Generate data
- cmd: "%PYTHON%\\python.exe eniric_scripts\\make_test_data.py"
- cmd: "%PYTHON%\\python.exe eniric\\obsolete\\make_test_data.py"

# Prepare atmosphere models
- cmd: "%PYTHON%\\python.exe eniric_scripts\\split_atmmodel.py -b ALL"
Expand Down
46 changes: 44 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import pytest

import eniric
from eniric.IOmodule import pdread_2col
import eniric.io_module as io
from eniric import utilities as utils
from eniric.atmosphere import Atmosphere

resampled_template = "Spectrum_{0}-PHOENIX-ACES_{1}band_vsini{2}_R{3}_res3.0.txt"

Expand Down Expand Up @@ -67,7 +69,7 @@ def resampled_data(request):
test_data = os.path.join(
eniric.paths["resampled"], resampled_template.format(star, band, vel, res)
)
wav, flux = pdread_2col(test_data)
wav, flux = io.pdread_2col(test_data)
return id_string, wav, flux


Expand Down Expand Up @@ -124,3 +126,43 @@ def trans_unit(request):
def grad_flag(request):
"""Gradient flag parameter."""
return request.param


@pytest.fixture(
params=[
# "Average_TAPAS_2014_H.txt",
"Average_TAPAS_2014_K.txt",
"Average_TAPAS_2014_J.txt",
]
)
def atm_model(request):
"""Get atmospheric model name to load."""
return os.path.join(eniric.paths["atmmodel"], request.param)


@pytest.fixture(params=[2.5, 4])
def atmosphere_fixture(request, atm_model):
percent_cutoff = request.param
atm = Atmosphere.from_file(atm_model)
atm.mask_transmission(percent_cutoff)
return atm


@pytest.fixture()
def short_atmosphere(atmosphere_fixture):
# First 2000 data points only to speed up tests
return atmosphere_fixture[:2000]


@pytest.fixture(params=[(0, 1500), (8000, 9000)])
def sliced_atmmodel_default_mask(request, atm_model):
"""To do own masking. Sliced in different places."""
lower, upper = request.param # slice limits
atm = Atmosphere.from_file(atm_model)
return atm[int(lower) : int(upper)]


@pytest.fixture(params=[[3900, 4.5, 0, 0], [2600, 4.5, 0, 0]])
def testing_spectrum(request):
wav, flux = utils.load_aces_spectrum(request.param)
return wav, flux
159 changes: 102 additions & 57 deletions docs/Notebooks/barycentric_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@
# coding: utf-8

# ## Testing barycentric shift in eniric
#
#

# In[ ]:


import matplotlib.pyplot as plt
import numpy as np

# to remove labels in one tick
from matplotlib.ticker import MaxNLocator

import eniric.IOmodule as IOmodule
import eniric.io_module as io
import eniric.Qcalculator as Qcalculator
from eniric.plotting_functions import (plot_atmosphere_model,
plot_stellar_spectum)
from eniric.obsolete.plotting_functions import (
plot_atmosphere_model,
plot_stellar_spectum,
)
from eniric.utilities import band_selector, wav_selector

# In[ ]:


def prepare_atmosphere():
""" Read in atmopheric model and prepare. """
wav_atm, flux_atm, std_flux_atm, mask_atm = IOmodule.pdread_4col(atmmodel)
wav_atm, flux_atm, std_flux_atm, mask_atm = io.pdread_4col(atmmodel)
# pandas lready returns numpy arrays
wav_atm = wav_atm / 1000.0 # conversion from nanometers to micrometers
mask_atm = np.array(mask_atm, dtype=bool)
Expand All @@ -34,40 +37,60 @@ def barycenter_shift(wav_atm, mask_atm, offset_RV=0.0):
""" Calculating impact of Barycentric movement on mask...
Extends the masked region to +-30 km/s due to the barycentic motion of the earth.
offset_RV: float
Radial veloctiy offset in km/s.
"""
RV_bary = 3.0e4 # 30 km/s barycentric velocity
offset_RV = offset_RV * 1.0e3 # Trun offset into m/s
RV_bary = 3.0e4 # 30 km/s barycentric velocity
offset_RV = offset_RV * 1.0e3 # Trun offset into m/s
pixels_start = np.sum(mask_atm)
pixels_total = len(mask_atm)

mask_atm_30kms = []
for wav_val, mask_val in zip(wav_atm, mask_atm):
if (mask_val is False and offset_RV == 666.0): # if the mask is false and the offset is equal to zero
if (
mask_val is False and offset_RV == 666.0
): # if the mask is false and the offset is equal to zero
mask_atm_30kms.append(mask_val)

else:
delta_lambda = wav_val * RV_bary / Qcalculator.c.value # doppler shift amount delta_lambda = lambda*v/c

starting_lambda = wav_val * offset_RV / Qcalculator.c.value # offset value

indexes_30kmslice = np.searchsorted(wav_atm, [starting_lambda+wav_val-delta_lambda, starting_lambda+wav_val+delta_lambda])

delta_lambda = (
wav_val * RV_bary / Qcalculator.c.value
) # doppler shift amount delta_lambda = lambda*v/c

starting_lambda = wav_val * offset_RV / Qcalculator.c.value # offset value

indexes_30kmslice = np.searchsorted(
wav_atm,
[
starting_lambda + wav_val - delta_lambda,
starting_lambda + wav_val + delta_lambda,
],
)

# Replaces any values outside len(wav_atm) with end index value
indexes_30kmslice = [index if(index < len(wav_atm)) else len(wav_atm)-1 for index in indexes_30kmslice]
mask_atm_30kmslice = np.array(mask_atm[indexes_30kmslice[0]:indexes_30kmslice[1]], dtype=bool) # selecting only the slice in question
indexes_30kmslice = [
index if (index < len(wav_atm)) else len(wav_atm) - 1
for index in indexes_30kmslice
]
mask_atm_30kmslice = np.array(
mask_atm[indexes_30kmslice[0] : indexes_30kmslice[1]], dtype=bool
) # selecting only the slice in question

# if(False in mask_atm_30kmslice):
# mask_atm_30kms.append(False)
# else:
# mask_atm_30kms.append(True)

mask_atm_30kmslice_reversed = [not i for i in mask_atm_30kmslice] # comp list of array is bad
mask_atm_30kmslice_reversed = [
not i for i in mask_atm_30kmslice
] # comp list of array is bad
print("mask_atm_30kmslice_reversed", mask_atm_30kmslice_reversed)

clump = np.array_split(mask_atm_30kmslice, np.where(np.diff(mask_atm_30kmslice_reversed))[0]+1)[::2]

clump = np.array_split(
mask_atm_30kmslice,
np.where(np.diff(mask_atm_30kmslice_reversed))[0] + 1,
)[::2]
print("clump", clump)
tester = True
for block in clump:
Expand All @@ -79,8 +102,11 @@ def barycenter_shift(wav_atm, mask_atm, offset_RV=0.0):

mask_atm = np.array(mask_atm_30kms, dtype=bool)
pixels_end = np.sum(mask_atm)
print(("Barycentric impact masks out {:04.1}\% more of the atmospheric"
" spectrum").format((pixels_end-pixels_start)/pixels_total))
print(
(
"Barycentric impact masks out {:04.1}\% more of the atmospheric" " spectrum"
).format((pixels_end - pixels_start) / pixels_total)
)
return mask_atm


Expand All @@ -90,6 +116,7 @@ def barycenter_shift(wav_atm, mask_atm, offset_RV=0.0):
def inner_function():
pass


def new_inner_function():
pass

Expand Down Expand Up @@ -129,44 +156,62 @@ def new_inner_function():
pixels_total = len(mask_atm)
print(pixels_start, pixels_total)

offset_RV=0
offset_RV = 0

mask_atm_30kms = []
for wav_val, mask_val in zip(wav_atm, mask_atm):
if (mask_val is False and offset_RV == 666.0): # if the mask is false and the offset is equal to zero
mask_atm_30kms.append(mask_val)

else:
delta_lambda = wav_val * 3.0e4 / Qcalculator.c.value
print("delta_lambda", delta_lambda)

starting_lambda = wav_val * offset_RV * 1.0e3 / Qcalculator.c.value
print("starting_lambda", starting_lambda)

indexes_30kmslice = np.searchsorted(wav_atm, [starting_lambda+wav_val-delta_lambda, starting_lambda+wav_val+delta_lambda])

indexes_30kmslice = [index if(index < len(wav_atm)) else len(wav_atm)-1 for index in indexes_30kmslice]

mask_atm_30kmslice = np.array(mask_atm[indexes_30kmslice[0]:indexes_30kmslice[1]], dtype=bool) # selecting only the slice in question

# if(False in mask_atm_30kmslice):
# mask_atm_30kms.append(False)
# else:
# mask_atm_30kms.append(True)

mask_atm_30kmslice_reversed = [not i for i in mask_atm_30kmslice]

clump = np.array_split(mask_atm_30kmslice, np.where(np.diff(mask_atm_30kmslice_reversed))[0]+1)[::2]

tester = True
for block in clump:
if len(clump) >= 3:
tester = False
break

mask_atm_30kms.append(tester)
if (
mask_val is False and offset_RV == 666.0
): # if the mask is false and the offset is equal to zero
mask_atm_30kms.append(mask_val)

else:
delta_lambda = wav_val * 3.0e4 / Qcalculator.c.value
print("delta_lambda", delta_lambda)

starting_lambda = wav_val * offset_RV * 1.0e3 / Qcalculator.c.value
print("starting_lambda", starting_lambda)

indexes_30kmslice = np.searchsorted(
wav_atm,
[
starting_lambda + wav_val - delta_lambda,
starting_lambda + wav_val + delta_lambda,
],
)

indexes_30kmslice = [
index if (index < len(wav_atm)) else len(wav_atm) - 1
for index in indexes_30kmslice
]

mask_atm_30kmslice = np.array(
mask_atm[indexes_30kmslice[0] : indexes_30kmslice[1]], dtype=bool
) # selecting only the slice in question

# if(False in mask_atm_30kmslice):
# mask_atm_30kms.append(False)
# else:
# mask_atm_30kms.append(True)

mask_atm_30kmslice_reversed = [not i for i in mask_atm_30kmslice]

clump = np.array_split(
mask_atm_30kmslice, np.where(np.diff(mask_atm_30kmslice_reversed))[0] + 1
)[::2]

tester = True
for block in clump:
if len(clump) >= 3:
tester = False
break

mask_atm_30kms.append(tester)

mask_atm = np.array(mask_atm_30kms, dtype=bool)
pixels_end = np.sum(mask_atm)
print(("Barycentric impact masks out {:04.1}\% more of the atmospheric"
" spectrum").format((pixels_end-pixels_start)/pixels_total))
print(
(
"Barycentric impact masks out {:04.1}\% more of the atmospheric" " spectrum"
).format((pixels_end - pixels_start) / pixels_total)
)
4 changes: 1 addition & 3 deletions eniric/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
__version__ = "0.6-beta"
__all__ = [
"atmosphere",
"IOmodule",
"nIRanalysis",
"plotting_functions",
"io_module",
"Qcalculator",
"resample",
"snr_normalization",
Expand Down

0 comments on commit 54fbb99

Please sign in to comment.