From e532578e60cea197691ab63e0023d631ec0116ef Mon Sep 17 00:00:00 2001 From: lukas leufen <l.leufen@fz-juelich.de> Date: Tue, 7 Jan 2020 15:21:45 +0100 Subject: [PATCH] post processing can plot station_map(), but countries are not filled with e.g. elevation data (just blank fill) --- README.md | 8 ++++++- requirements.txt | 10 +++++++- src/plotting/postprocessing_plotting.py | 32 ++++++++++++++++++++++--- src/run_modules/post_processing.py | 5 +++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 329b1f16..e49362e9 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,10 @@ This is a collection of all relevant functions used for ML stuff in the ESDE gro See a description [here](https://towardsdatascience.com/a-simple-guide-to-the-versions-of-the-inception-network-7fc52b863202) or take a look on the papers [Going Deeper with Convolutions (Szegedy et al., 2014)](https://arxiv.org/abs/1409.4842) -and [Network In Network (Lin et al., 2014)](https://arxiv.org/abs/1312.4400). \ No newline at end of file +and [Network In Network (Lin et al., 2014)](https://arxiv.org/abs/1312.4400). + + +# Installation + +* Install __proj__ on your machine using the console. E.g. for opensuse / leap `zypper install proj` +* c++ compiler required for cartopy installation \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 496c6426..f6c1eb24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,12 @@ statsmodels seaborn dask==0.20.2 toolz # for dask -cloudpickle # for dask \ No newline at end of file +cloudpickle # for dask +cython +pyshp +six +pyproj +shapely +cartopy==0.16.0 +matplotlib +pillow \ No newline at end of file diff --git a/src/plotting/postprocessing_plotting.py b/src/plotting/postprocessing_plotting.py index 4b196053..9ad7f87f 100644 --- a/src/plotting/postprocessing_plotting.py +++ b/src/plotting/postprocessing_plotting.py @@ -8,10 +8,9 @@ import xarray as xr import matplotlib import seaborn as sns import matplotlib.pyplot as plt +import cartopy.crs as ccrs +import cartopy.feature as cfeature -import dask.array as da -import dask -import dask.dataframe as ddf logging.getLogger('matplotlib').setLevel(logging.WARNING) @@ -53,3 +52,30 @@ def plot_monthly_summary(stations, data_path, name: str, window_lead_time, targe plt.close('all') +def plot_climsum_boxplot(): + return + + +def station_map(generators, plot_folder="."): + + logging.debug("run station_map()") + fig = plt.figure(figsize=(10, 5)) + ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree()) + ax.set_extent([0, 20, 42, 58], crs=ccrs.PlateCarree()) + ax.add_feature(cfeature.COASTLINE.with_scale("10m"), edgecolor='black') + ax.add_feature(cfeature.LAKES.with_scale("50m")) + ax.add_feature(cfeature.OCEAN.with_scale("50m")) + ax.add_feature(cfeature.RIVERS.with_scale("10m")) + ax.add_feature(cfeature.BORDERS.with_scale("10m"), facecolor='none', edgecolor='black') + + if generators is not None: + for color, gen in generators.items(): + for k, v in enumerate(gen): + station_coords = gen.get_data_generator(k).meta.loc[['station_lon', 'station_lat']] + station_names = gen.get_data_generator(k).meta.loc[['station_id']] + IDx, IDy = float(station_coords.loc['station_lon'].values), float(station_coords.loc['station_lat'].values) + ax.plot(IDx, IDy, mfc=color, mec='k', marker='s', markersize=6, transform=ccrs.PlateCarree()) + + plot_path = os.path.join(os.path.abspath(plot_folder), 'test_map_plot.pdf') + plt.savefig(plot_path) + plt.close('all') diff --git a/src/run_modules/post_processing.py b/src/run_modules/post_processing.py index 5d4c805a..96c8a40b 100644 --- a/src/run_modules/post_processing.py +++ b/src/run_modules/post_processing.py @@ -17,7 +17,7 @@ from src.model_modules.linear_model import OrdinaryLeastSquaredModel from src import statistics from src import helpers from src.helpers import TimeTracking -from src.plotting.postprocessing_plotting import plot_monthly_summary +from src.plotting.postprocessing_plotting import plot_monthly_summary, plot_climsum_boxplot, station_map class PostProcessing(RunEnvironment): @@ -39,11 +39,14 @@ class PostProcessing(RunEnvironment): self.plot() def plot(self): + logging.debug("Run plotting routines...") path = self.data_store.get("forecast_path", "general") window_lead_time = self.data_store.get("window_lead_time", "general") target_var = self.data_store.get("target_var", "general") + station_map(generators={'b': self.test_data}, plot_folder=self.plot_path) plot_monthly_summary(self.test_data.stations, path, r"forecasts_%s_test.nc", window_lead_time, target_var, plot_folder=self.plot_path) + # plot_climsum_boxplot() def calculate_test_score(self): test_score = self.model.evaluate(generator=self.test_data_distributed.distribute_on_batches(), -- GitLab