kNNpy makes use of the following packages:
numpyscipypyfftwpylianshealpy (optional)scikit-learn (optional)astropy-healpix (optional)matplotlib (optional)These need to be installed before using the package, preferably in a fresh virtual environment (see instructions below).
💡 Optional dependencies
scikit-learncan be skipped if you do not intend to use thekNNpy.kNN_2D_Angmoduleastropy-healpixcan be skipped if you do not intend to use theAuxiliary.TPCF.TracerField2Dmodule.healpyandmatplotlibcan be skipped if you do not intend to use thekNNpy.kNN_2D_Ang,kNNpy.Auxiliary.TPCF.TracerField2DandkNNpy.Auxiliary.PeakStatisticsmodules.
Change to your preferred installation directory, create a Python virtual environment and install the dependencies.
⚠️ Warning: Do not use anaconda or miniconda for the virtual environment as it may cause conflicts with Pylians. Also, do not name the virtual environment kNNpy to avoid namespace issues.
cd /path/to/installation/directory
python3 -m venv kNNpy_env
source kNNpy_env/bin/activate
pip install numpy scipy pyfftw Pylians healpy scikit-learn astropy-healpix matplotlib
💡 Note on Pylians installation
Sometimes, the Pylians installation fails when usingpip(especially on macOS). If that happens:
- First install all other dependencies (without Pylians)
- Then install Pylians in development mode following their official instructions:
👉 Pylians_documentation
If you do not want the optional dependencies, replace the last line above by:
pip install numpy scipy pyfftw Pylians
git clone https://github.com/vikhyat108/kNNpy.git
PYTHONPATHExport the path to the installed repository to your Python path:
export PYTHONPATH="${PYTHONPATH}:/path/to/installation/directory/kNNpy/"
~/.bashrc or ~/.zshrc.To check if kNNpy is successfully installed and ready to use, run the following command:
cd /path/to/installation/directory/
cd kNNpy/Tests/
python3 import_all_modules.py
If you did not install the optional dependencies, replace the last line above by:
python3 import_required_modules.py
If no error message is returned, the installation is succesful.
Unfortunately, kNNpy is currently not supported on Windows. Future support may be added in later releases.
Change to your working directory:
cd /my/working/directory
Activate your virtual environment:
source /path/to/virtual/environment/bin/activate
Set the PYTHONPATH (if not already done) and in your Python scripts or notebooks, you can now:
import kNNpy
💡 Note: If you skipped the optional dependencies, use the from kNNpy import <MODULE NAME> idiom instead of import kNNpy.