Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mag probe module - issues with astropy.units #69

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject
Expand Down
73 changes: 73 additions & 0 deletions hack/mag_probe_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 15 08:15:38 2022

@author: xuans
"""

'''An initial attempt to implement a magnetic pickup probe module.'''

import astropy.units as u

import numpy as np

from plasmapy.utils.decorators import validate_quantities

@validate_quantities(
validations_on_return=u.T
)
def probe_to_field(raw: u.V, turns, area: u.m**2, t_step: u.s) -> u.T:
'''Taking, as input, raw voltage from magnetic probe
(and number of coil turns) and convert it to magnetic field measurement
at that location.

We assume [raw] is an np.array of voltages. Turns is the number of turns
in the pick-up coil. Area is the area of a single turn in the pick-up coil.
t_step is the time step between consecutive voltage measurements,
assumed to be uniform given a fixed sampling frequency.

The output voltage depends on the rate of change of the magnetic flux.

The induced voltage in a circuit is proportional to the rate of change
over time of the magnetic flux through that circuit.

emf is measured in volts. We are given volts.

emf = - N dPhi_N/ dt

phi_B = surf_integral{B(t) dot dA}

To simplify, we assume we are computing the probe-aligned B field.
So phi_B_surf = B(t)_surf * A = B(t)_surf * turns * area
'''

# we assume instantaneous measurement of 0 to raw.
#raw = - turns * area * B_probe / t_step

B_probe = []

# now expand to an array of voltages with fixed time step time traces
for i, v in enumerate(raw):
mag_field = ((raw[i] - raw[i-1]) * t_step) / (turns * area)
B_probe.append(mag_field)

#B_probe = np.array(B_probe)


# include manual casting to Tesla as workaround
return B_probe#.to(u.T)


# provide synthetic signal - sine function TODO.
measured_volts = np.linspace(0, 10, 2) * u.mV
print(measured_volts)
#for i in range(len(measured_volts)):
# measured_volts[i] = measured_volts[i] * u.V
print(measured_volts)

measured_field = probe_to_field(measured_volts, 10, 0.1*0.1 * u.m**2, 0.01 * u.s)

print(measured_field)