ColRadPy icon indicating copy to clipboard operation
ColRadPy copied to clipboard

interp2d deprecated

Open d-v-t opened this issue 11 months ago • 3 comments

Per https://scipy.github.io/devdocs/tutorial/interpolate/interp_transition_guide.html, interp2d is deprecated. This shows up on ionization_balance_class.py line 15.

It seems this code is attempting to interpolate logged_gcr across a logarithmically regular grid of temperature and density. So, if I'm not mistaken, the switch is to simply replace interp2d with RectBivariateSpline.

I'll create a pull request with this update.

d-v-t avatar Feb 14 '25 21:02 d-v-t

It looks like this transition from interp2d to RectBivariateSpline caused a bug in interp_rates_adf11. When I try to pass in a set of ADF11 files I get the ValueError shown below:

Image

Per the legacy version of this function on the ionization_balance_with_cx_from_adf11 branch, it appears that there needs to be a .transpose(1,0) when passing logged_gcr[i,j,:,:] to the interp_rates_adf11() function:

def interp_rates_adf11(logged_temp,logged_dens,temp,dens,logged_gcr):
    gcr_arr = np.zeros( (np.shape(logged_gcr)[0],np.shape(logged_gcr)[1],len(temp),len(dens)) )
    for i in range(0,np.shape(logged_gcr)[0]):
        for j in range(0,np.shape(logged_gcr)[1]):
            for k in range(0,len(temp)):
                for l in range(0,len(dens)):
                    interp_gcr = interp2d(logged_temp,
                                          logged_dens,
                                          logged_gcr[i,j,:,:].transpose(1,0),
                                          kind="cubic")
                    gcr_arr[i,j,k,l] = interp_gcr(np.log10(temp[k]),np.log10(dens[l]))
    return 10**gcr_arr

Is this indeed the case? I'm just getting started with ColRadPy, so perhaps there is something else going on here that I'm missing?

ee-nn avatar Apr 24 '25 14:04 ee-nn

Good catch! I tested this code out on my machine and it didn't run either initially. I wrote a patch with some more accurate variable names, but never merged it with current code. I'm not totally sure, but it's likely the current ColRadPy is not using this updated code. The crux of it is logged_temp, logged_dens-->logged_gcr are the input data and temp, dens are the new points to interpolate gcr at. You're not missing anything.

I will add a pull request with these changes. Sorry this took a while, I thought I had done this.

d-v-t avatar Jun 11 '25 22:06 d-v-t