Skip to content

Commit

Permalink
Update tests and rename oft_io script to convert_hist
Browse files Browse the repository at this point in the history
  • Loading branch information
hansec committed Jul 5, 2024
1 parent 6618a8c commit 26d3c6f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 49 deletions.
70 changes: 35 additions & 35 deletions src/examples/ThinCurr/ports/ports_HODLR_eigenvalues.ipynb

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/python/OpenFUSIONToolkit/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,17 @@ def save_to_hdf5(self,filename):
def get(self, keyname, value=None):
return self._data.get(keyname,value)

def keys(self):
return self._data.keys()

def items(self):
return self._data.items()

def __getitem__(self, key):
return self._data[key]

def __iter__(self):
return iter(self._data)

def __repr__(self):
r'''Print information about the file'''
Expand Down
13 changes: 7 additions & 6 deletions src/tests/physics/test_ThinCurr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import numpy as np
test_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.abspath(os.path.join(test_dir, '..')))
sys.path.append(os.path.abspath(os.path.join(test_dir, '..','..','python')))
from oft_testing import run_OFT
from oft_io import oft_histfile
from OpenFUSIONToolkit.io import histfile

mu0 = np.pi*4.E-7

Expand Down Expand Up @@ -195,9 +196,9 @@ def validate_fr(fr_real, fr_imag, tols=(1.E-4, 1.E-4)):
"""
Helper function to validate frequency-response results against test case.
"""
hist_file = oft_histfile('thincurr_fr.dat')
fr_run_real = [hist_file.data[field][0] for field in hist_file.field_tags]
fr_run_imag = [hist_file.data[field][1] for field in hist_file.field_tags]
hist_file = histfile('thincurr_fr.dat')
fr_run_real = [hist_file[field][0] for field in hist_file]
fr_run_imag = [hist_file[field][1] for field in hist_file]
if not len(fr_run_real) == len(fr_real):
print("FAILED: Number of sensors does not match")
return False
Expand All @@ -220,8 +221,8 @@ def validate_td(sigs_final, tols=(1.E-8, 1.E-3)):
"""
Helper function to validate time-dependent results against test case.
"""
hist_file = oft_histfile('floops.hist')
td_sigs_final = [hist_file.data[field][-1] for field in hist_file.field_tags]
hist_file = histfile('floops.hist')
td_sigs_final = [hist_file[field][-1] for field in hist_file]
if not len(td_sigs_final) == len(sigs_final):
print("FAILED: Number of sensors does not match")
return False
Expand Down
8 changes: 2 additions & 6 deletions src/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# Python modules
set( OFT_PY_HELPER_MODS
oft_io.py
oft_mpl.py
tokamaker_fit.py
)
foreach( file ${OFT_PY_HELPER_MODS} )
install(FILES ${file} DESTINATION python COMPONENT app)
endforeach()

# Needed for testing
if( OFT_BUILD_TESTS )
file( COPY oft_io.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../tests )
endif()

# Scripts
install(PROGRAMS build_xdmf.py DESTINATION python COMPONENT app)
set( OFT_PYTHON_BINS build_xdmf.py ${OFT_PYTHON_BINS} CACHE INTERNAL "package_python_binaries" )
install(PROGRAMS convert_hist.py DESTINATION python COMPONENT app)
set( OFT_PYTHON_BINS convert_hist.py ${OFT_PYTHON_BINS} CACHE INTERNAL "package_python_binaries" )
install(PROGRAMS convert_cubit.py DESTINATION python COMPONENT app)
set( OFT_PYTHON_BINS convert_cubit.py ${OFT_PYTHON_BINS} CACHE INTERNAL "package_python_binaries" )
install(PROGRAMS scripts/plot_mug_hist.py DESTINATION python COMPONENT app)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/utilities/scripts/plot_mug_hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import numpy
import matplotlib.pyplot as plt
import oft_io
from OpenFUSIONToolkit.io import histfile
import oft_mpl

mu0 = numpy.pi*(4.E-7)
Expand Down Expand Up @@ -58,7 +58,7 @@ def get_gr(time, total_energy, hist_file):
for (i, file) in enumerate(files):
# Read fields from MUG history file
print('Reading file: "{0}"'.format(file))
dump = oft_io.oft_histfile(file)
dump = histfile(file)
ts = numpy.r_[dump.data['ts']]
time = numpy.r_[dump.data['time']]*1.E3
dt = time[1:-1] - time[0:-2]
Expand Down

0 comments on commit 26d3c6f

Please sign in to comment.