sbegueria / SPEI

An R package for computing the Standardized Precipitation-Evapotranspiration Index (SPEI), Penman-Monteith and other reference evapotranspiration, SPI, etc.
78 stars 34 forks source link

final year in dataset not calculated #56

Closed bakermel closed 1 year ago

bakermel commented 1 year ago

sorry if this is a missunderstanding on my behalf about how the index is calculated, but my input data is from 1963- Jan 2023. The spi is only calculated up to Jan 2022.

sbegueria commented 1 year ago

Hi, it's impossible to reproduce the error if no more information or data is provided. If you are calculating the SPI at a scale S, then you would get a time series of length N-(S-1), but it is the first S-1 months that are lost, and not the last ones. Might that be the problem with your case?

bakermel commented 1 year ago

Hi,

That is what I had thought. It shows NA for 1963. But it computes the spi index a year short. I’ve attached the data and this is the code I’ve used in R:

monthSPI <- as.monthly(dailySPI)

monthTS <- ts(monthSPI[, 'precipitation'], freq=12, start=c(1963,1))

data <- spei(monthTS, 12, ref.start=c(1963,1), ref.end=c(2000,1)) plot(data)

dataToExport <- timetk::tk_tbl(data$fitted)

Best wishes,

Melanie


Melanie Baker (She/Her)

ACCE DTP PhD Student

Mammalian Behaviour & Evolution Group

Institute of Infection, Veterinary and Ecological Sciences

University of Liverpool, Leahurst Campus

Neston CH64 7TE UK

Email: @.**@.>

Twitter: @Me1anieBakerhttps://twitter.com/Me1anieBaker

From: Santiago @.> Sent: 21 March 2023 01:56 PM To: @.> Cc: Baker, @.>; @.> Subject: Re: [sbegueria/SPEI] final year in dataset not calculated (Issue #56)

Hi, it's impossible to reproduce the error if no more information or data is provided. If you are calculating the SPI at a scale S, then you would get a time series of length N-(S-1), but it is the first S-1 months that are lost, and not the last ones. Might that be the problem with your case?

— Reply to this email directly, view it on GitHubhttps://github.com/sbegueria/SPEI/issues/56#issuecomment-1477881651, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A6UKEWK5KZNWBKVVLPDDPFDW5GXNRANCNFSM6AAAAAAWCPBDX4. You are receiving this because you authored the thread.Message ID: @.***>

sbegueria commented 1 year ago

Can't see the data.

bakermel commented 1 year ago

Apologies I'm new to github. MBaker.csv

sbegueria commented 1 year ago

Hi, your dataset seems to be incomplete since not all years have 12 months of data (e.g., 2016). But ts() doesn't know that and assumes the series is complete, therefore the shortening.