diff --git a/scopesim_templates/misc/misc.py b/scopesim_templates/misc/misc.py index 4276208..1c9f187 100644 --- a/scopesim_templates/misc/misc.py +++ b/scopesim_templates/misc/misc.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- """TBA.""" +from pathlib import Path import warnings + import numpy as np import synphot @@ -136,7 +138,7 @@ def source_from_imagehdu(image_hdu, filter_name, pixel_unit_amplitude=None, Parameters ---------- image_hdu : fits.ImageHDU - filter_name : str + filter_name : Path | str Either a standard filter name or a filter from an instrument package waverange: tuple wave_min and wave_max of the spectral range @@ -154,27 +156,38 @@ def source_from_imagehdu(image_hdu, filter_name, pixel_unit_amplitude=None, -------- Using a generic filter curve from the Spanish VO:: - >>> image_hdu = fits.ImageHDU(data=np.ones((11, 11))) + >>> from scopesim_templates.misc import misc + >>> image_hdu = fits.ImageHDU( + ... data=np.ones((11, 11)), + ... header=fits.Header({ + ... "CUNIT1": "deg", + ... "CUNIT2": "deg", + ... "CDELT1": 0.001, + ... "CDELT2": 0.001, + ... })) >>> # add WCS info to the header here >>> filter_name = "Generic/Johnson_UBVRIJHKL.N" - >>> src = misc.source_from_imagehdu(image_hdu=hdu, - filter_name=filter_name, - pixel_unit_amplitude=20*u.Jy) + >>> src = misc.source_from_imagehdu(image_hdu=image_hdu, + ... filter_name=filter_name, + ... pixel_unit_amplitude=20*u.Jy) Using the METIS H2O-ice filter from the METIS ScopeSim package:: >>> import scopesim - >>> filter_name = scopesim.rc.__search_path__[0] + \ - "/METIS/filters/TC_filter_H2O-ice.dat" - >>> src = misc.source_from_imagehdu(image_hdu=hdu, - filter_name=filter_name, - pixel_unit_amplitude=20*u.Jy) + >>> _ = scopesim.download_packages(["METIS"]) + >>> filter_name = scopesim.rc.__search_path__[0] / \ + ... "METIS/filters/TC_filter_H2O-ice.dat" + >>> src = misc.source_from_imagehdu(image_hdu=image_hdu, + ... filter_name=filter_name, + ... pixel_unit_amplitude=20*u.Jy) TODO: Check if the image_hdu has WCS """ if filter_name is None and waverange is None: raise ValueError("Wavelength information must be given with either a " "filter_name or a waverange") + if isinstance(filter_name, Path): + filter_name = str(filter_name) units = image_hdu.header.get("BUNIT") amp = 1. diff --git a/scopesim_templates/stellar/clusters.py b/scopesim_templates/stellar/clusters.py index f3a1d36..c7c7b1d 100644 --- a/scopesim_templates/stellar/clusters.py +++ b/scopesim_templates/stellar/clusters.py @@ -61,7 +61,7 @@ def cluster(mass=1E3, distance=50000, core_radius=1, ra=RA0, dec=DEC0, of around 0.2 pc at the extragalactic centre and 1000 solar masses worth of stars: - >>> from scopesim_templates.basic.stars import cluster + >>> from scopesim_templates.stellar.clusters import cluster >>> src = cluster(mass=1000, distance=8500, core_radius=0.2, seed=9001) """ diff --git a/scopesim_templates/stellar/stars.py b/scopesim_templates/stellar/stars.py index 4811c63..92365c9 100644 --- a/scopesim_templates/stellar/stars.py +++ b/scopesim_templates/stellar/stars.py @@ -177,7 +177,7 @@ def stars(filter_name, amplitudes, spec_types, x, y, library="pyckles", >>> from scopesim_templates.stellar import stars >>> >>> n = 100 - >>> spec_types = ["A0V", "G2V", "K0III", "M5III", "O8I"] + >>> spec_types = ["A0V", "G2V", "K0III", "M5III", "O8I"] * (n // 5) >>> ids = np.random.randint(0, 5, size=n) >>> star_list = [spec_types[i] for i in ids] >>> mags = np.random.normal(loc=20, scale=3, size=n) * u.mag @@ -189,13 +189,14 @@ def stars(filter_name, amplitudes, spec_types, x, y, library="pyckles", The final positions table is kept in the ``.fields`` attribute:: - >>> src.fields[0] + >>> my_pos_table = src.fields[0] Each star in this table has an associated spectrum kept in the ``.spectra`` attribute. These stars are connected to the spectra in the list by the "ref" column in the ``.fields`` table:: >>> src.spectra + [SpextrumNone, SpextrumNone, SpextrumNone, SpextrumNone, SpextrumNone] The stars can be scaled in units of u.mag, u.ABmag or u.Jansky. Any filter listed on the spanish VO filter profile service can be used for the scaling @@ -204,7 +205,7 @@ def stars(filter_name, amplitudes, spec_types, x, y, library="pyckles", >>> amplitudes = np.linspace(1, 3631, n) * u.Jansky >>> filter_name = "Paranal/HAWKI.Ks" - >>> stars(filter_name, amplitudes, spec_types, x=x, y=y) + >>> my_source = stars(filter_name, amplitudes, spec_types, x=x, y=y) """ if not isinstance(spec_types, (list, tuple, np.ndarray)): diff --git a/scopesim_templates/utils/samplers.py b/scopesim_templates/utils/samplers.py index 42574f3..3baa2e6 100644 --- a/scopesim_templates/utils/samplers.py +++ b/scopesim_templates/utils/samplers.py @@ -11,7 +11,7 @@ def randomvariate(pdf, n, xmin, xmax): arbitrary probability distribution. For reference, see Bevington's book, page 84. Based on rejection*.py. Usage: - >>> randomvariate(P,N,xmin,xmax) + randomvariate(P,N,xmin,xmax) where P : probability distribution function from which you want to generate random numbers