Source code for gfinder.simulator

"""Simulator module."""

import json

simulator =  [
    {
        'simulated_frame': 'JUICE_SPACECRAFT',
        'fixed_frames': ['JUICE_MAJIS_BASE', 'JUICE_MAJIS'],
        'geometry_class': 'Simulated_SC_Frame',
        'on': False
    },
    {
        'simulated_frame': 'JUICE_MAJIS_SCAN',
        'fixed_frames': [ 'JUICE_MAJIS_VISNIR', 'JUICE_MAJIS_IR'],
        'geometry_class': 'Simulated_Scan_Frame',
        'on': False
    }
]

[docs]def info(): for sim in simulator: print(json.dumps(sim, sort_keys=False, indent=2))
[docs]def simulated_frames(): frames = [] for sim in simulator: frames.append(sim['simulated_frame']) return frames
[docs]def frames(frame=None): frames = [] for sim in simulator: if frame: if sim['simulated_frame'] == frame: frames.append(frame) for frm in sim['fixed_frames']: frames.append(frm) else: frames.append(sim['simulated_frame']) for frm in sim['fixed_frames']: frames.append(frm) return frames
[docs]def is_on(frame=None): ons = [] for sim in simulator: if frame: if sim['simulated_frame'] == frame: return sim['on'] == True else: ons.append(sim['on'] == True) return any(ons)
[docs]def is_off(frame=None): ons = [] for sim in simulator: if frame: if sim['simulated_frame'] == frame: return sim['on'] == False else: ons.append(sim['on'] == False) return all(ons)
[docs]def turn_on(frame=None): for i, sim in enumerate(simulator): if frame: frame_exists = False if sim['simulated_frame'] == frame: simulator[i]['on'] = True frame_exists = True break else: simulator[i]['on'] = True if frame and not frame_exists: print('ERROR: Input frame <{}> not defined as simulated frame.'.format(frame)) info()
[docs]def turn_off(frame=None): for i, sim in enumerate(simulator): if frame: frame_exists = False if sim['simulated_frame'] == frame: simulator[i]['on'] = False frame_exists = True break else: simulator[i]['on'] = False if frame and not frame_exists: print('ERROR: Input frame <{}> not defined as simulated frame.'.format(frame)) info()