pySTEPS / pysteps

Python framework for short-term ensemble prediction systems.
https://pysteps.github.io/
BSD 3-Clause "New" or "Revised" License
441 stars 160 forks source link

Possibility of generating intermediate values between data points? #348

Closed atom5dev closed 5 months ago

atom5dev commented 5 months ago

Hi there, thank you for this library.

Please could you tell me if what I am trying to do is possible, and if so how I might accomplish it with this library?

I'm following the example here

I have 3 steps of hourly data. I've setup my code so that it follows pretty much how it is in that notebook but when I generating the forecast I'm running:

forecast_anvil = anvil.forecast(
    rainrate_field[-3:], velocity, 3, ar_window_radius=25, ar_order=2
)

My assumption is that this is passing in the 3 hourly steps of data which I have, and it's generating 3 more steps, predicting the motion/intensity of the rainfall at hours 4, 5 and 6. Is that correct?

I am currently able to display this data and as far as I can see it appears to be working.

What I would like to do is "train" the data using a sample size of say 3 hours. Then generate intermediate steps of say 5 minutes between hours 3 and 4 using the forecast.

Then repeat this using a rolling window now of hours 2,3,4 to train the data to give it an idea of the motion, and then generate the 5min increments between hours 4 and 5, etc etc.

Is this possible? If it is would it be possible to guide me through how to do it?

It seems to be possible as far as I can see when using something like:

motion = dense_lucaskanade(precip)

timesteps = [0, 0.1, 0.2, 0.5, 0.6, 6, 7]
thr = 0.5
slope = 1  # pixels / timestep

out = forecast(precip[0], motion, timesteps, thr, slope=slope)
for n, frame in enumerate(out):

    plt.subplot(2, 4, n + 1)
    frame[np.isnan(frame)] = 0
    plt.imshow(frame, interpolation="bilinear", vmin=0, vmax=1)
    plt.title(f"t={timesteps[n]}")

whereby it seems to support timesteps below 1, but that's just giving me probabilities I think. But the output does seem to make sense for the steps between 0 and 1.

Thank you in advance for any help, I'm far from an expert in this area so I hope I am making sense!

dnerini commented 5 months ago

hello @atom5dev

My assumption is that this is passing in the 3 hourly steps of data which I have, and it's generating 3 more steps, predicting the motion/intensity of the rainfall at hours 4, 5 and 6. Is that correct?

Correct, the definition of a time step is given by the velocity field: was this estimated based on an hourly sequence of rainfall fields? If yes, then the the nowcasting method will predict with the same hourly resolution.

What I would like to do is "train" the data using a sample size of say 3 hours. Then generate intermediate steps of say 5 minutes between hours 3 and 4 using the forecast. Is this possible? If it is would it be possible to guide me through how to do it?

Yes, it is possible and you are doing it right. All nowcasting methods can accept a list of floats as timestamps. You can pass a list of timestamps where the values are a fraction of the original hourly timestamp corresponding to 5 minutes (that is, 1/12), so for between hours 3-4: [3, 3 + 1/12, 3 + 1/6, 3 + 1/3, ..., 4].

whereby it seems to support timesteps below 1, but that's just giving me probabilities I think. But the output does seem to make sense for the steps between 0 and 1.

I think it's returning probabilities because you've been using the lagrangian_probability method, which is designed to predict exceedence probabilities. But if instead you use the plain extrapolation method you'll get the out the same units used for the input field. Remember to scale the units accordingly if you've been using something else than rainrate intensities for input.

I hope this helps. I'll close the issue. For usage questions, we'd recommend to use our slack channel. You can find invite link in the README.

atom5dev commented 5 months ago

Thank you for taking the time to reply @dnerini , very much appreciated.

How do you get access to slack? I've requested an invitation but not seen anything as of yet.