<jupyter_start><jupyter_text>Magentic field lines animation<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import astropy.io.fits as fits
import os
import glob
from astropy.table import Table
from astropy.io import ascii
import astropy.units as u
import astropy.constants as const

from matplotlib.patches import Circle

#matplotlib set up
%matplotlib inline
from matplotlib import rcParams
rcParams["figure.figsize"] = (14, 5)
rcParams["font.size"] = 20

#from https://scipython.com/blog/visualizing-the-earths-magnetic-field/

# Mean magnitude of the Earth's magnetic field at the equator in T
B0 = 60
# Radius of Earth, Mm (10^6 m: mega-metres!)
RE = 0.0179*u.Rsun.to(u.m)*1e-6
# Deviation of magnetic pole from axis
alpha = np.radians(90)

def B(r, theta):
    """Return the magnetic field vector at (r, theta)."""
    fac = B0 * (RE / r)**3
    return -2 * fac * np.cos(theta + alpha), -fac * np.sin(theta + alpha)

# Grid of x, y points on a Cartesian grid
nx, ny = 64, 64
XMAX, YMAX = 40, 40
x = np.linspace(-XMAX, XMAX, nx)
y = np.linspace(-YMAX, YMAX, ny)
X, Y = np.meshgrid(x, y)
r, theta = np.hypot(X, Y), np.arctan2(Y, X)

# Magnetic field vector, B = (Ex, Ey), as separate components
Br, Btheta = B(r, theta)
# Transform to Cartesian coordinates: NB make North point up, not to the right.
c, s = np.cos(np.pi/2 + theta), np.sin(np.pi/2 + theta)
Bx = -Btheta * s + Br * c
By = Btheta * c + Br * s

fig, ax = plt.subplots()

# Plot the streamlines with an appropriate colormap and arrow style
color = -2* np.log(np.hypot(Bx, By))
ax.streamplot(x, y, Bx, By, color=color, linewidth=1, cmap=plt.cm.cool,
              density=0.7, arrowstyle='->', arrowsize=1.5)

# Add a filled circle for the Earth; make sure it's on top of the streamlines.
ax.add_patch(Circle((0,0), RE, color='#08F7FE', zorder=100))

# ax.set_xlabel('$x$')
# ax.set_ylabel('$y$')
ax.set_xlim(-XMAX-10, XMAX+10)
ax.set_ylim(-YMAX-10, YMAX+10)
ax.set_aspect('equal')
col= '#000033'
bgcol ='#000033'
col='k'
bgcol='k'
fig.patch.set_facecolor(bgcol)
ax.set_facecolor(bgcol)
ax.spines['bottom'].set_color(col)
ax.spines['top'].set_color(col) 
ax.spines['right'].set_color(col)
ax.spines['left'].set_color(col)
#plt.grid(zorder=-10)
# plt.xlabel(r'X (R$_{\bigodot}$)')
# plt.ylabel(r'Y (R$_{\bigodot}$)')
plt.xticks(visible=False)
plt.yticks(visible=False)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15912897822445563, 'fraction_numerical': 0.02931323283082077, 'mean_word_length': 4.530092592592593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '197766', 'license': 'MIT', 'n_tokens_mistral': 1009, 'n_tokens_neox': 951, 'n_words': 259, 'path': '.ipynb_checkpoints/mag_am_test-checkpoint.ipynb', 'repo_name': 'davidjwilson/pceb', 'size': '2388'}