Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hpparvi committed May 4, 2021
2 parents 53610b1 + 91a1515 commit c3430bf
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ The second approach can be used to constrain the LD model parameter space direct

## News

- Version 1.6 (4.5.2021)

- Added `ldtk.SVOFilter` filter class that creates a filter using the [Spanish Virtual Observatory (SVO) Filter
Profile Service (FPS)](http://svo2.cab.inta-csic.es/theory/fps/). The FPS contains over 10000 named filters, and
creating a filter based on the FPS data is now as simple as giving the `SVOFilter` the SVO filter name.

- Version 1.5 (3.3.2021)

- LDTk can now use four different sets of the modelled stellar spectra: `vis`, `vis-lowres`, `visir`, and `visir-lowres`.
Expand Down
2 changes: 1 addition & 1 deletion ldtk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

from .version import __version__
from .ldtk import LDPSetCreator, LDPSet, load_ldpset
from .filters import BoxcarFilter, TabulatedFilter, sdss_g, sdss_r, sdss_i, sdss_z, kepler, tess
from .filters import BoxcarFilter, SVOFilter, TabulatedFilter, sdss_g, sdss_r, sdss_i, sdss_z, kepler, tess
60 changes: 59 additions & 1 deletion ldtk/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
from typing import Optional

import pandas as pd

from pathlib import Path

from matplotlib.pyplot import subplots, setp
from numpy import array, argsort, zeros_like, arange, loadtxt, linspace
from scipy.interpolate import interp1d

Expand All @@ -32,7 +35,6 @@ def __call__(self, wl):
raise NotImplementedError

def plot(self, ax=None, wl_min=300, wl_max=1000, wl_res=500):
from matplotlib.pyplot import subplots, setp
if ax is None:
fig, ax = subplots()
wl = linspace(wl_min, wl_max, wl_res)
Expand All @@ -41,6 +43,62 @@ def plot(self, ax=None, wl_min=300, wl_max=1000, wl_res=500):
return ax


class SVOFilter(Filter):
shortcuts = dict(kepler='Kepler/Kepler.k',
tess='TESS/TESS.Red',
sdss_g='SLOAN/SDSS.g',
sdss_r='SLOAN/SDSS.r',
sdss_i='SLOAN/SDSS.i',
sdss_z='SLOAN/SDSS.z')

def __init__(self, name: str):
"""Creates a filter using the Spanish Virtual Observatory (SVO) Filter Profile Service.
Creates a filter using the Spanish Virtual Observatory (SVO) Filter Profile
Service. The filter name can be either an SVO filter name such as "SLOAN/SDSS.z"
or "Kepler/Kepler.k" or a name shortcut. You can get a dictionary of available
shortcuts from `SVOFilter.shortcuts`.
Notes
-----
- Requires an internet connection.
- The SVO FPS is hosted at http://svo2.cab.inta-csic.es/theory/fps/
Parameters
----------
name : str
SVO filter name such as "SLOAN/SDSS.z" or a name shortcut such as "TESS".
"""
from astroquery.svo_fps import SvoFps as svo
if name.lower() in self.shortcuts.keys():
name = self.shortcuts[name.lower()]
super().__init__(name)
self._svo_data = svo.get_transmission_data(name)
self.wavelength = wl = self._svo_data['Wavelength'].compressed().astype('d') / 10
self.transmission = tr = self._svo_data['Transmission'].compressed().astype('d')
self.transmission /= self.transmission.max()
self.bbox = wl[tr > 1e-2][[0, -1]]
self._ip = interp1d(self.wavelength, self.transmission, kind='cubic')

def __call__(self, wl):
return self._ip(wl)

def sample(self, n: Optional[int] = 100):
return self.wavelength, self.transmission

def plot(self, bbox: bool = False, ax=None):
if ax is None:
fig, ax = subplots()
else:
fig, ax = None, ax

ax.plot(self.wavelength, self.transmission)
if bbox:
ax.axvspan(*self.bbox, fill=False, ls='--', ec='k')
setp(ax, xlabel='Wavelength [nm]', ylabel='Transmission')
return ax


class TabulatedFilter(Filter):
"""Tabulated filter where the transmission is
listed as a function of wavelength.
Expand Down
2 changes: 1 addition & 1 deletion ldtk/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

from semantic_version import Version

__version__ = Version('1.5.0')
__version__ = Version('1.6.0')
140 changes: 140 additions & 0 deletions notebooks/SVOFilter.ipynb

Large diffs are not rendered by default.

0 comments on commit c3430bf

Please sign in to comment.