Skip to content

Commit

Permalink
Mild speedup to cloudfield but still limited by interpolation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jranalli committed Oct 1, 2024
1 parent 83876e9 commit 48c8c7a
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/solarspatialtools/cloudfield.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy as np
from scipy.interpolate import RegularGridInterpolator
from jupyterlab.utils import deprecated
# from scipy.interpolate import RegularGridInterpolator, RectBivariateSpline
from scipy.ndimage import map_coordinates

import matplotlib.pyplot as plt
from scipy.ndimage import sobel, uniform_filter
Expand Down Expand Up @@ -35,11 +37,23 @@ def _random_at_scale(rand_size, final_size, plot=False):
xnew = np.linspace(0, 1, final_size[0])
ynew = np.linspace(0, 1, final_size[1])

interp_f = RegularGridInterpolator((x, y), random, method='linear')
Xnew, Ynew = np.meshgrid(xnew, ynew, indexing='ij')
random_new = interp_f((Xnew, Ynew))
# # # New Scipy Method
# interp_f = RegularGridInterpolator((x, y), random, method='linear')
# Xnew, Ynew = np.meshgrid(xnew, ynew, indexing='ij')
# random_new = interp_f((Xnew, Ynew))
# return random_new

# # # Alternate Scipy Method
# interp_f = RectBivariateSpline(x, y, random, kx=1, ky=1)
# # interp_ft = lambda xnew, ynew: interp_f(xnew, ynew).T
# random_new = interp_f(xnew, ynew)
# return random_new

# # Different potentially faster Scipy Method
Xnew, Ynew = np.meshgrid(xnew, ynew, indexing='ij')
Xnew = Xnew*len(x)
Ynew = Ynew*len(y)
random_new = map_coordinates(random, [Xnew.ravel(), Ynew.ravel()], order=1, mode='nearest').reshape(final_size)

if plot:
# generate side by side subplots to compare
Expand Down Expand Up @@ -398,4 +412,12 @@ def get_settings_from_timeseries(kt_ts, clear_threshold=0.95, plot=True):
plt.plot(field_final[1,:])
plt.show()

plt.hist(kt, bins=50)
plt.hist(field_final[1,:], bins=50)
plt.show()

plt.hist(np.diff(kt), bins=50)
plt.hist(np.diff(field_final[1,:]), bins=50)
plt.show()

# assert np.all(r == rnew)

0 comments on commit 48c8c7a

Please sign in to comment.