Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolation error on compute_solar_pattern(...) #83

Open
DEUCE1957 opened this issue Oct 28, 2024 · 2 comments
Open

Interpolation error on compute_solar_pattern(...) #83

DEUCE1957 opened this issue Oct 28, 2024 · 2 comments

Comments

@DEUCE1957
Copy link

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
Copy link
Collaborator

BDonnot commented Nov 8, 2024

Hi,

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

@BDonnot
Copy link
Collaborator

BDonnot commented Nov 8, 2024

(high quality dev I know :-/)

BDonnot added a commit that referenced this issue Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants