Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use a generic time-series for downscaling? #13

Open
matteodefelice opened this issue Dec 24, 2020 · 6 comments
Open

How to use a generic time-series for downscaling? #13

matteodefelice opened this issue Dec 24, 2020 · 6 comments

Comments

@matteodefelice
Copy link

I cannot find anything in the documentation, do we have an official way to load (wrap) generic time-series into an object that can be used with downscaleR?

@jbedia
Copy link
Member

jbedia commented Jan 2, 2021

Hi Matteo. There is not such a wrapper. However, you can access the internal atomic functions to deal with raw data, named as the methods. However, the proper handling of dates, members and other metadata can't be guaranteed, and that is the main reason this application is discouraged in general and therefore not documented. In any case, just let us know in case we can help with some specific application.

@matteodefelice
Copy link
Author

Hi Joaquin. I would like to downscale using as target a time-series of renewable energy generation (wind and hydropower data). Currently, I am using a station data structure, replacing the Data field with the data I have. This would be easier having more details on which fields (and metadata) are needed and which are optional, to avoid inconsistencies and strange error while using downscaleR.

@jbedia
Copy link
Member

jbedia commented Jan 19, 2021

Hi Matteo, sorry for my slow response this time. Usually the most important metadata are related with date information (dates need to be unequivocally defined, and consistency between time zones must be ensured). Also, geolocation is important in many cases to find nearest neighbors and so on... If you find problems with your data just let me know. You can mail me to discuss the particularities of your datasets to see if we can help or if additional functionalities should be added to climate4R. Cheers.

@matteodefelice
Copy link
Author

matteodefelice commented Jan 19, 2021 via email

@jbedia
Copy link
Member

jbedia commented Jan 19, 2021

Great, thanks Matteo. Yes, the "station" ASCII data format can actually work with any target variable stored as a time series, so it seems a good idea, and a nice example to include in the documentation. Best.

@matteodefelice
Copy link
Author

Can you tell me if there is something missing or something not needed?

# Define time vector -----------------------------------------
timebase = seq(
  from = lubridate::make_datetime(2010, 1, 1, 0, 0, 0),
  to   = lubridate::make_datetime(2012, 1, 1, 0, 0, 0),
  by = 'month'
)
# Create base list -------------------------------------------
custom_stn <- list()
# Create variable --------------------------------------------
custom_stn$Variable <- list(
  varName = 'myVarName',
  level = NULL
)
# Coordinates ------------------------------------------------
# X and Y are coordinates, here is a structure with 2 stations
custom_stn$xyCoords <- data.frame(x = c(0,0), y = c(0,0))
attr(custom_stn$xyCoords, 'resX') <- 0
attr(custom_stn$xyCoords, 'resY') <- 0

# Dates ------------------------------------------------------
# Dates must be character 
custom_stn$Dates <- list(
  start = timebase %>%
    as.character() %>%
    str_c(' 00:00:00'),
  end = (timebase+months(1)) %>%
    as.character()%>%
    str_c(' 00:00:00')
)
# Data -------------------------------------------------------
# Data is a matrix with time steps as rows and station as columns
custom_stn$Data <- matrix(rnorm(length(timebase) * 2), ncol = 2) %>%
  unname()
attr(custom_stn$Data, 'dimensions') <- c('time', 'loc')
# Metadata ---------------------------------------------------
custom_stn$Metadata <- list(
  station_id = c('a', 'b'),
  name = c('a', 'b')
)

# This seems working
visualizeR::temporalPlot(custom_stn)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants