ReFRACtor
forward_model.py
Go to the documentation of this file.
1 import numpy as np
2 
3 from .base import Creator
4 from .. import param
5 
6 from refractor import framework as rf
7 
8 class PerChannelMixin(object):
9 
10  num_channels = param.Scalar(int)
11 
12  def check_num_channels(self, check_num):
13  "Issue a warning when the number of channels in some data source does not match the expected number"
14 
15  if not self.num_channels() == check_num:
16  raise param.ParamError("Number of channels for data source: %d does not match expected number: %d" % (check_num, self.num_channels()))
17 
19 
20  window_ranges = param.ArrayWithUnit(dims=3)
21  bad_sample_mask = param.Array(dims=2, required=False)
22 
23  def create(self, **kwargs):
24 
25  win_ranges = self.window_ranges()
26  bad_sample_mask = self.bad_sample_mask()
27 
28  if bad_sample_mask is not None:
29  return rf.SpectralWindowRange(win_ranges, bad_sample_mask)
30  else:
31  return rf.SpectralWindowRange(win_ranges)
32 
34 
35  high_res_spacing = param.Choice(param.ArrayWithUnit(dims=1), param.DoubleWithUnit())
36 
37  def spacing(self):
38  "Returns the array with unit value for spacing specified regardless if it was specified as an array or scalar value with unit"
39 
40  spacing_val = self.high_res_spacing()
41  num_channels = self.num_channels()
42 
43  if isinstance(spacing_val, rf.DoubleWithUnit):
44  # Create an ArrayWithDouble matching the number of channels used
45  spacing_used = rf.ArrayWithUnit_double_1(np.full(num_channels, spacing_val.value), spacing_val.units)
46  else:
47  self.check_num_channels(spacing_val.value.shape[0])
48  spacing_used = spacing_val
49 
50  return spacing_used
51 
53 
54  def create(self, **kwargs):
55  return rf.SpectrumSamplingFixedSpacing(self.spacing())
56 
58 
59  def create(self, **kwargs):
60  return rf.UniformSpectrumSampling(self.spacing())
61 
63 
64  channel_domains = param.Iterable()
65 
66  def create(self, **kwargs):
67  domains = self.channel_domains()
68  full_spec_spacing = rf.SpectrumSamplingFixedSpacing(self.spacing())
69 
70  if len(domains) != self.num_channels():
71  raise param.ParamError("Number of channel domains %d does not match the number of channels %d" % (len(domains), self.num_channels()))
72 
73  for idx, dom in enumerate(domains):
74  if not isinstance(dom, rf.SpectralDomain):
75  raise param.ParamError("Channel domain value at index %d is not a instance of SpectralDomain" % idx)
76 
77  return rf.NonuniformSpectrumSampling(*domains, full_spec_spacing)
78 
80 
81  effects = param.Iterable(str)
82  num_channels = param.Scalar(int)
83 
84  def create(self, **kwargs):
85 
86  all_effects = []
87  for effect_name in self.effects():
88  self.register_parameter(effect_name, param.Iterable())
89  all_effects.append(self.param(effect_name))
90 
91  # Map these into an outer vector for each channel, with an inner vector for each effect
92  spec_eff = rf.vector_vector_spectrum_effect()
93  for chan_index in range(self.num_channels()):
94  per_channel_eff = rf.vector_spectrum_effect()
95 
96  for effect in all_effects:
97  per_channel_eff.push_back(effect[chan_index])
98 
99  spec_eff.push_back(per_channel_eff)
100 
101  return spec_eff
102 
104 
105  instrument = param.InstanceOf(rf.Instrument)
106  spec_win = param.InstanceOf(rf.SpectralWindow)
107  radiative_transfer = param.InstanceOf(rf.RadiativeTransfer)
108  spectrum_sampling = param.InstanceOf(rf.SpectrumSampling)
109  spectrum_effect = param.ObjectVector("vector_spectrum_effect")
110 
111  def create(self, **kwargs):
112  fm = rf.StandardForwardModel(self.instrument(),
113  self.spec_win(),
114  self.radiative_transfer(),
115  self.spectrum_sampling(),
116  self.spectrum_effect())
117 
118  fm.setup_grid()
119 
120  return fm
def register_parameter(self, param_name, param_def)
Definition: base.py:95
def param(self, param_name, kwargs)
Definition: base.py:111

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:10