From 4d7c3bce294d679a23197c4bdd48139f13d0a47e Mon Sep 17 00:00:00 2001 From: Fabien Maussion Date: Thu, 8 Sep 2022 10:29:55 +0000 Subject: [PATCH] Fix issues with smoothed centerlines (#1469) * Fix issues with smoothed centerlines * ups * ups --- docs/assets.rst | 2 +- oggm/tests/test_workflow.py | 8 ++++---- oggm/utils/_workflow.py | 10 +++++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/assets.rst b/docs/assets.rst index 1dd9d6ab4..4951df698 100644 --- a/docs/assets.rst +++ b/docs/assets.rst @@ -49,7 +49,7 @@ These data are tabular summary from available global datasets: - https://cluster.klima.uni-bremen.de/~oggm/rgi/rgi62_stats.h5: the global RGI stripped from the geometries - https://cluster.klima.uni-bremen.de/~oggm/g2ti/rgi62_itmix_df.h5: ice volumes from [Farinotti_etal_2019]_ in tabular form -- https://cluster.klima.uni-bremen.de/~oggm/geodetic_ref_mb/hugonnet_2021_ds_rgi60_pergla_rates_10_20_worldwide_filled.hdf: glacier geodetic mass balance data from `Hugonnet et al., 2021 _` corrected for RGI region 12 and missing glaciers, in tabular form +- https://cluster.klima.uni-bremen.de/~oggm/geodetic_ref_mb/hugonnet_2021_ds_rgi60_pergla_rates_10_20_worldwide_filled.hdf: glacier geodetic mass balance data from `Hugonnet et al., 2021 `_ corrected for RGI region 12 and missing glaciers, in tabular form - `an example of OGGM output summary `_ from the pre-processed directories. Useful outputs include terminus position, topographical variables, etc. diff --git a/oggm/tests/test_workflow.py b/oggm/tests/test_workflow.py index 6d69271a0..9a51d542d 100644 --- a/oggm/tests/test_workflow.py +++ b/oggm/tests/test_workflow.py @@ -52,10 +52,10 @@ def up_to_climate(reset=False, use_mp=None): cfg.initialize() # Use multiprocessing - if use_mp is None: - cfg.PARAMS['use_multiprocessing'] = use_multiprocessing() - else: - cfg.PARAMS['use_multiprocessing'] = use_mp + # if use_mp is None: + # cfg.PARAMS['use_multiprocessing'] = use_multiprocessing() + # else: + # cfg.PARAMS['use_multiprocessing'] = use_mp # Working dir cfg.PATHS['working_dir'] = _TEST_DIR diff --git a/oggm/utils/_workflow.py b/oggm/utils/_workflow.py index 75689fd6b..5f3885e23 100644 --- a/oggm/utils/_workflow.py +++ b/oggm/utils/_workflow.py @@ -742,7 +742,7 @@ def get_centerline_lonlat(gdir, # Intersect with exterior geom line = line.intersection(exterior) - if line.type == 'MultiLineString': + if line.type in ['MultiLineString', 'GeometryCollection']: # Take the longest lens = [il.length for il in line.geoms] line = line.geoms[np.argmax(lens)] @@ -874,6 +874,14 @@ def write_centerlines_to_shape(gdirs, *, path=True, to_tar=False, odf = gpd.GeoDataFrame(itertools.chain.from_iterable(olist)) odf = odf.sort_values(by='RGIID') odf.crs = to_crs + # Sanity checks to avoid bad surprises + gtype = np.array([g.type for g in odf.geometry]) + if 'GeometryCollection' in gtype: + errdf = odf.loc[gtype == 'GeometryCollection'] + if not np.all(errdf.length) == 0: + errdf = errdf.loc[errdf.length > 0] + raise RuntimeError('Some geometries are non-empty GeometryCollection ' + f'at RGI Ids: {errdf.RGIID.values}') _write_shape_to_disk(odf, path, to_tar=to_tar)