Skip to content

Commit

Permalink
Merge pull request #45 from AstarVienna/dev_master
Browse files Browse the repository at this point in the history
Merge dev_master into master for 0.4.3 release
  • Loading branch information
hugobuddel authored Feb 15, 2023
2 parents 508f815 + 6a6371a commit ab3405c
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 19 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ include README.md
include LICENCE.txt
include scopesim_templates/defaults.yaml
include scopesim_templates/stellar/mamajek_alt.dat
graft scopesim_templates/micado/data/
graft scopesim_templates/micado/viking_fields/
prune scopesim_templates/tests*
prune *OLD_*
2 changes: 1 addition & 1 deletion scopesim_templates/extragalactic/galaxy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def sersic_profile(r_eff=100, n=4, ellipticity=0.5, angle=30,
"""

# Silently cast to integer
os_factor = np.int(oversample)
os_factor = int(oversample)

if os_factor <= 0:
raise ValueError("Oversampling factor must be >=1.")
Expand Down
8 changes: 7 additions & 1 deletion scopesim_templates/micado/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .darkness import darkness as _darkness
from .flatlamp import flatlamp as _flatlamp
from .pinhole_masks import pinhole_mask as _pinhole_mask
from .cluster import cluster as _cluster
from .viking_fields import viking_fields
from ..utils.general_utils import add_function_call_str
Expand All @@ -23,9 +24,14 @@ def flatlamp():
return _flatlamp()


@add_function_call_str
def pinhole_mask():
return _pinhole_mask()


@add_function_call_str
def cluster():
return _cluster()


__all__ = [darkness, flatlamp, empty_sky, cluster]
__all__ = [darkness, flatlamp, empty_sky, cluster, pinhole_mask]
7 changes: 4 additions & 3 deletions scopesim_templates/micado/flatlamp.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Flat lamp for MICADO."""
import numpy
import numpy as np
import scopesim
from astropy.io import fits
from scopesim import Source
import astropy.units as u
from scopesim import Source
import scopesim


def flatlamp(
Expand Down Expand Up @@ -76,7 +76,8 @@ def flatlamp(

sa = 1.0200000e+02
se = 3.3502039e+05
lam = numpy.logspace(numpy.log(sa), numpy.log(se), base=numpy.e, num=number_of_points) * u.Angstrom
lam = numpy.logspace(numpy.log(sa), numpy.log(se), base=numpy.e,
num=number_of_points) * u.Angstrom

return Source(
image_hdu=hdu,
Expand Down
60 changes: 60 additions & 0 deletions scopesim_templates/micado/pinhole_masks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import numpy as np
from astropy import units as u
from scopesim import Source
from synphot import BlackBody1D, SourceSpectrum, Empirical1D


def pinhole_mask(x, y, waves, temperature=1500*u.K, sum_factor=1):
"""
Creates a Source object with point sources at coordinates (x, y) in the slit
Parameters
----------
x, y : array-like
[arcsec] Coords relative to centre of FOV (i.e. optical axis)
waves : array-like, u.Quantity
[um] Array of wavelength values.
temperature : float, u.Quantity, optional
[deg K] Temperature of WCU blackbody spectrum.
sum_factor : float, optional
Rescale the spectrum to sum to this value
Returns
-------
src : scopesim.Source
Examples
--------
Pin-holes every 0.5 arcsec along the MICADO long-slit
::
x = np.arange(-1.5, 13.51, 0.5)
y = np.zeros_like(x)
waves = np.arange(0.7, 2.5, 0.001) * u.um
src = pinhole_mask(x, y, waves, sum_factor=9001)
A grid of pin-holes every 5 arcsec for the MICADO 4mas IMG mode
::
dr = np.arange(-25, 26, 5) # [arcsec]
x, y = np.meshgrid(dr, dr)
x, y = x.flatten(), y.flatten()
waves = np.arange(0.7, 2.5, 0.001) * u.um
src = pinhole_mask(x, y, waves, sum_factor=9001)
"""
if not isinstance(waves, u.Quantity):
waves *= u.um
if not isinstance(temperature, u.Quantity):
temperature *= u.K

blackbody_spectrum = BlackBody1D(temperature=temperature)
flux = blackbody_spectrum(waves.to(u.AA))
flux *= sum_factor / np.trapz(flux)
spec = SourceSpectrum(Empirical1D, points=waves, lookup_table=flux)
src = Source(x=x, y=y, ref=np.ones_like(x), weight=np.ones_like(x),
spectra=[spec])

return src
10 changes: 5 additions & 5 deletions scopesim_templates/stellar/mamajek_alt.dat
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ A4V | 1.76 | 1.47 | 1.41 | 1.90
A5V | 1.84 | 1.51 | 1.44 | 1.85
A6V | 1.89 | 1.54 | 1.46 | 1.83
A7V | 2.07 | 1.64 | 1.54 | 1.76
A8V | 2.29 | 1.78 | 1.66 | 1.67
A9V | 2.30 | 1.78 | 1.66 | 1.67
A8V | 2.29 | 1.78 | 1.66 | 1.68
A9V | 2.30 | 1.79 | 1.67 | 1.67
F0V | 2.51 | 1.90 | 1.76 | 1.59
F1V | 2.79 | 2.13 | 1.96 | 1.50
F2V | 2.99 | 2.26 | 2.07 | 1.44
Expand Down Expand Up @@ -82,9 +82,9 @@ M5V | 14.30 | 9.25 | 8.36 | 0.16
M5.5V | 15.51 | 9.93 | 9.01 | 0.12
M6V | 16.62 | 10.28 | 9.32 | 0.10
M6.5V | 17.07 | 10.47 | 9.47 | 0.097
M7V | 17.81 | 10.76 | 9.76 | 0.090
M7.5V | 18.42 | 10.68 | 9.97 | 0.089
M7V | 17.81 | 10.66 | 9.76 | 0.090
M7.5V | 18.42 | 10.78 | 9.97 | 0.089
M8V | 18.84 | 11.23 | 10.11 | 0.082
M8.5V | 19.14 | 11.45 | 10.22 | 0.081
M9V | 19.36 | 11.53 | 10.30 | 0.079
M9V | 30.00 | 20.00 | 20.00 | 0.01
M9.5V | 30.00 | 20.00 | 20.00 | 0.01
14 changes: 9 additions & 5 deletions scopesim_templates/stellar/stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
]


def star_field(n, mmin, mmax, width, height=None, filter_name="V", ra=RA0, dec=DEC0, **kwargs):
def star_field(n, mmin, mmax, width, height=None, filter_name="V",
ra=RA0, dec=DEC0, **kwargs):
"""
Creates a super basic field of stars with random positions and brightnesses
Expand Down Expand Up @@ -145,7 +146,8 @@ def star_grid(n, mmin, mmax, filter_name="V", separation=1, ra=RA0, dec=DEC0):


@deprecated_renamed_argument('mags', 'amplitudes', '0.1')
def stars(filter_name, amplitudes, spec_types, x, y, library="pyckles", ra=RA0, dec=DEC0):
def stars(filter_name, amplitudes, spec_types, x, y, library="pyckles",
ra=RA0, dec=DEC0):
"""
Creates a scopesim.Source object for a list of stars with given amplitudes
Expand All @@ -166,9 +168,11 @@ def stars(filter_name, amplitudes, spec_types, x, y, library="pyckles", ra=RA0,
ra, dec : float
coordinates of the center of the field
library: str
Library where the spectroscopic types are taken. By default are taken from the pickles library using
the `pyckles` package. Other libraries available are kurucz, bosz/lr, bosz/mr, bosz/hr, etc for MIR coverage
and different spectral resolutions. Please see the `spextra` package for more information
Library where the spectroscopic types are taken. By default are taken
from the pickles library using the `pyckles` package. Other libraries
available are kurucz, bosz/lr, bosz/mr, bosz/hr, etc for MIR coverage
and different spectral resolutions. Please see the `spextra` package
for more information
Returns
Expand Down
1 change: 1 addition & 0 deletions scopesim_templates/tests/test_micado/test_flatlamp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test for flatlamp."""
from astropy.io.fits import ImageHDU
from synphot import SourceSpectrum

from scopesim_templates.micado import flatlamp
from scopesim_templates.rc import Source

Expand Down
46 changes: 46 additions & 0 deletions scopesim_templates/tests/test_micado/test_pinhole_mask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Test for flatlamp."""
import numpy as np
from astropy.table import Table
from astropy import units as u
from matplotlib import pyplot as plt
from synphot import SourceSpectrum

from scopesim import load_example_optical_train

from scopesim_templates.micado.pinhole_masks import pinhole_mask
from scopesim_templates.rc import Source

PLOTS = False


class TestPinholeMask:
def test_pinhole_mask_returns_source_object(self):
""" Example from pinhole_mask docstring"""
dr = np.arange(-25, 26, 5) # [arcsec]
x, y = np.meshgrid(dr, dr)
x, y = x.flatten(), y.flatten()
waves = np.arange(0.7, 2.5, 0.001) * u.um

ph_mask = pinhole_mask(x, y, waves, sum_factor=9001)

assert isinstance(ph_mask, Source)
assert isinstance(ph_mask.spectra[0], SourceSpectrum)
assert isinstance(ph_mask.fields[0], Table)

def test_pinhole_with_basic_instrument(self):
dr = np.arange(-25, 26, 5) # [arcsec]
x, y = np.meshgrid(dr, dr)
x, y = x.flatten(), y.flatten()
waves = np.arange(0.7, 2.5, 0.001) * u.um

src = pinhole_mask(x, y, waves, sum_factor=9001)
opt = load_example_optical_train()
opt.observe(src)

im = opt.image_planes[0].data

if PLOTS:
plt.imshow(im)
plt.show()

assert np.max(im) > np.average(im)
4 changes: 2 additions & 2 deletions scopesim_templates/tests/test_stellar/test_cluster_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def test_returns_a0v_for_2_3_msun(self):
def test_returns_g2v_for_1_msun(self):
assert cu.mass2spt(1.02) == "G2V"

def test_returns_m9v_for_0_01_msun(self):
assert cu.mass2spt(0.01) == "M9V"
def test_returns_m95v_for_0_01_msun(self):
assert cu.mass2spt(0.01) == "M9.5V"

def test_multiple_masses_at_once(self):
spts = cu.mass2spt([2.3, 1.02])
Expand Down
8 changes: 6 additions & 2 deletions scopesim_templates/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
version = '0.4.2'
date = '2022-07-12 17:00:00 GMT'
version = '0.4.3'
date = '2023-02-15 17:00:00 GMT'
yaml_descriptions = """
- version : 0.4.3
date : 2023-02-15
comment : Add pinhole mask and minor bugfixes
- version : 0.4.2
date : 2022-07-12
comment : Updated DLC server to point to scopesim.univie.ac.at
Expand Down

0 comments on commit ab3405c

Please sign in to comment.