Skip to content

Commit

Permalink
Merge pull request #68 from hover2pi/UBV
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
hover2pi authored Oct 15, 2021
2 parents a3c4aed + 5ad5772 commit 76ea2bd
Show file tree
Hide file tree
Showing 23 changed files with 4,699 additions and 2,185 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ A variety of evolutionary model grids can be used to infer fundamental parameter

```python
trap1.evo_model = 'DUSTY00'
trap1.mass_from_age()
trap1.infer_mass()
```

<img src="https://github.com/hover2pi/sedkit/blob/master/sedkit/data/figures/Lbol_v_mass.png" height="400">
Expand All @@ -222,7 +222,7 @@ trap1.fit_modelgrid(SpexPrismLibrary())
Inspect the SED at any time with the interactive plotting method.

```python
trap1.plot()
trap1.plot(integral=True, best_fit=True)
```

<img src="https://github.com/hover2pi/sedkit/blob/master/sedkit/data/figures/sed_plot.png" height="500">
Expand Down
7 changes: 4 additions & 3 deletions env/environment-3.7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ channels:
- defaults
dependencies:
- numpy>=1.18.1
- astropy>=4.0
- astropy>=4.3.1
- astroquery>=0.4.2
- python>=3.7
- bokeh>=1.4.0
- scipy>=1.4.1
- pandas>=0.23.4
- pickle5>=0.0.11
- pip>=20.3.3
- selenium>=2.49.2
- sphinx>=3.4.3
Expand All @@ -19,8 +21,7 @@ dependencies:
- jupyter>=1.0.0
- ipython>=7.12.0
- pip:
- svo-filters==0.4.0
- svo-filters==0.4.1
- dustmaps==1.0.4
- numpydoc==0.8.0
- emcee>=3.0.2
- git+https://github.com/astropy/astroquery.git@ccc96185beeff86f3a12a31a00a801afcebe1dbe
7 changes: 4 additions & 3 deletions env/environment-3.8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ channels:
- defaults
dependencies:
- numpy>=1.18.1
- astropy>=4.0
- astropy>=4.3.1
- astroquery>=0.4.2
- python>=3.8
- bokeh>=1.4.0
- scipy>=1.4.1
Expand All @@ -16,11 +17,11 @@ dependencies:
- sphinx-automodapi>=0.13
- pytest>=6.2.1
- pygments>=2.7.4
- tqdm>=4.62.3
- jupyter>=1.0.0
- ipython>=7.12.0
- pip:
- svo-filters==0.4.0
- svo-filters==0.4.1
- dustmaps==1.0.4
- numpydoc==0.8.0
- emcee>=3.0.2
- git+https://github.com/astropy/astroquery.git@ccc96185beeff86f3a12a31a00a801afcebe1dbe
2 changes: 1 addition & 1 deletion sedkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
__version_commit__ = ''
_regex_git_hash = re.compile(r'.*\+g(\w+)')

__version__ = '1.1.3'
__version__ = '1.2.0'

# from pkg_resources import get_distribution, DistributionNotFound
# try:
Expand Down
30 changes: 27 additions & 3 deletions sedkit/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import pickle
from copy import copy
from pkg_resources import resource_filename
import shutil

from astropy.io import ascii
Expand Down Expand Up @@ -126,6 +127,12 @@ def add_SED(self, sed):
sed: sedkit.sed.SED
The SED object to add
"""
# Overwrite duplicate names
idx = None
if sed.name in self.results['name']:
self.message("{}: Target already in catalog. Overwriting with new SED...")
idx = np.where(self.results['name'] == sed.name)[0][0]

# Turn off print statements
sed.verbose = False

Expand Down Expand Up @@ -182,8 +189,13 @@ def add_SED(self, sed):
# Add the absolute uncertainty
new_row['M_' + row['band'] + '_unc'] = row['abs_magnitude_unc']

# Add the new row
self.results.add_row(new_row)
# Add the new row...
if idx is None:
self.results.add_row(new_row)

# ...or replace existing
else:
self.results[idx] = new_row

self.message("Successfully added SED '{}'".format(sed.name))

Expand Down Expand Up @@ -298,7 +310,7 @@ def from_file(self, filepath, run_methods=['find_2MASS'], delimiter=','):
# Make the SED
s = SED(row['name'], verbose=False)
if 'ra' in row and 'dec' in row:
s.sky_coords = row['ra']*q.deg, row['dec']*q.deg
s.sky_coords = row['ra'] * q.deg, row['dec'] * q.deg

# Run the desired methods
s.run_methods(run_methods)
Expand Down Expand Up @@ -688,3 +700,15 @@ def source(self):
results_dict = {key: val for key, val in dict(self.results).items() if key != 'SED'}

return ColumnDataSource(data=results_dict)


class MdwarfCatalog(Catalog):
"""A catalog of M dwarf stars"""
def __init__(self, **kwargs):
"""Initialize the catalog object"""
# Initialize object
super().__init__(name='M Dwarf Catalog', **kwargs)

# Read the names from the file
file = resource_filename('sedkit', 'data/sources.txt')
self.from_file(file, run_methods=['find_SDSS', 'find_2MASS', 'find_WISE'])
4 changes: 2 additions & 2 deletions sedkit/isochrone.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def evaluate(self, xval, age, xparam, yparam, plot=False):
if np.isnan(nominal):
raise ValueError("I got a nan from {} for some reason.".format(self.name))

return nominal, error
return nominal, error, self.name

def interpolate(self, xval, age, xparam, yparam):
"""Interpolate a value between two isochrones
Expand Down Expand Up @@ -252,7 +252,7 @@ def interpolate(self, xval, age, xparam, yparam):

