Skip to content

Commit

Permalink
Merge a115d65 into 08a1b1a
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Mar 20, 2022
2 parents 08a1b1a + a115d65 commit b84909f
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- workflow-multi
- graphics-mpl
container:
- ghcr.io/oggm/untested_base:20211114
- ghcr.io/oggm/untested_base:20220320
- ghcr.io/oggm/untested_base:py3.7
- ghcr.io/oggm/untested_base:py3.9
include:
Expand Down
4 changes: 2 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ Users usually don't have to care about *where* the data is located.
fdem = gdir.get_filepath('dem')
fdem
import xarray as xr
import rioxarray as rioxr
@savefig plot_gdir_dem.png width=80%
xr.open_rasterio(fdem).plot(cmap='terrain');
rioxr.open_rasterio(fdem).plot(cmap='terrain');
This persistence on disk allows for example to continue a workflow that has
been previously interrupted. Initialising a GlacierDirectory from a non-empty
Expand Down
2 changes: 2 additions & 0 deletions docs/cloud.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ link below to get you started!
.. image:: https://img.shields.io/badge/Launch-OGGM%20tutorials-579ACA.svg?style=popout&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAlCAYAAAAjt+tHAAAACXBIWXMAABcSAAAXEgFnn9JSAAAAB3RJTUUH4wENDyoWA+0MpQAAAAZiS0dEAP8A/wD/oL2nkwAACE5JREFUWMO9WAtU1FUaH1BTQVJJKx+4BxDEgWEGFIzIVUMzPVBauYng8Jr3AxxAHObBvP6MinIUJdLwrTwqzXzkWVMSLW3N7bTrtmvpno7l6WEb7snMB6DffvfOzJ87A5a27t5zvjP/x/1/v9/9Xve7IxA84BFXYBMIi+zBIoUrOCLbxD9PVLgE/9MRtdhKfycW2gfGFzkMCFgXV2C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aQksySSVE60hhGiNIXwuG4OgqQgWAJKPISgEPBHdNNhnHYhCNVL6fxJKlYHXf1ezDh6Stp0oC2gK1Y42XPeQDTTy+irgJacEHHhyqrQtCYkVAFCTSlKGd5XQqLaAhKVw8/fjOkPSZTVkT6Msdl9HPUmMt3qw/PLgnCrFmIPtw3j4lbvvt8dAOTuE9gbdK9G5pjC+zr89BqhmSUCac0Wpk13vIAKLt/vqchb6/+Mi5odmq3lT8dohfs4I05X98fVr2LjAQvWUVR8GEl1BAKSediAnsccr4/Nt6YTFRmla3l1v1tkur8zKnYsKQj0lx4/Vt9C8Kf4CZNzQ4c+b4gam22Mf2iuLkIQ8/wA9nvZqq140FX/9v8E0P+5GDy3EbybEMA60RSHBYu+TDL0/dFM1QP4uyPDd1QLIxtVKuZuE66+QyznXhb8v0bkYrPf/ag/VIwYLzWHsdXzQYz/ABScQI1BUjcgAAAAAElFTkSuQmCC
:target: https://mybinder.org/v2/gh/OGGM/binder/stable?urlpath=git-pull?repo=https://github.com/OGGM/tutorials%26amp%3Bbranch=master%26amp%3Burlpath=lab/tree/tutorials/notebooks/welcome.ipynb%3Fautodecode

<br>

If you are new to the Jupyter Notebooks or to JupyterLab, you will probably
find this `introduction to interactive notebooks`_ quite useful.

Expand Down
28 changes: 20 additions & 8 deletions docs/installing-oggm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ GIS tools:
- shapely
- pyproj
- rasterio
- rioxarray
- geopandas

Testing:
Expand Down Expand Up @@ -113,7 +114,7 @@ window, type::
conda create --name oggm_env python=3.X


where ``3.X`` is the Python version shipped with conda (currently 3.8).
where ``3.X`` is the Python version shipped with conda (currently 3.9).
You can of course use any other name for your environment.

Don't forget to activate it before going on::
Expand All @@ -124,15 +125,20 @@ Don't forget to activate it before going on::
.. _environment: https://conda.io/projects/conda/en/latest/user-guide/concepts/environments.html


