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

No more deprecation warnings #15

Merged
merged 1 commit into from
Dec 8, 2015
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
1 change: 1 addition & 0 deletions docs/INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ I/O:

GIS and geometrical tools:
- gdal
- rasterio
- shapely
- pyproj
- geopandas
Expand Down
2 changes: 1 addition & 1 deletion docs/install_virtualenv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Details: http://tylerickson.blogspot.co.at/2011/09/installing-gdal-in-python-vir

Install further stuffs::

$ pip install pyproj Pillow geopandas netcdf4 scikit-image configobj joblib
$ pip install pyproj rasterio Pillow geopandas netcdf4 scikit-image configobj joblib

And the external libraries::

Expand Down
17 changes: 9 additions & 8 deletions oggm/prepro/centerlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# Locals
import oggm.conf as cfg
from salem import lazy_property
from oggm.utils import tuple2int

# Module logger
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -452,9 +453,9 @@ def compute_centerlines(gdir, div_id=None):
nc.close()

# Find for local maximas on the outline
x, y = tuple2int(poly_pix.exterior.xy)
ext_yx = tuple(reversed(poly_pix.exterior.xy))
ext_yx = (ext_yx[0][:-1], ext_yx[1][:-1]) # last point is first point
zoutline = topo[ext_yx]
zoutline = topo[y[:-1], x[:-1]] # last point is first point

# Size of the half window to use to look for local maximas
maxorder = np.rint(cfg.params['localmax_window'] / gdir.grid.dx)
Expand Down Expand Up @@ -495,12 +496,12 @@ def compute_centerlines(gdir, div_id=None):
costgrid = _make_costgrid(glacier_mask, glacier_ext, topo)

# Terminus
t_coord = np.asarray(ext_yx)[:, np.argmin(zoutline)]
t_coord = np.asarray(ext_yx)[:, np.argmin(zoutline)].astype(np.int64)

# Compute the routes
lines = []
for h in heads:
h_coord = np.asarray(h.xy)[::-1]
h_coord = np.asarray(h.xy)[::-1].astype(np.int64)
indices, _ = route_through_array(costgrid, h_coord, t_coord)
lines.append(shpg.LineString(np.array(indices)[:, [1, 0]]))
log.debug('%s: computed the routes', gdir.rgi_id)
Expand Down Expand Up @@ -562,8 +563,8 @@ def compute_downstream_lines(gdir):
topo = nc.variables['topo_smoothed'][:]

# Variables we gonna need
xmesh, ymesh = np.meshgrid(np.arange(0, gdir.grid.nx, 1),
np.arange(0, gdir.grid.ny, 1))
xmesh, ymesh = np.meshgrid(np.arange(0, gdir.grid.nx, 1, dtype=np.int64),
np.arange(0, gdir.grid.ny, 1, dtype=np.int64))
_h = [topo[:, 0], topo[0, :], topo[:, -1], topo[-1, :]]
_x = [xmesh[:, 0], xmesh[0, :], xmesh[:, -1], xmesh[-1, :]]
_y = [ymesh[:, 0], ymesh[0, :], ymesh[:, -1], ymesh[-1, :]]
Expand All @@ -574,8 +575,8 @@ def compute_downstream_lines(gdir):
div_ids = list(gdir.divide_ids)
for div_id in div_ids:
head = gdir.read_pickle('centerlines', div_id=div_id)[-1].tail
heigts.append(topo[head.y, head.x])
heads.append((head.y, head.x))
heigts.append(topo[int(head.y), int(head.x)])
heads.append((int(head.y), int(head.x)))

# Now the lowest first
aso = np.argsort(heigts)
Expand Down
8 changes: 6 additions & 2 deletions oggm/prepro/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ def mb_climate_on_height(gdir, heights, time_range=None, year_range=None):
time = netCDF4.num2date(time[:], time.units)
if time_range is not None:
p0 = np.where(time == time_range[0])[0]
if len(p0) == 0:
try:
p0 = p0[0]
except IndexError:
raise RuntimeError('time_range[0] not found in file')
p1 = np.where(time == time_range[1])[0]
if len(p1) == 0:
try:
p1 = p1[0]
except IndexError:
raise RuntimeError('time_range[1] not found in file')
else:
p0 = 0
Expand Down
13 changes: 7 additions & 6 deletions oggm/prepro/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import oggm.conf as cfg
from oggm import utils
import oggm.prepro.centerlines
from oggm.utils import tuple2int

# Module logger
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -467,7 +468,7 @@ def catchment_area(gdir, div_id=None):
cost_factor = 0. # Make it cheap
dic_catch = dict()
for i, cl in enumerate(cls):
x, y = cl.line.xy
x, y = tuple2int(cl.line.xy)
costgrid[y, x] *= cost_factor
for x, y in [(int(x), int(y)) for x, y in cl.line.coords]:
assert (y, x) not in dic_catch
Expand All @@ -477,11 +478,11 @@ def catchment_area(gdir, div_id=None):
computed = np.where(mask == 1, 0, np.nan)

# Coords of Terminus
endcoords = np.array(cls[0].tail.coords[0])[::-1]
endcoords = np.array(cls[0].tail.coords[0])[::-1].astype(np.int64)

