[docs]class Detector:
def __init__(self, detector_name, ops_mode=None):
self.name = detector_name
self.mode = ops_mode
self.id, found = spice.bodn2c(detector_name)
self.frame = ''
self.bsight = []
self.bounds = []
self.ifov = []
self.valid = True
if not found:
self.valid = False
print('Unable to retrieve SPICE instrument code for detector name: ' + self.name)
return
# Retrieve SPICE detector FOV
try:
shape, frame, bsight, n, bounds = spice.getfov(self.id, 100)
except:
print(
'Unable to retrieve FOV parameters for SPICE instrument code: ' + str(self.id) + ' (' + self.name + ')')
self.valid = False
return
self.frame = frame
self.bsight = bsight
self.bounds = bounds
self.ifov, found = spice.gdpool('INS' + str(self.id) + '_IFOV', 0, 2)
# Set MAJIS detector binning (1,2, or 4) based on detector name
self.binning = 1
token = self.name.split('_')[-1]
if token == 'B2':
self.binning = 2
elif token == 'B4':
self.binning = 4
def __repr__(self):
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
[docs] def get_bounds(self):
N_PVECS = 100 # x2 actually
bounds = self.bounds
interpolated = True
if not interpolated:
return bounds
n_bounds = len(bounds)
facet_sizes = []
for j in range(n_bounds):
facet_sizes.append(spice.vnorm(bounds[(j + 1) % n_bounds] - bounds[j]))
min_facet_size = min(facet_sizes)
max_facet_size = max(facet_sizes)
n_max = int(N_PVECS / (1 + (min_facet_size / max_facet_size)))
n_min = N_PVECS - n_max
pvecs = []
for j in range(n_bounds):
# set number of facet pointing vectors
if facet_sizes[j] == min_facet_size:
n_facet_pvecs = 2 #n_min
else:
n_facet_pvecs = 100 #n_max
# create and append facet pointing vectors
for i in range(n_facet_pvecs):
pvec = bounds[j] + i * (bounds[(j + 1) % n_bounds] - bounds[j]) / n_facet_pvecs
pvecs.append(list(pvec))
return pvecs
[docs] def get_bsight(self):
return self.bsight
[docs] def get_forward_bsight(self):
# detector frame +Y direction (~SC velocity direction, when "forward motion")
return spice.vrotv(self.bsight, [1.0, 0.0, 0.0], -0.5*self.ifov[1])
[docs] def get_backward_bsight(self):
# detector frame -Y direction (~SC velocity direction, when "reverse motion")
return spice.vrotv(self.bsight, [1.0, 0.0, 0.0], +0.5*self.ifov[1])
[docs] def isValid(self):
return self.valid