Grid2op / chronix2grid

https://chronix2grid.readthedocs.io/en/latest/?
Mozilla Public License 2.0
19 stars 5 forks source link

Interpolation error on compute_solar_pattern(...) #83

Open DEUCE1957 opened 1 month ago

DEUCE1957 commented 1 month ago

On Linux, Chronix2Grid version 1.2.0.post1, Python 3.12.7

When running:

def compute_solar_pattern(params, solar_pattern, tol=0.0):
    # ...
    start_year = pd.to_datetime(str(params['start_date'].year) + '-01-01', format='%Y-%m-%d')
    end_min = int(pd.Timedelta(params['end_date'] - start_year).total_seconds() // 60)

    Nt_inter_hr = int(end_min // 60 + 1)
    N_repet = int((Nt_inter_hr - 1) // len(solar_pattern) + 1) 
    stacked_solar_pattern = solar_pattern
    for i in range(N_repet - 1):
        stacked_solar_pattern = np.append(stacked_solar_pattern, solar_pattern)

    # The time is in minutes
    t_pattern = 60 * np.linspace(0, 8760 * N_repet, 8760 * N_repet, endpoint=False)
    f2 = interp1d(t_pattern, stacked_solar_pattern, kind='cubic')
    # f2 = interp1d(t_pattern, stacked_solar_pattern, kind='linear')

    Nt_inter = int(params['T'] // params['dt'] + 1)
    start_year = pd.to_datetime(str(params['start_date'].year) + '-01-01', format='%Y-%m-%d')
    start_min = int(pd.Timedelta(params['start_date'] - start_year).total_seconds() // 60)
    end_min = int(pd.Timedelta(params['end_date'] - start_year).total_seconds() // 60)

    t_inter = np.linspace(start_min, end_min, Nt_inter, endpoint=True)
    output = f2(t_inter) # >> ERROR HERE <<

In the edge case where start_date is '2012-07-01' and end-date is '2012-07-02', the above code will throw the following Error on Scipy's inter1pd (i.e. the line output=f2(t_inter):

A value (525545.0) in x_new is above the interpolation range's maximum value (525540.0).

Solution: Turn

N_repet = int((Nt_inter_hr - 1) // len(solar_pattern) + 1) 

Into

N_repet = int((Nt_inter_hr) // len(solar_pattern) + 1) 
BDonnot commented 2 weeks ago

Hi,

Thanks for reporting this issue. I'll try to add it to the code and see if it breaks something

BDonnot commented 2 weeks ago

(high quality dev I know :-/)