Stellar Module

This module include general functions to work with stars

Stellar cluster

In the following example we generate a young star cluster with a core radius r_c=1 pc, M=1000 Msun and located in the LMC (d=50kpc)

[1]:
import numpy as np
from scopesim_templates.stellar import cluster


src = cluster(mass=1E3, distance=50000, core_radius=1)

Lets have a look inside the object:

[2]:
src.fields[0]
[2]:
Table length=2434
xyrefweightmassesspec_types
arcsecarcsecsolMass
float64float64int64float64float64str3
0.7047941071430335-0.34193400839906835322.702228328228619e-190.023450818028910993M6V
3.017163801660643-1.531947677274888275.985543114133627e-120.5030213194041789M1V
5.545342770168751-0.5059378004225308244.961396135881094e-110.6887993545486397K5V
0.043374844051356950.47394950595035895319.301655464729025e-140.16592467519086804M5V
-0.16951980261071412.689008599028229275.728214836974918e-120.4981528843145076M1V
2.903227971744357-0.42880293404815345327.235335661968081e-190.030385458123976427M6V
2.91477255218179551.4290979035892837312.5344525453154387e-140.12048133658240405M5V
2.18793226010121661.7393082707150282291.1280665937633994e-120.33768446357534043M3V
-0.5711617098260228-5.393018142881724211.6102797118853998e-100.8167460590486888K2V
-0.11710185806601776-5.100956140168292321.5282472923135797e-140.11036638034546091M6V
-2.1461762891994114.292793390010554296.746584693259497e-130.284529520314177M3V
-6.516561394056243-0.8923876990270431282.141385549412798e-120.4021587190742773M2V
..................
-4.6796616129839742.5527643902258825328.043671952122561e-160.0800771445221511M6V
-1.67089936055686652.038654094696279313.598973661189041e-140.13306765925503572M5V
1.4678772515789662-0.17251949373959752245.335448880937463e-110.6961978840502374K5V
-2.98626562542259630.5421006937620638312.702271491358672e-140.12278256100621125M5V
3.1577403844249683.0596228361838076159.931528833544933e-101.1792543689064683F8V
2.358628131504372-1.557299020469622326.093043334547767e-200.012963210764621674M6V
1.4521739653435157-0.851382522869428322.1990614865733614e-140.117485467623293M6V
-0.45657045898361540.18085670454520986295.555250603467652e-130.26443896759352503M3V
-4.28802070519306264.243801810096584274.805552069892325e-120.48208630286109483M1V
-1.07173986642689873.7082294509014195321.471179396509044e-150.08623356844839875M6V
2.12248367569153061.1488760649099696324.0087183177773387e-170.05865254767345462M6V
-4.8865711479535051.7463696161882218299.928282883555495e-130.3244795598952535M3V

Here we can see the spatial information is in the form of an astropy.Table.

The columns x and y show the position of each star in arcsec relative to the centre of the field of view.

The column ref connects each star in this table to a spectrum in the following list:

[3]:
src.spectra
[3]:
[<synphot.spectrum.SourceSpectrum object at 0x7fb8e6488b80>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8e6488760>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f47945e0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4794790>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f463edf0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f465df10>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f463e910>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f466afd0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f477ff70>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f463ed00>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46f8d90>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4706a90>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4706af0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f466a910>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4717e20>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f465db50>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4706610>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4724e20>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4730fd0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f47065b0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f47068b0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46c2ca0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4730df0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8fe602d00>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f47248b0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8e60c55e0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f47300a0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46c2eb0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46dea60>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f4730580>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46dc2e0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46b0d30>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46dc040>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46a3fd0>,
 <synphot.spectrum.SourceSpectrum object at 0x7fb8f46deac0>]

When ScopeSim ingests this Source object, it will look primarily at these three columns.

Now for a graphical representation of the cluster as it will be seen by ScopeSim:

[4]:
import matplotlib.pyplot as plt

