From cc63fc3966efcaf280f62de6d3d1264296f005cf Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Mon, 15 Nov 2021 19:11:02 +0000 Subject: [PATCH 1/5] add sun plot --- .../visualization/data_sources/plot_sun.py | 21 +++++++++++++++++ tests/visualization/data_sources/test_sun.py | 23 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 nowcasting_utils/visualization/data_sources/plot_sun.py create mode 100644 tests/visualization/data_sources/test_sun.py diff --git a/nowcasting_utils/visualization/data_sources/plot_sun.py b/nowcasting_utils/visualization/data_sources/plot_sun.py new file mode 100644 index 0000000..13bb443 --- /dev/null +++ b/nowcasting_utils/visualization/data_sources/plot_sun.py @@ -0,0 +1,21 @@ +""" General functions for plotting PV data """ + +import plotly.graph_objects as go +from nowcasting_dataset.data_sources.sun.sun_model import Sun +from typing import List + +from nowcasting_utils.visualization.line import make_trace + + +def get_elevation_and_azimuth_trace(sun: Sun, example_index: int) -> List[go.Scatter]: + """Produce plot of centroid pv system""" + + y1 = sun.elevation[example_index] + y2 = sun.azimuth[example_index] + x = sun.time[example_index] + + trace_elevation = make_trace(x, y1, truth=True, name="elevation") + trace_azimuth = make_trace(x, y2, truth=True, name="azimuth") + + return [trace_elevation, trace_azimuth] + diff --git a/tests/visualization/data_sources/test_sun.py b/tests/visualization/data_sources/test_sun.py new file mode 100644 index 0000000..610372a --- /dev/null +++ b/tests/visualization/data_sources/test_sun.py @@ -0,0 +1,23 @@ +from nowcasting_utils.visualization.data_sources.plot_sun import ( + get_elevation_and_azimuth_trace +) +from nowcasting_dataset.geospatial import osgb_to_lat_lon +from nowcasting_dataset.data_sources.fake import ( + sun_fake, +) +import os +import plotly.graph_objects as go + + +def test_get_trace_centroid_pv(): + + sun = sun_fake(batch_size=2, seq_length_5=19) + + traces = get_elevation_and_azimuth_trace(sun=sun, example_index=1) + + # here's if you need to plot the trace + fig = go.Figure() + for trace in traces: + fig.add_trace(trace) + if "CI" not in os.environ.keys(): + fig.show(renderer="browser") From 825d247899049c8824d76a47149907cafcb28448 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Mon, 15 Nov 2021 19:15:10 +0000 Subject: [PATCH 2/5] flake8 --- nowcasting_utils/visualization/data_sources/plot_sun.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nowcasting_utils/visualization/data_sources/plot_sun.py b/nowcasting_utils/visualization/data_sources/plot_sun.py index 13bb443..89c6dc7 100644 --- a/nowcasting_utils/visualization/data_sources/plot_sun.py +++ b/nowcasting_utils/visualization/data_sources/plot_sun.py @@ -18,4 +18,3 @@ def get_elevation_and_azimuth_trace(sun: Sun, example_index: int) -> List[go.Sca trace_azimuth = make_trace(x, y2, truth=True, name="azimuth") return [trace_elevation, trace_azimuth] - From 252e020f5031c6538c63c033c785e3658087897b Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Mon, 15 Nov 2021 19:16:28 +0000 Subject: [PATCH 3/5] sort isort --- nowcasting_utils/visualization/data_sources/plot_sun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nowcasting_utils/visualization/data_sources/plot_sun.py b/nowcasting_utils/visualization/data_sources/plot_sun.py index 89c6dc7..409413e 100644 --- a/nowcasting_utils/visualization/data_sources/plot_sun.py +++ b/nowcasting_utils/visualization/data_sources/plot_sun.py @@ -1,8 +1,9 @@ """ General functions for plotting PV data """ +from typing import List + import plotly.graph_objects as go from nowcasting_dataset.data_sources.sun.sun_model import Sun -from typing import List from nowcasting_utils.visualization.line import make_trace From 2734d074b39be02c1a9dced87abace593be23913 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Nov 2021 20:12:40 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../visualization/data_sources/README.md | 4 +- .../data_sources/plot_satellite.py | 6 +- tests/visualization/data_sources/test_pv.py | 16 +++--- .../data_sources/test_satellite.py | 55 +++++++++++-------- tests/visualization/data_sources/test_sun.py | 12 ++-- 5 files changed, 50 insertions(+), 43 deletions(-) diff --git a/nowcasting_utils/visualization/data_sources/README.md b/nowcasting_utils/visualization/data_sources/README.md index e75ff60..9d1431f 100644 --- a/nowcasting_utils/visualization/data_sources/README.md +++ b/nowcasting_utils/visualization/data_sources/README.md @@ -10,6 +10,6 @@ The main pv plot view gives a view of the pv sources in two subplots # Satellite -The main satellite plot show a video for each satellite channel over. +The main satellite plot show a video for each satellite channel over. - \ No newline at end of file + diff --git a/nowcasting_utils/visualization/data_sources/plot_satellite.py b/nowcasting_utils/visualization/data_sources/plot_satellite.py index 15a39bc..cb55522 100644 --- a/nowcasting_utils/visualization/data_sources/plot_satellite.py +++ b/nowcasting_utils/visualization/data_sources/plot_satellite.py @@ -84,7 +84,7 @@ def make_traces_one_timestep(satellite: Satellite, example_index: int, time_inde def make_animation_one_channels(satellite: Satellite, example_index: int, channel_index: int): - """ Make animation of one channel """ + """Make animation of one channel""" traces = make_traces_one_channel( satellite=satellite, example_index=example_index, channel_index=0 ) @@ -150,7 +150,7 @@ def make_animation_all_channels(satellite: Satellite, example_index: int): rows=n_rows, cols=n_cols, # subplot_titles= satellite.channels, - specs=specs + specs=specs, ) print(len(traces_all[0])) @@ -181,7 +181,7 @@ def make_animation_all_channels(satellite: Satellite, example_index: int): mapbox = dict(style="carto-positron", center=dict(lat=lat, lon=lon), zoom=7) - layout_dict = {f'mapbox{i}': mapbox for i in range(1, n_channels+1)} + layout_dict = {f"mapbox{i}": mapbox for i in range(1, n_channels + 1)} fig.update_layout(layout_dict) return fig diff --git a/tests/visualization/data_sources/test_pv.py b/tests/visualization/data_sources/test_pv.py index 61a7a4e..890c701 100644 --- a/tests/visualization/data_sources/test_pv.py +++ b/tests/visualization/data_sources/test_pv.py @@ -1,16 +1,16 @@ +import os + +import plotly.graph_objects as go +from nowcasting_dataset.data_sources.fake import pv_fake +from nowcasting_dataset.geospatial import osgb_to_lat_lon + from nowcasting_utils.visualization.data_sources.plot_pv import ( - get_trace_centroid_pv, + get_fig_pv_combined, get_trace_all_pv_systems, + get_trace_centroid_pv, get_traces_pv_intensity, make_fig_of_animation_from_frames, - get_fig_pv_combined, -) -from nowcasting_dataset.geospatial import osgb_to_lat_lon -from nowcasting_dataset.data_sources.fake import ( - pv_fake, ) -import os -import plotly.graph_objects as go def test_get_trace_centroid_pv(): diff --git a/tests/visualization/data_sources/test_satellite.py b/tests/visualization/data_sources/test_satellite.py index b33fe84..45cbc09 100644 --- a/tests/visualization/data_sources/test_satellite.py +++ b/tests/visualization/data_sources/test_satellite.py @@ -1,28 +1,32 @@ """ Tests to plot satellite data """ +import os + +import numpy as np +import plotly.graph_objects as go +from nowcasting_dataset.data_sources.fake import satellite_fake +from nowcasting_dataset.geospatial import osgb_to_lat_lon +from plotly.subplots import make_subplots + from nowcasting_utils.visualization.data_sources.plot_satellite import ( - make_traces_one_channel_one_time, - make_traces_one_channel, - make_animation_one_channels, make_animation_all_channels, + make_animation_one_channels, + make_traces_one_channel, + make_traces_one_channel_one_time, make_traces_one_timestep, ) -from nowcasting_dataset.geospatial import osgb_to_lat_lon -from nowcasting_dataset.data_sources.fake import ( - satellite_fake, -) -from plotly.subplots import make_subplots -import os -import numpy as np -import plotly.graph_objects as go -from nowcasting_utils.visualization.utils import make_slider, make_buttons +from nowcasting_utils.visualization.utils import make_buttons, make_slider def test_make_traces_one_channel_one_time(): - satellite = satellite_fake(batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, number_satellite_channels=2) + satellite = satellite_fake( + batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, number_satellite_channels=2 + ) example_index = 1 - trace = make_traces_one_channel_one_time(satellite=satellite, example_index=example_index, channel_index=0, time_index=1) + trace = make_traces_one_channel_one_time( + satellite=satellite, example_index=example_index, channel_index=0, time_index=1 + ) fig = go.Figure(trace) @@ -41,10 +45,14 @@ def test_make_traces_one_channel_one_time(): def test_make_traces_one_channel(): - satellite = satellite_fake(batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, number_satellite_channels=2) + satellite = satellite_fake( + batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, number_satellite_channels=2 + ) - example_index =1 - traces = make_traces_one_channel(satellite=satellite, example_index=example_index, channel_index=0) + example_index = 1 + traces = make_traces_one_channel( + satellite=satellite, example_index=example_index, channel_index=0 + ) x = satellite.x[example_index].mean() y = satellite.y[example_index].mean() @@ -70,10 +78,12 @@ def test_make_traces_one_channel(): if "CI" not in os.environ.keys(): fig.show(renderer="browser") + def test_make_animation_one_channels(): - satellite = satellite_fake(batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, - number_satellite_channels=2) + satellite = satellite_fake( + batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, number_satellite_channels=2 + ) fig = make_animation_one_channels(satellite=satellite, example_index=1, channel_index=0) @@ -87,12 +97,11 @@ def test_make_animation_all_channesl(): # satellite = xr.load_dataset('/Users/peterdudfield/Documents/Github/nowcasting_utils/tests/data/sat/000000.nc') # satellite = satellite.rename({'stacked_eumetsat_data':'data', "variable":"channels"}) - satellite = satellite_fake(batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, - number_satellite_channels=8) + satellite = satellite_fake( + batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, number_satellite_channels=8 + ) fig = make_animation_all_channels(satellite=satellite, example_index=1) if "CI" not in os.environ.keys(): fig.show(renderer="browser") - - diff --git a/tests/visualization/data_sources/test_sun.py b/tests/visualization/data_sources/test_sun.py index 610372a..24436be 100644 --- a/tests/visualization/data_sources/test_sun.py +++ b/tests/visualization/data_sources/test_sun.py @@ -1,12 +1,10 @@ -from nowcasting_utils.visualization.data_sources.plot_sun import ( - get_elevation_and_azimuth_trace -) -from nowcasting_dataset.geospatial import osgb_to_lat_lon -from nowcasting_dataset.data_sources.fake import ( - sun_fake, -) import os + import plotly.graph_objects as go +from nowcasting_dataset.data_sources.fake import sun_fake +from nowcasting_dataset.geospatial import osgb_to_lat_lon + +from nowcasting_utils.visualization.data_sources.plot_sun import get_elevation_and_azimuth_trace def test_get_trace_centroid_pv(): From 6fa9d4224c96ee0b9c16917714931025597ff585 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 19 Nov 2021 14:35:34 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/visualization/data_sources/test_satellite.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/visualization/data_sources/test_satellite.py b/tests/visualization/data_sources/test_satellite.py index d59496f..a304df1 100644 --- a/tests/visualization/data_sources/test_satellite.py +++ b/tests/visualization/data_sources/test_satellite.py @@ -94,7 +94,6 @@ def test_make_animation_one_channels(): def test_make_animation_all_channesl(): """Test 'make_animation_all_channels' functions""" - satellite = satellite_fake( batch_size=2, seq_length_5=5, satellite_image_size_pixels=32, number_satellite_channels=8 )