def __call__(self, **kwargs) : # input : {axisName: condition, ...} # standardize the axisNames for axisName, condition in kwargs.iteritems() : del kwargs[axisName] if type(condition) == tuple : condition = tuple(sorted(condition[:2]))+condition[2:] kwargs[Axes.standardize(axisName)] = condition output = self.extract_data(**kwargs) # do we need to interpolate along an axis ? for axisName, condition in kwargs.iteritems() : # did we ask for a single value for an axis # yet still have this axis in the output variable ? # this signifies extract_data returned the neighbouring points # because this single value is not on the grid if type(condition) != tuple and axisName in output.axes : output.data # kludge for grib files firstSlice = [slice(None)]*len(output.shape) secondSlice = [slice(None)]*len(output.shape) firstSlice[output.axes.index(axisName)] = 0 secondSlice[output.axes.index(axisName)] = 1 # linear interpolation ! try : output = \ (output[secondSlice] - output[firstSlice])/\ (output.axes[axisName].data[1] - \ output.axes[axisName].data[0])\ *(condition - output.axes[axisName].data[0]) \ + output[firstSlice] except IndexError : # sometimes, due to rounding errors, extract_data will return one # value when two were expected, thus output...[1] fails output = output[firstSlice] output.metadata[axisName] = condition return output
def mean(self, axisNames) : # input can either either be like 'zy' or like ['lev', 'lat'] # turn the 'zy' into ['z', 'y'] axisNames = list(axisNames) for i in range(len(axisNames)) : axisNames[i] = Axes.standardize(axisNames[i]) # levels must be averaged first # 'level' must be at the top of the list if axisNames[i] == 'level' : del axisNames[i] axisNames = ['level'] + axisNames return self.averager(axisNames)