Skip to content

Commit

Permalink
sunpy.sun python file review
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Mar 18, 2019
1 parent dfd2c5a commit 0b210fa
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 168 deletions.
11 changes: 2 additions & 9 deletions sunpy/sun/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
"""
Contains astronomical and physical constants for use in SunPy or other
places.
"""

import sunpy.sun.constants as constants
from sunpy.sun._constants import *
from sunpy.sun.sun import *

from . import _constants
from . import constants
20 changes: 5 additions & 15 deletions sunpy/sun/_constants.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
"""
Collection of solar physical constants.
The list is not meant to be comprehensive, but just a convenient list for
everyday use.
.. todo:: Need better sources for some constants as well as error values.
This module provies a non-comprehensive collection of solar physical constants.
"""

from astropy.constants import Constant

# We want to keep the old constants for now.
# TODO: Need better sources for some constants as well as error values.
# This is to keep the old solar values until we make the choice to move to IAU2015 Values
import astropy
if int(astropy.__version__[0]) >= 2:
import astropy.constants.astropyconst13 as astrocon
else:
import astropy.constants as astrocon
import astropy.constants.astropyconst13 as astrocon
from astropy.constants import Constant

__all__ = ['physical_constants']

Expand Down
49 changes: 17 additions & 32 deletions sunpy/sun/constants.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
"""
Fundamental Solar Physical Constants
------------------------------------
These constants are taken from various sources. The structure of this module is heavily
based on if not directly copied from the SciPy constants module but contains Solar
Physical constants.
This module provides fundamental solar physical constants.
"""

from astropy.table import Table

from sunpy.sun import _constants as _con # pylint: disable=E0611
from sunpy.sun import _constants as _con

__all__ = [
'get', 'find', 'print_all', 'spectral_classification', 'au', 'mass', 'equatorial_radius',
Expand All @@ -26,17 +21,17 @@ def get(key):
Parameters
----------
key : Python string or unicode
Key in dictionary in `constants`
key : `str`
Key in dictionary in ``constants``.
Returns
-------
constant : `~astropy.units.Constant`
constant : `~astropy.units.Constant`
See Also
--------
_constants : Contains the description of `constants`, which, as a
dictionary literal object, does not itself possess a docstring.
`sunpy.sun.constants`
Contains the description of ``constants``, which, as a dictionary literal object, does not itself possess a docstring.
Examples
--------
Expand All @@ -49,45 +44,39 @@ def get(key):

def find(sub=None):
"""
Return list of constants keys containing a given string
Return list of constants keys containing a given string.
Parameters
----------
sub : str, unicode
Sub-string to search keys for. By default, return all keys.
sub : `str`, optional
Sub-string to search keys for. By default set to `None` and returns all keys.
Returns
-------
keys : None or list
`None`, `list`
The matching keys.
See Also
--------
_constants : Contains the description of `constants`, which, as a
dictionary literal object, does not itself possess a docstring.
`sunpy.sun.constants`
Contains the description of ``constants``, which, as a dictionary literal object, does not itself possess a docstring.
"""
if sub is None:
result = list(constants.keys())
else:
result = [key for key in constants \
if sub.lower() in key.lower()]
result = [key for key in constants if sub.lower() in key.lower()]

result.sort()
return result


def print_all(key=None):
def print_all():
"""
Provides a table of the complete list of constants.
Parameters
----------
key : Python string or unicode
Key in dictionary `constants`
Returns
-------
table : `astropy.table.Table`
`astropy.table.Table`
"""
data_rows = []
for key, this_constant in constants.items():
Expand All @@ -102,9 +91,7 @@ def print_all(key=None):

# Spectral class is not included in physical constants since it is not a number
spectral_classification = 'G2V'

au = astronomical_unit = get('mean distance')

# The following variables from _gets are brought out by making them
# accessible through a call such as sun.volume
mass = get('mass')
Expand All @@ -117,8 +104,6 @@ def print_all(key=None):
luminosity = get('luminosity')
mass_conversion_rate = get('mass conversion rate')
escape_velocity = get('escape velocity')

sfu = get('solar flux unit')

# Observable parameters
average_angular_size = get('average angular size')
22 changes: 8 additions & 14 deletions sunpy/sun/models.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
"""
Solar Physical Models
---------------------
This module contains standard models of
the sun from various sources. All data is saved
in Astropy QTables with an added attribute
This module contains standard models of the Sun from various sources.
All data is saved in `astropy.table.QTable` with an added attribute:
* source : names the source of the data
Object
------
interior : `astropy.table.QTable`
The standard model of the solar interior
The standard model of the solar interior.
evolution : `astropy.table.QTable`
The evolution as a function of time of the Sun
.. todo:: Need source for evolution model.
The evolution as a function of time of the Sun.
References
----------
* Adapted from Turck-Chieze et al. (1988) with composition: X = 0.7046, Y = 0.2757, Z = 0.0197
"""

from astropy import units as u
from astropy.table import QTable
import sunpy.sun.constants as con

__all__ = ["interior", "evolution"]

# Solar radius measured outside earth's atmosphere in arcseconds

# Standard Model - Interior Structure
# adapted from Turck-Chieze et al. (1988)
# Composition X = 0.7046, Y = 0.2757, Z = 0.0197

# Radius - R_sun
_radius = [0, 0.01, 0.022, 0.061, 0.090, 0.120,
Expand Down
Loading

0 comments on commit 0b210fa

Please sign in to comment.