def _payload(self, field): """Calculate the payload data depth (in bytes) and type.""" if field.lbpack.n1 == 0: # Data payload is not packed. data_depth = (field.lblrec - field.lbext) * self._word_depth # Determine PP field 64-bit payload datatype. lookup = _LBUSER_DTYPE_LOOKUP dtype_template = lookup.get(field.lbuser[0], lookup['default']) dtype_name = dtype_template.format(word_depth=self._word_depth) data_type = np.dtype(dtype_name) else: # Data payload is packed. if field.lbpack.n1 == 1: # Data packed using WGDOS archive method. data_depth = ((field.lbnrec * 2) - 1) * pp.PP_WORD_DEPTH elif field.lbpack.n1 == 2: # Data packed using CRAY 32-bit method. data_depth = (field.lblrec - field.lbext) * pp.PP_WORD_DEPTH else: msg = 'PP fields with LBPACK of {} are not supported.' raise NotYetImplementedError(msg.format(field.lbpack)) # Determine PP field payload datatype. lookup = pp.LBUSER_DTYPE_LOOKUP data_type = lookup.get(field.lbuser[0], lookup['default']) return data_depth, data_type
def _timeunit_detail(self): """Return the (string, seconds) describing the message time unit.""" unit_code = self.indicatorOfUnitOfTimeRange if unit_code not in TIME_CODES_EDITION1: message = 'Unhandled time unit for forecast ' \ 'indicatorOfUnitOfTimeRange : ' + str(unit_code) raise NotYetImplementedError(message) return TIME_CODES_EDITION1[unit_code]
def _payload(self, field): """Calculate the payload data depth (in bytes) and type.""" lbpack_n1 = field.raw_lbpack % 10 if lbpack_n1 == 0: word_depth = self._word_depth # Data payload is not packed. data_words = field.lblrec - field.lbext # Determine PP field 64-bit payload datatype. lookup = _LBUSER_DTYPE_LOOKUP dtype_template = lookup.get(field.lbuser[0], lookup["default"]) dtype_name = dtype_template.format(word_depth=self._word_depth) data_type = np.dtype(dtype_name) else: word_depth = pp.PP_WORD_DEPTH # Data payload is packed. if lbpack_n1 == 1: # Data packed using WGDOS archive method. data_words = field.lbnrec * 2 elif lbpack_n1 == 2: # Data packed using CRAY 32-bit method. data_words = field.lblrec - field.lbext else: msg = "PP fields with LBPACK of {} are not supported." raise NotYetImplementedError(msg.format(field.raw_lbpack)) # Determine PP field payload datatype. lookup = pp.LBUSER_DTYPE_LOOKUP data_type = lookup.get(field.lbuser[0], lookup["default"]) if field.boundary_packing is not None: if lbpack_n1 not in (0, 2): # Can't handle the usual packing methods with LBC data. raise ValueError( "LBC data has LBPACK = {:d}, but packed LBC data is not " "supported.".format(field.raw_lbpack) ) # Adjust to packed data size, for LBC data. # NOTE: logic duplicates that in pp._data_bytes_to_shaped_array. pack_dims = field.boundary_packing boundary_height = pack_dims.y_halo + pack_dims.rim_width boundary_width = pack_dims.x_halo + pack_dims.rim_width y_height, x_width = field.lbrow, field.lbnpt mid_height = y_height - 2 * boundary_height data_words = ( boundary_height * x_width * 2 + boundary_width * mid_height * 2 ) data_depth = data_words * word_depth return data_depth, data_type