Skip to content

Commit

Permalink
Merge pull request #30 from greglucas/mnt-cleanup
Browse files Browse the repository at this point in the history
cleanup, linting, type annotations
  • Loading branch information
greglucas authored Jan 29, 2023
2 parents 606a11f + 9190a62 commit 0bfed27
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 176 deletions.
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

5 changes: 3 additions & 2 deletions .github/workflows/download_mirror.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""This is only for CI downloading/testing."""
from pathlib import Path
"""Only for CI downloading/testing."""
import tarfile
import urllib.request
from pathlib import Path


MSIS21_FILE = (
"https://gist.github.com/greglucas/"
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ concurrency:

on:
push:
branches: [ '*' ]
branches: [ 'main' ]
pull_request:
branches: [ main ]

jobs:
build:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install mypy
run: |
python -m pip install mypy numpy
mypy pymsis
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -60,11 +70,6 @@ jobs:
python -m pip install --upgrade pip
pip install -v .[tests]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --show-source --statistics
- name: Test with pytest
run: |
# TODO: Get coverage for other modules without specifying pymsis.msis directly
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
run: |
python .github/workflows/download_mirror.py
- uses: pypa/cibuildwheel@v2.11.2
- uses: pypa/cibuildwheel@v2.12.0
with:
only: ${{ matrix.only }}

Expand All @@ -103,7 +103,7 @@ jobs:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
name: Install Python
Expand Down
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ci:
autofix_prs: false
repos:
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.236'
hooks:
- id: ruff
args: [--fix]
45 changes: 21 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@
![image](https://swxtrec.github.io/pymsis/_static/pymsis-logo.png)

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5348502.svg)](https://doi.org/10.5281/zenodo.5348502)
![PyPi](https://badge.fury.io/py/pymsis.svg)
![Downloads](https://pepy.tech/badge/pymsis/month)
![GitHubActions](https://github.com/SWxTREC/pymsis/actions/workflows/tests.yml/badge.svg)
[![PyPi](https://badge.fury.io/py/pymsis.svg)](https://badge.fury.io/py/pymsis)
[![Downloads](https://static.pepy.tech/badge/pymsis/month)](https://pepy.tech/project/pymsis)
[![GitHubActions](https://github.com/SWxTREC/pymsis/actions/workflows/tests.yml/badge.svg)](https://github.com/SWxTREC/pymsis/actions?query=workflow%3Atests)
[![codecov](https://codecov.io/gh/SWxTREC/pymsis/branch/main/graph/badge.svg?token=NSUGKPJ3F7)](https://codecov.io/gh/SWxTREC/pymsis)

Pymsis is meant to be a minimal and fast Python wrapper of the NRLMSIS
models. Documentation to get started quickly can be found on the [home
page](https://swxtrec.github.io/pymsis/). It includes some
[examples](https://swxtrec.github.io/pymsis/examples/index.html) that
demonstrate how to access and plot the data.
Pymsis is a minimal and fast Python wrapper of the NRLMSIS
models (MSISE-00, MSIS2.0, MSIS2.1).

## Quickstart

A few short lines of code to get started quickly with pymsis.
Use Numpy to create a range of dates during the 2003 Halloween storm.
Then run the model at the location (lon, lat) (0, 0) and 400 km altitude.
The model will automatically download and access the F10.7 and ap data for you
if you have an internet connection.
The returned data structure has shape [ndates, nlons, nlats, nalts, 11],
but note that for this example we only have one longitude, latitude, and altitude.
The 11 is for each of the species MSIS calculates at each point of input.
The first element is the Total Mass Density (kg/m3) and if we plot that over
time, we can see how the mass density increased at 400 km altitude during this storm.
[Web viewer](https://swx-trec.com/msis): An interactive website using pymsis through cloud-based serverless functions.
[Project homepage](https://swxtrec.github.io/pymsis/): Location for all documentation.
[API Reference](https://swxtrec.github.io/pymsis/reference/index.html): Details about the various options and configurations available in the functions.
[Examples](https://swxtrec.github.io/pymsis/examples/index.html): Demo for how to access and plot the data.

**A few short lines of code to get started quickly with pymsis.**

1. Create a range of dates during the 2003 Halloween storm.
2. Run the model at the desired location (lon, lat) (0, 0) and 400 km altitude.
3. Plot the results to see how the mass density increased at 400 km altitude during this storm.

```python
import numpy as np
Expand All @@ -38,15 +36,14 @@ data = msis.run(dates, 0, 0, 400, geomagnetic_activity=-1)
import matplotlib.pyplot as plt
# Total mass density over time
plt.plot(dates, data[:, 0, 0, 0, 0])
plt.tight_layout()
plt.show()
```

[Additional examples](https://swxtrec.github.io/pymsis/examples/index.html) that
demonstrate how to access and plot the data.

[API Documentation](https://swxtrec.github.io/pymsis/reference/index.html) with
details about the various options and configurations available.
> **note**
>
> * The model will automatically download and access the F10.7 and ap data for you if you have an internet connection.
> * The returned data structure has shape [ndates, nlons, nlats, nalts, 11], but for this example we only have one point with many dates [ndates, 1, 1, 1, 11].
> * The 11 is for each of the species MSIS calculates for each input point. The first element is the Total Mass Density (kg/m3).
## NRL Mass Spectrometer, Incoherent Scatter Radar Extended Model (MSIS)

Expand Down
17 changes: 11 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
"""
Configuration file for the Sphinx documentation builder.
This file only contains a selection of the most common options. For a full
list see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""

