aosss.physics package

Submodules

aosss.physics.photometry module

aosss.physics.photometry.calculate_magnitude(sp, bp, system='stdflux', zero_point=0.0, flag_force_band_range=False)

Calculates magnitude from a Spectrum object.

Parameters:
  • spf311.Spectrum instance. flux unit must be erg/cm**2/s/Hz aka “Fnu”
  • bp

    Bandpass object, or string in “UBVRIYJHKLMNQ”. How it works:

    • If string in “UBVRI”, creates a UBVTabular Bandpass object;
    • If string otherwise, creates a UBVParametric object.
  • system

    reference magnitude system. Possible values:

    • "stdflux": literature reference values for bands U,B,V,R,I,J,H,K only
    • "vega": uses the Vega star spectrum as a reference
    • "ab": AB[solute] magnitude system
  • zero_point – subtracts this value from the calculated magnitude to implement some desired correction.
  • flag_force_band_range

    this flag has effect when the spectrum does not completely overlap the bandpass filter. How it works:

    • False (default): restricts the weighted mean flux calculation to the overlap range between the spectrum and the filter
    • True: zero-fill the spectrum to overlap the filter range completely
Returns:

dictionary with the following keys:

  • "calc_l0": lower edge of wavelength interval considered,
  • "calc_lf": upper edge of wavelength interval considered,
  • "filtered_sp": filtered spectrum
  • "filtered_sp_area": area of filtered spectrum within [calc_l0, calc_lf]
  • "weighted_mean_flux": weighted mean of flux; weights are band values
  • "zero_flux": flux value for which magnitude is zero
  • "cmag": calculated magnitude

Return type:

dict

Example:

>>> from aosss import physics as ph
... ph.calculate_magnitude(ph.get_vega_spectrum(), "U", "stdflux", 0, False)
aosss.physics.photometry.get_vega_spectrum()

Returns a spectrum of the Vega star

Creates a new f311.filetypes.Spectrum object at every call

Returns:spectrum
Return type:f311.filetypes.Spectrum
class aosss.physics.photometry.Bandpass(name)

Bases: object

Wavelength filter band, with class tools

This class is kept clean whereas UBVRIBands has examples and deeper documentation on parameters

Parameters:name
area(l0, lf)

Calculates area (unit: a.u.*angstrom) under given range [l0, lf] :param l0: lower edge of range :param lf: upper edge of range

l0
lf
ufunc(flag_force_parametric=False)
class aosss.physics.photometry.UBVTabulated(name)

Bases: aosss.physics.photometry.Bandpass

Tabular filter

