Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checking branch protection #2

Merged
merged 13 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,20 @@ make test

# Formatting

Use the Makefile commands to locally format and check the code with `ruff`:
Use the Makefile commands to locally format and check the code with `ruff` and
`pylint`:

```
make style
```

This will run the following commands:

```
make check
make format
make lint
make pylint
```

# Building docs
Expand Down
57 changes: 44 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: CI

# define when this workflow is triggered
on:
workflow_dispatch:
pull_request:
push:
branches:
- main

# cancel any currently running workflows in this same PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
FORCE_COLOR: 3
NUMBA_DISABLE_JIT: "1"
# Use bash by default in all jobs
defaults:
run:
shell: bash -el {0}

jobs:
# run pre-commit which includes many formatting and linting tools
pre-commit:
name: Format
runs-on: ubuntu-latest
Expand All @@ -33,12 +40,14 @@ jobs:
run: |
echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
pipx run nox -s pylint

checks:
# Run tests and upload to codecov
test:
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
needs: [pre-commit]
strategy:
# Otherwise, the workflow would stop if a single job fails. We want to
# run all of them to catch failures in different combinations.
fail-fast: false
matrix:
python-version: ["3.8", "3.11", "3.12"]
Expand All @@ -47,24 +56,46 @@ jobs:
include:
- python-version: pypy-3.9
runs-on: ubuntu-latest
env:
FORCE_COLOR: 3
NUMBA_DISABLE_JIT: "1"

steps:
- uses: actions/checkout@v4
# Checkout current git repository
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v4
- name: Switch to Current Branch
run: git checkout ${{ env.BRANCH }}

# Install Mambaforge with conda-forge dependencies
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: invert4geom
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
allow-prereleases: true
channels: conda-forge,nodefaults
channel-priority: strict
miniforge-version: latest
miniforge-variant: Mambaforge
mamba-version: "*"
use-mamba: true
auto-activate-base: false

# Show installed pkg information for postmortem diagnostic
- name: List installed packages
run: mamba list

- name: Install package
run: python -m pip install .[test]
# Install the package in editable mode
- name: Install local package
run: pip install -e .

- name: Test package
- name: Run the tests
run: >-
python -m pytest -ra --cov --cov-report=xml --cov-report=term
--durations=20
pytest -ra --cov --cov-report=xml --cov-report=term --durations=20

- name: Upload coverage report
uses: codecov/codecov-action@v3.1.4
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ repos:
- id: codespell
name: codespell
description: Checks for common misspellings in text files.
entry: codespell --skip="*.js,*.html,*.css,*.svg,*.ipynb"
entry: codespell --skip="*.js,*.html,*.css,*.svg,*.ipynb" -L ore

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.9.0.6"
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ check:

lint:
pre-commit run --all-files

pylint:
pylint invert4geom

style: format check lint pylint
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ tesseroids instead of prisms.
See the [overview](overview.md) for further description of this package and what
it can be used for.

The tutorials

<!-- prettier-ignore-start -->
[actions-badge]: https://github.com/mdtanker/invert4geom/workflows/CI/badge.svg
[actions-link]: https://github.com/mdtanker/invert4geom/actions
Expand Down
4 changes: 4 additions & 0 deletions docs/citing.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Citing Invert4geom

```{warning}
Citation info still to come ...
```
4 changes: 4 additions & 0 deletions docs/gallery/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Gallery

```{warning}
Gallery examples still to come ...
```
30 changes: 30 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# Install

```{warning}
Install instructions still to come ...
```

For now, clone the GitHub repository and change directories into it:

```
git clone https://github.com/mdtanker/invert4geom.git
cd invert4geom
```

assuming you have `Python` and `make` installed, as well as `mamba` (install
mamba with `pip install mamba`) installed within your Python environment, run
the following to install the package locally:

```
make create
conda activate invert4geom
make install
```

If you don't have or want `make` or `mamba` installed, you can accomplish the
same with the following:

```
conda create --name invert4geom --yes --force antarctic-plots python=3.11
conda activate invert4geom
pip install -e .[viz,test,dev,docs]
```
24 changes: 24 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# Overview

Invert4geom provides a series of tools for conducting a specific style of
gravity inversion. Many gravity inversions aim to model the density distribution
of the subsurface. These are commonly used to identify bodies of anomalous
densities, such as igneous intrusions or ore deposits. The typical way these are
performed is to _discretize_ the subsurface into a series of finite volumes,
such as cubes or prisms, where the shape of the volumes doesn't change. The
inversion then alters the density values of each of these volumes to match the
observed gravity anomaly. In these inversions the _density_ values changes,
while the _geometry_ of the volumes remains unchanged. These types of inversions
may be referred to as _density inversions_. Here, instead, we are performing
_geometric inversions_.

