def setUp(self, *args, **kwargs): # Call the original setup function super(Test_validate, self).setUp(*args, **kwargs) # Construct a mock 'minimal' file that passes the validation tests. self.ff = FieldsFile() self.ff.fixed_length_header.dataset_type = 3 self.ff.fixed_length_header.grid_staggering = 3 self.ff.fixed_length_header.horiz_grid_type = 0 self.ff.integer_constants = FF_IntegerConstants.empty() self.ff.integer_constants.num_cols = self._dflt_nx self.ff.integer_constants.num_rows = self._dflt_ny self.ff.integer_constants.num_p_levels = self._dflt_nz self.ff.real_constants = FF_RealConstants.empty() self.ff.real_constants.start_lon = self._dflt_x0 self.ff.real_constants.col_spacing = self._dflt_dx self.ff.real_constants.start_lat = self._dflt_y0 self.ff.real_constants.row_spacing = self._dflt_dy self.ff.level_dependent_constants = ( FF_LevelDependentConstants.empty(self._dflt_nz + 1)) # Construct a mock 'minimal' field that passes the validation tests. self.fld = Field3.empty() self.fld.lbrel = 3 self.fld.lbcode = 1 self.fld.lbhem = 0 self.fld.lbrow = self._dflt_ny self.fld.bzy = self._dflt_y0 - self._dflt_dy self.fld.bdy = self._dflt_dy self.fld.lbnpt = self._dflt_nx self.fld.bzx = self._dflt_x0 - self._dflt_dx self.fld.bdx = self._dflt_dx
def _field_from_data(self, data): fld = Field3.empty() fld.lbrel = 3 fld.lbrow = data.shape[0] fld.lbnpt = data.shape[1] fld.bmdi = self.MDI provider = ArrayDataProvider(data) fld.set_data_provider(provider) return fld
def setUp(self, *args, **kwargs): # Call the original setup function super(Test_LBCOperators, self).setUp(*args, **kwargs) # Construct a mock 'minimal' field that passes the validation tests. self.fld = Field3.empty() self.fld.lbrel = 3 self.fld.lbcode = 1 self.fld.lbhem = 0 self.fld.lbrow = self._dflt_ny self.fld.bzy = self._dflt_y0 - self._dflt_dy self.fld.bdy = self._dflt_dy self.fld.lbnpt = self._dflt_nx self.fld.bzx = self._dflt_x0 - self._dflt_dx self.fld.bdx = self._dflt_dx
def make_field(): headers = (np.arange(64) + 1) * 10 return Field3(headers[:45], headers[45:], None)
def add_field(level_: int, time_step_: int) -> None: """ Add a minimal field to the new :class:`~mule.FieldsFile`. Includes the minimum information to allow Mule saving and Iris loading, as well as incrementation for vertical levels and time steps to allow generation of z and t dimensions. """ new_field = Field3.empty() # To correspond to the header-release 3 class used. new_field.lbrel = 3 # Mule uses the first element of the lookup to test for # unpopulated fields (and skips them), so the first element should # be set to something. The year will do. new_field.raw[1] = datetime.now().year # Horizontal. new_field.lbcode = 1 new_field.lbnpt = len_x new_field.lbrow = len_y new_field.bdx = new_ff.real_constants.col_spacing new_field.bdy = new_ff.real_constants.row_spacing new_field.bzx = new_ff.real_constants.start_lon - 0.5 * new_field.bdx new_field.bzy = new_ff.real_constants.start_lat - 0.5 * new_field.bdy # Hemisphere. new_field.lbhem = 32 # Processing. new_field.lbproc = 0 # Vertical. # Hybrid height values by simulating sequences similar to those in a # theta file. new_field.lbvc = 65 if level_ == 0: new_field.lblev = 9999 else: new_field.lblev = level_ level_1 = level_ + 1 six_rec = 20 / 3 three_rec = six_rec / 2 new_field.blev = level_1**2 * six_rec - six_rec new_field.brsvd1 = (level_1**2 * six_rec + (six_rec * level_1) - three_rec) brsvd2_simulated = np.linspace(0.995, 0, len_z) shift = min(len_z, 2) bhrlev_simulated = np.concatenate( [np.ones(shift), brsvd2_simulated[:-shift]]) new_field.brsvd2 = brsvd2_simulated[level_] new_field.bhrlev = bhrlev_simulated[level_] # Time. new_field.lbtim = 11 new_field.lbyr = time_step_ for attr_name in ["lbmon", "lbdat", "lbhr", "lbmin", "lbsec"]: setattr(new_field, attr_name, 0) new_field.lbyrd = time_step_ + 1 for attr_name in ["lbmond", "lbdatd", "lbhrd", "lbmind", "lbsecd"]: setattr(new_field, attr_name, 0) # Data and packing. new_field.lbuser1 = 1 new_field.lbpack = int(compress) new_field.bacc = 0 new_field.bmdi = -1 new_field.lbext = 0 new_field.set_data_provider(array_provider) new_ff.fields.append(new_field)