Skip to content

Commit

Permalink
Improving cloud field demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Ranalli committed Oct 24, 2024
1 parent dfbe3a4 commit de4459d
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 79 deletions.
302 changes: 251 additions & 51 deletions demos/synthetic_clouds_demo.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demos/synthetic_clouds_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# #### Load Timeseries Data

datafn = "../../../demos/data/hope_melpitz_1s.h5"
datafn = "data/hope_melpitz_1s.h5"
twin = pd.date_range('2013-09-08 9:15:00', '2013-09-08 10:15:00', freq='1s', tz='UTC')
data = pd.read_hdf(datafn, mode="r", key="data")
data_i = data[40]
Expand Down
56 changes: 29 additions & 27 deletions src/solarspatialtools/synthirrad/cloudfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,33 +411,35 @@ def get_timeseries_stats(kt_ts, clear_threshold=0.95, plot=False):
return ktmean, kt_1_pct, ktmax, frac_clear, vs, weights, scales


def space_to_time(pixres=1, cloud_speed=50):

# Existing code uses 1 pixel per meter, and divides by cloud speed to get X size
# does 3600 pixels, but assumes the clouds move by one full timestep.

# ECEF coordinate system (Earth Centered Earth Fixed) is used to convert lat/lon to x/y.
# This seems really weird. https://en.wikipedia.org/wiki/Geographic_coordinate_conversion

# [X, Y] = geod2ecef(Lat_to_Sim, Lon_to_Sim, zeros(size(Lat_to_Sim)));
# ynorm1 = Y - mean(Y);
# xnorm1 = X - mean(X);
# ynorm=round((ynorm1-min(ynorm1))./Cloud_Spd(qq))+1;
# xnorm=round((xnorm1-min(xnorm1))./Cloud_Spd(qq))+1;
# Xsize=60*60+max(xnorm);
# Ysize=max(ynorm);
# Xsize and Ysize are the pixel sizes generated

# Extracting a time series has us loop through the entire size of X pixels, and choose a window 3600 pixels wide, and multiply by GHI_cs
# GHI_syn(i,hour(datetime2(GHI_timestamp))==h1)=clouds_new{h1}(ynorm(i),xnorm(i):xnorm(i)+3600-1)'.*GHI_clrsky(hour(datetime2(GHI_timestamp))==h1);

pixjump = cloud_speed / pixres
# n space
# dx space
# velocity
# dt = dx / velocity
# max space = n * dx
# max time = max space / velocity
def get_positional_ts(tgt_position, field, cloud_speed=50, duration=3600, pixres=1):
"""
Get a time series of kt values for a target position in the field.
Parameters
----------
tgt_position : tuple
The spatial target position in the field (in meters)
field : np.ndarray
The field of clouds generated by cloudfield_timeseries
cloud_speed : int
The speed of the clouds in meters per second
duration : int
The duration of the time series in seconds
pixres : int
The resolution of the field in seconds
Returns
-------
sim_kt : np.ndarray
The simulated time series of kt values for the point within the field
"""

# Convert to the temporatal coordinate system
x = int(tgt_position[0]/cloud_speed)
y = int(tgt_position[1]/cloud_speed)
sim_kt = field[x:x + int(duration) + 1, y]

return sim_kt



Expand Down

0 comments on commit de4459d

Please sign in to comment.