Skip to content

Commit

Permalink
Fix pytest --doctest-modules (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobuddel authored Oct 29, 2024
2 parents 5ebe043 + 086a098 commit 55455de
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
33 changes: 23 additions & 10 deletions scopesim_templates/misc/misc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
"""TBA."""

from pathlib import Path
import warnings

import numpy as np
import synphot

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion scopesim_templates/stellar/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
Expand Down
7 changes: 4 additions & 3 deletions scopesim_templates/stellar/stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -189,13 +189,14 @@ def stars(filter_name, amplitudes, spec_types, x, y, library="pyckles",
The final positions table is kept in the ``<Source>.fields`` attribute::
>>> src.fields[0]
>>> my_pos_table = src.fields[0]
Each star in this table has an associated spectrum kept in the
``<Source>.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
Expand All @@ -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)):
Expand Down
2 changes: 1 addition & 1 deletion scopesim_templates/utils/samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55455de

Please sign in to comment.