{"id":22565151,"url":"https://github.com/cphyc/ppyv","last_synced_at":"2025-03-28T13:17:48.070Z","repository":{"id":263999606,"uuid":"892041070","full_name":"cphyc/ppyv","owner":"cphyc","description":"Tool to project AMR datasets onto a position-position-velocity (PPV) cube for kinematics analysis.","archived":false,"fork":false,"pushed_at":"2024-11-22T17:47:04.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T13:43:16.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cphyc.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-21T12:08:03.000Z","updated_at":"2024-11-26T15:52:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"395b5ceb-cd74-43fe-b384-354c1d1663d9","html_url":"https://github.com/cphyc/ppyv","commit_stats":null,"previous_names":["cphyc/ppyv"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cphyc%2Fppyv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cphyc%2Fppyv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cphyc%2Fppyv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cphyc%2Fppyv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cphyc","download_url":"https://codeload.github.com/cphyc/ppyv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246034312,"owners_count":20712857,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T23:19:41.927Z","updated_at":"2025-03-28T13:17:48.064Z","avatar_url":"https://github.com/cphyc.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PPyV\n\nThe PPyV package allows to project 3D AMR datasets onto a xyv cube.\nThe package is written in C++ and uses:\n- the [Kokkos](https://github.com/kokkos/kokkos) library for parallelization on GPUs and CPUs,\n- the [pybind11](https://github.com/pybind/pybind11) library to create a Python interface.\n\n## Installation\n\n### Requirements\n\nThe PPyV package requires:\n- a C++17 compiler (GCC, clang, ...),\n- cmake,\n- a compiler for the GPU if compiling for that target.\n\n## Installation\n\n```bash\n# Clone the repository\ngit clone https://github.com/cphyc/ppyv.git --recursive\n\n# Pip install the package (single threaded)\npip install .\n\n# Pip install the package (with OpenMP support)\npip install . -Ccmake.define.Kokkos_ENABLE_OPENMP=ON\n\n# Pip install the package (with CUDA support)\npip install . -Ccmake.define.Kokkos_ENABLE_CUDA=ON\n\n# Pip install the package (with CUDA support, using clang as compiler)\nCC=clang CXX=clang++ pip install . -Ccmake.define.Kokkos_ENABLE_CUDA=ON\n\n# Test import\npython -c 'import ppyv'\n```\n\n## Note on compiling with CUDA\n\nRefer to https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#host-compiler-support-policy to check the compatibility of your compiler with CUDA. For example, CUDA 12.6 supports only GCC 6.x to 13.2 or Clang 7.x to 18.0.\n\n# Usage\n\n```python\nfrom matplotlib import pyplot as plt\nimport numpy as np\n\nimport yt\nfrom ppyv import ppyv\n\n\n# Create velocity dispersion field\n@yt.derived_field(\n    name=(\"gas\", \"velocity_dispersion\"),\n    units=\"km/s\",\n    sampling_type=\"cell\",\n    validators=[yt.ValidateSpatial(ghost_zones=1)],\n)\ndef velocity_dispersion(field, data):\n    m = (data[\"cell_mass\"].to(\"Msun\")).d\n    px = (m * data[\"velocity_x\"].to(\"km/s\")).d\n    py = (m * data[\"velocity_y\"].to(\"km/s\")).d\n    pz = (m * data[\"velocity_z\"].to(\"km/s\")).d\n\n    output = np.zeros_like(m)\n    for i in range(1, output.shape[0] - 1):\n        for j in range(1, output.shape[1] - 1):\n            for k in range(1, output.shape[2] - 1):\n                # Use 27 neighbours to estimate the velocity dispersion\n                sl = slice(i - 1, i + 2), slice(j - 1, j + 2), slice(k - 1, k + 2)\n                mtot = m[sl].sum(axis=(0, 1, 2))\n                varx = np.var(px[sl], axis=(0, 1, 2))\n                vary = np.var(py[sl], axis=(0, 1, 2))\n                varz = np.var(pz[sl], axis=(0, 1, 2))\n                output[i, j, k] = np.sqrt(varx + vary + varz) / mtot\n\n    return data.apply_units(output, \"km/s\")\n\n\nNpix = 256\nNpix_velocity = 256\n\n# Load example dataset\nds = yt.load_sample(\"output_00080\")\n\n# Find the densest cell\nad = ds.all_data()\ncenter = ds.arr(ad.argmax(\"density\"))\n\n# Create a sphere around it\nr = ds.quan(400, \"kpc\")\nsp = ds.sphere(center, r)\nsp[\"velocity_dispersion\"]\nspp = ds.sphere(center, (5, \"kpc\"))\n\nbulk_velocity = spp.quantities.bulk_velocity(use_gas=True, use_particles=False)\nnormal = sp.quantities.angular_momentum_vector(use_gas=True, use_particles=False)\nnormal = (normal / np.linalg.norm(normal)).d\n\n# Extract data\nxc = (np.stack([(sp[k]).to(\"kpc\") for i, k in enumerate(\"xyz\")], axis=1)).d\nvc = np.stack([(sp[f\"velocity_{k}\"] - bulk_velocity[i]).to(\"km/s\") for i, k in enumerate(\"xyz\")], axis=1).d\ndx = sp[\"dx\"].to(\"kpc\").d\nsigma_v = sp[\"velocity_dispersion\"].to(\"km/s\").d\nrho = sp[\"density\"].to(\"mp/cm**3\").d\n\n# Parameters for the plot\nvmin = -50\nvmax =50\n\n## Compute normal vectors\n\nw = normal\nu = np.cross(w, [1, 0, 0])\nu /= np.linalg.norm(u)\nv = np.cross(w, u)\nv /= np.linalg.norm(v)\nO = sp.center.to(\"kpc\").d\n\nprint(\"================\")\nprint(u, v, w)\nprint(\"================\")\n\ncube = ppyv.compute_hypercube(\n    pos=xc,\n    vel=vc,\n    dx=dx,\n    sigma_v=sigma_v,\n    weight=rho,\n    Npix=Npix,\n    Npix_velocity=Npix_velocity,\n    u=u,\n    v=v,\n    O=O,\n    width=2 * r.d,\n    vmin=vmin,\n    vmax=vmax,\n)\n\nfig, axes = plt.subplots(1, 3, figsize=(15, 5), constrained_layout=True)\n\nnorm = plt.matplotlib.colors.LogNorm()\naxes[0].imshow(\n    cube.sum(axis=2).T,\n    origin=\"lower\",\n    norm=norm,\n    extent=(-r.d, r.d, -r.d, r.d),\n    cmap=\"plasma\",\n)\naxes[0].set(\n    xlabel=f\"x [{r.units}]\",\n    ylabel=f\"y [{r.units}]\",\n)\nsl = slice(Npix//4, 3*Npix//4)\naxes[1].imshow(\n    cube[:, sl, :].sum(axis=1).T,\n    origin=\"lower\",\n    extent=(-r.d, r.d, vmin, vmax),\n    norm=norm,\n    cmap=\"plasma\",\n)\naxes[1].set_aspect(\"auto\")\naxes[1].set(\n    xlabel=f\"x [{r.units}]\",\n    ylabel=\"v [km/s]\",\n)\naxes[2].imshow(\n    cube[sl, :, :].sum(axis=0).T,\n    origin=\"lower\",\n    extent=(-r.d, r.d, vmin, vmax),\n    norm=norm,\n    cmap=\"plasma\",\n)\naxes[2].set_aspect(\"auto\")\naxes[2].set(\n    xlabel=f\"y [{r.units}]\",\n    ylabel=\"v [km/s]\",\n)\n# Create axis for colorbar\nplt.colorbar(\n    plt.cm.ScalarMappable(norm=norm, cmap=\"plasma\"),\n    ax=axes,\n    orientation=\"vertical\",\n    fraction=0.05,\n    aspect=20,\n)\nplt.show()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcphyc%2Fppyv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcphyc%2Fppyv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcphyc%2Fppyv/lists"}