Reading from R-Instat into Buckets: Code #110
Replies: 20 comments 13 replies
-
@jkmusyoka @rdstern here is some data to test this out. So the following is a script to run all of this:
To download the packages:
|
Beta Was this translation helpful? Give feedback.
-
@lilyclements |
Beta Was this translation helpful? Give feedback.
-
@jkmusyoka yes, this means you need the authentication key. @Vitalis95 is in the process of setting this up on the dialog, but I'll send you the key via email for now. Before running the R code, just run:
|
Beta Was this translation helpful? Give feedback.
-
@lilyclements Thanks. the code worked ok and the export was successful. Quick question - Is there a way to check what has been exported into the bucket? |
Beta Was this translation helpful? Give feedback.
-
@lilyclements thanks for the link but it doesn't work for me. Perhaps @ChrisMarsh82 has to give me permissions to access the bucket |
Beta Was this translation helpful? Give feedback.
-
@jkmusyoka please could you try again. You should have permissions now |
Beta Was this translation helpful? Give feedback.
-
@ChrisMarsh82 thanks, I now have access to the bucket. But I I can't find the exported file(s) in the bucket despite getting a successful export message in R. This is what I see when I open the bucket. There is no new file since Jan 2024. Am I looking at the right place? |
Beta Was this translation helpful? Give feedback.
-
@jkmusyoka good question.
e.g. here we have "annual_rainfall_summaries_test_3_.rds" for the annual rainfall summaries file. |
Beta Was this translation helpful? Give feedback.
-
@lilyclements. I couldn't find a way of including a second definition of "start of rains" for the same station in the summaries file that I uploaded into the bucket. Is this possible in the current set up or could be added if not there? Sometimes this is needed. |
Beta Was this translation helpful? Give feedback.
-
@jkmusyoka this is really useful to know is a requirement. I spoke with @rdstern about it today, and I will implement it in. I will let you know how I get on! Thank you for this |
Beta Was this translation helpful? Give feedback.
-
@lilyclements. The uploading into the google buckets works fine with the R script. I am now waiting to test the same process with the new R-Instat dialogues. An observation - I have noticed that the names of the files uploaded into the google bucket have a extension that looks like a combination of date and time added to the station_id i.e. annual_rainfall_summaries_zambia_eastern.20240510181254.rds and similarly for the other related files. So I went ahead to test the APIs using this data but I got an error 500 which is not very informative. So I am not sure where the problem is but kept wondering whether the names could be an issue. This is because only test_1 works fine with the API. Test_1 seems to be the only file in the zambia summary folder without the funny extension to its name. Your thoughts? |
Beta Was this translation helpful? Give feedback.
-
@lilyclements and @ChrisMarsh82 I am getting the following server response error 500 with the "Get Annual Summaries" API for station_id: zambia_eastern. Am not sure what this means and whether this is an error in the R code or with API By the way, the only station that does not return an error with the API is test_1 which is the only station without timestamp on its respective filenames. |
Beta Was this translation helpful? Give feedback.
-
@lilyclements I still get the same error 500 but with a bit more information. See image |
Beta Was this translation helpful? Give feedback.
-
See I have the correct setting for country and station_id |
Beta Was this translation helpful? Give feedback.
-
Thanks @lilyclements. But I am still getting the same error 500 with the API after updating and running the script again. Not sure why. The error message is the same. I have now saved the data as zambia_eastern_2. Could you call the data from R to see if you get the same error or not? |
Beta Was this translation helpful? Give feedback.
-
@jkmusyoka if you update your epicsadata branch again, then you can now use |
Beta Was this translation helpful? Give feedback.
-
Changes to the R Code - If you update
This is not yet reflected in the R-Instat dialog. In the dialog, TODO:
For For (The name when that variable was created is that of the name of the definition we call to construct it. We call the column name here to get the correct definitions. Problem may arise if they have changed variable names. I should look into fixing that). |
Beta Was this translation helpful? Give feedback.
-
@lilyclements , we are encountering an error when we use Malawi dataset. Here is the code;
This is the error we are getting |
Beta Was this translation helpful? Give feedback.
-
@lilyclements I get this same error when I try to upload summaries from Zambia Eastern by station. And this is how I populated the dialogue I will send the data by email as I can't attach an rds file here |
Beta Was this translation helpful? Give feedback.
-
I have fixed the bug you have reported - you can update and get the changes in Another (small) issue I spotted -
In here you are calling |
Beta Was this translation helpful? Give feedback.
-
Here is a bit of a glimpse in the code to read from R-Instat into the google buckets
So if you firstly run in R-Instat your start of rains, end of rains, seasonal length, crop success probabilities, etc. Then you can reformat these into the format used in python and the app (i.e., same variable names and types).
Here:
ghana_by_station_year
(and createsghana_by_station_year_month_abbr
for monthly temperature summaries.ghana_by_station_year
which is used in theannual_summaries
ghana_by_station_year
which is used in theannual_summaries
summary.crop_prop
andcrop_def
data framesSo here's the code if you create these and wish to reformat them. In this code, we are using the names that came out of this using the
ghana_2_stations
data stored in R-InstatThen we can run the function to export our definitions and summaries into R-Instat.
Hopefully the documentation explains these options in details but in brief:
summaries
states which summaries to calculate (not yet ready for extremes)_data
is the data itself. In our case, we've reformatted these using our reformat functions above.As always, any feedback would be great. If others could test this out too then that would be very helpful.
Beta Was this translation helpful? Give feedback.
All reactions