コード例 #1
0
    def register_variable(self,varname,units):
        if varname == 'b_x':
            interpolator=self.bx
        if varname == 'b_y':
            interpolator=self.by
        if varname == 'b_z':
            interpolator=self.bz
        if varname == 'bvec':
            interpolator=self.b
        if varname == 'PF':
            interpolator=self.pressure_function
            
        self.variables[varname]['interpolator']= interpolator

        def interpolate(xvec):
            return self.variables[varname]['interpolator'](xvec)

        interpolate.__doc__ = "A function that returns {} in [{}].".format(varname,units)

        self[varname] = kamodofy(interpolate, 
                                 units = units, 
                                 citation = self.citation,
                                 data = None)
        self[varname + '_ijk'] = kamodofy(gridify(self[varname], 
                                                  x_i = self.x, 
                                                  y_j = self.y, 
                                                  z_k = self.z),
                                          units = units,
                                          citation = self.citation,
                                          data = None) 
コード例 #2
0
    def register_variables(self):
        for variable_name, df in self.data.items():

            dependencies = []
            for i in ['TIME'] + list('01234'):
                dependency_name = self.meta[variable_name].get(
                    'DEPEND_{}'.format(i))
                if dependency_name is not None:
                    dependencies.append(dependency_name)
            if len(dependencies) == 0:
                print('not registering {}: no dependencies'.format(
                    variable_name))
                continue

            if not hasattr(df, 'index'):
                print('{} has no index, skipping..'.format(variable_name))
                continue

            regname = self._regnames.get(variable_name, variable_name)
            docstring = self.meta[variable_name]['CATDESC']
            units = self.meta[variable_name]['UNITS']
            citation = self._citation

            if isinstance(df.index, pd.MultiIndex):
                indices = df.index.levels
                data_shape = [len(i) for i in indices]
                grid_interpolator = RegularGridInterpolator(
                    indices, df.values.reshape(data_shape), bounds_error=False)

                grid_interpolator.__name__ = variable_name

                grid_args = {d: self.get_dependency(d) for d in dependencies}
                interpolator = gridify(grid_interpolator, **grid_args)

            # catch time dependencies such as Epoch_state and Epoch
            elif (len(dependencies) == 1) & ('epoch'
                                             in dependencies[0].lower()):
                interpolator = get_interpolator(time_interpolator, regname, df,
                                                df.index, docstring)
            else:
                print('can not register {}'.format(variable_name))
                continue

            self[regname] = kamodofy(interpolator,
                                     units=units,
                                     citation=citation)