예제 #1
0
 def arg_factory(self, arg, type_):
     if type_ == 'measurement':
         return Constant(arg)
     elif type_ == 'parameter':
         return Parameter('arg', value=arg)
     elif type_ == 'const':
         return arg
예제 #2
0
 def measurement(self, frame, level, out_maps, droplevel):
     if (frame.index.nlevels == 1) and not len(out_maps) and droplevel:
         xfail('Scalar output is not supported.')
     out = []
     for out_name, out_map in out_maps.items():
         out.extend((out_name, out_map))
     return Reshape(Constant(frame), level, *out, droplevel=droplevel)
예제 #3
0
 def test_fit_zero_results(self):
     frame = pd.DataFrame({'data': np.zeros((50, ))},
                          pd.Index(np.linspace(-5., 5., 50), name='x'))
     source = Constant(frame)
     fitter = self._fitter('PeakFind')
     measurement = FittingMeasurement(source, fitter, plot=None)
     with raises(ContinueIteration):
         measurement()
     measurement.fail_func = lambda: False
     assert measurement(output_data=True) is None
예제 #4
0
 def measurement(self, request, frame, coordinate):
     self.frame = frame
     average = request.param[0]
     start, stop = (1, 2) if request.param[1] else (None, None)
     if (len(frame) == 1) and (start is not None):
         return skip()
     return Integrate(Constant(frame),
                      coordinate=coordinate,
                      average=average,
                      start=start,
                      stop=stop)
예제 #5
0
 def source(self, pawg_factory, normalize):
     kwargs = {
         'template_func': normalize.template_func
     } if normalize is not None else {}
     store = pawg_factory(**kwargs)()
     frame = store['/map']
     if normalize is None:
         frame['data'] = list(range(len(frame)))
     else:
         frame['data'] = [-1, 1] + list(range(len(frame) - 2))
     return Constant(frame)
예제 #6
0
 def source(self, request):
     # one to three index levels with the segment level in different positions
     prefix, suffix = request.param
     levels = []
     if prefix:
         levels.append(('x', list(range(2))))
     levels.append(('segment', list(range(10))))
     if suffix:
         levels.append(('y', list(range(3))))
     names, levels = zip(*levels)
     index = pd.MultiIndex.from_product(levels, names=names)
     segment_labels = index.get_level_values('segment').values
     data = np.concatenate(([-1, 1], np.linspace(-1, 1, 8)))[segment_labels]
     frame = pd.DataFrame({'data': data}, index)
     return Constant(frame)
예제 #7
0
 def _source(self, param):
     ''' return a Constant measurement returning Lorentzian curves '''
     # determine output coordinates
     xs = np.linspace(-5., 5., 100)
     lorentzian = lambda f0, amp=1.: Lorentzian.f(
         xs, f0=f0, df=0.5, offset=0., amplitude=amp)
     if param == '1d':
         # 1d data
         self.f0s = 1.
         data = lorentzian(self.f0s)
         index = pd.Float64Index(xs, name='x')
     elif param == '1d/3pk':
         # 1d data with multiple peaks
         self.f0s = [-3., 0., 3.]
         data = np.zeros_like(xs)
         for f0, amp in zip(self.f0s, [0.5, 1., 0.5]):
             data += lorentzian(f0, amp)
         index = pd.Float64Index(xs, name='x')
     elif (param == '2d>1d') or (param == '2d>1d.T'):
         # 2d data with a singleton dimension
         self.f0s = [0.]
         data = lorentzian(*self.f0s)
         if param == '2d>1d':
             index = pd.MultiIndex.from_product((xs, self.f0s),
                                                names=['x', 'f'])
         else:
             index = pd.MultiIndex.from_product((self.f0s, xs),
                                                names=['f', 'x'])
     elif param == '2d':
         # 2d data
         self.f0s = np.linspace(-3., 3., 5)
         data = np.array([lorentzian(f0) for f0 in self.fs]).ravel()
         index = pd.MultiIndex.from_product((xs, self.f0s),
                                            names=['x', 'f'])
     else:
         raise ValueError('Unsupported number of dimensions.')
     frame = pd.DataFrame({'data': data, 'reversed': data[::-1]}, index)
     # generate measurement
     self.npeaks = 1 if np.isscalar(self.f0s) else len(self.f0s)
     return Constant(frame)
예제 #8
0
 def measurement(self, frame):
     return Constant(frame.copy())