Skip to main content

Simple Python interface with the spatstat R package using rpy2

Project description

spatstat-interface

Build PyPi version codecov Code style: black

Simple Python interface with the spatial statistics R package spatstat using rpy2.

Dependencies

  • R (programming language),

  • Python dependencies are listed in the pyproject.toml file. Note that they mostly correspond to the latest version.

    [tool.poetry.dependencies]
    python = "^3.8"
    
    matplotlib = "^3.4.2"
    numpy = "^1.20.3"
    pandas = "^1.2.4"
    rpy2 = "^3.4.5"
    

Installation

You may consider using poetry to manage your whole project as described here https://github.com/guilgautier/template-python-project.

Install the project as a dependency

  • Install the latest version published on PyPi version

    # activate your virtual environment an run
    poetry add spatstat-interface
    # pip install spatstat-interface
    
  • Install from source (this may be broken)

    # activate your virtual environment an run
    poetry add git+https://github.com/For-a-few-DPPs-more/spatstat-interface.git
    # pip install git+https://github.com/For-a-few-DPPs-more/spatstat-interface.git
    

Install in editable mode and potentially contribute to the project

You may consider forking the repository.

In any case, your can clone the repository

  • if you have forked the repository

    git clone https://github.com/your_user_name/spatstat-interface.git
    
  • if you have not forked the repository

    git clone https://github.com/For-a-few-DPPs-more/spatstat-interface.git
    

Using poetry

The package can be installed in editable mode along with

  • main (non-optional) dependencies, see [tool.poetry.dependencies] in pyproject.toml
  • development dependencies, [tool.poetry.dev-dependencies] in pyproject.toml
cd spatstat-interface
# activate your virtual environment or run
# poetry shell  # to create/activate local .venv (see poetry.toml)
poetry install
# poetry install --no-dev  # to avoid installing the development dependencies

Using pip

For now, packages defined only by a pyproject.toml file can't be installed editable mode directly using pip.

Alternatives

  1. consider using poetry instead

  2. otherwise, for your convenience, the pyproject.toml file was duplicated into a setup.cfg file to enable editable install using pip.

    • modify the [build-system] section in pyproject.toml to

      [build-system]
      requires = ["setuptools >= 40.9.0", "wheel"]
      build-backend = "setuptools.build_meta"
      
    • intstall the project in editable mode

      cd spatstat-interface
      # activate your virtual environment and run
      pip install -e .
      

Documentation

Main ressources

Notes about spatstat

The spatstat package has recently been split into multiple sub-packages and extensions.

Using spatstat-interface, sub-packages and extensions are accessible in the following way

from spatstat_interface import SpatstatInterface

spatstat = SpatstatInterface(update=True)
# spatstat.core is None
# spatstat.geom is None

# load/import sub-packages or extensions
spatstat.import_package("core", "geom", update=True)
spatstat.core
spatstat.geom

Notes about calling functions

Calling function.variant

Instead of calling function.variant as in R replace . by _ in Python.

# R code pcf.ppp
spatstat.core::pcf.ppp(X)
# Python code pcf_ppp
my_dpp = spatstat.core.pcf_ppp(X)

Using keyword arguments

Consider using Python dictionaries to pass keyword arguments. Below are a few examples.

  • dot keywords, for example passing var.approx keyword argument won't work in Python

    # R code
    spatstat.core::pcf.ppp(X, kernel="epanechnikov", var.approx=False)
    
    # Python code
    params = {"kernel": "epanechnikov", "var.approx": False}
    my_dpp = spatstat.core.pcf_pp(X, **params)
    
  • reserved keywords, for example lambda is a reserved Python keyword ; it can't be used as a keyword argument

    # R code
    spatstat.core::dppGauss(lambda=rho, alpha=alpha, d=d)
    
    # Python code
    params = {"lambda": rho, "alpha": alpha, "d": d}
    my_dpp = spatstat.core.dppGauss(**params)
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spatstat-interface-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

spatstat_interface-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file spatstat-interface-0.1.0.tar.gz.

File metadata

  • Download URL: spatstat-interface-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.10 CPython/3.8.5 Darwin/20.6.0

File hashes

Hashes for spatstat-interface-0.1.0.tar.gz
Algorithm Hash digest
SHA256 325d230423b8a9ffc2224781fa3771e2d5f08a102c5d0f3913fef54717455b4a
MD5 699a986eff5a65a4dc02e28069ebad02
BLAKE2b-256 f80a61d26ac9a6b677e98b0f92bbd6057859cdb3a96d2aaaf8419804b6a7eb82

See more details on using hashes here.

File details

Details for the file spatstat_interface-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spatstat_interface-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a90a8c1c3f6fd0768c2eb8287c4b477d34b87dbfb73d28bdc93ae13b85c8a5f6
MD5 9f2729662bf7dca0778424953a21a762
BLAKE2b-256 fb1fa2348fe752bd77fc9918e23f7fbb325fa1dcbdf7c0664020b673a142fedc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page