def _link_item_buffer_(self, item, stagger, localde): # # check to see if they are done # if item == GridItem.MASK: # if self.mask[stagger] is not None: # raise GridItemAlreadyLinked # elif item == GridItem.AREA: # if self.area[stagger] is not None: # raise GridItemAlreadyLinked # else: # raise GridItemNotSupported # get the data pointer and bounds of the ESMF allocation data = ESMP_GridGetItem(self, item, staggerloc=stagger, localde=localde) lb, ub = ESMP_GridGetCoordBounds(self, staggerloc=stagger, localde=localde) # create Array of the appropriate type the appropriate type if item == GridItem.MASK: self._mask[stagger] = ndarray_from_esmf(data, TypeKind.I4, ub - lb) elif item == GridItem.AREA: self._area[stagger] = ndarray_from_esmf(data, TypeKind.R8, ub - lb) else: raise GridItemNotSupported
def _link_coord_buffer_1Dcoords(self, stagger, localde): # get the data pointer and bounds of the ESMF allocation lb, ub = ESMP_GridGetCoordBounds(self, staggerloc=stagger, localde=localde) gc0 = ndarray_from_esmf( ESMP_GridGetCoordPtr(self, 0, staggerloc=stagger, localde=localde), self.type, ((ub - lb)[0], )) gc1 = ndarray_from_esmf( ESMP_GridGetCoordPtr(self, 1, staggerloc=stagger, localde=localde), self.type, ((ub - lb)[1], )) if self.rank == 3: gc2 = ndarray_from_esmf( ESMP_GridGetCoordPtr(self, 2, staggerloc=stagger, localde=localde), self.type, ((ub - lb)[2], )) gc00, gc11, gc22 = np.meshgrid(gc0, gc1, gc2, indexing="ij") elif self.rank == 2: gc00, gc11 = np.meshgrid(gc0, gc1, indexing="ij") else: raise ValueError("Grid rank must be 2 or 3") # alias the coordinates to a grid property self._coords[stagger][0] = gc00 self._coords[stagger][1] = gc11 if self.rank == 3: self._coords[stagger][2] = gc22 if stagger in (StaggerLoc.CORNER, StaggerLoc.CORNER_VFACE): self._has_corners = True
def _add_(self, key_name, typekind=None): # allocate the key ESMP_LocStreamAddKeyAlloc(self.struct, key_name, keyTypeKind=typekind) # get a pointer to the Fortran buffer to the key key_ptr = ESMP_LocStreamGetKeyPtr(self.struct, key_name) # create a numpy array out of the pointer keyvals = ndarray_from_esmf(key_ptr, typekind, (self.size, )) return keyvals
def _add_(self, key_name, typekind=None): # allocate the key ESMP_LocStreamAddKeyAlloc(self.struct, key_name, keyTypeKind=typekind) # get a pointer to the Fortran buffer to the key key_ptr = ESMP_LocStreamGetKeyPtr(self.struct, key_name) # create a numpy array out of the pointer keyvals = ndarray_from_esmf(key_ptr, typekind, (self.size,)) return keyvals
def _link_coord_buffer_(self, coord_dim, stagger): # get the data pointer and bounds of the ESMF allocation data = ESMP_GridGetCoordPtr(self, coord_dim, staggerloc=stagger) lb, ub = ESMP_GridGetCoordBounds(self, staggerloc=stagger) gridCoordP = ndarray_from_esmf(data, self.type, ub - lb) # alias the coordinates to a grid property self._coords[stagger][coord_dim] = gridCoordP if stagger in (StaggerLoc.CORNER, StaggerLoc.CORNER_VFACE): self._has_corners = True