def get_date_list(start, stop, days): ret = [] delta = datetime.timedelta(days=days) check = start while check <= stop: ret.append(check) try: check += delta except TypeError: # Probably an older netcdftime object check = datetime.datetime(check.year, check.month, check.day, check.hour, check.second, check.microsecond) check += delta check = netcdftime.datetime(check.year, check.month, check.day, check.hour, check.second, check.microsecond) return ret
def _calculate_structure(self): # Make value arrays for the vectorisable field elements. element_definitions = self._field_vector_element_arrays() # Identify the vertical elements and payload. blev_array = dict(element_definitions).get('blev') vertical_elements = ('lblev', 'bhlev', 'bhrlev', 'brsvd1', 'brsvd2', 'brlev') # Make an ordering copy. ordering_definitions = element_definitions[:] # Replace time value tuples with integers and bind the vertical # elements to the (expected) primary vertical element "blev". for index, (name, array) in enumerate(ordering_definitions): if name in ('t1', 't2'): array = np.array( [self._time_comparable_int(*tuple(val)) for val in array]) ordering_definitions[index] = (name, array) if name in vertical_elements and blev_array is not None: ordering_definitions[index] = (name, blev_array) # Perform the main analysis: get vector dimensions, elements, arrays. dims_shape, primary_elements, vector_element_arrays_and_dims = \ optimal_array_structure(ordering_definitions, element_definitions) # Replace time tuples in the result with real datetime-like values. # N.B. so we *don't* do this on the whole (expanded) input arrays. for name in ('t1', 't2'): if name in vector_element_arrays_and_dims: arr, dims = vector_element_arrays_and_dims[name] arr_shape = arr.shape[:-1] extra_length = arr.shape[-1] # Flatten out the array apart from the last dimension, # convert to netcdftime objects, then reshape back. arr = np.array([ netcdftime.datetime(*args) for args in arr.reshape(-1, extra_length) ]).reshape(arr_shape) vector_element_arrays_and_dims[name] = (arr, dims) # Write the private cache values, exposed as public properties. self._vector_dims_shape = dims_shape self._primary_dimension_elements = primary_elements self._element_arrays_and_dims = vector_element_arrays_and_dims # Do all this only once. self._structure_calculated = True
def _calculate_structure(self): # Make value arrays for the vectorisable field elements. element_definitions = self._field_vector_element_arrays() # Identify the vertical elements and payload. blev_array = dict(element_definitions).get('blev') vertical_elements = ('lblev', 'bhlev', 'bhrlev', 'brsvd1', 'brsvd2', 'brlev') # Make an ordering copy. ordering_definitions = element_definitions[:] # Replace time value tuples with integers and bind the vertical # elements to the (expected) primary vertical element "blev". for index, (name, array) in enumerate(ordering_definitions): if name in ('t1', 't2'): array = np.array( [self._time_comparable_int(*tuple(val)) for val in array]) ordering_definitions[index] = (name, array) if name in vertical_elements and blev_array is not None: ordering_definitions[index] = (name, blev_array) # Perform the main analysis: get vector dimensions, elements, arrays. dims_shape, primary_elements, vector_element_arrays_and_dims = \ optimal_array_structure(ordering_definitions, element_definitions) # Replace time tuples in the result with real datetime-like values. # N.B. so we *don't* do this on the whole (expanded) input arrays. for name in ('t1', 't2'): if name in vector_element_arrays_and_dims: arr, dims = vector_element_arrays_and_dims[name] arr_shape = arr.shape[:-1] extra_length = arr.shape[-1] # Flatten out the array apart from the last dimension, # convert to netcdftime objects, then reshape back. arr = np.array([netcdftime.datetime(*args) for args in arr.reshape(-1, extra_length)] ).reshape(arr_shape) vector_element_arrays_and_dims[name] = (arr, dims) # Write the private cache values, exposed as public properties. self._vector_dims_shape = dims_shape self._primary_dimension_elements = primary_elements self._element_arrays_and_dims = vector_element_arrays_and_dims # Do all this only once. self._structure_calculated = True