COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
sutra_wrap.py
1 import importlib
2 
3 
4 def smart_import(mod, cls, verbose=False, silent=False):
5  try:
6  if verbose:
7  print("trying from " + mod + " import " + cls)
8  # my_module = __import__(mod, globals(), locals(), [cls], 0)
9  my_module = importlib.import_module(mod)
10  return getattr(my_module, cls)
11 
12  except ImportError as err:
13  if not silent:
14  import warnings
15  warnings.warn(
16  "Error importing %s, it will be simulated due to: %s" %
17  (cls, err.msg), Warning)
18 
19  class tmp_cls:
20 
21  def __init__(self, *args, **kwargs):
22  raise RuntimeError("Can not initilize the simulation with fake objects")
23 
24  return tmp_cls
25 
26  except AttributeError as err:
27  if not silent:
28  import warnings
29  warnings.warn(
30  "Error importing %s, it will be simulated due to: %s" %
31  (cls, err.args), Warning)
32 
33  class tmp_cls:
34 
35  def __init__(self, *args, **kwargs):
36  raise RuntimeError("Can not initialize the simulation with fake objects")
37 
38  return tmp_cls
39 
40 
41 # The import of carmaWrap MUST be done first
42 # since MAGMA >= 2.5.0
43 # Otherwise, it causes huge memory leak
44 # plus not working code
45 # Why ? We don't know... TB check with further version of MAGMA
46 carmaWrap_context = smart_import("carmaWrap", "context")
47 
48 Dms = smart_import("sutraWrap", "Dms")
49 Rtc_FFF = smart_import("sutraWrap", "Rtc_FFF")
50 Rtc_FHF = smart_import("sutraWrap", "Rtc_FHF", silent=True)
51 Rtc_UFF = smart_import("sutraWrap", "Rtc_UFF", silent=True)
52 Rtc_UHF = smart_import("sutraWrap", "Rtc_UHF", silent=True)
53 Rtc_FFU = smart_import("sutraWrap", "Rtc_FFU", silent=True)
54 Rtc_FHU = smart_import("sutraWrap", "Rtc_FHU", silent=True)
55 Rtc_UFU = smart_import("sutraWrap", "Rtc_UFU", silent=True)
56 Rtc_UHU = smart_import("sutraWrap", "Rtc_UHU", silent=True)
57 Rtc_brahma = smart_import("sutraWrap", "Rtc_brahma", silent=True)
58 Rtc_cacao_FFF = smart_import("sutraWrap", "Rtc_cacao_FFF", silent=True)
59 Rtc_cacao_UFF = smart_import("sutraWrap", "Rtc_cacao_UFF", silent=True)
60 Rtc_cacao_FFU = smart_import("sutraWrap", "Rtc_cacao_FFU", silent=True)
61 Rtc_cacao_UFU = smart_import("sutraWrap", "Rtc_cacao_UFU", silent=True)
62 Rtc_cacao_FHF = smart_import("sutraWrap", "Rtc_cacao_FHF", silent=True)
63 Rtc_cacao_UHF = smart_import("sutraWrap", "Rtc_cacao_UHF", silent=True)
64 Rtc_cacao_FHU = smart_import("sutraWrap", "Rtc_cacao_FHU", silent=True)
65 Rtc_cacao_UHU = smart_import("sutraWrap", "Rtc_cacao_UHU", silent=True)
66 Sensors = smart_import("sutraWrap", "Sensors")
67 Atmos = smart_import("sutraWrap", "Atmos")
68 Telescope = smart_import("sutraWrap", "Telescope")
69 Target = smart_import("sutraWrap", "Target")
70 Target_brahma = smart_import("sutraWrap", "Target_brahma", silent=True)
71 Gamora = smart_import("sutraWrap", "Gamora")
72 Groot = smart_import("sutraWrap", "Groot")
shesha.sutra_wrap.smart_import
def smart_import(mod, cls, verbose=False, silent=False)
Definition: sutra_wrap.py:4