Geometric inversions are essentially the opposite. The density values of the
volumes in the discretized model remain unchanged, while their geometry is
altered. Here we use layers of vertical right-rectangular prisms and alter their
_tops_ and _bottoms_ during the inversion. Typically use cases for these style
of inversion are modeling the topography of the Moho, the contact between
sediment and basement, or the shape of the seafloor in locations where it is not
easily mapped.

Currently, this package is only intended to perform inversions using right
rectangular prisms. Other types of volumes, such as tesseroids, are currently
not implemented.
31 changes: 31 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Requirements for running the github action: test only need run-time dependencies
name: invert4geom
channels:
- conda-forge
- defaults
dependencies:
- python>=3.8
- pip
# Run-time
- numpy
- pandas
- xarray
- verde>=1.8.0
- rioxarray
- pykdtree
- xrft
- harmonica>=0.6.0
- antarctic-plots
- numba
- scipy
- nptyping
# viz
- pyvista
- trame
- ipywidgets
- matplotlib
# test
- pytest >=6
- pytest-cov >=3
- pip:
- numba-progress
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dev = [
"ruff",
"nox",
"pre-commit",
"pylint",
]
docs = [
"sphinx>=4.0",
Expand Down
2 changes: 1 addition & 1 deletion src/invert4geom/inversion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations
from __future__ import annotations # pylint: disable=too-many-lines

import copy
import itertools
Expand Down
18 changes: 9 additions & 9 deletions src/invert4geom/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def plot_inversion_topo_results(
for g in [initial_topo, final_topo]:
topo_lims.append(ap_utils.get_min_max(g))

topo_min = min([i[0] for i in topo_lims]) * topo_cmap_perc
topo_max = max([i[1] for i in topo_lims]) * topo_cmap_perc
topo_min = min([i[0] for i in topo_lims]) * topo_cmap_perc # pylint: disable=consider-using-generator
topo_max = max([i[1] for i in topo_lims]) * topo_cmap_perc # pylint: disable=consider-using-generator

# set figure parameters
sub_width = 5
Expand Down Expand Up @@ -349,15 +349,15 @@ def plot_inversion_iteration_results(
for g in corrections_grids:
corrections_lims.append(ap_utils.get_min_max(g))

misfit_min = min([i[0] for i in misfit_lims])
misfit_max = max([i[1] for i in misfit_lims])
misfit_min = min([i[0] for i in misfit_lims]) # pylint: disable=consider-using-generator
misfit_max = max([i[1] for i in misfit_lims]) # pylint: disable=consider-using-generator
misfit_lim = vd.maxabs(misfit_min, misfit_max) * misfit_cmap_perc

topo_min = min([i[0] for i in topo_lims]) * topo_cmap_perc
topo_max = max([i[1] for i in topo_lims]) * topo_cmap_perc
topo_min = min([i[0] for i in topo_lims]) * topo_cmap_perc # pylint: disable=consider-using-generator
topo_max = max([i[1] for i in topo_lims]) * topo_cmap_perc # pylint: disable=consider-using-generator

corrections_min = min([i[0] for i in corrections_lims])
corrections_max = max([i[1] for i in corrections_lims])
corrections_min = min([i[0] for i in corrections_lims]) # pylint: disable=consider-using-generator
corrections_max = max([i[1] for i in corrections_lims]) # pylint: disable=consider-using-generator
corrections_lim = (
vd.maxabs(corrections_min, corrections_max) * corrections_cmap_perc
)
Expand Down Expand Up @@ -729,7 +729,7 @@ def show_prism_layers(
plotter.camera.zoom(kwargs.get("zoom", 1.2))

# Add a ceiling light
add_light(plotter, prisms[i])
add_light(plotter, prisms[i]) # pylint: disable=undefined-loop-variable

plotter.show_axes()

Expand Down
2 changes: 1 addition & 1 deletion src/invert4geom/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def synthetic_topography_simple(
pixel_register = True

# create grid of coordinates
(x, y) = vd.grid_coordinates(
(x, y) = vd.grid_coordinates( # pylint: disable=unbalanced-tuple-unpacking
region=region,
spacing=spacing,
pixel_register=pixel_register,
Expand Down
Loading