Skip to content

Commit

Permalink
MNT: Formatting and type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
greglucas committed Dec 18, 2024
1 parent 7949d9f commit 2cb8b1b
Show file tree
Hide file tree
Showing 10 changed files with 548 additions and 392 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
docs/source/examples
docs/source/reference/generated
docs/source/sg_execution_times.rst

led / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018-2020 Greg Lucas
Copyright (c) 2018 Greg Lucas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
86 changes: 37 additions & 49 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
#
import os
import sys

import pysecs

sys.path.append(os.path.abspath('..'))
sys.path.append('..')

sys.path.append(os.path.abspath(".."))
sys.path.append("..")


# -- General configuration ---------------------------------------------
Expand All @@ -33,37 +35,36 @@

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.githubpages', # Helpful for publishing to gh-pages
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinx_gallery.gen_gallery',
]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.githubpages", # Helpful for publishing to gh-pages
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx_gallery.gen_gallery",
]

autosummary_generate = True

napoleon_google_docstring = False

intersphinx_mapping = {
'numpy': ('https://docs.scipy.org/doc/numpy/', None)
}
intersphinx_mapping = {"numpy": ("https://numpy.org/doc/stable/", None)}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'pysecs'
copyright = "2018-2021, Greg Lucas"
project = "pysecs"
copyright = "2018-, Greg Lucas"
author = "Greg Lucas"

# The version info for the project you're documenting, acts as replacement
Expand All @@ -75,20 +76,13 @@
# The full version, including alpha/beta/rc tags.
release = pysecs.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'lovelace'
pygments_style = "lovelace"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -99,12 +93,12 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'pydata_sphinx_theme'
html_theme = "pydata_sphinx_theme"

html_logo = "_static/pysecs.png"

html_theme_options = {
"github_url": "https://github.com/greglucas/pysecs",
"github_url": "https://github.com/greglucas/pysecs",
}

# Add any paths that contain custom static files (such as style sheets) here,
Expand All @@ -116,16 +110,16 @@

# Sphinx gallery
sphinx_gallery_conf = {
'examples_dirs': '../../examples', # path to example scripts
'gallery_dirs': 'examples', # path for where to save generated output
'matplotlib_animations': True,
"examples_dirs": "../../examples", # path to example scripts
"gallery_dirs": "examples", # path for where to save generated output
"matplotlib_animations": True,
}


# -- Options for HTMLHelp output ---------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'pysecsdoc'
htmlhelp_basename = "pysecsdoc"


# -- Options for LaTeX output ------------------------------------------
Expand All @@ -134,15 +128,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -152,21 +143,15 @@
# (source start file, target name, title, author, documentclass
# [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pysecs.tex',
'pysecs Documentation',
'Greg Lucas', 'manual'),
(master_doc, "pysecs.tex", "pysecs Documentation", "Greg Lucas", "manual"),
]


# -- Options for manual page output ------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pysecs',
'pysecs Documentation',
[author], 1)
]
man_pages = [(master_doc, "pysecs", "pysecs Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------
Expand All @@ -175,10 +160,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pysecs',
'pysecs Documentation',
author,
'pysecs',
'Spherical Elementary Current Systems in Python.',
'Miscellaneous'),
(
master_doc,
"pysecs",
"pysecs Documentation",
author,
"pysecs",
"Spherical Elementary Current Systems in Python.",
"Miscellaneous",
),
]
25 changes: 14 additions & 11 deletions examples/plot_B_divergence_free.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
an SECS pole placed at the north pole. Figure 2 from
Amm and Viljanen 1999.
"""

import matplotlib.pyplot as plt
import numpy as np

from pysecs import SECS


# Radius of Earth
R_E = 6378e3

# Pole of the current system at the North Pole
sec_loc = np.array([90., 0., R_E + 100e3])
sec_loc = np.array([90.0, 0.0, R_E + 100e3])

# Set up the system with a single SEC
system_df = SECS(sec_df_loc=sec_loc)
Expand All @@ -33,27 +36,27 @@
pred_loc = np.zeros(shape=(N, 3))
angles = np.linspace(0, 45, N)

pred_loc[:, 0] = 90-angles
pred_loc[:, 0] = 90 - angles
pred_loc[:, 2] = R_E

B_pred = system_df.predict(pred_loc=pred_loc)

# B_theta == -Bx == -B_pred[:,0]
# Convert to nT (1e9)
B_theta = -B_pred[:, 0]*1e9
B_theta = -B_pred[:, 0] * 1e9
# B_r == -Bz = -B_pred[:,2]
B_r = -B_pred[:, 2]*1e9
B_r = -B_pred[:, 2] * 1e9

fig, ax = plt.subplots()

ax.plot(angles, B_theta, c='b', label=r'B$_{\theta}$')
ax.plot(angles, B_r, c='r', label=r'B$_r$')
ax.legend(loc='upper right')
ax.plot(angles, B_theta, c="b", label=r"B$_{\theta}$")
ax.plot(angles, B_r, c="r", label=r"B$_r$")
ax.legend(loc="upper right")
ax.set_xlim(angles[0], angles[-1])
ax.set_ylim(-5, 10)
ax.set_xlabel('Angle from pole (deg)')
ax.set_ylabel('B (nT)')
ax.axhline(0., c='k', alpha=0.5, linewidth=0.5)
ax.set_title('Amm and Viljanen (1999) Figure 2')
ax.set_xlabel("Angle from pole (deg)")
ax.set_ylabel("B (nT)")
ax.axhline(0.0, c="k", alpha=0.5, linewidth=0.5)
ax.set_title("Amm and Viljanen (1999) Figure 2")

plt.show()
58 changes: 33 additions & 25 deletions examples/plot_J_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
This example demonstrates the resulting current surfaces
from the curl-free and divergence-free SEC poles.
"""