Feeling adventurous? Try mamba (optional)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In a hurry? Try mamba (optional)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The conda package manager has recently been criticized for being slow (it *is*
quite slow to be honest). A new, faster tool is now available to replace conda: `mamba <https://mamba.readthedocs.io>`_.
Mamba is a drop-in replacement for all conda commands.
If you feel like it, install mamba in your conda environment (``conda install -c conda-forge mamba``)
The conda package manager has been criticized for being slow (it *is*
quite slow to be honest). A new, faster tool is now available
to replace conda: `mamba <https://mamba.readthedocs.io>`_. Mamba is a drop-in
replacement for all conda commands. If you feel like it, install mamba in your conda
environment (``conda install -c conda-forge mamba``)
and replace all occurrences of ``conda`` with ``mamba`` in the instructions below.

*Note March 2022: soon, conda will use mamba per default. See
`this post <https://www.anaconda.com/blog/a-faster-conda-for-a-growing-community>`_
for more info.*


Install dependencies
~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -272,6 +278,11 @@ If everything worked fine, you should see something like::
You can safely ignore deprecation warnings and other messages (if any),
as long as the tests end without errors.

.. important::

The tests (without the ``--run-slow`` option) should run in 5 to 10 minutes.
If this takes too long, this may be an indiv

This runs a minimal suite of tests. If you want to run the entire test suite
(including graphics and slow running tests), type::

Expand Down Expand Up @@ -303,7 +314,7 @@ environment from the following ``environment.yml`` file used to work::
channels:
- conda-forge
dependencies:
- python=3.8
- python=3.9
- jupyter
- jupyterlab
- numpy
Expand All @@ -324,6 +335,7 @@ environment from the following ``environment.yml`` file used to work::
- cartopy
- geopandas
- rasterio
- rioxarray
- seaborn
- pytables
- salem
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ scikit-image
configobj
joblib
xarray
rioxarray
progressbar2
pytest
tables
Expand Down
2 changes: 1 addition & 1 deletion docs/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Enhancements
glacier geometry at the start of the simulation is iteratively changed with
a short constant climate run with a varying temperature bias
(:pull:`1342`, :pull:`1361`).
By `Patrick Schmitt <https://github.com/pat-schmitt/>`_
By `Patrick Schmitt <https://github.com/pat-schmitt>`_
- Added new options to `write_centerlines_to_shape` which allow to output
smoother and more correct centerlines (:pull:`1357`).
By `Fabien Maussion <https://github.com/fmaussion>`_
Expand Down
4 changes: 4 additions & 0 deletions oggm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
except ImportError:
pass

# TODO: remove this when geopandas will behave a bit better
import warnings
warnings.filterwarnings(action='ignore', category=FutureWarning, module=r'.*geopandas')

# API
# Some decorators used by many
from oggm.utils import entity_task, global_task
Expand Down
14 changes: 8 additions & 6 deletions oggm/core/centerlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import copy
from itertools import groupby
from collections import Counter
from distutils.version import LooseVersion
from packaging.version import Version

# External libs
import numpy as np
Expand All @@ -28,9 +28,8 @@
import scipy.signal
import shapely.geometry as shpg
from scipy.interpolate import RegularGridInterpolator
from scipy.ndimage.filters import gaussian_filter1d
from scipy.ndimage.morphology import distance_transform_edt
from scipy.ndimage.measurements import label, find_objects
from scipy.ndimage import (gaussian_filter1d, distance_transform_edt,
label, find_objects)

# Optional libs
try:
Expand Down Expand Up @@ -1326,7 +1325,10 @@ def _point_width(normals, point, centerline, poly, poly_no_nunataks):
# Make sure we are always returning a MultiLineString for later
line = line.intersection(poly)
if line.type == 'LineString':
line = shpg.MultiLineString([line])
try:
line = shpg.MultiLineString([line])
except shapely.errors.EmptyPartError:
return np.NaN, shpg.MultiLineString()
elif line.type == 'MultiLineString':
pass # nothing to be done
elif line.type == 'GeometryCollection':
Expand Down Expand Up @@ -1605,7 +1607,7 @@ def catchment_intersections(gdir):
to_crs=gdir.grid.proj, inplace=True)
except TypeError:
# from_crs not available yet
if LooseVersion(gpd.__version__) >= LooseVersion('0.7.0'):
if Version(gpd.__version__) >= Version('0.7.0'):
raise ImportError('You have installed geopandas v0.7 or higher. '
'Please also update salem for compatibility.')
gdfc.crs = gdir.grid
Expand Down
8 changes: 4 additions & 4 deletions oggm/core/flowline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4721,12 +4721,12 @@ def clean_merged_flowlines(gdir, buffer=None):
oix = 9999
if _overlap.length > 0 and fl1 != fl2 and fl2.flows_to != fl1:
if isinstance(_overlap, shpg.MultiLineString):
if _overlap[0].coords[0] == fl1.line.coords[0]:
if _overlap.geoms[0].coords[0] == fl1.line.coords[0]:
# if the head of overlap is same as the first line,
# best guess is, that the heads are close topgether!
_ov1 = _overlap[1].coords[1]
_ov1 = _overlap.geoms[1].coords[1]
else:
_ov1 = _overlap[0].coords[1]
_ov1 = _overlap.geoms[0].coords[1]
else:
_ov1 = _overlap.coords[1]
for _i, _p in enumerate(fl1.line.coords):
Expand Down Expand Up @@ -4762,7 +4762,7 @@ def clean_merged_flowlines(gdir, buffer=None):
# if the tributary flowline is longer than the main line,
# _line will contain multiple LineStrings: only keep the first
if isinstance(_linediff, shpg.MultiLineString):
_linediff = _linediff[0]
_linediff = _linediff.geoms[0]

