def test_sround_range(self): self.assertEqual( sround_range((-0.000067128731732, 6.362984893743), ndigits=1), (0.0, 6.4)) self.assertEqual( sround_range((-0.000067128731732, 6362.984893743), ndigits=3), (0.0, 6362.985)) self.assertEqual(sround_range((6361.239852345, 6362.68923), ndigits=0), (6361.0, 6363.0)) self.assertEqual(sround_range((6361.239852345, 6362.68923), ndigits=2), (6361.24, 6362.69)) self.assertEqual( sround_range((-6362.68923, +6361.239852345), ndigits=2), (-6362.69, 6361.24)) self.assertEqual( sround_range((-0.000067128731732, +0.0027635092345), ndigits=2), (-0.00007, +0.00276)) self.assertEqual( sround_range((-0.000067128731732, +0.0027635092345), ndigits=1), (-0.0001, +0.0028)) self.assertEqual( sround_range((-0.000067128731732, +0.0027635092345), ndigits=0), (0.0, +0.003))
def get_workspace_variable_statistics(self, base_dir: str, res_name: str, var_name: str, var_index: Sequence[int], monitor=Monitor.NONE): workspace_manager = self.workspace_manager workspace = workspace_manager.get_workspace(base_dir) if res_name not in workspace.resource_cache: raise ValueError('Unknown resource "%s"' % res_name) dataset = workspace.resource_cache[res_name] if not isinstance(dataset, xr.Dataset): raise ValueError('Resource "%s" must be a Dataset' % res_name) if var_name not in dataset: raise ValueError('Variable "%s" not found in "%s"' % (var_name, res_name)) variable = dataset[var_name] if var_index: variable = variable[tuple(var_index)] with monitor.starting('Computing min/max', total_work=100.): with monitor.child(work=50.).observing('Computing min'): actual_min = float(variable.min(skipna=True)) with monitor.child(work=50.).observing('Computing max'): actual_max = float(variable.max(skipna=True)) actual_min, actual_max = sround_range((actual_min, actual_max), ndigits=2) return dict(min=actual_min, max=actual_max)