From df33ccd814ec6fe0c66ae6c352fa87b3d28e4356 Mon Sep 17 00:00:00 2001 From: SorooshMani-NOAA Date: Wed, 7 Aug 2024 15:26:15 -0400 Subject: [PATCH 1/2] Use geodatasets for naturalearth --- ensembleperturbation/plotting/nodes.py | 3 ++- ensembleperturbation/plotting/perturbation.py | 5 +++-- ensembleperturbation/plotting/surrogate.py | 7 ++++--- .../uncertainty_quantification/karhunen_loeve_expansion.py | 3 ++- pyproject.toml | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ensembleperturbation/plotting/nodes.py b/ensembleperturbation/plotting/nodes.py index c55cebf3..e0b7d80a 100644 --- a/ensembleperturbation/plotting/nodes.py +++ b/ensembleperturbation/plotting/nodes.py @@ -1,6 +1,7 @@ from os import PathLike import cartopy +import geodatasets import geopandas from matplotlib import cm, gridspec, pyplot from matplotlib.axis import Axis @@ -217,7 +218,7 @@ def plot_node_map( float(nodes.coords['y'].max().values), ] - countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) + countries = geopandas.read_file(geodatasets.get_path('naturalearth land')) countries.plot(color='lightgrey', ax=map_axis) coast = cartopy.feature.NaturalEarthFeature( category='physical', scale='50m', facecolor='none', name='coastline' diff --git a/ensembleperturbation/plotting/perturbation.py b/ensembleperturbation/plotting/perturbation.py index 65af1ef1..e224b352 100644 --- a/ensembleperturbation/plotting/perturbation.py +++ b/ensembleperturbation/plotting/perturbation.py @@ -2,6 +2,7 @@ from pathlib import Path from typing import List +import geodatasets import geopandas from matplotlib import pyplot from matplotlib.cm import get_cmap @@ -175,7 +176,7 @@ def plot_perturbations( figure.suptitle(f'{num_perturbations} perturbations of storm track') map_axis = figure.add_subplot(1, 1, 1) - countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) + countries = geopandas.read_file(geodatasets.get_path('naturalearth land')) unique_perturbation_types = numpy.unique(perturbation_types) encoded_perturbation_types = encode_categorical_values( @@ -269,7 +270,7 @@ def plot_track_perturbations( map_axis = figure.add_subplot(2, 1, 1) Vmax_axis = figure.add_subplot(2, 2, 3) Rmax_axis = figure.add_subplot(2, 2, 4) - countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) + countries = geopandas.read_file(geodatasets.get_path('naturalearth land')) unique_perturbation_types = numpy.unique(perturbation_types) encoded_perturbation_types = encode_categorical_values( diff --git a/ensembleperturbation/plotting/surrogate.py b/ensembleperturbation/plotting/surrogate.py index fb827a6d..c89cbab9 100644 --- a/ensembleperturbation/plotting/surrogate.py +++ b/ensembleperturbation/plotting/surrogate.py @@ -4,6 +4,7 @@ from typing import Dict, List import cartopy +import geodatasets import geopandas from matplotlib import gridspec, pyplot from matplotlib.axis import Axis @@ -410,7 +411,7 @@ def plot_selected_validations( for index, source in enumerate(sources): map_axis = figure.add_subplot(2, len(sources), index + 1) map_axis.title.set_text(f'{source}') - countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) + countries = geopandas.read_file(geodatasets.get_path('naturalearth land')) map_axis.set_xlim((bounds[0], bounds[2])) map_axis.set_ylim((bounds[1], bounds[3])) @@ -485,7 +486,7 @@ def plot_selected_percentiles( for index, source in enumerate(sources): map_axis = figure.add_subplot(2, len(sources), index + 1) map_axis.title.set_text(f'{source}') - countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) + countries = geopandas.read_file(geodatasets.get_path('naturalearth land')) map_axis.set_xlim((bounds[0], bounds[2])) map_axis.set_ylim((bounds[1], bounds[3])) @@ -622,7 +623,7 @@ def plot_selected_probability_fields( for index, source in enumerate(sources): map_axis = figure.add_subplot(2, len(sources), index + 1) map_axis.title.set_text(f'{source}') - countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) + countries = geopandas.read_file(geodatasets.get_path('naturalearth land')) map_axis.set_xlim((bounds[0], bounds[2])) map_axis.set_ylim((bounds[1], bounds[3])) diff --git a/ensembleperturbation/uncertainty_quantification/karhunen_loeve_expansion.py b/ensembleperturbation/uncertainty_quantification/karhunen_loeve_expansion.py index 5953462d..1ff0db79 100644 --- a/ensembleperturbation/uncertainty_quantification/karhunen_loeve_expansion.py +++ b/ensembleperturbation/uncertainty_quantification/karhunen_loeve_expansion.py @@ -4,6 +4,7 @@ from typing import Union import cartopy +import geodatasets import geopandas import cmocean from matplotlib import pyplot @@ -228,7 +229,7 @@ def karhunen_loeve_prediction( map_axis = figure.add_subplot(2, len(sources), index, projection=map_crs) map_axis.title.set_text(f'{source}') countries = geopandas.read_file( - geopandas.datasets.get_path('naturalearth_lowres') + geodatasets.get_path('naturalearth land') ) countries.plot(color='lightgrey', ax=map_axis) coast = cartopy.feature.NaturalEarthFeature( diff --git a/pyproject.toml b/pyproject.toml index 8201b27d..c4817ad6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ dunamai = { version = '*', optional = true } f90nml = '*' fiona = '*' geopandas = '*' +geodatasets = '*' netcdf4 = '*' matplotlib = { version = '*', optional = true } numpy = '*' From 4404ea25635a84ddc17f114932dab65af2322ecd Mon Sep 17 00:00:00 2001 From: SorooshMani-NOAA Date: Wed, 7 Aug 2024 15:28:40 -0400 Subject: [PATCH 2/2] oitnb fix --- .../uncertainty_quantification/karhunen_loeve_expansion.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ensembleperturbation/uncertainty_quantification/karhunen_loeve_expansion.py b/ensembleperturbation/uncertainty_quantification/karhunen_loeve_expansion.py index 1ff0db79..ff149c2d 100644 --- a/ensembleperturbation/uncertainty_quantification/karhunen_loeve_expansion.py +++ b/ensembleperturbation/uncertainty_quantification/karhunen_loeve_expansion.py @@ -228,9 +228,7 @@ def karhunen_loeve_prediction( index += 1 map_axis = figure.add_subplot(2, len(sources), index, projection=map_crs) map_axis.title.set_text(f'{source}') - countries = geopandas.read_file( - geodatasets.get_path('naturalearth land') - ) + countries = geopandas.read_file(geodatasets.get_path('naturalearth land')) countries.plot(color='lightgrey', ax=map_axis) coast = cartopy.feature.NaturalEarthFeature( category='physical', scale='50m', facecolor='none', name='coastline'