IDEMSInternational / R-Instat

A statistics software package powered by R
http://r-instat.org/
GNU General Public License v3.0
38 stars 102 forks source link

Adding dialog to export climatic definitions (and data) #8885

Closed lilyclements closed 2 months ago

lilyclements commented 4 months ago

As part of an EPICSA project, we are currently developing a series of functions in epicsawrap which aim to read the climatic definitions from R-Instat and export them to google buckets. All this is just background stuff which no one else needs to worry about.

The R code on this is in progress, but we would like to have a front end for it in R-Instat. This should just require one function to be called in the dialog with some simple parameters. I don't think this would be a complex dialog at all, and if someone could start on the design that would be great.

image

Here is the design:

Notes

@N-thony could you suggest someone who might be suitable for this task?

Vitalis95 commented 4 months ago

@lilyclements , should be added the last item on Climatic > File, that is below Export to Climpact?

lilyclements commented 4 months ago

@Vitalis95 that sounds suitable - thanks for the suggestion

Vitalis95 commented 3 months ago

@lilyclements , I am done with the design

lilyclements commented 3 months ago

@Vitalis95 this is great, well done! There's two new receivers to add if that's ok:

The R Function is called export_r_instat_to_bucket. There are a few parameters:

The first four receivers select a data frame (not a column):

The next five receivers select a column from a data frame:

Then the next options are:

Does this make sense?

To access the function: The function is in the epicsawrap package. This can be accessed by:

devtools::install_github("IDEMSInternational/epicsawrap")

Is it possible to add that package into R-Instat too?

To test the function: We can go through this - perhaps by a call? Or I can create and send a video outlining it :)

Example of the code An example of the R code is:

export_r_instat_to_bucket(data = "ghana",
                          data_by_year = "ghana_by_station_year",
                          data_by_year_month = "ghana_by_station_year_month_abbr",
                          crop_data_name = "crop_def",
                          rain = "rainfall",
                          tmin = "min_temperature",
                          tmax = "max_temperature",
                          year = "year",
                          month = "month_abbr",
                          summaries = c("annual_rainfall", "annual_temperature", "monthly_temperature", "extremes", "crop_success", "start_season"),
                          station_id = "test_3",
                          country = "zm",
                          include_summary_data = TRUE,
                          annual_rainfall_data = annual_rain,
                          annual_temperature_data = annual_temp,
                          monthly_temperature_data = monthly_temp,
                          crop_success_data = crop_prop,
                          season_start_data = crop_def)
Vitalis95 commented 3 months ago

@lilyclements thank you for the code

for thesummaries make it to be annual_rainfall = TRUEif checked, annual_rainfall = FALSE if not The file will be saved in whichformat? i.e csv, txt, ...

Then we can arrange a call for a time that suits you. Thanks

lilyclements commented 3 months ago

@Vitalis95 saved in json format. Thanks! Let’s have a call next week?

Vitalis95 commented 3 months ago

@Vitalis95 saved in json format. Thanks! Let’s have a call next week?

@lilyclements, Schedule a meeting when it works for you

lilyclements commented 3 months ago

A few changes:

  1. We can remove the ucrSave - we no longer have file_path or file_name in the function
  2. Can you add two new ucrInputs: "Station ID" and "Country". The R parameters for these are station_id and country

When Include Summary Data is Checked:

If "Annual Rainfall" is checked and if "Include Summary Data" is checked, then:

  1. We want a button next to the checkbox that leads to a sub dialog
  2. In our R code on the main page, run annual_rainfall_data = annual_rain when the define button is checked. (If this button is not pressed, then annual_rain does not exist.
image

The sub dialog is where we define our variables for Annual Rainfall. The layout would be like a "mini-define" dialog. We have many single receivers and labels:

Receiver Label R Parameter
Station station_col
Year year_col
Start Rains (DOY) start_rains_doy_col
Start Rains (Date) start_rains_date_col
End Rains (DOY) end_rains_doy_col
End Rains (Date) end_rains_date_col
End Season (DOY) end_season_doy_col
End Season (Date) end_season_date_col
Seasonal Rain seasonal_rain_col
Number of Rainy Days in Season n_seasonal_rain_col
Seasonal Length season_length_col
Annual Rain annual_rain_col
Number of Rainy Days in Year n_rain_col

The code run here is

annual_rain <- data_book$get_data_frame("ghana_by_station_year")
annual_rain <- reformat_annual_summaries(data = annual_rain, station = "station", ...)

This should be run before the main dialog R code.

Similarly for our Temperature, Crop, and Season Start

Crop success probabilities:

  1. In the sub dialog, run crop_prop = reformat_crop_success(...)
  2. In our R code on the main page, run crop_success_data = crop_prop when the define button is checked. (If this button is not pressed, then crop_prop may not exist).

Sub Dialog:

Receiver Label R Parameter
Station station_col
Total rainfall total_rain_col
Planting day plant_day_col
Planting length plant_length_col
Proportion of success prop_success_col

Season start probabilities:

  1. In the sub dialog, run season_data = reformat_season_start(...)
  2. In our R code on the main page, run season_start_data = season_data when the define button is checked. (If this button is not pressed, then season_data may not exist).

Sub Dialog:

Receiver Label R Parameter
Station station_col
Year year_col
Planting day plant_day_col
Planting day condition (L) plant_day_cond_col

Annual temperature summaries:

  1. In the sub dialog, run annual_temp = reformat_temperature_summaries(...)
  2. In our R code on the main page, run annual_temperature_data = annual_temp when the define button is checked. (If this button is not pressed, then annual_temp may not exist).

Sub Dialog:

Receiver Label R Parameter
Station station_col
Year year_col
Mean minimum temperature mean_tmin_col
Min minimum temperature min_tmin_col
Max minimum temperature max_tmin_col
Mean maximum temperature mean_tmax_col
Min maximum temperature min_tmax_col
Max maximum temperature max_tmax_col

Monthly temperature summaries:

  1. In the sub dialog, run monthly_temp = reformat_temperature_summaries(...)
  2. In our R code on the main page, run monthly_temperature_data = monthly_temp when the define button is checked. (If this button is not pressed, then monthly_temp may not exist).

Sub Dialog (same as above, but with a month receiver):

Receiver Label R Parameter
Station station_col
Year year_col
Month month_col
Mean minimum temperature mean_tmin_col
Min minimum temperature min_tmin_col
Max minimum temperature max_tmin_col
Mean maximum temperature mean_tmax_col
Min maximum temperature min_tmax_col
Max maximum temperature max_tmax_col
lilyclements commented 2 months ago

Can we have a new button above the selector which says "Connect to Google Buckets"

When clicked, a very simple sub-dialog comes up, looking somewhat like this:

image

Then the code that is run by this dialog is:

epicsawrap::gcs_auth_file(file = " FILE PATH.json ")

On the "Import from Climsoft" dialog, we have in red that no connection is made if there is no connection, and then this turns green if a valid connection is made. If this is straight forward, can we have this as well? If it isn't straightforward then no worries. It would just be a useful way to say if OK can be enabled or not.

image

rdstern commented 2 months ago

@Vitalis95 I note the requests by @lilyclements that now include a feature from the Import from Climsoft, that was done by @Patowhiz . Just to mention the importance of using our user controls and adapting existing ones, rather than making new ones. If that's tricky here, maybe Patrick can help?