import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import numpy as np
from matplotlib.colors import LogNorm

from pysecs import SECS


# Radius of Earth
R_E = 6378e3

# Pole of the current system at the North Pole
sec_loc = np.array([90., 0., R_E + 100e3])
sec_loc = np.array([90.0, 0.0, R_E + 100e3])

# Set up the system with a single SEC
system_df = SECS(sec_df_loc=sec_loc)
Expand All @@ -39,16 +42,16 @@
lats = np.arange(lat_min, lat_max, delta)
lons = np.arange(lon_min, lon_max, delta)

lats2 = np.arange(lat_min-delta/2, lat_max+delta/2, delta)
lons2 = np.arange(lon_min-delta/2, lon_max+delta/2, delta)
lats2 = np.arange(lat_min - delta / 2, lat_max + delta / 2, delta)
lons2 = np.arange(lon_min - delta / 2, lon_max + delta / 2, delta)

nlat = len(lats)
nlon = len(lons)

xx, yy = np.meshgrid(lons, lats)
xx2, yy2 = np.meshgrid(lons2, lats2)

points = np.zeros((nlat*nlon, 3))
points = np.zeros((nlat * nlon, 3))
points[:, 0] = yy.ravel()
points[:, 1] = xx.ravel()
points[:, 2] = R_E
Expand All @@ -70,33 +73,38 @@
J_cf_theta = np.linalg.norm(J_cf[:, :2], axis=1).reshape(nlat, nlon)
J_cf_r = J_cf[:, 2].reshape(nlat, nlon)

fig, (ax_cf, ax_df) = plt.subplots(figsize=(8, 3), ncols=2,
constrained_layout=True)
fig.suptitle('Amm and Viljanen (1999) Figure 1')
fig, (ax_cf, ax_df) = plt.subplots(figsize=(8, 3), ncols=2, constrained_layout=True)
fig.suptitle("Amm and Viljanen (1999) Figure 1")

# Limit quiver to only a few points
nstep = 30

norm = LogNorm(vmin=1e-5, vmax=1e-2)
cax = ax_cf.pcolormesh(xx2, yy2, J_cf_theta, norm=norm)
ax_cf.quiver(xx[nstep//2::nstep, nstep//2::nstep*2],
yy[nstep//2::nstep, nstep//2::nstep*2],
J_cf_y[nstep//2::nstep, nstep//2::nstep*2],
J_cf_x[nstep//2::nstep, nstep//2::nstep*2],
color='w', zorder=9)
ax_cf.set_ylabel('Latitude (deg)')
ax_cf.set_xlabel('Longitude (deg)')
ax_cf.quiver(
xx[nstep // 2 :: nstep, nstep // 2 :: nstep * 2],
yy[nstep // 2 :: nstep, nstep // 2 :: nstep * 2],
J_cf_y[nstep // 2 :: nstep, nstep // 2 :: nstep * 2],
J_cf_x[nstep // 2 :: nstep, nstep // 2 :: nstep * 2],
color="w",
zorder=9,
)
ax_cf.set_ylabel("Latitude (deg)")
ax_cf.set_xlabel("Longitude (deg)")

cax = ax_df.pcolormesh(xx2, yy2, J_df_phi, norm=norm)
ax_df.quiver(xx[nstep//2::nstep, nstep//2::nstep*2],
yy[nstep//2::nstep, nstep//2::nstep*2],
J_df_y[nstep//2::nstep, nstep//2::nstep*2],
J_df_x[nstep//2::nstep, nstep//2::nstep*2],
color='w', zorder=9)
ax_df.set_ylabel('Latitude (deg)')
ax_df.set_xlabel('Longitude (deg)')

ax_cf.set_title('Curl Free')
ax_df.set_title('Divergence Free')
ax_df.quiver(
xx[nstep // 2 :: nstep, nstep // 2 :: nstep * 2],
yy[nstep // 2 :: nstep, nstep // 2 :: nstep * 2],
J_df_y[nstep // 2 :: nstep, nstep // 2 :: nstep * 2],
J_df_x[nstep // 2 :: nstep, nstep // 2 :: nstep * 2],
color="w",
zorder=9,
)
ax_df.set_ylabel("Latitude (deg)")
ax_df.set_xlabel("Longitude (deg)")

ax_cf.set_title("Curl Free")
ax_df.set_title("Divergence Free")

plt.show()
Loading

0 comments on commit 2cb8b1b

Please sign in to comment.