Debian Codegraph @

asdf_astropy/converters/transform/math_functions.py

raw
1 from .core import TransformConverterBase
2
3 _MODEL_NAMES = [
4 "AbsoluteUfunc",
5 "AddUfunc",
6 "ArccosUfunc",
7 "ArccoshUfunc",
8 "ArcsinUfunc",
9 "ArcsinhUfunc",
10 "Arctan2Ufunc",
11 "ArctanUfunc",
12 "ArctanhUfunc",
13 "CbrtUfunc",
14 "CosUfunc",
15 "CoshUfunc",
16 "Deg2radUfunc",
17 # DivideUfunc is an alias for True_divideUfunc
18 "DivmodUfunc",
19 "Exp2Ufunc",
20 "ExpUfunc",
21 "Expm1Ufunc",
22 "FabsUfunc",
23 "Floor_divideUfunc",
24 "FmodUfunc",
25 "HypotUfunc",
26 "Log10Ufunc",
27 "Log1pUfunc",
28 "Log2Ufunc",
29 "LogUfunc",
30 "Logaddexp2Ufunc",
31 "LogaddexpUfunc",
32 # ModUfunc is an alias for RemainderUfunc
33 "MultiplyUfunc",
34 "NegativeUfunc",
35 "PositiveUfunc",
36 "PowerUfunc",
37 "Rad2degUfunc",
38 "ReciprocalUfunc",
39 "RemainderUfunc",
40 "RintUfunc",
41 "SinUfunc",
42 "SinhUfunc",
43 "SqrtUfunc",
44 "SquareUfunc",
45 "SubtractUfunc",
46 "TanUfunc",
47 "TanhUfunc",
48 "True_divideUfunc",
49 ]
50
51
52 class MathFunctionsConverter(TransformConverterBase):
53 """
54 ASDF support for serializing the math functions models,
55 each of which corresponds to a numpy ufunc.
56 """
57
58 tags = ("tag:stsci.edu:asdf/transform/math_functions-*",)
59 types = tuple("astropy.modeling.math_functions." + m for m in _MODEL_NAMES)
60
61 def to_yaml_tree_transform(self, model, tag, ctx):
62 return {"func_name": model.func.__name__}
63
64 def from_yaml_tree_transform(self, node, tag, ctx):
65 from astropy.modeling import math_functions
66
67 klass_name = math_functions._make_class_name(node["func_name"])
68 klass = getattr(math_functions, klass_name)
69 return klass()