Skip to content

Commit

Permalink
Merge pull request #29 from mdtanker/dev
Browse files Browse the repository at this point in the history
replaced geopandas calls with pyogrio, replaced bedmap2 with bedmachine
  • Loading branch information
mdtanker authored Aug 31, 2022
2 parents 3813d99 + 2f5f8a5 commit 4fd63eb
Show file tree
Hide file tree
Showing 18 changed files with 2,344 additions and 1,483 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ publish:
package:
poetry build

poetry_env:
poetry install --sync
poetry export -f requirements.txt --output requirements.txt --with dev

delete_env:
mamba remove --name antarctic_plots_dev --all --yes

new_env:
mamba create --name antarctic_plots_dev --yes python=3.9 pygmt=0.7.0 geopandas=0.11.0

install_reqs:
pip install --no-deps --requirement requirements.txt
pip install --editable .

clean:
find . -name "*.pyc" -exec rm -v {} \;
find . -name ".coverage.*" -exec rm -v {} \;
Expand Down
5 changes: 3 additions & 2 deletions antarctic_plots/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import warnings
from typing import Union

import geopandas as gpd
import pyogrio
import pygmt

from antarctic_plots import fetch, utils
Expand Down Expand Up @@ -229,7 +229,8 @@ def plot_grd(
position=f"J{inset_pos}+j{inset_pos}+w{fig_width*.25}c",
verbose="q",
):
gdf = gpd.read_file(fetch.groundingline())
# gdf = gpd.read_file(fetch.groundingline())
gdf = pyogrio.read_dataframe(fetch.groundingline())
fig.plot(
projection=inset_map,
region=inset_reg,
Expand Down
23 changes: 13 additions & 10 deletions antarctic_plots/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from typing import Union

import geopandas as gpd
import pyogrio
import numpy as np
import pandas as pd
import pygmt
Expand Down Expand Up @@ -62,7 +62,8 @@ def create_profile(
elif method == "shapefile":
if shapefile is None:
raise ValueError(f"If method = {method}, need to provide a valid shapefile")
shp = gpd.read_file(shapefile)
# shp = gpd.read_file(shapefile)
shp = pyogrio.read_dataframe(shapefile)
df = pd.DataFrame()
df["coords"] = shp.geometry[0].coords[:]
coordinates = df.coords.apply(pd.Series, index=["x", "y"])
Expand Down Expand Up @@ -206,16 +207,17 @@ def make_data_dict(names: list, grids: list, colors: list) -> dict:

def default_layers() -> dict:
"""
Fetch default Bedmap2 layers.
Fetch default Bedmachine layers.
Returns
-------
dict[dict]
Nested dictionary of Bedmap2 layers and attributes
Nested dictionary of Bedmachine layers and attributes
"""
surface = fetch.bedmap2("surface")
icebase = fetch.bedmap2("surface") - fetch.bedmap2("thickness")
bed = fetch.bedmap2("bed")
surface = fetch.bedmachine("surface")
# icebase = fetch.bedmachine("surface") - fetch.bedmachine("thickness")
icebase = fetch.bedmachine('icebase')
bed = fetch.bedmachine("bed")
layer_names = [
"surface",
"icebase",
Expand Down Expand Up @@ -308,7 +310,7 @@ def plot_profile(
map_cmap: str
Change the map colorscale by passing a valid GMT cmap string, by default is 'earth'.
map_buffer: float (0-1)
Change map zoom as relative percentage of profile length, by default is 0.2.
Change map zoom as relative percentage of profile length, by default is 0.3.
layer_buffer: float (0-1)
Change vertical white space within cross-section, by default is 0.1.
data_buffer: float (0-1)
Expand Down Expand Up @@ -363,7 +365,7 @@ def plot_profile(
if add_map is True:
# Automatic data extent + buffer as % of line length
df_reg = vd.get_region((df_layers.x, df_layers.y))
buffer = df_layers.dist.max() * kwargs.get("map_buffer", 0.2)
buffer = df_layers.dist.max() * kwargs.get("map_buffer", 0.3)
fig_reg = utils.alter_region(df_reg, buffer=buffer)[1]
# Set figure parameters
fig_proj, fig_proj_ll, fig_width, fig_height = utils.set_proj(
Expand Down Expand Up @@ -454,7 +456,8 @@ def plot_profile(
position=f"J{inset_pos}+j{inset_pos}+w{fig_width*.25}c",
verbose="q",
):
gdf = gpd.read_file(fetch.groundingline())
# gdf = gpd.read_file(fetch.groundingline())
gdf = pyogrio.read_dataframe(fetch.groundingline())
fig.plot(
projection=inset_map,
region=inset_reg,
Expand Down
19 changes: 9 additions & 10 deletions antarctic_plots/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import warnings
from typing import Union

import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -647,14 +646,14 @@ def raps(
args = f"{fin} -Er+wk -Na+d -G{fout}"
session.call_module("grdfft", args)
if plot_type == "mpl":
# raps = pd.read_csv('tmp_outputs/raps.txt', header=None,
# delimiter='\t',
# names=('wavelength','power','stdev'))
# ax = sns.lineplot(raps.wavelength, raps.power,
# label=j, palette='viridis')
# ax = sns.scatterplot(x=raps.wavelength, y=raps.power)
# ax.set_xlabel('Wavelength (km)')
# ax.set_ylabel('Radially Averaged Power ($mGal^{2}km$)')
raps = pd.read_csv('tmp_outputs/raps.txt', header=None,
delimiter='\t',
names=('wavelength','power','stdev'))
ax = sns.lineplot(raps.wavelength, raps.power,
label=j, palette='viridis')
ax = sns.scatterplot(x=raps.wavelength, y=raps.power)
ax.set_xlabel('Wavelength (km)')
ax.set_ylabel('Radially Averaged Power ($mGal^{2}km$)')
pass
elif plot_type == "pygmt":
color = f"{random.randrange(255)}/{random.randrange(255)}/{random.randrange(255)}"
Expand Down Expand Up @@ -700,7 +699,7 @@ def coherency(grids: list, label: str, **kwargs):
region = kwargs.get("region", None)
spacing = kwargs.get("spacing", None)

# plt.figure()
plt.figure()

if isinstance(grids[0], (str, xr.DataArray)):
pygmt.grdfill(grids[0], mode="n", outgrid=f"tmp_outputs/fft_1.nc")
Expand Down
43 changes: 13 additions & 30 deletions docs/contribute.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
# Contribution guide
## Build the docs
The Docs are build with `Sphinx` and `Read the Docs`. Due to issues with included C programs (GMT and GDAL) in a pip-installed package, `PyGMT` and `GeoPandas` aren't included in the package dependencies, so `RTD` can't run the scripts which are part of the docs (i.e. `walkthrough.ipynb`). Because of this the notebooks don't execute on a build, as specified by `execute_notebooks: 'off'` in `_config.yml`.
The Docs are build with `Sphinx` and `Read the Docs`. Due to issues with included C programs (GMT and GDAL) in a pip-installed package, `PyGMT` and `GeoPandas` aren't included in the package dependencies, so `Read the Docs` can't run the scripts which are part of the docs (i.e. the gallery examples). Because of this the notebooks don't execute on a build, as specified by `execute_notebooks: 'off'` in `_config.yml`.

Additionally we use `Poetry` as a package manager, which also can't include `PyGMT` or `GeoPandas` successfully. To get around this, we will export the poetry venv, add `PyGMT` and `Geopandas`, run the .ipynb's for the docs, then build the docs.
Additionally we use `Poetry` as a package manager, which also can't include `PyGMT` or `GeoPandas` successfully (since it installs with Pip). To get around this, we will export the poetry venv, add `PyGMT` and `Geopandas` independently, run the .ipynb's for the docs, then build the docs.

### Set up a virtual environment

Set up the poetry virutal environment:
Set up the poetry virtual environment:

poetry install
make poetry_env

Export to a requirements.txt:
This solves the dependencies for the packages listed in pyproject.toml, adds the versions to a .lock file, install them in a poetry virtual environment, and exports the resulting environment to a requirements.txt file.

poetry export -f requirements.txt --output requirements.txt --dev
Next we need to create a conda/mamba env:
make delete_env
make new_env

Deactivate poetry shell:

deactivate

Create a conda/mamba env:

mamba create --name antarctic_plots python=3.9 pygmt=0.7.0 geopandas=0.11.0
mamba activate antarctic_plots

Add pinned dependencies
This will create a new conda env `antarctic_plots_dev` and install `PyGMT`.

pip install --no-deps -r requirements.txt

Install local antarctic_plots in editable mode:

pip install -e .
Activate it and install the package requirements and local antarctic_plots package in editable mode:

Or install from PyPI (docs won't update if you build them!):

pip install antarctic_plots
mamba activate antarctic_plots_dev
make install_reqs

### Run all .ipynb's to update them

Expand Down Expand Up @@ -78,14 +66,9 @@ or if the package is only for development/documentation

poetry add <PACKAGE> -D

Then:

poetry lock
poetry install <optionally add --remove-untracked>
Then run through the commands at the top of this page again to update the environement.

Note, you may need to deleted the .lock file, and run `poetry install --remove-untracked for removals to take place. This will take some time.

This will solve the dependencies for the added package, re-write the `poetry.lock` file, and install the new lock file.

<!-- This uses the doc_requirements.txt included in the repository, which was create with the below code:
Expand Down
Binary file added docs/cover_fig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions docs/gallery/basic_map.ipynb

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions docs/gallery/extend_pygmt.ipynb

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions docs/gallery/profile.ipynb

Large diffs are not rendered by default.

33 changes: 13 additions & 20 deletions docs/gallery/profile_with_data.ipynb

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions docs/gallery/profile_with_map.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/gallery/setting_projection.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/gallery/subplots.ipynb

Large diffs are not rendered by default.

23 changes: 8 additions & 15 deletions docs/tutorial/fetch_walkthrough.ipynb

Large diffs are not rendered by default.

177 changes: 93 additions & 84 deletions docs/tutorial/profile_walkthrough.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 4fd63eb

Please sign in to comment.