def test_reading_select_region_half_box(filename): """ Tests reading the spatial region and sees if it lies within the region we told it to! Specifically, we test to see if all particles lie within half a boxsize. """ full_data = load(filename) # Mask off the lower bottom corner of the volume. mask_region = mask(filename, spatial_only=True) restrict = array([ [0.0, 0.0, 0.0] * full_data.metadata.boxsize.units, full_data.metadata.boxsize * 0.49, ]).T mask_region.constrain_spatial(restrict=restrict) selected_data = load(filename, mask=mask_region) selected_coordinates = selected_data.gas.coordinates # Some of these particles will be outside because of the periodic BCs assert ( (selected_coordinates / full_data.metadata.boxsize) > 0.5).sum() < 25
def test_reading_select_region_spatial(filename): """ Tests reading select regions of the volume, comparing the masks attained with spatial_only = True and spatial_only = False. """ full_data = load(filename) # Mask off the lower bottom corner of the volume. mask_region = mask(filename, spatial_only=True) mask_region_nospatial = mask(filename, spatial_only=False) restrict = array([ [0.0, 0.0, 0.0] * full_data.metadata.boxsize.units, full_data.metadata.boxsize * 0.5, ]).T mask_region.constrain_spatial(restrict=restrict) mask_region_nospatial.constrain_spatial(restrict=restrict) selected_data = load(filename, mask=mask_region) selected_data_nospatial = load(filename, mask=mask_region_nospatial) selected_coordinates = selected_data.gas.coordinates selected_coordinates_nospatial = selected_data_nospatial.gas.coordinates assert (selected_coordinates_nospatial == selected_coordinates).all() return
def test_reading_select_region_metadata_not_spatial_only(filename): """ The same as test_reading_select_region_metadata but for spatial_only=False. """ full_data = load(filename) # Mask off the centre of the volume. mask_region = mask(filename, spatial_only=False) restrict = array( [full_data.metadata.boxsize * 0.26, full_data.metadata.boxsize * 0.74]).T mask_region.constrain_spatial(restrict=restrict) selected_data = load(filename, mask=mask_region) selected_coordinates = selected_data.gas.coordinates # Now need to repeat the selection by hand: subset_mask = logical_and.reduce([ logical_and(x > y_lower, x < y_upper) for x, (y_lower, y_upper) in zip(full_data.gas.coordinates.T, restrict) ]) # We also need to repeat for the thing we just selected; the cells only give # us an _approximate_ selection! selected_subset_mask = logical_and.reduce([ logical_and(x > y_lower, x < y_upper) for x, (y_lower, y_upper) in zip(selected_data.gas.coordinates.T, restrict) ]) hand_selected_coordinates = full_data.gas.coordinates[subset_mask] assert (hand_selected_coordinates == selected_coordinates[selected_subset_mask]).all() return