|
|
|
|
| from scipy.interpolate import RegularGridInterpolator
|
| import numpy as np
|
|
|
|
|
|
|
|
|
|
|
| class SolarEnergyInterpolator:
|
| def __init__(self, data_dir=None):
|
| """
|
| 1. Loads 3D grid file
|
| 2. Initializes interpolator
|
| """
|
| import os
|
| if data_dir is None:
|
| data_file = "pv_potential_3d.npz"
|
| else:
|
| data_file = os.path.join(data_dir, "pv_potential_3d.npz")
|
| print(f"Loading efficiency data from: {data_file}")
|
| print(f"File exists: {os.path.exists(data_file)}")
|
| data = np.load(data_file)
|
| print("File loaded")
|
|
|
|
|
| pv_data = data["pv_data"]
|
| lons = data["lons"]
|
| lats = data["lats"]
|
| months_axis = np.arange(1, 13)
|
|
|
|
|
| self.interpolator = RegularGridInterpolator(
|
| (lons, lats, months_axis),
|
| pv_data,
|
| method='linear',
|
| bounds_error=False,
|
| fill_value=0
|
| )
|
| print("Grid interpolator initialized")
|
|
|
| def get_solar_efficiency(self, latitude, longitude):
|
| """
|
| Interpolates the solar energy for the given lat, long, and month of year.
|
| Calculates efficiency based on yearly average energy.
|
|
|
| Parameters:
|
| latitude (float): Latitude of the query point. (-60 to 65)
|
| longitude (float): Longitude of the query point. (-180 to 180)
|
|
|
| Returns:
|
| float: Interpolated solar efficiency value or 0 if out of range.
|
| """
|
|
|
|
|
| days_vec = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
|
| month = list(range(1,13))
|
| specEnergy = self.interpolator((longitude, latitude, month))
|
| efficiency = round(np.average(specEnergy)*(365/100),2)
|
|
|
| return efficiency
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|