Skip to content

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 Mar 29, 2023
1 parent 0b7f11b commit 1c1710f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
15 changes: 7 additions & 8 deletions gradboost_pv/preprocessing/region_filtered.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import itertools
import logging
import multiprocessing as mp
import os
from pathlib import Path
from typing import Iterable, Tuple, Union
import os

import geopandas as gpd
import numpy as np
Expand All @@ -16,7 +16,6 @@

from gradboost_pv.models.utils import DEFAULT_DIRECTORY_TO_PROCESSED_NWP


logger = logging.getLogger(__name__)

ESO_GEO_JSON_URL = (
Expand Down Expand Up @@ -148,9 +147,9 @@ def check_points_in_multipolygon_multiprocessed(
Returns:
np.ndarray: _description_
"""
filename = './data/uk_region_mask_train.npy'
filename = "./data/uk_region_mask_train.npy"
if os.path.exists(filename):
logger.debug('Loading UK region mask from file')
logger.debug("Loading UK region mask from file")
return np.load(filename)
items = [(point, polygon) for point in points]
results = list()
Expand All @@ -160,8 +159,8 @@ def check_points_in_multipolygon_multiprocessed(

a = np.asarray(results)

logger.debug(f'Saving UK region mask from file {filename}')
np.save('./data/uk_region_mask_train.npy', a)
logger.debug(f"Saving UK region mask from file {filename}")
np.save("./data/uk_region_mask_train.npy", a)

return a

Expand Down Expand Up @@ -207,14 +206,14 @@ def load_mask(self) -> xr.DataArray:
xr.DataArray: UK-region mask, on NWP (x,y) coords
"""

logger.info('Loading UK region mask from National Grid ESO')
logger.info("Loading UK region mask from National Grid ESO")

uk_polygon = query_eso_geojson()
uk_polygon = process_eso_uk_multipolygon(uk_polygon)
mask = generate_polygon_mask(self.nwp.coords["x"], self.nwp.coords["y"], uk_polygon)

# convert numpy array to xarray mask for a 1 variable, 1 step times series of (x,y) coords
logger.debug('Making mask')
logger.debug("Making mask")
mask = xr.DataArray(
np.tile(mask.T, (len(self.nwp.coords["init_time"]), 1, 1)),
dims=["init_time", "x", "y"],
Expand Down
17 changes: 9 additions & 8 deletions scripts/preprocessing/uk_region_downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

logger = getLogger("uk-region-filter-nwp-data")

formatString = "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s" # specify a format string
formatString = (
"[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s" # specify a format string
)
logLevel = logging.DEBUG # specify standard log level
logging.basicConfig(format=formatString, level=logLevel, datefmt="%Y-%m-%d %I:%M:%S")

logging.getLogger('gcsfs').setLevel(logging.INFO)
logging.getLogger('geopandas').setLevel(logging.INFO)
logging.getLogger("gcsfs").setLevel(logging.INFO)
logging.getLogger("geopandas").setLevel(logging.INFO)

FORECAST_HORIZONS = range(NWP_STEP_HORIZON)

Expand Down Expand Up @@ -74,14 +76,13 @@ def main(base_save_directory: Path):
date_years.append(dt.datetime(year=years[-1] + 1, month=1, day=1))

for i in range(len(date_years) - 1):

year = date_years[i].year
logger.info('Loading NWP data for year %s', year)
logger.info("Loading NWP data for year %s", year)
start_datetime, end_datetime = date_years[i], date_years[i + 1]
_nwp = nwp.sel(init_time=slice(start_datetime, end_datetime))

# time points to interpolate our nwp data onto.
logger.info('Loading GSP datetimes for year %s', year)
logger.info("Loading GSP datetimes for year %s", year)
evaluation_timeseries = (
gsp.coords["datetime_gmt"]
.where(
Expand All @@ -92,8 +93,8 @@ def main(base_save_directory: Path):
.values
)

logger.debug(f'{evaluation_timeseries=}')
logger.debug(f'{evaluation_timeseries.shape=}')
logger.debug(f"{evaluation_timeseries=}")
logger.debug(f"{evaluation_timeseries.shape=}")

dataset_builder = NWPUKRegionMaskedDatasetBuilder(
_nwp,
Expand Down

0 comments on commit 1c1710f

Please sign in to comment.