if len(_linediff.coords) < 10:
bufferuse -= 1
Expand Down
8 changes: 3 additions & 5 deletions oggm/core/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import logging
import warnings
from distutils.version import LooseVersion
from packaging.version import Version
from functools import partial

# External libs
Expand All @@ -16,9 +16,7 @@
import xarray as xr
import shapely.geometry as shpg
import scipy.signal
from scipy.ndimage.measurements import label
from scipy.ndimage import binary_erosion
from scipy.ndimage.morphology import distance_transform_edt
from scipy.ndimage import label, distance_transform_edt, binary_erosion
from scipy.interpolate import griddata
from scipy import optimize as optimization

Expand Down Expand Up @@ -358,7 +356,7 @@ def _get_nodata(rio_ds):
if len(dem_list) == 1:
dem_dss = [rasterio.open(dem_list[0])] # if one tile, just open it
dem_data = rasterio.band(dem_dss[0], 1)
if LooseVersion(rasterio.__version__) >= LooseVersion('1.0'):
if Version(rasterio.__version__) >= Version('1.0'):
src_transform = dem_dss[0].transform
else:
src_transform = dem_dss[0].affine
Expand Down
4 changes: 2 additions & 2 deletions oggm/shop/gcm_climate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Climate data pre-processing"""
# Built ins
import logging
from distutils.version import LooseVersion
from packaging.version import Version
import warnings

# External libs
Expand Down Expand Up @@ -209,7 +209,7 @@ def process_cesm_data(gdir, filesuffix='', fpath_temp=None, fpath_precc=None,
fpath_precl = cfg.PATHS['cesm_precl_file']

# read the files
if LooseVersion(xr.__version__) < LooseVersion('0.11'):
if Version(xr.__version__) < Version('0.11'):
raise ImportError('This task needs xarray v0.11 or newer to run.')

tempds = xr.open_dataset(fpath_temp)
Expand Down
4 changes: 2 additions & 2 deletions oggm/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from distutils.version import LooseVersion
from packaging.version import Version

import pytest
import matplotlib.ft2font
Expand All @@ -12,7 +12,7 @@

# Matplotlib version changes plots, too
HAS_MPL_FOR_TESTS = False
if LooseVersion(matplotlib.__version__) >= LooseVersion('2'):
if Version(matplotlib.__version__) >= Version('2'):
HAS_MPL_FOR_TESTS = True
BASELINE_DIR = os.path.join(cfg.CACHE_DIR,
'oggm-sample-data-%s' % SAMPLE_DATA_COMMIT,
Expand Down
16 changes: 8 additions & 8 deletions oggm/tests/test_prepro.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import os
import shutil
from distutils.version import LooseVersion
from packaging.version import Version
import pytest
import warnings

Expand Down Expand Up @@ -301,8 +301,8 @@ def test_glacier_masks(self):
with pytest.raises(RuntimeError):
gis.glacier_masks(gdir)

@pytest.mark.skipif((LooseVersion(rasterio.__version__) <
LooseVersion('1.0')),
@pytest.mark.skipif((Version(rasterio.__version__) <
Version('1.0')),
reason='requires rasterio >= 1.0')
def test_simple_glacier_masks(self):

Expand Down Expand Up @@ -357,8 +357,8 @@ def test_simple_glacier_masks(self):
assert dft.sum()[0] == 1000
assert utils.rmsd(dft['ref'], dft['oggm']) < 5

@pytest.mark.skipif((LooseVersion(rasterio.__version__) <
LooseVersion('1.0')),
@pytest.mark.skipif((Version(rasterio.__version__) <
Version('1.0')),
reason='requires rasterio >= 1.0')
def test_glacier_masks_other_glacier(self):

Expand Down Expand Up @@ -390,8 +390,8 @@ def test_glacier_masks_other_glacier(self):
np.testing.assert_allclose(dfh['Zmax'], entity.Zmax, atol=20)
np.testing.assert_allclose(dfh['Zmin'], entity.Zmin, atol=20)

@pytest.mark.skipif((LooseVersion(rasterio.__version__) <
LooseVersion('1.0')),
@pytest.mark.skipif((Version(rasterio.__version__) <
Version('1.0')),
reason='requires rasterio >= 1.0')
def test_rasterio_glacier_masks(self):

Expand Down Expand Up @@ -3086,7 +3086,7 @@ def test_find_calving_full_fl(self):
df = inversion.find_inversion_calving(gdir)

assert df['calving_flux'] > 2
assert df['calving_rate_myr'] > 500
assert df['calving_rate_myr'] > 450
assert df['calving_mu_star'] == 0

# Test that new MB equal flux
Expand Down
7 changes: 4 additions & 3 deletions oggm/tests/test_shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import oggm
import xarray as xr
import rioxarray as rioxr
import numpy as np
import pandas as pd
from oggm import utils
Expand Down Expand Up @@ -66,9 +67,9 @@ def test_repro_to_glacier(self, class_case_dir, monkeypatch):
gis.rasterio_to_gdir(gdir, region_files['ALA']['vy'], 'its_live_vy',
resampling='bilinear')

with xr.open_rasterio(gdir.get_filepath('its_live_vx')) as da:
with rioxr.open_rasterio(gdir.get_filepath('its_live_vx')) as da:
_vx = da.where(mask).data.squeeze()
with xr.open_rasterio(gdir.get_filepath('its_live_vy')) as da:
with rioxr.open_rasterio(gdir.get_filepath('its_live_vy')) as da:
_vy = da.where(mask).data.squeeze()

_vel = np.sqrt(_vx**2 + _vy**2)
Expand Down Expand Up @@ -552,7 +553,7 @@ def test_add_consensus(self, class_case_dir, monkeypatch):
with xr.open_dataset(gdir.get_filepath('gridded_data')) as ds:
mine = ds.consensus_ice_thickness

with xr.open_rasterio(gdir.get_filepath('consensus')) as ds:
with rioxr.open_rasterio(gdir.get_filepath('consensus')) as ds:
ref = ds.isel(band=0)

# Check area
Expand Down
7 changes: 3 additions & 4 deletions oggm/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,10 +1653,9 @@ def prepare_verify_test(self, valid_size=True, valid_crc32=True,
file_sha256 = file_sha256.digest()

data = utils.get_dl_verify_data('cluster.klima.uni-bremen.de')
s = pd.Series({'size': file_size, 'sha256': file_sha256},
name='test.txt')
data = data.append(s)
cfg.DATA['dl_verify_data_test.com'] = data
s = pd.DataFrame({'size': file_size, 'sha256': file_sha256},
index=['test.txt'])
cfg.DATA['dl_verify_data_test.com'] = pd.concat([data, s])

return 'https://test.com/test.txt'

Expand Down
10 changes: 5 additions & 5 deletions oggm/utils/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import logging
import warnings
import shutil
from distutils.version import LooseVersion
from packaging.version import Version

# External libs
import pandas as pd
import numpy as np
from scipy.ndimage import filters
from scipy.ndimage import convolve1d
try:
from scipy.signal.windows import gaussian
except AttributeError:
Expand Down Expand Up @@ -268,7 +268,7 @@ def smooth1d(array, window_size=None, kernel='gaussian'):
else:
raise NotImplementedError('Kernel: ' + kernel)
kernel = kernel / np.asarray(kernel).sum()
return filters.convolve1d(array, kernel, mode='mirror')
return convolve1d(array, kernel, mode='mirror')


def line_interpol(line, dx):
Expand Down Expand Up @@ -375,7 +375,7 @@ def clip_scalar(value, vmin, vmax):
return vmin if value < vmin else vmax if value > vmax else value


if LooseVersion(np.__version__) < LooseVersion('1.17'):
if Version(np.__version__) < Version('1.17'):
clip_array = np.clip
else:
# TODO: reassess this when https://github.com/numpy/numpy/issues/14281
Expand Down Expand Up @@ -509,7 +509,7 @@ def polygon_intersections(gdf):
'{}.'.format(line.type))
line = gpd.GeoDataFrame([[i, j, line]],
columns=out_cols)
out = out.append(line)
out = pd.concat([out, line])

return out

Expand Down
Loading

0 comments on commit b84909f

Please sign in to comment.