Ejemplo n.º 1
0
def ConfigStar(mass=1.0):
    """
    Determines the radius (in solar radii), temperature (in K), and
    hexcolor of a star of given mass, assuming it is a main sequence star.

    Parameters
    ----------
    mass : float
            Mass of star in solar masses (default 1.0)

    Returns
    -------
    radius : float
              radius of star in units of solar radius.
    temp : float
              temperature of star in Kelvin
    hexcolor: string
              hexcolor corresponding to stellar temperature.
    """

    # Determine approximate radius in solar radii for both stars.
    radius = Rad_calc(mass)

    # Determines the approximate temperature of each star.
    temp = Temp_calc(mass)

    # Use scalar temperature to estimate hexcolor appropriate to each star
    hexcolor = tc.rgb2hex(tc.temp2rgb(temp))[0]

    return (radius, temp, hexcolor)
Ejemplo n.º 2
0
def OldStarMesh(temp=Te_Sun, rad=1,  scale=(1, 1, 1), pos=[0, 0, 0]):
    """
    This function creates a pythreejs object that represents a star using
    a texture based on public domain STEREO Heliographic map made with
    images taken of the Sun on Dec. 30, 2011.  Image downloaded from
       https://stereo.gsfc.nasa.gov/360blog/
    and had its brightness and resolution rescaled.

    Parameters
    ----------
    temp : float
            temperature of star in Kelvin (default 5777)
    rad : float
            radius of the star in system units (default 1)
    scale : tuple
             pythreejs scale in each dimension as tuple (default (1, 1, 1) )
    pos : list
           three-dimensional position as list (default [0, 0, 0] )

    Returns
    -------
    star : pythreejs.Mesh
              a spherical pythreejs Mesh object representing a star
    """

    # Check is position is a list
    if isinstance(pos, list):
        # Check if this is a list of 3 items
        if (len(pos) != 3):
            raise TypeError('pos passed to StarMesh must be list of 3 numbers')
        # Check that all the items in the list are numbers
        for this_pos in pos:
            try:
                i = float(this_pos)
            except ValueError:
                raise TypeError('ValueError: pos contains list item that is not a number.')
    else:
        raise TypeError('pos passed to StarMesh must be list of 3 numbers')

    # Check is scale is a tuple
    if isinstance(scale, tuple):
        if (len(scale) != 3):
            raise TypeError('scale passed to StarMesh must be tuple of 3 numbers')
    else:
        raise TypeError('scale must be a tuple')

    # Define color and texture of star surface
    hexcolor = tc.rgb2hex(tc.temp2rgb(float(temp)))[0]
    StarTexture = p3j.ImageTexture(imageUri='images/sun_surface.jpg')

    # Create sphere using MeshBasicMaterial (which is unaffected by lighting)
    StarSurface = p3j.MeshBasicMaterial(color=hexcolor, map=StarTexture)

    StarGeom = p3j.SphereBufferGeometry(radius=rad, widthSegments=32,
                                        heightSegments=16)
    return p3j.Mesh(geometry=StarGeom, material=StarSurface,
                    position=pos, scale=scale)
Ejemplo n.º 3
0
def StarMesh(temp=Te_Sun, rad=1, scale=(1, 1, 1), pos=[0, 0, 0]):
    """
    This function creates a pythreejs object that represents a star using
    a set of nested spheres that are partly transparent to simulate limb
    darkening.

    Parameters
    ----------
    temp : float
            temperature of star in Kelvin (default 5777)
    rad : float
            radius of the star in system units (default 1)
    scale : tuple
             pythreejs scale in each dimension as tuple (default (1, 1, 1) )
    pos : list
           three-dimensional position as list (default [0, 0, 0] )

    Returns
    -------
    star : pythreejs.Mesh
              a spherical pythreejs Mesh object representing a star
    """

    # Check is position is a list
    if isinstance(pos, list):
        # Check if this is a list of 3 items
        if (len(pos) != 3):
            raise TypeError('pos passed to StarMesh must be list of 3 numbers')
        # Check that all the items in the list are numbers
        for this_pos in pos:
            try:
                i = float(this_pos)
            except ValueError:
                raise TypeError(
                    'ValueError: pos contains list item that is not a number.')
    else:
        raise TypeError('pos passed to StarMesh must be list of 3 numbers')

    # Check is scale is a tuple
    if isinstance(scale, tuple):
        if (len(scale) != 3):
            raise TypeError(
                'scale passed to StarMesh must be tuple of 3 numbers')
    else:
        raise TypeError('scale must be a tuple')

    # Define color of star surface
    hexcolor = tc.rgb2hex(tc.temp2rgb(float(temp)))[0]

    # Number of transparent layers to use to build star
    layers = 20

    # Radial scaling
    drad = 0.97

    # Starting resolution
    N_azi, N_pol = 32, 16

    # Layer opacity
    tau = 0.4

    # Radii to use
    radii = rad * drad**np.array(range(layers - 1, -1, -1))

    # 3D object to represent star
    star = p3j.Object3D()

    # Build the object from inside out
    for i in range(layers):
        # Tweak number of vertices in sphere up for the outer surface sphere
        if (i > (layers - 2)):
            N_azi *= 2
            N_pol *= 2

        geom = p3j.SphereBufferGeometry(radius=radii[i],
                                        widthSegments=N_azi,
                                        heightSegments=N_pol,
                                        renderOrder=-i)

        material = p3j.MeshBasicMaterial(color=hexcolor,
                                         transparent=True,
                                         opacity=tau)
        star.add(p3j.Mesh(geom, material))

    # Set the position and scale of this mesh
    star.position = pos
    star.scale = scale

    return star