# Start with all the paths at the boundaries, they are more likely
# to cover much of the glacier
for headx, heady in glacier_pix.exterior.coords:
for headx, heady in tuple2int(glacier_pix.exterior.coords):
indices, _ = route_through_array(costgrid, np.array([heady, headx]),
endcoords)
inds = np.array(indices).T
Expand All @@ -498,7 +499,7 @@ def catchment_area(gdir, div_id=None):
not_computed = np.where(computed == 0)
if len(not_computed[0]) == 0: # All points computed !!
break
headcoords = np.array([not_computed[0][0], not_computed[1][0]])
headcoords = np.array([not_computed[0][0], not_computed[1][0]]).astype(np.int64)
indices, _ = route_through_array(costgrid, headcoords, endcoords)
inds = np.array(indices).T
computed[inds[0], inds[1]] = 1
Expand Down Expand Up @@ -678,8 +679,8 @@ def catchment_width_geom(gdir, div_id=None):

# Filter +- widths at junction points
for fid in fl.inflow_indices:
i0 = np.clip(fid-jpix, jpix/2, n-jpix/2)
i1 = np.clip(fid+jpix+1, jpix/2, n-jpix/2)
i0 = np.clip(fid-jpix, jpix/2, n-jpix/2).astype(np.int64)
i1 = np.clip(fid+jpix+1, jpix/2, n-jpix/2).astype(np.int64)
widths[i0:i1] = np.NaN

valid = np.where(np.isfinite(widths))
Expand Down
17 changes: 9 additions & 8 deletions oggm/prepro/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
from shutil import copyfile
from functools import partial
# External libs
import osr
from osgeo import osr
import salem
import gdal
from osgeo import gdal
import pyproj
import numpy as np
import shapely.ops
Expand All @@ -38,11 +38,12 @@
from scipy.ndimage.measurements import label
# Locals
import oggm.conf as cfg
from oggm.utils import tuple2int

# Module logger
log = logging.getLogger(__name__)

# Variable needed later
# Needed later
label_struct = np.ones((3, 3))


Expand Down Expand Up @@ -205,12 +206,12 @@ def proj(x, y):
(x, y) = glacier_poly_pix.exterior.xy
glacier_mask[skdraw.polygon(np.array(y), np.array(x))] = 1
for gint in glacier_poly_pix.interiors:
x, y = gint.xy
glacier_mask[skdraw.polygon(np.array(y), np.array(x))] = 0
x, y = tuple2int(gint.xy)
glacier_mask[skdraw.polygon(y, x)] = 0
glacier_mask[y, x] = 0 # on the nunataks, no
ext_yx = tuple(reversed(glacier_poly_pix.exterior.xy))
glacier_mask[ext_yx] = 1
glacier_ext[ext_yx] = 1
x, y = tuple2int(glacier_poly_pix.exterior.xy)
glacier_mask[y, x] = 1
glacier_ext[y, x] = 1

# Because of the 0 values at nunataks boundaries, some "Ice Islands"
# can happen within nunataks (e.g.: RGI40-11.00062)
Expand Down
7 changes: 2 additions & 5 deletions oggm/tests/test_graphics.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from __future__ import division

from nose.tools import assert_true
import warnings
warnings.filterwarnings("once", category=DeprecationWarning)

import os
import sys
import copy
import shutil
import warnings
from six.moves.urllib.request import urlopen
from six.moves.urllib.error import URLError

Expand Down
18 changes: 8 additions & 10 deletions oggm/tests/test_prepro.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
from __future__ import absolute_import, division

import warnings
warnings.filterwarnings("once", category=DeprecationWarning) # , module=r'.*oggm.*'

import unittest
import os
import sys
import pickle

import shapely.geometry as shpg
import numpy as np
import shutil
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import netCDF4
import multiprocessing as mp

# Local imports
from oggm.prepro import gis, centerlines, geometry, climate, inversion
import oggm.conf as cfg
from oggm.utils import get_demo_file
from oggm import utils
import logging
from xml.dom import minidom
import salem
from oggm.utils import tuple2int

# Globals
current_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -107,7 +106,6 @@ def test_glacier_masks(self):
np.testing.assert_allclose(area,gdir.glacier_area, rtol=1e-1)
nc.close()


class TestCenterlines(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -211,8 +209,8 @@ def test_baltoro_centerlines(self):
my_mask = np.zeros((gdir.grid.ny, gdir.grid.nx), dtype=np.uint8)
cls = gdir.read_pickle('centerlines', div_id=1)
for cl in cls:
ext_yx = tuple(reversed(cl.line.xy))
my_mask[ext_yx] = 1
x, y = tuple2int(cl.line.xy)
my_mask[y, x] = 1

# Transform
kien_mask = np.zeros((gdir.grid.ny, gdir.grid.nx), dtype=np.uint8)
Expand Down Expand Up @@ -240,8 +238,8 @@ def proj(x, y):

kgm = transform(project, kgm)

ext_yx = tuple(reversed(kgm.xy))
kien_mask[ext_yx] = 1
x, y = tuple2int(kgm.xy)
kien_mask[y, x] = 1

# We test the Heidke Skill score of our predictions
rest = kien_mask + 2 * my_mask
Expand Down
3 changes: 2 additions & 1 deletion oggm/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division

import warnings
warnings.filterwarnings("once", category=DeprecationWarning)
import unittest
import os

Expand Down
3 changes: 2 additions & 1 deletion oggm/tests/test_workflow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division

import warnings
warnings.filterwarnings("once", category=DeprecationWarning)
import os
import logging
import shutil
Expand Down
3 changes: 3 additions & 0 deletions oggm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import shutil
import zipfile
import sys
from functools import partial

# External libs
import numpy as np
Expand Down Expand Up @@ -42,6 +43,8 @@
7.86570726e-01, 1.06450772e-01,
2.63865083e-04])

tuple2int = partial(np.array, dtype=np.int64)


def empty_cache(): # pragma: no cover
"""Empty oggm's cache directory."""
Expand Down