def getter(self): current_value = getattr(self, f"_{name}") if current_value is not None: return current_value else: with h5py.File(filename, "r") as handle: try: if mask is not None: # First, need to calculate data shape (which may be # non-trivial), so we read in the first value first_value = handle[field][0] output_type = first_value.dtype output_size = first_value.size if output_size != 1: output_shape = (mask_size, output_size) else: output_shape = mask_size setattr( self, f"_{name}", cosmo_array( read_ranges_from_file( handle[field], mask, output_shape=output_shape, output_type=output_type, columns=columns, ), unit, cosmo_factor=cosmo_factor, name=description, ), ) else: setattr( self, f"_{name}", cosmo_array( # Only use column data if array is multidimensional, otherwise # we will crash here handle[field][:, columns] if handle[field].ndim > 1 else handle[field][:], unit, cosmo_factor=cosmo_factor, name=description, ), ) except KeyError: print(f"Could not read {field}") return None return getattr(self, f"_{name}")
def getter(self): current_value = getattr(self, f"_{name}") if current_value is not None: return current_value else: with h5py.File(filename, "r") as handle: try: if mask is not None: # First, need to claculate data shape (which may be # non-trivial), so we read in the first value first_value = handle[field][0] output_type = first_value.dtype output_size = first_value.size if output_size != 1: output_shape = (mask_size, output_size) else: output_shape = mask_size import pdb pdb.set_trace() setattr( self, f"_{name}", cosmo_array( read_ranges_from_file( handle[field], mask, output_shape=output_shape, output_type=output_type, ), unit, cosmo_factor=cosmo_factor, ), ) else: setattr( self, f"_{name}", cosmo_array(handle[field][...], unit, cosmo_factor=cosmo_factor), ) except KeyError: print(f"Could not read {field}") return None return getattr(self, f"_{name}")
def test_argless_copyfuncs(self, func): arr = cosmo_array( np.ones((10, 10)), units="Mpc", cosmo_factor=cosmo_factor("a^1", 1), comoving=False, ) assert hasattr(getattr(arr, func)(), "cosmo_factor") assert hasattr(getattr(arr, func)(), "comoving")
def test_unit_array(self): arr = cosmo_array( np.ones((10, 10)), units="Mpc", cosmo_factor=cosmo_factor("a^1", 1), comoving=False, ) res = arr.unit_array assert hasattr(res, "cosmo_factor") assert hasattr(res, "comoving")