Parameters:name – band name. Choices: U,B,V,R,I
DATA = OrderedDict([('U', ((3000, 0.0), (3050, 0.016), (3100, 0.068), (3150, 0.167), (3200, 0.287), (3250, 0.423), (3300, 0.56), (3350, 0.673), (3400, 0.772), (3450, 0.841), (3500, 0.905), (3550, 0.943), (3600, 0.981), (3650, 0.993), (3700, 1.0), (3750, 0.989), (3800, 0.916), (3850, 0.804), (3900, 0.625), (3950, 0.423), (4000, 0.238), (4050, 0.114), (4100, 0.051), (4150, 0.019), (4200, 0.0))), ('B', ((3600, 0.0), (3700, 0.03), (3800, 0.134), (3900, 0.567), (4000, 0.92), (4100, 0.978), (4200, 1.0), (4300, 0.978), (4400, 0.935), (4500, 0.853), (4600, 0.74), (4700, 0.64), (4800, 0.536), (4900, 0.424), (5000, 0.325), (5100, 0.235), (5200, 0.15), (5300, 0.095), (5400, 0.043), (5500, 0.009), (5600, 0.0))), ('V', ((4700, 0.0), (4800, 0.03), (4900, 0.163), (5000, 0.458), (5100, 0.78), (5200, 0.967), (5300, 1.0), (5400, 0.973), (5500, 0.898), (5600, 0.792), (5700, 0.684), (5800, 0.574), (5900, 0.461), (6000, 0.359), (6100, 0.27), (6200, 0.197), (6300, 0.135), (6400, 0.081), (6500, 0.045), (6600, 0.025), (6700, 0.017), (6800, 0.013), (6900, 0.009), (7000, 0.0))), ('R', ((5500, 0.0), (5600, 0.23), (5700, 0.74), (5800, 0.91), (5900, 0.98), (6000, 1.0), (6100, 0.98), (6200, 0.96), (6300, 0.93), (6400, 0.9), (6500, 0.86), (6600, 0.81), (6700, 0.78), (6800, 0.72), (6900, 0.67), (7000, 0.61), (7100, 0.56), (7200, 0.51), (7300, 0.46), (7400, 0.4), (7500, 0.35), (8000, 0.14), (8500, 0.03), (9000, 0.0))), ('I', ((7000, 0.0), (7100, 0.024), (7200, 0.232), (7300, 0.555), (7400, 0.785), (7500, 0.91), (7600, 0.965), (7700, 0.985), (7800, 0.99), (7900, 0.995), (8000, 1.0), (8100, 1.0), (8200, 0.99), (8300, 0.98), (8400, 0.95), (8500, 0.91), (8600, 0.86), (8700, 0.75), (8800, 0.56), (8900, 0.33), (9000, 0.15), (9100, 0.03), (9200, 0.0)))])
ufunc(flag_force_parametric=False)
class aosss.physics.photometry.UBVParametric(name, num_stds=3)

Bases: aosss.physics.photometry.Bandpass

Parametric Gaussian filter

Parameters:
  • name – band name. Choices: U,B,V,R,I,Y,J,H,K,L,M,N,Q
  • num_stds=3 – number of standard deviations to left and right of midpoint to consider as band limits. Does not affect self.ufunc()
X0_FWHM = OrderedDict([('U', (3650.0, 660.0)), ('B', (4450.0, 940.0)), ('V', (5510.0, 880.0)), ('R', (6580.0, 1380.0)), ('I', (8060.0, 1490.0)), ('Y', (10200.0, 1200.0)), ('J', (12200.0, 2130.0)), ('H', (16300.0, 3070.0)), ('K', (21900.0, 3900.0)), ('L', (34500.0, 4720.0)), ('M', (47500.0, 4600.0)), ('N', (105000.0, 25000.0)), ('Q', (210000.0, 58000.0))])
ufunc(flag_force_parametric=False)
aosss.physics.photometry.get_ubv_bandpasses()

Returns list with UBVRI… Bandpass objects

aosss.physics.photometry.get_zero_flux(bp, system='stdflux')

Returns flux (erg/cm**2/s/Hz) for which magnitude is zero

Parameters:
  • bp – Bandpass object, or band name, e.g., “U”
  • system – {“stdflux”, “ab”, “vega”} reference magnitude system

For more on arguments, see calculate_magnitude()

Returns: float

aosss.physics.photometry.flux_to_mag(flux, bp, system='stdflux', zero_point=0.0)

Calculates magnitude for a single scalar flux value

Parameters:
  • flux – float (erg/cm**2/s/Hz), of Spectrum instance
  • system, zero_point (bp,) – see calculate_magnitude()
Returns:

float

aosss.physics.photometry.mag_to_flux(mag, bp, system='stdflux')

Inverse of calc_mag()

aosss.physics.photometry.get_ubv_bandpass(bp)

Returns a BandPass object for given band name

Parameters:bp – band name or BandPass object
Returns:BandPass object. If bp is already a BandPass object, returns bp
Return type:BandPass
aosss.physics.photometry.get_ubv_bandpasses_dict()

Returns dictionary with band name, i.e., U/B/V/etc. as dict

