Commit da083c4f authored by Maximilian Schanner's avatar Maximilian Schanner
Browse files

Updated the Model to generate the built

-ins directly. + Docstring update.
parent eab7ca1b
......@@ -60,8 +60,9 @@ class Model(object):
Parameters
----------
name : str
The name of the model.
fname : str
The name of the model. If fname is none, the built-in model will be
used.
fname : str, optional
The path leading to a model file in the format of gufm1 and the CALSxk-
series.
......@@ -79,9 +80,16 @@ class Model(object):
splines : scipy.interpolate.BSpline
A `BSpline` instance representing the model.
'''
def __init__(self, name, fname):
def __init__(self, name, fname=None):
self.name = name
# parse the file
if fname is None:
try:
fname = built_in_models()[name]
except KeyError:
raise KeyError(f"Model {name} is not a built-in model. Please "
f"provide a path to the model file.")
with open(fname, 'r') as fh:
self.t_min, self.t_max = map(float, fh.readline().split()[0:2])
# read the rest as a long string
......@@ -296,6 +304,9 @@ def field(z_at, splines):
* z_at[1] contains longitudes in degrees.
* z_at[2] contains radii in km.
* z_at[3] contains dates in years.
You can use pymagglobal.utils.get_z_at to generate an array of input
points.
splines : scipy.interpolate.BSpline
The splines specifying the model.
......
......@@ -19,6 +19,8 @@
import unittest
from numpy.testing import assert_array_equal
import pymagglobal
try:
......@@ -31,3 +33,13 @@ try:
Version(pymagglobal.__version__)
except (ImportError, ModuleNotFoundError):
print("Skipped version test, as the packaging package is not available.")
class TestModels(unittest.TestCase):
'''Test whether the built-in models can be parsed.'''
def test_built_ins(self):
models = pymagglobal.built_in_models()
for name, fname in models.items():
implicit = pymagglobal.Model(name)
direct = pymagglobal.Model(name, fname)
assert_array_equal(implicit.coeffs, direct.coeffs)
assert_array_equal(implicit.knots, direct.knots)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment