Skip to content

Commit aa078b3

Browse files
authored
ci tools to build documentation in pr and test fix for oom issues in build (#145)
* added ci workflow to build documentation on pull request * added option to increase border pading around catalog plots * added function to label figures for publication * changed test_global_binning to use california_relm_region to preserve memory * fixed bug in workflow yaml file * added checklist for pycsep pull requests * bug in docs run script. removed manual triggering. * updates to CONTRIBUTING.md
1 parent e02e7da commit aa078b3

9 files changed

+125
-28
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: docs
2+
on:
3+
pull_request:
4+
branches: [ master ]
5+
jobs:
6+
build_docs:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Set up Python 3.7
11+
uses: actions/setup-python@v2
12+
with:
13+
python-version: 3.7
14+
- name: Install dependencies
15+
run: |
16+
sudo apt-get update
17+
sudo apt-get install libproj-dev proj-data proj-bin
18+
sudo apt-get install libgeos-dev
19+
sudo apt-get install python3-sphinx
20+
python -m pip install --upgrade pip
21+
pip install numpy
22+
pip install wheel
23+
pip install pytest pytest-cov
24+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
25+
pip install pillow
26+
- name: Install PyCSEP
27+
run: |
28+
python setup.py install
29+
- name: Build documentation
30+
run: |
31+
make -C docs clean
32+
make -C docs html

.github/workflows/build-sphinx.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ on:
66

77
jobs:
88
build_docs:
9-
109
runs-on: ubuntu-latest
11-
1210
steps:
1311
- uses: actions/checkout@v2
1412
- name: Set up Python 3.7
@@ -26,11 +24,7 @@ jobs:
2624
pip install wheel
2725
pip install pytest pytest-cov
2826
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
29-
pip install sphinx-gallery>=0.7.0
30-
pip install sphinx-rtd-theme
3127
pip install pillow
32-
pip uninstall -y shapely
33-
pip install shapely --no-binary shapely
3428
- name: Install PyCSEP
3529
run: |
3630
python setup.py install

.github/workflows/python-app.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
build:
1414

1515
runs-on: ubuntu-latest
16-
1716
steps:
1817
- uses: actions/checkout@v2
1918
- name: Set up Python 3.7

CONTRIBUTING.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Contributing to PyCSEP
1+
# Contributing to pyCSEP
22

3-
This document provides an overview on how to contribute to PyCSEP. It will provide step-by-step instructions and hope to
3+
This document provides an overview on how to contribute to pyCSEP. It will provide step-by-step instructions and hope to
44
answer some questions.
55

66

77
## Getting Started
88

99
* Make sure you have an active GitHub account
10-
* Download and install git
11-
* Read the git documentation
12-
* Install a development version of PyCSEP
13-
* If you haven't worked with Git Forks before, make sure to read the documentation linked here:
10+
* Download and install `git`
11+
* Read git documentaion if you aren't familiar with `git`
12+
* Install the **development version** of PyCSEP
13+
* If you haven't worked with git Forks before, make sure to read the documentation linked here:
1414
[some helping info](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks).
1515

1616
## Developer Installation
@@ -24,17 +24,21 @@ We recommend using `conda` to install the development environment.
2424
conda env create -f requirements.yml
2525
conda activate csep-dev
2626
pip install -e .[all]
27-
# sync with default repository
27+
# add upstream repository
2828
git remote add upstream https://github.com/SCECCode/pycsep.git
2929

30-
Note: use the commend `conda deactivate` to go back to your regular environment.
30+
Note: use the command `conda deactivate` to go back to your regular environment when you are done working with pyCSEP.
3131

3232
## Submitting a Pull Request
3333

34-
Pull requests are great! Please submit them to us! Here's how:
34+
### Some notes for starting a pull request
35+
36+
Pull requests are how we use your changes to the code! Please submit them to us! Here's how:
3537

3638
1. Make a new branch. For features/additions base your new branch at `master`.
37-
2. Add a test! Only pull requests for documentation and refactoring do not require a test.
39+
2. Make sure to add tests! Only pull requests for documentation, refactoring, or plotting features do not require a test.
40+
3. Also, documentation must accompany new feature requests.
41+
- Note: We would really appreciate pull requests that help us improve documentation.
3842
3. Make sure the tests pass. Run `./run_tests.sh` in the top-level directory of the repo.
3943
4. Push your changes to your fork and submit a pull request. Make sure to set the branch to `pycsep:master`.
4044
5. Wait for our review. There may be some suggested changes or improvements. Changes can be made after
@@ -43,9 +47,26 @@ the pull request has been opening by simply adding more commits to your branch.
4347
Pull requests can be changed after they are opened, so create a pull request as early as possible.
4448
This allows us to provide feedback during development and to answer any questions.
4549

46-
Please make sure to set the correct branch for your pull request. Also, please do not include large files in your pull request.
47-
If you feel that you need to add large files, let us know and we can figure something out.
50+
Also, if you find pyCSEP to be useful, but don't want to contribute to the code we highly encourage updates to the documentation!
4851

52+
Please make sure to set the correct branch for your pull request. Also, please do not include large files in your pull request.
53+
If you feel that you need to add large files, such as a benchmark forecast, let us know and we can figure something out.
54+
55+
### Tips to get your pull request accepted quickly
56+
57+
1. Any new feature that contains calculations must contain unit-tests to ensure that the calculations are doing what you
58+
expect. Some exceptions to this are documentation changes and new plotting features.
59+
2. Documentation should accompany any new feature additions into the package.
60+
* Plotting functions should provide a sphinx-gallery example, which can be found [here](https://github.com/SCECcode/pycsep/blob/master/examples/tutorials/catalog_filtering.py).
61+
* More complex features might require additional documentation. We will let you know upon seeing your pull request.
62+
* The documentation use sphinx which compiles reST. Some notes on that can be found [here](https://www.sphinx-doc.org/en/master/usage/quickstart.html).
63+
3. pyCSEP uses pytest as a test runner. Add new tests to the `tests` folder in an existing file or new file starting matching `test_*.py`
64+
4. New scientific capabilities that are not previously published should be presented to the CSEP science group as part of a
65+
science review. This will consist of a presentation that provides a scientific justification for the feature.
66+
5. Code should follow the [pep8](https://pep8.org/) style-guide.
67+
6. Functions should use [Google style docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html). These
68+
get compiled by Sphinx to become part of the documentation.
69+
4970
## Submitting an Issue
5071

5172
Please open an issue if you want to ask a question about PyCSEP.
@@ -54,15 +75,17 @@ Please open an issue if you want to ask a question about PyCSEP.
5475
* Please apply the correct tag to your issue so others can search
5576

5677
If you want to submit a bug report, please provide the information below:
57-
* PyCSEP version, Python version, and Platform (Linux, Windows, Mac OSX, etc)
58-
* How did you install PyCSEP (pip, anaconda, from source...)
78+
* pyCSEP version, Python version, and Platform (Linux, Windows, Mac OSX, etc)
79+
* How did you install pyCSEP (pip, anaconda, from source...)
5980
* Please provide a short, complete, and correct example that demonstrates the issue.
6081
* If this broke in a recent update, please tell us when it used to work.
6182

6283
## Additional Resources
6384
* [Working with Git Forks](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks)
6485
* [Style Guide](http://google.github.io/styleguide/pyguide.html)
6586
* [Docs or it doesn’t exist](https://lukeplant.me.uk/blog/posts/docs-or-it-doesnt-exist/)
87+
* [Quickstart guide for Sphinx](https://www.sphinx-doc.org/en/master/usage/quickstart.html)
88+
* [Pep8 style guide](https://pep8.org/)
6689
* Performance Tips:
6790
* [Python](https://wiki.python.org/moin/PythonSpeed/PerformanceTips)
6891
* [NumPy and ctypes](https://scipy-cookbook.readthedocs.io/)

PULL_REQUEST_TEMPLATE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# pyCSEP Pull Request Checklist
2+
3+
Please check out the [contributing guidelines](https://github.com/SCECcode/pycsep/blob/master/CONTRIBUTING.md) for some tips
4+
on making pull requests to pyCSEP.
5+
6+
Fixes issue #(*please fill in or delete if not needed*).
7+
8+
## Type of change:
9+
10+
Please delete options that are not relevant.
11+
12+
- [ ] Bug fix (non-breaking change which fixes an issue)
13+
- [ ] New feature (non-breaking change which adds functionality)
14+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
15+
- [ ] Documentation update (this pull request adds no new code)
16+
- [ ] Unpublished science feature (This may require a science review)
17+
- [ ] This change requires a documentation update
18+
19+
## Checklist:
20+
21+
- [ ] I have performed a self-review of my own code
22+
- [ ] I have commented my code, particularly in hard-to-understand areas
23+
- [ ] I have made corresponding changes to the documentation
24+
- [ ] My changes generate no new warnings
25+
- [ ] I have added tests that prove my fix is effective or that my feature works
26+
- [ ] New and existing unit tests pass locally with my changes

csep/utils/plots.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Third-party imports
44
import numpy
5+
import string
6+
57
import scipy.stats
68
import matplotlib
79
from matplotlib import cm
@@ -705,6 +707,7 @@ def plot_catalog(catalog, ax=None, show=False, extent=None, set_global=False, pl
705707
mag_ticks = plot_args.get('mag_ticks', False)
706708
labelspacing = plot_args.get('labelspacing', 1)
707709
region_border = plot_args.get('region_border', True)
710+
legend_borderpad = plot_args.get('legend_borderpad', 0.4)
708711
# cartopy properties
709712
projection = plot_args.get('projection', ccrs.PlateCarree(central_longitude=0.0))
710713
basemap = plot_args.get('basemap', None)
@@ -782,7 +785,7 @@ def size_map(markersize, values, scale):
782785
alpha=0.3)
783786
ax.legend(handles, numpy.round(mag_ticks, 1),
784787
loc=legend_loc, title=legend_title, fontsize=legend_fontsize, title_fontsize=legend_titlesize,
785-
labelspacing=labelspacing, handletextpad=5, framealpha=legend_framealpha)
788+
labelspacing=labelspacing, handletextpad=5, borderpad=legend_borderpad, framealpha=legend_framealpha)
786789

787790
if region_border:
788791
try:
@@ -1602,4 +1605,18 @@ def plot_calibration_test(evaluation_result, axes=None, plot_args=None, show=Fal
16021605
if show:
16031606
pyplot.show()
16041607

1605-
return ax
1608+
return ax
1609+
1610+
def add_labels_for_publication(figure, style='bssa', labelsize=16):
1611+
""" Adds publication labels too the outside of a figure. """
1612+
all_axes = figure.get_axes()
1613+
ascii_iter = iter(string.ascii_lowercase)
1614+
for ax in all_axes:
1615+
# check for colorbar and ignore for annotations
1616+
if ax.get_label() == 'Colorbar':
1617+
continue
1618+
annot = next(ascii_iter)
1619+
if style == 'bssa':
1620+
ax.annotate(f'({annot})', (0.025, 1.025), xycoords='axes fraction', fontsize=labelsize)
1621+
1622+
return

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ python-dateutil
99
pytest
1010
vcrpy
1111
pytest-cov
12+
sphinx
1213
sphinx-gallery
1314
sphinx-rtd-theme
1415
pillow

requirements.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies:
1313
- python-dateutil
1414
- pytest
1515
- cartopy
16+
- sphinx
1617
- sphinx-gallery
1718
- sphinx_rtd_theme
1819
- pillow

tests/test_spatial.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy
66

77
from csep.core.regions import CartesianGrid2D, compute_vertex, compute_vertices, _bin_catalog_spatio_magnitude_counts, \
8-
_bin_catalog_spatial_counts, _bin_catalog_probability, global_region
8+
_bin_catalog_spatial_counts, _bin_catalog_probability, global_region, california_relm_region
99
from csep.models import Polygon
1010

1111

@@ -230,13 +230,17 @@ def test_bin_spatial_magnitudes(self):
230230
self.assertEqual(test_result[0, 1], 1)
231231
self.assertEqual(test_result[9, 0], 1)
232232

233-
def test_global_region_binning(self):
233+
def test_binning_using_bounds(self):
234+
""" Tests whether point correctly fall within the bin edges.
234235
235-
gr = global_region()
236+
This test is not exhaustive but checks a few points within the region and verifies that the points correctly fall
237+
within the bin edges.
238+
"""
239+
gr = california_relm_region()
236240

237241
# test points
238-
lons = numpy.array([-178.6, -178.6, -178.02, -177.73, -177.79])
239-
lats = numpy.array([-15.88, -51.75, -30.61, -29.98, -30.6])
242+
lons = numpy.array([-117.430, -117.505, -117.466, -117.5808, -117.612])
243+
lats = numpy.array([35.616, 35.714, 35.652, 35.7776, 35.778])
240244

241245
# directly compute the indexes from the region object
242246
idxs = gr.get_index_of(lons, lats)

0 commit comments

Comments
 (0)