# Download data

**URL:** <https://forum.ecmwf.int/t/download-data/1801>\
**Category:** Other - Software and tools\
**Tags:** c3s, toolbox\
**Created:** [5 September 2023 10:40 UTC](https://forum.ecmwf.int/t/download-data/1801 "2023-09-05T10:40:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_Littledale](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/a/76d3ee/32.png) [@Andy\_Littledale](https://forum.ecmwf.int/u/Andy_Littledale)\
**Post date:** [5 September 2023 10:40 UTC](https://forum.ecmwf.int/t/download-data/1801/1 "2023-09-05T10:40:19Z")

</div>

Hi there,&nbsp;

I'm not a great coder but I've managed to write something to graph rainfall data by hour for a certain location. I would like to download this data as a CSV so I can use it in R. However, I keep getting errors or empty files. I'd be very grateful if someone could help me amend my code (please see below). Many thanks, Andy

import cdstoolbox as ct

# Initialise an application&nbsp;  
 @ct.application(title='Rainfall at the Wildplace')

# Add output widget to the application  
 @ct.output.livefigure()

# Create a function that retrieves the Near Surface Air Temperature dataset, extracts data from a point and plots the line on the livefigure  
 def plot\_time\_series():  
 &nbsp; &nbsp;&nbsp;  
 &nbsp; &nbsp; &nbsp;# Retrieve a variable over a defined time range  
 &nbsp; &nbsp; data = ct.catalogue.retrieve(  
 &nbsp; &nbsp; &nbsp; &nbsp; 'reanalysis-era5-single-levels',  
 &nbsp; &nbsp; &nbsp; &nbsp; {  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'variable': 'total\_precipitation',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'product\_type': 'reanalysis',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'year': [  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '2023'  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'month': [  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '06', '07', '08'  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'day': [  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '01', '02', '03', '04', '05', '06',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '07', '08', '09', '10', '11', '12',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '13', '14', '15', '16', '17', '18',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '19', '20', '21', '22', '23', '24',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '25', '26', '27', '28', '29', '30',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '31'  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'time':[  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '00:00','01:00','02:00',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '03:00','04:00','05:00',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '06:00','07:00','08:00',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '09:00','10:00','11:00',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '12:00','13:00','14:00',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '15:00','16:00','17:00',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '18:00','19:00','20:00',  
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '21:00','22:00','23:00'  
 &nbsp; &nbsp; &nbsp; &nbsp; ],  
 &nbsp; &nbsp; &nbsp; &nbsp; 'grid':[3, 3]  
 &nbsp; &nbsp; &nbsp; &nbsp; }  
 &nbsp; &nbsp; )  
 &nbsp; &nbsp;&nbsp;  
 &nbsp; &nbsp; # Select a location, defined by longitude and latitude coordinates  
 &nbsp; &nbsp;&nbsp;  
 &nbsp; &nbsp;&nbsp;  
 &nbsp; &nbsp; tp\_hourly\_column = data \* 3600 \* 1000

&nbsp; &nbsp; tp\_hourly\_column = ct.cdm.update\_attributes(tp\_hourly\_column, {'units': 'mm'})  
 &nbsp; &nbsp;&nbsp;  
 &nbsp; &nbsp; print (tp\_hourly\_column)

&nbsp; &nbsp;

&nbsp; &nbsp; # Compute the daily mean for the selected data  
 &nbsp; &nbsp; #data\_daily = ct.climate.daily\_sum(data\_point\*1000)  
 &nbsp; &nbsp; data\_point = ct.geo.extract\_point(  
 &nbsp; &nbsp; &nbsp; &nbsp; tp\_hourly\_column,&nbsp;  
 &nbsp; &nbsp; &nbsp; &nbsp; lon=-2.6119880971029983,&nbsp;  
 &nbsp; &nbsp; &nbsp; &nbsp; lat=51.53050814340124  
 &nbsp; &nbsp; )  
 &nbsp; &nbsp;

&nbsp; &nbsp; # Show the result as a time-series on an interactive chart  
 &nbsp; &nbsp; figure = ct.chart.line(data\_point);

&nbsp; &nbsp; return figure
