From 5a0e83619644116fa20bef94541fd294aa9466bb Mon Sep 17 00:00:00 2001 From: Karl Laundal Date: Fri, 15 Jul 2022 12:44:21 -0400 Subject: [PATCH] restructured so the code is installable --- README.md | 18 ++++++++++--- setup.py | 39 +++++++++++++++++++++++++++ IGRF13.shc => src/ppigrf/IGRF13.shc | 0 __init__.py => src/ppigrf/__init__.py | 0 ppigrf.py => src/ppigrf/ppigrf.py | 0 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 setup.py rename IGRF13.shc => src/ppigrf/IGRF13.shc (100%) rename __init__.py => src/ppigrf/__init__.py (100%) rename ppigrf.py => src/ppigrf/ppigrf.py (100%) diff --git a/README.md b/README.md index 6af7425..0074915 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,21 @@ See https://www.ngdc.noaa.gov/IAGA/vmod/igrf.html for details and https://doi.or The code is vectorized, so calculations should be pretty fast. -TODO: Some more testing -## How? -The only dependencies are Numpy and Pandas. There is no install. Just copy ppigrf.py and IGRF13.shc to your working directory and you are good to go. Or have the ppigrf directory somewhere that Python can find it. Then you should be able to import like this: +## Install +The only dependencies are Numpy and Pandas. Install by either +``` +pip install ppigrf +``` +or clone the repository and run +``` +python setup.py install +``` + +Also, if you don't want to install a module but use the code in your project, just grap ppigrf.py and the .shc file (from src/ppigrf) and place it in your working directory. That's all. + +## Example +All the above choices should enable you to import like this: ```python import ppigrf ``` @@ -57,6 +68,7 @@ It should be straightforward to swap the IGRF .shc file with another model, but The code is vectorized, so it will be quite fast, but probably not as fast as compiled Fortran code. One application which may require more optimization is field line tracing: In the current implementation, the coefficients are loaded and interpolated in time for every function call, which gives a lot of unnecessary overhead. +Thanks to Juha Vierinen for the setup script, and for making ppigrf available via PyPI. ## Contact If you find errors, please let me know! diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3d50421 --- /dev/null +++ b/setup.py @@ -0,0 +1,39 @@ +import setuptools + +# Howto +# +#This is how to upload a project to pipy. This is mainly a note to self, as this is the first project I have uplo#aded to pypi: +# +#python3 -m venv /tmp/venv +#source /tmp/venv/bin/activate +#pip install build +#pip install twine +#python3 -m build +#python3 -m twine upload dist/ppigrf-1.0.0.tar.gz + +#Genrate long description using readme file +with open("README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + +setuptools.setup( + name="ppigrf", + version="1.0.0", + author="Karl Laundal", + author_email="readme@file.md", + description="Pure Python IGRF", + long_description=long_description, + long_description_content_type="text/markdown", + classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "Natural Language :: English", + "Programming Language :: Python :: 3", + ], + install_requires=[ + 'numpy>=0.13.1', + ], + package_dir={"": "src"}, + package_data={'':['IGRF13.shc']}, + packages=setuptools.find_packages(where="src"), + python_requires=">=3.6", +) \ No newline at end of file diff --git a/IGRF13.shc b/src/ppigrf/IGRF13.shc similarity index 100% rename from IGRF13.shc rename to src/ppigrf/IGRF13.shc diff --git a/__init__.py b/src/ppigrf/__init__.py similarity index 100% rename from __init__.py rename to src/ppigrf/__init__.py diff --git a/ppigrf.py b/src/ppigrf/ppigrf.py similarity index 100% rename from ppigrf.py rename to src/ppigrf/ppigrf.py