Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 8, 2023
1 parent 43ccd70 commit a298fb3
Show file tree
Hide file tree
Showing 51 changed files with 14 additions and 124 deletions.
2 changes: 0 additions & 2 deletions notebooks/2021-08/2021-08-25/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cv2
import numpy as np
import pandas as pd
import plotly
import plotly.graph_objects as go

from nowcasting_dataset.dataset import SAT_MEAN, SAT_STD, NetCDFDataset
Expand Down Expand Up @@ -69,7 +68,6 @@
channel_indexes = [1, 8, 9]
satellite_data = []
for channel_index in channel_indexes:

# renormalize
satellite_data.append(
data["sat_data"][batch_index, :, :, :, channel_index] * SAT_STD.values[channel_index]
Expand Down
3 changes: 0 additions & 3 deletions notebooks/2021-08/2021-08-26/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import cv2
import numpy as np
import pandas as pd
import plotly
import plotly.express as px
import plotly.graph_objects as go

# get satellite image, currently from https://github.com/openclimatefix/py-staticmaps
Expand Down Expand Up @@ -90,7 +88,6 @@
channel_indexes = [1, 9, 8]
satellite_data = []
for channel_index in channel_indexes:

# renormalize
satellite_data.append(
data["sat_data"][batch_index, :, :, :, channel_index] * SAT_STD.values[channel_index]
Expand Down
2 changes: 1 addition & 1 deletion notebooks/2021-09/2021-09-06/gsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


# find out if point is in gsp
from shapely.geometry import Point, Polygon
from shapely.geometry import Point

_pnts = [Point(3, 3), Point(8, 8), Point(0, 51.38)]
pnts = gpd.GeoDataFrame(geometry=_pnts, index=["A", "B", "C"])
Expand Down
2 changes: 1 addition & 1 deletion notebooks/2021-09/2021-09-07/gsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


# find out if point is in gsp
from shapely.geometry import Point, Polygon
from shapely.geometry import Point

_pnts = [Point(3, 3), Point(8, 8), Point(0, 51.38)]
pnts = gpd.GeoDataFrame(geometry=_pnts, index=["A", "B", "C"])
Expand Down
1 change: 0 additions & 1 deletion notebooks/2021-09/2021-09-08/dan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gcsfs
import xarray as xr

filename = "gs://solar-pv-nowcasting-data/satellite/EUMETSAT/SEVIRI_RSS/OSGB36/all_zarr_int16_single_timestep.zarr/"
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2021-09/2021-09-13/remove_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

for filenames in [train_filenames, validation_filenames]:
for file in train_filenames:

print(file)

filename = file.split("/")[-1]
Expand All @@ -30,7 +29,7 @@

try:
rename_file(remote_file=file, new_filename=new_filename)
except Exception as e:
except Exception:
pass
else:
print(f"Skipping {filename}")
2 changes: 0 additions & 2 deletions notebooks/2021-09/2021-09-14/gsp_centroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from nowcasting_dataset.data_sources.gsp.eso import (
get_gsp_metadata_from_eso,
get_gsp_shape_from_eso,
)
from nowcasting_dataset.geospatial import WGS84_CRS

Expand All @@ -16,7 +15,6 @@

# for index in range(0, len(shape_data_raw)):
for index in range(140, 150):

# just select the first one
shape_data = shape_data_raw.iloc[index : index + 1]
shapes_dict = json.loads(shape_data["geometry"].to_json())
Expand Down
2 changes: 0 additions & 2 deletions notebooks/2021-09/2021-09-14/gsp_duplicated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import plotly.graph_objects as go

from nowcasting_dataset.data_sources.gsp.eso import (
get_gsp_metadata_from_eso,
get_gsp_shape_from_eso,
)

Expand All @@ -13,7 +12,6 @@
duplicated_raw["Amount"] = range(0, len(duplicated_raw))

for i in range(0, 8, 2):

# just select the first one
duplicated = duplicated_raw.iloc[i : i + 2]
shapes_dict = json.loads(duplicated["geometry"].to_json())
Expand Down
1 change: 0 additions & 1 deletion notebooks/2021-09/2021-09-28/get_raw_sun_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from nowcasting_dataset.data_sources.gsp.eso import get_gsp_metadata_from_eso
from nowcasting_dataset.data_sources.sun.raw_data_load_save import (
get_azimuth_and_elevation,
save_to_zarr,
)

# set up
Expand Down
2 changes: 0 additions & 2 deletions notebooks/2021-09/2021-09-29/gsp_duplicated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import plotly.graph_objects as go

from nowcasting_dataset.data_sources.gsp.eso import (
get_gsp_metadata_from_eso,
get_gsp_shape_from_eso,
)
from nowcasting_dataset.geospatial import WGS84_CRS
Expand All @@ -15,7 +14,6 @@
duplicated_raw["Amount"] = range(0, len(duplicated_raw))

for i in range(0, 8, 2):

# just select the first one
duplicated = duplicated_raw.iloc[i : i + 2]
shapes_dict = json.loads(duplicated["geometry"].to_json())
Expand Down
8 changes: 3 additions & 5 deletions notebooks/2021-09/2021-09-29/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@


def get_trace(dt):

# plot to check it looks right
return go.Choroplethmapbox(
geojson=shapes_dict,
Expand All @@ -54,7 +53,6 @@ def get_trace(dt):


def get_frame(dt):

# plot to check it looks right
return go.Choroplethmapbox(
z=gps_data[dt],
Expand All @@ -71,8 +69,8 @@ def get_frame(dt):
fig.update_layout(title="Midday")

# fig.show(renderer="browser")
fig.write_html(f"midday_fix.html")
fig.write_image(f"midday_fix.png")
fig.write_html("midday_fix.html")
fig.write_image("midday_fix.png")

# make annimation
frames = []
Expand Down Expand Up @@ -147,4 +145,4 @@ def get_frame(dt):
)

fig.show(renderer="browser")
fig.write_html(f"video.html")
fig.write_html("video.html")
4 changes: 1 addition & 3 deletions notebooks/2021-10/2021-10-01/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import numpy as np
import torch
import xarray as xr
from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field

from nowcasting_dataset.config.model import Configuration

Array = Union[xr.DataArray, np.ndarray, torch.Tensor]


class Satellite(BaseModel):

# width: int = Field(..., g=0, description="The width of the satellite image")
# height: int = Field(..., g=0, description="The width of the satellite image")
# num_channels: int = Field(..., g=0, description="The width of the satellite image")
Expand Down Expand Up @@ -49,7 +48,6 @@ class Config:


class Batch(BaseModel):

batch_size: int = Field(
...,
g=0,
Expand Down
7 changes: 3 additions & 4 deletions notebooks/2021-10/2021-10-08/xr_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
def get_satellite_xrarray_data_array(
batch_size, seq_length_5, satellite_image_size_pixels, number_sat_channels=10
):

r = np.random.randn(
# self.batch_size,
seq_length_5,
Expand Down Expand Up @@ -53,9 +52,9 @@ def sat_data_array_to_dataset(sat_xr):
ds = coord_to_range(ds, dim, prefix="sat")
ds = ds.rename(
{
"channels": f"sat_channels",
"x": f"sat_x",
"y": f"sat_y",
"channels": "sat_channels",
"x": "sat_x",
"y": "sat_y",
}
)

Expand Down
5 changes: 1 addition & 4 deletions notebooks/2021-10/2021-10-08/xr_pydantic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from typing import List, Union
from typing import Union

import numpy as np
import torch
import xarray as xr
from pydantic import BaseModel, Field, validator

from nowcasting_dataset.config.model import Configuration

Array = Union[xr.DataArray, np.ndarray, torch.Tensor]


Expand All @@ -27,7 +25,6 @@ def v_image_data(cls, v):


class Batch(BaseModel):

batch_size: int = 0
satellite: Satellite

Expand Down
1 change: 0 additions & 1 deletion nowcasting_dataset/data_sources/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def __post_init__(self):
def _get_start_dt(
self, t0_datetime_utc: Union[pd.Timestamp, pd.DatetimeIndex]
) -> Union[pd.Timestamp, pd.DatetimeIndex]:

return t0_datetime_utc - self.history_duration

def _get_end_dt(
Expand Down
1 change: 0 additions & 1 deletion nowcasting_dataset/data_sources/fake/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ def topographic_fake(
# make batch of arrays
xr_arrays = []
for i in range(batch_size):

x, y = make_image_coords_osgb(
size_x=image_size_pixels_width,
size_y=image_size_pixels_height,
Expand Down
1 change: 0 additions & 1 deletion nowcasting_dataset/data_sources/gsp/eso.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def get_gsp_shape_from_eso(
shape_gpd["RegionID"] = range(1, len(shape_gpd) + 1)

if save_local_file:

# rename the columns to less than 10 characters
shape_gpd_to_save = shape_gpd.copy()
shape_gpd_to_save.rename(columns=rename_save_columns, inplace=True)
Expand Down
5 changes: 0 additions & 5 deletions nowcasting_dataset/data_sources/gsp/gsp_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def get_all_locations(self, t0_datetimes_utc: pd.DatetimeIndex) -> List[SpaceTim
if total_gsp_nan_count > 0:
assert Exception("There are nans in the GSP data. Can't get locations for all GSPs")
else:

t0_datetimes_utc.name = "t0_datetime_utc"

# get all locations
Expand Down Expand Up @@ -236,7 +235,6 @@ def get_locations(self, t0_datetimes_utc: pd.DatetimeIndex) -> List[SpaceTimeLoc

total_gsp_nan_count = self.gsp_power.isna().sum().sum()
if total_gsp_nan_count == 0:

# get random GSP metadata
indexes = sorted(
list(self.rng.integers(low=0, high=len(self.metadata), size=len(t0_datetimes_utc)))
Expand All @@ -249,7 +247,6 @@ def get_locations(self, t0_datetimes_utc: pd.DatetimeIndex) -> List[SpaceTimeLoc
ids = list(metadata.index)

else:

logger.warning(
"There are some nans in the gsp data, "
"so to get x,y locations we have to do a big loop"
Expand All @@ -262,7 +259,6 @@ def get_locations(self, t0_datetimes_utc: pd.DatetimeIndex) -> List[SpaceTimeLoc
ids = []

for t0_dt in t0_datetimes_utc:

# Choose start and end times
start_dt = self._get_start_dt(t0_dt)
end_dt = self._get_end_dt(t0_dt)
Expand Down Expand Up @@ -290,7 +286,6 @@ def get_locations(self, t0_datetimes_utc: pd.DatetimeIndex) -> List[SpaceTimeLoc

locations = []
for i in range(len(x_centers_osgb)):

locations.append(
SpaceTimeLocation(
t0_datetime_utc=t0_datetimes_utc[i],
Expand Down
1 change: 0 additions & 1 deletion nowcasting_dataset/data_sources/gsp/pvlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def load_pv_gsp_raw_data_from_pvlive(
future_tasks = []
with futures.ThreadPoolExecutor(max_workers=4) as executor:
for gsp_id in gsp_ids:

# set the first chunk start and end times
start_chunk = first_start_chunk
end_chunk = first_end_chunk
Expand Down
1 change: 0 additions & 1 deletion nowcasting_dataset/data_sources/metadata/metadata_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def save_to_csv(self, path):
metadata_df = pd.DataFrame(metadata_dict)

else:

metadata_df = pd.read_csv(filename)

metadata_df_extra = pd.DataFrame(metadata_dict)
Expand Down
2 changes: 0 additions & 2 deletions nowcasting_dataset/data_sources/pv/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def get_metadata_from_database(providers: List[str] = None) -> pd.DataFrame:

pv_system_all_df = []
for provider in providers:

logger.debug(f"Get PV systems from database for {provider}")

with db_connection.get_session() as session:
Expand Down Expand Up @@ -132,7 +131,6 @@ def get_pv_power_from_database(
logger.debug(f"Found {len(pv_yields_df)} pv yields")

if len(pv_yields_df) == 0:

data = create_empty_pv_data(end_utc=now, providers=providers, start_utc=start_utc)

return data
Expand Down
3 changes: 1 addition & 2 deletions nowcasting_dataset/data_sources/pv/pv_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def get_data_model_for_batch():
return PV

def _load_metadata(self):

logger.debug(f"Loading PV metadata from {self.files_groups}")

# collect all metadata together
Expand Down Expand Up @@ -155,7 +154,6 @@ def _load_metadata(self):
logger.debug(f"Found {len(pv_metadata)} pv systems")

def _load_pv_power(self):

logger.debug(f"Loading PV Power data from {self.files_groups}")

if not self.is_live:
Expand Down Expand Up @@ -452,6 +450,7 @@ def get_locations(self, t0_datetimes_utc: pd.DatetimeIndex) -> List[SpaceTimeLoc
Returns: x_locations, y_locations. Each has one entry per t0_datetime.
Locations are in OSGB coordinates.
"""

# Set this up as a separate function, so we can cache the result!
@functools.cache # functools.cache requires Python >= 3.9
def _get_pv_system_ids(t0_datetime: pd.Timestamp) -> pd.Int64Index:
Expand Down
3 changes: 0 additions & 3 deletions nowcasting_dataset/data_sources/sun/raw_data_load_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ def get_azimuth_and_elevation(
names = []
# loop over locations and find azimuth and elevation angles,
with futures.ThreadPoolExecutor() as executor:

logger.debug("Setting up jobs")

# Submit tasks to the executor.
future_azimuth_and_elevation_per_location = []
for i in tqdm(range(len(x_centers))):

name = x_y_to_name(x_centers[i], y_centers[i])
if name not in names:

lat, lon = geospatial.osgb_to_lat_lon(x=x_centers[i], y=y_centers[i])

future_azimuth_and_elevation = executor.submit(
Expand Down
3 changes: 0 additions & 3 deletions nowcasting_dataset/data_sources/sun/sun_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def get_example(self, location: SpaceTimeLocation) -> xr.Dataset:
end_dt = self._get_end_dt(t0_datetime_utc)

if not self.load_live:

# The names of the columns get truncated when saving, therefore we need to look for the
# name of the columns near the location we are looking for
locations = np.array(
Expand All @@ -96,7 +95,6 @@ def get_example(self, location: SpaceTimeLocation) -> xr.Dataset:
elevation = self.elevation.loc[start_dt:end_dt][name]

else:

latitude, longitude = osgb_to_lat_lon(x=x_center_osgb, y=y_center_osgb)

datestamps = pd.date_range(start=start_dt, end=end_dt, freq="5T").tolist()
Expand All @@ -115,7 +113,6 @@ def get_example(self, location: SpaceTimeLocation) -> xr.Dataset:
return sun

def _load(self):

logger.info(f"Loading Sun data from {self.zarr_path}")

if not self.load_live:
Expand Down
Loading

0 comments on commit a298fb3

Please sign in to comment.