def test_argwhere_str():
    x = np.array(list("Hello world"))
    d = da.from_array(x, chunks=(4, ))

    x_nz = np.argwhere(x)
    d_nz = da.argwhere(d)

    assert_eq(d_nz, x_nz)
Exemplo n.º 2
0
def test_argwhere_str():
    x = np.array(list("Hello world"))
    d = da.from_array(x, chunks=(4,))

    x_nz = np.argwhere(x)
    d_nz = da.argwhere(d)

    assert_eq(d_nz, x_nz)
def test_argwhere_obj():
    x = np.random.randint(10, size=(15, 16)).astype(object)
    d = da.from_array(x, chunks=(4, 5))

    x_nz = np.argwhere(x)
    d_nz = da.argwhere(d)

    assert_eq(d_nz, x_nz)
Exemplo n.º 4
0
def test_argwhere_obj():
    x = np.random.randint(10, size=(15, 16)).astype(object)
    d = da.from_array(x, chunks=(4, 5))

    x_nz = np.argwhere(x)
    d_nz = da.argwhere(d)

    assert_eq(d_nz, x_nz)
def test_argwhere():
    for shape, chunks in [(0, ()), ((0, 0), (0, 0)), ((15, 16), (4, 5))]:
        x = np.random.randint(10, size=shape)
        d = da.from_array(x, chunks=chunks)

        x_nz = np.argwhere(x)
        d_nz = da.argwhere(d)

        assert_eq(d_nz, x_nz)
Exemplo n.º 6
0
def test_argwhere():
    for shape, chunks in [(0, ()), ((0, 0), (0, 0)), ((15, 16), (4, 5))]:
        x = np.random.randint(10, size=shape)
        d = da.from_array(x, chunks=chunks)

        x_nz = np.argwhere(x)
        d_nz = da.argwhere(d)

        assert_eq(d_nz, x_nz)
Exemplo n.º 7
0
    def select_valid_oof(y, oof):
        if isinstance(oof, da.Array):
            oof = DaskToolBox.make_chunk_size_known(oof)
            if len(oof.shape) == 1:
                nan_rows = da.isnan(oof[:])
            elif len(oof.shape) == 2:
                nan_rows = da.isnan(oof[:, 0])
            elif len(oof.shape) == 3:
                nan_rows = da.isnan(oof[:, 0, 0])
            else:
                raise ValueError(f'Unsupported shape:{oof.shape}')

            if nan_rows.sum().compute() == 0:
                return y, oof

            idx = da.argwhere(~nan_rows)
            idx = DaskToolBox.make_chunk_size_known(idx).ravel()
            idx = DaskToolBox.make_chunk_size_known(idx)
            if isinstance(y, da.Array):
                return y[idx], oof[idx]
            else:
                return DaskToolBox.select_1d(y, idx), oof[idx]
        else:
            return ToolBox.select_valid_oof(y, oof)
Exemplo n.º 8
0
        z_pz, z_pz_bins = da.histogramdd(
            df[['position_z', 'momentum_z']].to_dask_array(),
            bins=[80, 80],
            range=[[z_min, z_max], [-8.0e-23, 8.0e-23]],
            weights=df["weighting"].to_dask_array())
        print(z_pz.compute())

        #   example4: save all data data to parquet files
        delayed_save = delayed(df.to_parquet("electrons.parquet"))
        delayed_save.compute()

    # Meshes
    if found_dask:
        E = s.iterations[400].meshes["E"]
        E_x = E["x"]
        E_y = E["y"]
        E_z = E["z"]
        darr_x = E_x.to_dask_array()
        darr_y = E_y.to_dask_array()
        darr_z = E_z.to_dask_array()

        # example compute intensity
        Intensity = darr_x * darr_x + darr_y * darr_y + darr_z * darr_z
        Intensity_max = Intensity.max().compute()
        idx_max = da.argwhere(Intensity == Intensity_max).compute()[0]
        pos_max = E.grid_unit_SI * 1.0e6 * (idx_max * E.grid_spacing +
                                            E.grid_global_offset)
        print("maximum intensity I={} at index={} z={}mu".format(
            Intensity_max, idx_max, pos_max[2]))