Contour plot of Earth's magnetic field in Python

In summary: No, you are making sense. The cylindrical coordinates are basically Cartesian coordinates in this case because the B_φ = 0.
  • #1
jackthestudent
3
0
OP warned about not using the homework template
The Earth's magnetic field is cylindrically symmetric and can be described using cylindrical coordinates, (ρ,z,φ). The components of the magnetic field are given by:

(B_φ) = 0

(B_ρ) = −∂A/∂z,

(B_z) =(1/ρ) * ∂(ρA)/∂ρ.

The vector potential for a dipole field is given by

(A_φ) = (B_e)(ρ) * (R_e)^3/r^3

where B_e and R_e are the equatorial surface magnetic field strength and the radius of the Earth, respectively, and r is the radial distance from the center of the planet. Magnetic field lines are given by contours of a flux function F given by

F = ρ(A_φ).

The Earth's surface magnetic field at the equator B_e is 3,120 nT and its radius R_e is 6,371 km.

Using this information, create a contour plot of the Earth's magnetic field along a bisecting plane covering ρ<20R_e (it's symmetric, so the horizontal coordinate goes from -20R_e to +20R_e and −10R_e < z< 10R_e. Use the following steps:

1) Start by creating the coordinate grids for ρ and z, and the radius r. A grid cell size of ~0.02 R_e should be fine.

2) Compute the vector potential A and the flux function F.

Show the magnetic field lines (which are contours of F, computed from A as shown above) in a plot using about 5 or so black lines roughly equally spaced at the equator.

-------------------------------------------------
I have created 2 arrays, one for rho and one for z and then I have turned them into a 2D array in the form of F, the flux function. This is what I have entered into the interpreter:

Re = 6371000
rho = np.linspace(-20*Re, 20*Re, 2000)
z1 = np.linspace(-10*Re, 10*Re, 2000)
z = z1[:, np.newaxis]
Be = 3120*10**(-9)
F = (rho**2)*Be*(Re/np.sqrt(rho**2 + z**2))**3
plt.contour(rho, z1, F)

It returns a contour map with one dot on zero and nothing else even though there should be several contours. I can't figure out what I've done wrong or what to try next? Any help would be greatly appreciated :)
 
Technology news on Phys.org
  • #2
I haven't gone through all of your code, but you haven't set up the plots properly. For one thing, the radius rho should never be negative. For another thing, what is the horizontal coordinate in your plots? You don't want it to be rho, you want to define an x-coordinate for plotting. A third thing I'm not clear on in your coordinate system is what is the difference between rho and r?
 
  • #3
Thank you for your help! It turns out the problem was that Matplotlib didn't automatically show any contours so I had to define the levels I wanted manually. This is the code I used (I have also changed rho and z to meshgrids):
Re = 6371000
rho1 = np.linspace(-20*Re, 20*Re, 2000)
z1 = np.linspace(-10*Re, 10*Re, 2000)
rho, z = np.meshgrid(rho1, z1)
Be = 3120*10**(-9)
r = np.sqrt(rho**2 + z**2)
F = rho**2*Be*(Re/r)**3
plt.contour(rho, z, F, [6E6, 7E6, 8E6, 9E6, 1E7], colors = 'k')

In answer to your questions:
rho is the horizontal coordinate, z is the vertical coordinate and r (the radius from the centre of the planet) is equal to sqrt(rho^2 + z^2). The cylindrical coordinates are basically Cartesian coordinates in this case because the B_φ = 0.
 
  • #4
jackthestudent said:
In answer to your questions:
rho is the horizontal coordinate, z is the vertical coordinate and r (the radius from the centre of the planet) is equal to sqrt(rho^2 + z^2). The cylindrical coordinates are basically Cartesian coordinates in this case because the B_φ = 0.

I think you're still confused on your coordinate system. In cylindrical coordinates, it is definitely not true that "The cylindrical coordinates are basically Cartesian coordinates in this case because the B_φ = 0" I suggest that you study these coordinate systems a little more.
 
  • Like
Likes berkeman
  • #5
phyzguy said:
I think you're still confused on your coordinate system. In cylindrical coordinates, it is definitely not true that "The cylindrical coordinates are basically Cartesian coordinates in this case because the B_φ = 0" I suggest that you study these coordinate systems a little more.

Sorry I worded that badly- I meant that rho and z are perpendicular to each other and when φ = 0 they form the opposite and adjacent sides of a right angled triangle so I could have used a Cartesian coordinate system in the first place (not that the cylindrical and Cartesian coordinates are the same) if I'm making any sense?
 

1. What is a contour plot?

A contour plot is a graphical representation of a 3-dimensional surface in 2 dimensions. It uses contour lines to show the values of a variable on a map or plot.

2. Why is it important to study Earth's magnetic field?

Earth's magnetic field plays a crucial role in protecting our planet from harmful solar radiation and cosmic rays. Understanding its behavior is important for predicting and mitigating the effects of space weather on our technology and environment.

3. How is the contour plot of Earth's magnetic field created in Python?

The contour plot can be created by using Python's "matplotlib" library, along with data from Earth's magnetic field models such as the International Geomagnetic Reference Field (IGRF). The data is processed and plotted using various functions and parameters to create the final contour plot.

4. What can we learn from the contour plot of Earth's magnetic field?

The contour plot can reveal the shape and strength of Earth's magnetic field at different locations, as well as any anomalies or changes over time. It can also provide insights into the underlying processes and dynamics of our planet's magnetic field.

5. How accurate is the contour plot of Earth's magnetic field in Python?

The accuracy of the contour plot depends on the quality and resolution of the data used, as well as the algorithms and methods used to process and plot the data. Generally, the contour plot can provide a good representation of Earth's magnetic field, but it may not capture small-scale variations or anomalies due to limitations in data and techniques.

Similar threads

  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
864
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
3
Views
754
  • Advanced Physics Homework Help
Replies
8
Views
7K
Replies
4
Views
3K
  • Introductory Physics Homework Help
Replies
10
Views
2K
  • Introductory Physics Homework Help
Replies
17
Views
3K
Back
Top