mirror of
https://github.com/JHUAPL/kaipy.git
synced 2026-01-09 14:28:02 -05:00
Add tests for msphViz
This commit is contained in:
@@ -18,11 +18,13 @@ def gamera_pipe(tmpdir):
|
||||
fdir = tmpdir.mkdir("data")
|
||||
ftag = "test"
|
||||
file_path = fdir.join("test.gam.h5")
|
||||
print(f'file_path: {file_path}')
|
||||
mjds = []
|
||||
with h5py.File(file_path, 'w') as f:
|
||||
f.create_dataset("X", data=np.zeros((Ni+1, Nj+1, Nk+1)))
|
||||
f.create_dataset("Y", data=np.zeros((Ni+1, Nj+1, Nk+1)))
|
||||
f.create_dataset("Z", data=np.zeros((Ni+1, Nj+1, Nk+1)))
|
||||
f.create_dataset("X", data=np.linspace(-100, 100, Ni+1).reshape(Ni+1, 1, 1).repeat(Nj+1, axis=1).repeat(Nk+1, axis=2).T)
|
||||
f.create_dataset("Y", data=np.linspace(-100, 100, Nj+1).reshape(1, Nj+1, 1).repeat(Ni+1, axis=0).repeat(Nk+1, axis=2).T)
|
||||
f.create_dataset("Z", data=np.linspace(-100, 100, Nk+1).reshape(1, 1, Nk+1).repeat(Ni+1, axis=0).repeat(Nj+1, axis=1).T)
|
||||
f.create_dataset("dV", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
for i in range(3):
|
||||
grp = f.create_group("Step#{}".format(i))
|
||||
grp.attrs['time'] = np.double(i)
|
||||
@@ -30,14 +32,17 @@ def gamera_pipe(tmpdir):
|
||||
grp.attrs['MJD'] = mjd
|
||||
mjds.append(mjd)
|
||||
grp.attrs['timestep'] = i
|
||||
grp.create_dataset("D", data=np.zeros((Ni, Nj, Nk)))
|
||||
grp.create_dataset("P", data=np.zeros((Ni, Nj, Nk)))
|
||||
grp.create_dataset("Bx", data=np.zeros((Ni, Nj, Nk)))
|
||||
grp.create_dataset("By", data=np.zeros((Ni, Nj, Nk)))
|
||||
grp.create_dataset("Bz", data=np.zeros((Ni, Nj, Nk)))
|
||||
grp.create_dataset("Vx", data=np.zeros((Ni, Nj, Nk)))
|
||||
grp.create_dataset("Vy", data=np.zeros((Ni, Nj, Nk)))
|
||||
grp.create_dataset("Vz", data=np.zeros((Ni, Nj, Nk)))
|
||||
grp.create_dataset("D", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("P", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("Bx", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("By", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("Bz", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("Vx", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("Vy", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("Vz", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("Jx", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("Jy", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
grp.create_dataset("Jz", data=np.zeros((Ni, Nj, Nk)).T)
|
||||
|
||||
file_path = fdir.join("test.mix.h5")
|
||||
lat = np.arange(Nlat+1)
|
||||
@@ -57,5 +62,13 @@ def gamera_pipe(tmpdir):
|
||||
grp.create_dataset("Potential SOUTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Field-aligned current NORTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Field-aligned current SOUTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Pedersen conductance NORTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Pedersen conductance SOUTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Hall conductance NORTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Hall conductance SOUTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Average energy NORTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Average energy SOUTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Number flux NORTH", data=np.zeros((Nlat, Nlon)))
|
||||
grp.create_dataset("Number flux SOUTH", data=np.zeros((Nlat, Nlon)))
|
||||
|
||||
return GamsphPipe(str(fdir), ftag, doFast=True, uID="Earth")
|
||||
150
tests/gamera/test_mspViz.py
Normal file
150
tests/gamera/test_mspViz.py
Normal file
@@ -0,0 +1,150 @@
|
||||
import pytest
|
||||
import numpy as np
|
||||
import os
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.gridspec as gridspec
|
||||
import argparse
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
import kaipy.remix.remix as remix
|
||||
from kaipy.gamera.msphViz import AddSizeArgs, GetSizeBds, PlotEqErrAbs, PlotEqErrRel, PlotLogicalErrAbs, PlotLogicalErrRel, CalcTotalErrAbs, CalcTotalErrRel, PlotEqB, PlotMerid, PlotJyXZ, PlotEqEphi, PlotMPI, AddIonBoxes, plotPlane, plotXY, plotXZ
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return argparse.ArgumentParser(formatter_class=RawTextHelpFormatter)
|
||||
|
||||
def test_AddSizeArgs(parser):
|
||||
AddSizeArgs(parser)
|
||||
args = parser.parse_args(['-size', 'big'])
|
||||
assert args.size == 'big'
|
||||
|
||||
def test_GetSizeBds():
|
||||
class Args:
|
||||
size = 'big'
|
||||
args = Args()
|
||||
result = GetSizeBds(args)
|
||||
assert result == [-100.0, 20.0, -60.0, 60.0]
|
||||
|
||||
def test_PlotEqErrAbs(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsphP = gamera_pipe
|
||||
gsphO = gamera_pipe
|
||||
fieldNames = ['Bz']
|
||||
xyBds = [-100, 100, -100, 100]
|
||||
result = PlotEqErrAbs(gsphP, gsphO, 0, xyBds, ax, fieldNames)
|
||||
assert isinstance(result, np.ndarray)
|
||||
|
||||
def test_PlotEqErrRel(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsphP = gamera_pipe
|
||||
gsphO = gamera_pipe
|
||||
fieldNames = ['Bz']
|
||||
xyBds = [-100, 100, -100, 100]
|
||||
result = PlotEqErrRel(gsphP, gsphO, 0, xyBds, ax, fieldNames)
|
||||
assert isinstance(result, np.ndarray)
|
||||
|
||||
def test_PlotLogicalErrAbs(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsphP = gamera_pipe
|
||||
gsphO = gamera_pipe
|
||||
fieldNames = ['Bz']
|
||||
result = PlotLogicalErrAbs(gsphP, gsphO, 0, ax, fieldNames, 0)
|
||||
assert isinstance(result, np.ndarray)
|
||||
|
||||
def test_PlotLogicalErrRel(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsphP = gamera_pipe
|
||||
gsphO = gamera_pipe
|
||||
fieldNames = ['Bz']
|
||||
result = PlotLogicalErrRel(gsphP, gsphO, 0, ax, fieldNames, 0)
|
||||
assert isinstance(result, np.ndarray)
|
||||
|
||||
def test_CalcTotalErrAbs(gamera_pipe):
|
||||
gsphP = gamera_pipe
|
||||
gsphO = gamera_pipe
|
||||
fieldNames = ['Bz']
|
||||
result = CalcTotalErrAbs(gsphP, gsphO, 0, fieldNames)
|
||||
assert isinstance(result, float)
|
||||
|
||||
def test_CalcTotalErrRel(gamera_pipe):
|
||||
gsphP = gamera_pipe
|
||||
gsphO = gamera_pipe
|
||||
fieldNames = ['Bz']
|
||||
result = CalcTotalErrRel(gsphP, gsphO, 0, fieldNames)
|
||||
assert isinstance(result, float)
|
||||
|
||||
def test_PlotEqB(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsph = gamera_pipe
|
||||
xyBds = [-100, 100, -100, 100]
|
||||
result = PlotEqB(gsph, 0, xyBds, ax)
|
||||
assert isinstance(result, np.ndarray)
|
||||
|
||||
def test_PlotMerid(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsph = gamera_pipe
|
||||
xyBds = [-100, 100, -100, 100]
|
||||
PlotMerid(gsph, 0, xyBds, ax)
|
||||
assert True # No return value to check
|
||||
|
||||
def test_PlotJyXZ(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsph = gamera_pipe
|
||||
xyBds = [-100, 100, -100, 100]
|
||||
PlotJyXZ(gsph, 0, xyBds, ax)
|
||||
assert True # No return value to check
|
||||
|
||||
def test_PlotEqEphi(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsph = gamera_pipe
|
||||
xyBds = [-100, 100, -100, 100]
|
||||
PlotEqEphi(gsph, 0, xyBds, ax)
|
||||
assert True # No return value to check
|
||||
|
||||
def test_PlotMPI(gamera_pipe):
|
||||
fig, ax = plt.subplots()
|
||||
gsph = gamera_pipe
|
||||
PlotMPI(gsph, ax)
|
||||
assert True # No return value to check
|
||||
|
||||
def test_AddIonBoxes(gamera_pipe):
|
||||
fig = plt.figure()
|
||||
gs = gridspec.GridSpec(3,6,height_ratios=[20,1,1],hspace=0.025)
|
||||
iontag = gamera_pipe.ftag.replace('.gam', '')
|
||||
ionfn = os.path.join(gamera_pipe.fdir, iontag + '.mix.h5')
|
||||
print(f'ionfn: {ionfn}')
|
||||
ion = remix.remix(ionfn, 0)
|
||||
AddIonBoxes(gs[0,3:], ion)
|
||||
assert True # No return value to check
|
||||
|
||||
def test_plotPlane(gamera_pipe):
|
||||
fig = plt.figure()
|
||||
gs = gridspec.GridSpec(2,1,height_ratios=[20,1],hspace=0.025)
|
||||
AxM = fig.add_subplot(gs[0, 0])
|
||||
AxCB = fig.add_subplot(gs[-1, 0])
|
||||
gsph = gamera_pipe
|
||||
data = gsph.EggSlice('D', 0, doEq=True)
|
||||
xyBds = [-100, 100, -100, 100]
|
||||
plotPlane(gsph, data, xyBds, AxM, AxCB)
|
||||
assert True # No return value to check
|
||||
|
||||
def test_plotXY(gamera_pipe):
|
||||
fig = plt.figure()
|
||||
gs = gridspec.GridSpec(2,1,height_ratios=[20,1],hspace=0.025)
|
||||
AxM = fig.add_subplot(gs[0, 0])
|
||||
AxCB = fig.add_subplot(gs[-1, 0])
|
||||
gsph = gamera_pipe
|
||||
xyBds = [-100, 100, -100, 100]
|
||||
result = plotXY(gsph, 0, xyBds, AxM, AxCB)
|
||||
assert isinstance(result, np.ndarray)
|
||||
|
||||
def test_plotXZ(gamera_pipe):
|
||||
fig = plt.figure()
|
||||
gs = gridspec.GridSpec(2,1,height_ratios=[20,1],hspace=0.025)
|
||||
AxM = fig.add_subplot(gs[0, 0])
|
||||
AxCB = fig.add_subplot(gs[-1, 0])
|
||||
gsph = gamera_pipe
|
||||
xzBds = [-100, 100, -100, 100]
|
||||
result = plotXZ(gsph, 0, xzBds, AxM, AxCB)
|
||||
assert isinstance(result, np.ndarray)
|
||||
Reference in New Issue
Block a user