Skip to content

Interpolation error on compute_solar_pattern(...) #83

@DEUCE1957

Description

@DEUCE1957

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) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions