Coverage for python/lsst/afw/geom/transformFromString.py: 33%

9 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-23 02:38 -0700

1# This product includes software developed by the LSST Project 

2# (https://www.lsst.org). 

3# See the COPYRIGHT file at the top-level directory of this distribution 

4# for details of code ownership. 

5# 

6# This program is free software: you can redistribute it and/or modify 

7# it under the terms of the GNU General Public License as published by 

8# the Free Software Foundation, either version 3 of the License, or 

9# (at your option) any later version. 

10# 

11# This program is distributed in the hope that it will be useful, 

12# but WITHOUT ANY WARRANTY; without even the implied warranty of 

13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14# GNU General Public License for more details. 

15# 

16# You should have received a copy of the GNU General Public License 

17# along with this program. If not, see <https://www.gnu.org/licenses/>. 

18 

19from ._python import transformRegistry 

20 

21__all__ = ["transformFromString"] 

22 

23 

24def transformFromString(data): 

25 """Read a Transform from a string that was saved using 

26 ``Transform.writeString`` 

27 

28 Unlike ``Transform.readString``, you need not know the ``Transform`` class in 

29 advance 

30 

31 Parameters 

32 ---------- 

33 data : `str` 

34 A string in the format produced by ``Transform.writeString``. 

35 

36 Returns 

37 ------- 

38 transform : a ``Transform`` class 

39 An object of the same type used to create ``data``. 

40 """ 

41 version, transformClassName, remainder = data.split(" ", 2) 

42 try: 

43 transformClass = transformRegistry[transformClassName] 

44 except LookupError: 

45 raise RuntimeError(f"Unknown transform class {transformClassName!r}") 

46 

47 return transformClass.readString(data)