Exemplo n.º 1
0
def sph_answer(ds, ds_str_repr, ds_nparticles, field, weight, ds_obj, axis):
    # Make sure we're dealing with the right dataset
    assert str(ds) == ds_str_repr
    # Set up keys of test names
    hex_digests = {}
    dd = ds.all_data()
    assert dd["particle_position"].shape == (ds_nparticles, 3)
    tot = sum(dd[ptype, "particle_position"].shape[0]
              for ptype in ds.particle_types if ptype != "all")
    # Check
    assert tot == ds_nparticles
    dobj = create_obj(ds, ds_obj)
    s1 = dobj["ones"].sum()
    s2 = sum(mask.sum() for block, mask in dobj.blocks)
    assert s1 == s2
    if field[0] in ds.particle_types:
        particle_type = True
    else:
        particle_type = False
    if not particle_type:
        ppv_hd = pixelized_projection_values(ds, axis, field, weight, ds_obj)
        hex_digests["pixelized_projection_values"] = ppv_hd
    fv_hd = field_values(ds, field, ds_obj, particle_type=particle_type)
    hex_digests["field_values"] = fv_hd
    return hex_digests
Exemplo n.º 2
0
def test_pkdgrav():
    cosmology_parameters = dict(current_redshift=0.0,
                                omega_lambda=0.728,
                                omega_matter=0.272,
                                hubble_constant=0.702)
    kwargs = dict(field_dtypes={"Coordinates": "d"},
                  cosmology_parameters=cosmology_parameters,
                  unit_base={'length': (60.0, "Mpccm/h")},
                  n_ref=64)
    ds = data_dir_load(pkdgrav, TipsyDataset, (), kwargs)
    assert_equal(str(ds), "halo1e11_run1.00400")
    dso = [None, ("sphere", ("c", (0.3, 'unitary')))]
    dd = ds.all_data()
    assert_equal(dd["Coordinates"].shape, (26847360, 3))
    tot = sum(dd[ptype, "Coordinates"].shape[0] for ptype in ds.particle_types
              if ptype != "all")
    assert_equal(tot, 26847360)
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None]:
                    yield PixelizedProjectionValuesTest(
                        ds, axis, field, weight_field, dobj_name)
            yield FieldValuesTest(ds, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        assert_equal(s1, s2)
Exemplo n.º 3
0
def pixelized_projection_values(ds,
                                axis,
                                field,
                                weight_field=None,
                                dobj_type=None):
    if dobj_type is not None:
        obj = create_obj(ds, dobj_type)
    else:
        obj = None
    proj = ds.proj(field, axis, weight_field=weight_field, data_source=obj)
    frb = proj.to_frb((1.0, "unitary"), 256)
    frb[field]
    if weight_field is not None:
        frb[weight_field]
    d = frb.data
    for f in proj.field_data:
        # Sometimes f will be a tuple.
        d[f"{f}_sum"] = proj.field_data[f].sum(dtype="float64")
    # This is to try and remove python-specific anchors in the yaml
    # answer file. Also, using __repr__() results in weird strings
    # of strings that make comparison fail even though the data is
    # the same
    result = None
    for k, v in d.items():
        k = k.__repr__().encode("utf8")
        if result is None:
            result = hashlib.md5(k + v.tobytes())
        else:
            result.update(k + v.tobytes())
    return result.hexdigest()
Exemplo n.º 4
0
def test_gasoline():
    cosmology_parameters = dict(current_redshift=0.0,
                                omega_lambda=0.728,
                                omega_matter=0.272,
                                hubble_constant=0.702)
    kwargs = dict(cosmology_parameters=cosmology_parameters,
                  unit_base={'length': (1.0 / 60.0, "Mpccm/h")},
                  n_ref=64)
    ds = data_dir_load(gasoline, TipsyDataset, (), kwargs)
    yield assert_equal, str(ds), "agora_1e11.00400"
    dso = [None, ("sphere", ("c", (0.3, 'unitary')))]
    dd = ds.all_data()
    yield assert_equal, dd["Coordinates"].shape, (10550576, 3)
    tot = sum(dd[ptype, "Coordinates"].shape[0] for ptype in ds.particle_types
              if ptype != "all")
    yield assert_equal, tot, 10550576
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None]:
                    yield PixelizedProjectionValuesTest(
                        ds, axis, field, weight_field, dobj_name)
            yield FieldValuesTest(ds, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        yield assert_equal, s1, s2
def test_gasoline():
    cosmology_parameters = dict(current_redshift = 0.0,
                                omega_lambda = 0.728,
                                omega_matter = 0.272,
                                hubble_constant = 0.702)
    kwargs = dict(cosmology_parameters = cosmology_parameters,
                  unit_base = {'length': (1.0/60.0, "Mpccm/h")},
                  n_ref = 64)
    ds = data_dir_load(gasoline, TipsyDataset, (), kwargs)
    yield assert_equal, str(ds), "agora_1e11.00400"
    dso = [ None, ("sphere", ("c", (0.3, 'unitary')))]
    dd = ds.all_data()
    yield assert_equal, dd["Coordinates"].shape, (10550576, 3)
    tot = sum(dd[ptype,"Coordinates"].shape[0]
              for ptype in ds.particle_types if ptype != "all")
    yield assert_equal, tot, 10550576
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None]:
                    yield PixelizedProjectionValuesTest(
                        ds, axis, field, weight_field,
                        dobj_name)
            yield FieldValuesTest(ds, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        yield assert_equal, s1, s2
Exemplo n.º 6
0
def test_particle_fields():
    ds = data_dir_load(ep_cosmo)

    dso = [None, ("sphere", ("max", (0.1, "unitary")))]
    for dobj_name in dso:
        for field in _pfields:
            yield FieldValuesTest(ep_cosmo,
                                  field,
                                  dobj_name,
                                  particle_type=True)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj[("index", "ones")].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        assert_equal(s1, s2)
Exemplo n.º 7
0
def test_hello_world():
    ds = data_dir_load(hello_world)

    dso = [None, ("sphere", ("max", (0.25, "unitary")))]
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None, ("gas", "density")]:
                    yield PixelizedProjectionValuesTest(
                        hello_world, axis, field, weight_field, dobj_name)
            yield FieldValuesTest(hello_world, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj[("index", "ones")].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        assert_equal(s1, s2)
Exemplo n.º 8
0
def field_values(ds, field, obj_type=None, particle_type=False):
    # If needed build an instance of the dataset type
    obj = create_obj(ds, obj_type)
    determined_field = obj._determine_fields(field)[0]
    # Get the proper weight field depending on if we're looking at
    # particles or not
    if particle_type:
        weight_field = (determined_field[0], "particle_ones")
    else:
        weight_field = ("index", "ones")
    # Get the average, min, and max
    avg = obj.quantities.weighted_average_quantity(determined_field,
                                                   weight=weight_field)
    minimum, maximum = obj.quantities.extrema(field)
    # Return as a hashable bytestring
    return np.array([avg, minimum, maximum])
Exemplo n.º 9
0
def test_output_00080():
    ds = data_dir_load(output_00080)
    assert_equal(str(ds), "info_00080")
    dso = [None, ("sphere", ("max", (0.1, 'unitary')))]
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None, "density"]:
                    yield PixelizedProjectionValuesTest(
                        output_00080, axis, field, weight_field, dobj_name)
            yield FieldValuesTest(output_00080, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        assert_equal(s1, s2)
    assert_equal(ds.particle_type_counts, {'io': 1090895})
Exemplo n.º 10
0
def test_sizmbhloz():
    ds = data_dir_load(sizmbhloz)
    ds.max_range = 1024 * 1024
    yield assert_equal, str(ds), "sizmbhloz-clref04SNth-rs9_a0.9011.art"
    dso = [None, ("sphere", ("max", (0.1, 'unitary')))]
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None, "density"]:
                    yield PixelizedProjectionValuesTest(
                        sizmbhloz, axis, field, weight_field, dobj_name)
            yield FieldValuesTest(sizmbhloz, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        yield assert_equal, s1, s2
def test_output_00080():
    ds = data_dir_load(output_00080)
    yield assert_equal, str(ds), "info_00080"
    dso = [ None, ("sphere", ("max", (0.1, 'unitary')))]
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None, "density"]:
                    yield PixelizedProjectionValuesTest(
                        output_00080, axis, field, weight_field,
                        dobj_name)
            yield FieldValuesTest(output_00080, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        yield assert_equal, s1, s2
Exemplo n.º 12
0
def test_sizmbhloz():
    ds = data_dir_load(sizmbhloz)
    ds.max_range = 1024 * 1024
    assert_equal(str(ds), "sizmbhloz-clref04SNth-rs9_a0.9011.art")
    dso = [None, ("sphere", ("max", (0.1, "unitary")))]
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None, "density"]:
                    yield PixelizedProjectionValuesTest(
                        ds, axis, field, weight_field, dobj_name)
            yield FieldValuesTest(ds, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        assert_equal(s1, s2)
    assert_equal(ds.particle_type_counts, {"N-BODY": 100000, "STAR": 110650})
def test_sizmbhloz():
    ds = data_dir_load(sizmbhloz)
    ds.max_range = 1024*1024
    yield assert_equal, str(ds), "sizmbhloz-clref04SNth-rs9_a0.9011.art"
    dso = [ None, ("sphere", ("max", (0.1, 'unitary')))]
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None, "density"]:
                    yield PixelizedProjectionValuesTest(
                        sizmbhloz, axis, field, weight_field,
                        dobj_name)
            yield FieldValuesTest(sizmbhloz, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        yield assert_equal, s1, s2
Exemplo n.º 14
0
def test_snapshot_033():
    ds = data_dir_load(os33)
    yield assert_equal, str(ds), "snap_033"
    dso = [None, ("sphere", ("c", (0.1, 'unitary')))]
    dd = ds.all_data()
    yield assert_equal, dd["particle_position"].shape[0], 2 * (128 * 128 * 128)
    yield assert_equal, dd["particle_position"].shape[1], 3
    tot = sum(dd[ptype, "particle_position"].shape[0]
              for ptype in ds.particle_types if ptype != "all")
    yield assert_equal, tot, (2 * 128 * 128 * 128)
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None, "density"]:
                    yield PixelizedProjectionValuesTest(
                        os33, axis, field, weight_field, dobj_name)
            yield FieldValuesTest(os33, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        yield assert_equal, s1, s2
def test_snapshot_033():
    ds = data_dir_load(os33)
    yield assert_equal, str(ds), "snap_033"
    dso = [ None, ("sphere", ("c", (0.1, 'unitary')))]
    dd = ds.all_data()
    yield assert_equal, dd["particle_position"].shape[0], 2*(128*128*128)
    yield assert_equal, dd["particle_position"].shape[1], 3
    tot = sum(dd[ptype,"particle_position"].shape[0]
              for ptype in ds.particle_types if ptype != "all")
    yield assert_equal, tot, (2*128*128*128)
    for dobj_name in dso:
        for field in _fields:
            for axis in [0, 1, 2]:
                for weight_field in [None, "density"]:
                    yield PixelizedProjectionValuesTest(
                        os33, axis, field, weight_field,
                        dobj_name)
            yield FieldValuesTest(os33, field, dobj_name)
        dobj = create_obj(ds, dobj_name)
        s1 = dobj["ones"].sum()
        s2 = sum(mask.sum() for block, mask in dobj.blocks)
        yield assert_equal, s1, s2
Exemplo n.º 16
0
def projection_values(ds, axis, field, weight_field, dobj_type):
    if dobj_type is not None:
        dobj = create_obj(ds, dobj_type)
    else:
        dobj = None
    if ds.domain_dimensions[axis] == 1:
        # This originally returned None, but None can't be converted
        # to a bytes array (for hashing), so use -1 as a string,
        # since ints can't be converted to bytes either
        return bytes(str(-1).encode("utf-8"))
    proj = ds.proj(field, axis, weight_field=weight_field, data_source=dobj)
    # This is to try and remove python-specific anchors in the yaml
    # answer file. Also, using __repr__() results in weird strings
    # of strings that make comparison fail even though the data is
    # the same
    result = None
    for k, v in proj.field_data.items():
        k = k.__repr__().encode("utf8")
        if result is None:
            result = hashlib.md5(k + v.tobytes())
        else:
            result.update(k + v.tobytes())
    return result.hexdigest()