return result * unit

def message(self, msg, pre='[sedkit.Isochrone]'):
def message(self, msg, pre='[sedkit]'):
"""
Only print message if verbose=True
Expand Down
4 changes: 2 additions & 2 deletions sedkit/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ def mcmc_go(self, nwalk_mult=20, nstep_mult=50):
sampler = emcee.EnsembleSampler(nwalkers, self.ndim, log_probability, args=(self.model_grid, self.spectrum))

# Burn in the walkers
pos, prob, state = sampler.run_mcmc(p0, nsteps / 10, progress=True)
pos, prob, state = sampler.run_mcmc(p0, int(nsteps / 10), progress=True)

# Reset the walkers, so the burn-in steps aren't included in analysis
sampler.reset()

# Run MCMC with the walkers starting at the end of the burn-in
pos, prob, state = sampler.run_mcmc(pos, nsteps, progress=True)
pos, prob, state = sampler.run_mcmc(pos, int(nsteps), progress=True)

# Chains contains the positions for each parameter, for each walker
self.chain = sampler.chain
Expand Down
22 changes: 14 additions & 8 deletions sedkit/modelgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def __init__(self, name, parameters, wave_units=None, flux_units=None,
self.ref = ref
self.verbose = verbose
self.phot = False
self.bandpasses = []

# Make all args into attributes
for key, val in kwargs.items():
Expand Down Expand Up @@ -262,7 +263,7 @@ def filter(self, **kwargs):
# Get the relevant table rows
return u.filter_table(self.index, **kwargs)

def get_spectrum(self, closest=False, snr=None, interp=True, spec_obj=True, trim=None, resolution=None, **kwargs):
def get_spectrum(self, closest=False, snr=None, interp=True, spec_obj=True, trim=None, resolution=None, const=1, **kwargs):
"""Retrieve the first model with the specified parameters
Parameters
Expand All @@ -275,6 +276,8 @@ def get_spectrum(self, closest=False, snr=None, interp=True, spec_obj=True, trim
Interpolate the model grid if not present
spec_obj: bool
Return a sedkit.spectrum.Spectrum object
const: float
Multiplicative factor fof the flux
Returns
-------
Expand Down Expand Up @@ -325,7 +328,7 @@ def get_spectrum(self, closest=False, snr=None, interp=True, spec_obj=True, trim
spec = u.scrub(spec)

# Convert to specobj
spec = Spectrum(spec[0] * self.wave_units, spec[1] * self.flux_units, name=name, snr=snr, ref=self.ref, phot=self.phot, **kwargs)
spec = Spectrum(spec[0] * self.wave_units, spec[1] * self.flux_units, name=name, snr=snr, ref=self.ref, phot=self.phot, const=const, **kwargs)

if trim is not None:
spec = spec.trim(include=trim, concat=True)
Expand Down Expand Up @@ -533,14 +536,12 @@ def photometry(self, bandpasses, weight=False):
# Collect data
data = []
weights = []
bands = []
for band in bandpasses:

# Get the bandpass
bp = svo.Filter(band)

# Weight the bands by the inverse of the band width
weights.append((bp.wave_max - bp.wave_min).to(q.um).value if weight else 1)

# Calculate the synthetic flux
flx, flx_unc = spec.synthetic_flux(bp)
wav = bp.wave_eff.astype(np.float16).value
Expand All @@ -552,11 +553,18 @@ def photometry(self, bandpasses, weight=False):
# data.append([bp.wave_eff.astype(np.float16).value, flx.to(self.flux_units).value])
data.append([wav, flx.value])

# Store the band names
bands.append(band)

# Weight the bands by the inverse of the band width
weights.append((bp.wave_max - bp.wave_min).to(q.um).value if weight else 1)

# Unpack and save as new spectrum
dataT = np.array(data).T
phot.add_model(dataT if err else dataT[:2], weights=weights, label=row['label'], **params)
phot.phot = True
phot.native_wave_units = bp.wave_units
phot.bandpasses = bands

return phot

Expand Down Expand Up @@ -722,9 +730,7 @@ def __init__(self):
self.load(root)

# Add numeric spectral type
self.index['SpT'] = [u.specType(i.split(',')[0].replace('Opt:','')\
.replace('NIR:',''))[0] for i in\
self.index['spty']]
self.index['SpT'] = [u.specType(i.split(',')[0].replace('Opt:','').replace('NIR:',''))[0] for i in self.index['spty']]


def format_XML(modeldir):
Expand Down
Loading

0 comments on commit 76ea2bd

Please sign in to comment.