plt.figure(figsize=(8, 8))
plt.plot(src.fields[0]["x"], src.fields[0]["y"], '.')
plt.xlabel("X [arcsec]")
plt.ylabel("Y [arcsec]")
[4]:
Text(0, 0.5, 'Y [arcsec]')
../_images/notebooks_stellar_8_1.png

Star Grid and Field

These are two functions that are good to test simulations quickly

[5]:
from scopesim_templates.stellar import star_field, star_grid

field = star_field(n=400, mmin=15, mmax=25, width=20, height=20, filter_name="Ks")
grid = star_grid(n=400, mmin=15, mmax=25, separation=1 , filter_name="Ks")

plt.figure(figsize=(14, 7))
plt.subplot(121)

size =  np.log10(field.fields[0]["weight"])**2
plt.scatter(field.fields[0]["x"], field.fields[0]["y"], s=size, marker="o")

plt.subplot(122)

size =  np.log10(grid.fields[0]["weight"])**2
plt.scatter(grid.fields[0]["x"], grid.fields[0]["y"], s=size, marker="o")
['A0V']
['A0V']
[5]:
<matplotlib.collections.PathCollection at 0x7fb8e090f460>
../_images/notebooks_stellar_10_2.png

In both cases we generated 400 sources between magnitudes 15 (mmin) and 25 (mmax).

star_field places the stars at random, whereas star_grid place them in a regular partern controled by separation distance.

The size of the simbols illustrate the magnitudes of the stars

Stars

The core of the stellar module is however the star function which can create any field according to the user needs

In this case we generate a stellar field following a 2D gaussian distribution with a star of every type in the pickles stellar library

[6]:
from scopesim_templates.stellar import stars
from spextra.database import SpecLibrary

[7]:
lib = SpecLibrary("pickles")

spectypes = lib.template_names
nstars = len(spectypes)

x = np.random.randn(nstars) * 10
y = np.random.randn(nstars) * 10
mags = np.linspace(10, 20, nstars)

src = stars(filter_name="J", amplitudes=mags, x=x, y=y, spec_types=spectypes, library="pickles")
[8]:
src.fields
[8]:
[<Table length=131>
          x                   y           ref   weight spec_types
        arcsec              arcsec
       float64             float64       int64 float64    str6
 ------------------- ------------------- ----- ------- ----------
   2.007451224861396  0.1681071655341375   105     1.0        o5v
   8.593728449012035  1.0022428226715767   106     1.0      o8iii
  15.794690993340524   1.048888607243668   107     1.0        o9v
 0.12354371714603121  2.9528383261426407    13     1.0        b0i
 -0.4828399272073905 -1.8187067436493747    14     1.0        b0v
   8.269207260479128 -3.4031373210003206    15     1.0     b12iii
   8.302089462394221  -9.269016047589648    16     1.0        b1i
   6.231844521598118  -6.148941889604722    17     1.0        b1v
 -1.6268286899162279   18.51644268014349    18     1.0       b2ii
 -0.3335389243832958 0.45403662143450824    19     1.0       b2iv
  -6.112911809076027   8.548989247553019    20     1.0        b3i
 -18.560993941068592 -2.7797644404218276    21     1.0      b3iii
                 ...                 ...   ...     ...        ...
  14.288097551509324   5.393734390407308    94     1.0      m3iii
 -3.4645252882727835  -7.660729789710751    95     1.0        m3v
  11.695467015092449 -0.9015068233794685    96     1.0      m4iii
 -3.8953999312417196  -3.202120466135513    97     1.0        m4v
  21.966363419323997 -13.237923825721369    98     1.0      m5iii
 -1.0680582531325613 -11.609390621966567    99     1.0        m5v
  12.865638982994145   3.020365939546597   100     1.0      m6iii
    6.38962463871831  -6.146996576751654   101     1.0        m6v
 -16.111343878523737  11.306217143666768   102     1.0      m7iii
  -4.618571067109303  10.398491786225657   103     1.0      m8iii
 -0.4056773956303084  19.390809913922574   104     1.0      m9iii
  13.552636359858983  -8.507559747977913    86     1.0     m10iii]