# -- Path setup --------------------------------------------------------------

import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use resolve() to make it absolute, like shown here.
#
from pathlib import Path
import sys

from sphinx_gallery.sorting import ExampleTitleSortKey

import pymsis


sys.path.insert(0, Path("../../pymsis").resolve())

# -- Project information -----------------------------------------------------
Expand Down
27 changes: 25 additions & 2 deletions docs/source/development/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@
Development
===========

To contribute to pymsis, all you need to do is fork the GitHub repository,
To contribute to pymsis, you can fork the GitHub repository,
add your code, and make a pull request. If you are adding additional functionality,
you should also include a test with your enhancement.

Pymsis is purposefully minimal, with numpy as the only dependency.
Pymsis is purposefully minimal, with Numpy as the only dependency.
This makes it easy for other packages to leverage the interface to the Fortran
code without imposing a specific data storage or plotting framework.

A typical development workflow might look like the following:

.. code:: bash
# Install the development dependencies
pip install .[dev]
# Install the pre-commit hooks
pre-commit install
# Update the code on a feature branch
git checkout -b my-cool-feature
# Run the tests
pytest
# Commit the changes and push to your remote repository
git add my-file
git commit
git push -u origin my-cool-feature
# Go to GitHub and open a pull request!
5 changes: 3 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Pymsis Documentation
====================

This is a lightweight Python wrapper around the MSIS00 and MSIS2 Fortran source code.
The `MSIS model <https://www.nrl.navy.mil/ssd/branches/7630/modeling-upper-atmosphere>`_ is
developed by the Naval Research Laboratory.
The `MSIS model <https://www.nrl.navy.mil/Our-Work/Areas-of-Research/Space-Science/>`_ is
developed by the Naval Research Laboratory. For quick access to the model data without any code,
there is a web viewer that uses pymsis: `<https://swx-trec.com/msis>`_.

The :ref:`examples` are a good reference for quickly getting started with the Python code and demonstrate
how to call the models and plot the results. The explicit interfaces are described in the :ref:`api`.
Expand Down
2 changes: 1 addition & 1 deletion examples/plot_diurnal_variation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
diurnal variation at a single location.
"""
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np

from pymsis import msis
Expand Down
2 changes: 1 addition & 1 deletion examples/plot_surface_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"""
import matplotlib
from matplotlib.animation import FuncAnimation
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation

from pymsis import msis

Expand Down
24 changes: 2 additions & 22 deletions pymsis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
import os
from pathlib import Path
"""Python interface to the MSIS codes."""

__version__ = "0.6.0"

# If we are on Windows, Python 3.8+ then we need to add a DLL search path
# The libraries are located relative to this init file.
if os.name == "nt":
pymsis_dir = None
pymsis_dir_libs = None
try:
# add folder to Windows DLL search paths
pymsis_dir = Path(__file__).resolve().parent
pymsis_dir_libs = pymsis_dir / ".libs"
# This was added in Python 3.8, so we can default to this
# once we only support 3.8+
os.add_dll_directory(pymsis_dir)
# Additionally, we need the .libs directory which has gfortran
os.add_dll_directory(pymsis_dir_libs)

os.environ["PATH"] = f"{pymsis_dir};{pymsis_dir_libs};" f"{os.environ['PATH']}"
except Exception:
pass
del pymsis_dir, pymsis_dir_libs
__version__ = "0.6.0"
Loading

0 comments on commit 0bfed27

Please sign in to comment.