aosss.physics.photometry.calc_mag(sp, bp, system='stdflux', zero_point=0.0, flag_force_band_range=False)

Calculates magnitude from a Spectrum object. See calculate_magnitude for arguments documentation

Returns: (float) calculated magnitude

Example:

>>> import aosss.physics as ph
>>> import tabulate
>>> systems = ["stdflux", "ab", "vega"]
>>> bands = "UBVRIJHK"
>>> sp = ph.get_vega_spectrum()
>>> rows = [([band]+[ph.calc_mag(sp, band, system) for system in systems]) for band in bands]
>>> print(tabulate.tabulate(rows, ["band"]+systems))
band        stdflux          ab    vega
------  -----------  ----------  ------
U        0.00572505   0.761594       -0
B        0.0696287   -0.10383        -0
V        0.0218067    0.0191189      -0
R        0.0359559    0.214645       -0
I        0.0661095    0.449825       -0
J       -0.0150993    0.874666       -0
H        0.0315447    1.34805        -0
K        0.0246046    1.85948        -0

aosss.physics.rainbow module

Rainbow colors

Example:

>>> for color in rainbow_colors:
...     color
Color('Violet', [ 0.54509804  0.          1.        ], 4000.0, 3775.0, 4225.0)
Color('Indigo', [ 0.29411765  0.          0.50980392], 4450.0, 4225.0, 4600.0)
Color('Blue', [ 0.  0.  1.], 4750.0, 4600.0, 4925.0)
Color('Green', [ 0.  1.  0.], 5100.0, 4925.0, 5400.0)
Color('Yellow', [ 1.  1.  0.], 5700.0, 5400.0, 5800.0)
Color('Orange', [ 1.          0.49803922  0.        ], 5900.0, 5800.0, 6200.0)
Color('Red', [ 1.  0.  0.], 6500.0, 6200.0, 6800.0)

Example:

>>> import aosss
>>> import matplotlib.pyplot as plt
>>> for color in aosss.rainbow_colors:
...     _ = plt.fill_between([color.l0, color.lf], [1., 1.], color=color.rgb, label=color.name)
>>> _ = plt.legend(loc=0)
>>> _ = plt.xlabel('Wavelength (angstrom)')
>>> _ = plt.tight_layout()
>>> _ = plt.show()
class aosss.physics.rainbow.Color(name, rgb, clambda, l0=-1, lf=-1)

Bases: a99.parts.AttrsPart

Definition of a color: name, RGB code, wavelength range

attrs = ['name', 'rgb', 'clambda', 'l0', 'lf']
aosss.physics.rainbow.rainbow_colors = [Color('Violet', [ 0.54509804 0. 1. ], 4000.0, 3775.0, 4225.0), Color('Indigo', [ 0.29411765 0. 0.50980392], 4450.0, 4225.0, 4600.0), Color('Blue', [ 0. 0. 1.], 4750.0, 4600.0, 4925.0), Color('Green', [ 0. 1. 0.], 5100.0, 4925.0, 5400.0), Color('Yellow', [ 1. 1. 0.], 5700.0, 5400.0, 5800.0), Color('Orange', [ 1. 0.49803922 0. ], 5900.0, 5800.0, 6200.0), Color('Red', [ 1. 0. 0.], 6500.0, 6200.0, 6800.0)]

Rainbow colors

aosss.physics.sp2rgb module

aosss.physics.sp2rgb.spectrum_to_rgb(spectrum, visible_range=None, method=1)

Takes weighted average of rainbow colors RGB’s using spectrum.y as weights

Parameters:
  • spectrum – f311.Spectrum object
  • visible_range – (default: [4000, 7000]) (angstrom) if passed, affine-transforms the rainbow colors
  • -- (method) – 0: rainbow colors 1: RGB (reproduces better the colors of the stars in the sky)
Returns:

[red, green, blue] where values range from 0 to 1

Return type:

np.array

Module contents