Skip to content

Instantly share code, notes, and snippets.

@bubbobne
Last active September 1, 2020 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bubbobne/442eb9ebfa56955550b83416ddc7746b to your computer and use it in GitHub Desktop.
Save bubbobne/442eb9ebfa56955550b83416ddc7746b to your computer and use it in GitHub Desktop.
dati_idrometro
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
# coding: utf-8
# ## Download data
#
# Data are available at [UFFICIO DIGHE](https://www.floods.it/public/DatiStoriciDown.php?Argomento=Trento%20Ponte%20S%20Lorenzo&Corpo=fiume%20Adige) whith [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/) license and with attribuition to "Dati della rete di monitoraggio dell'Ufficio Dighe – Servizio Prevenzione rischi della Provincia Autonoma di Trento"
# In[36]:
years = range(1994,2020)
data_dir = './data'
file_str = data_dir + '/portate_san_lorenzo_{}.zip'
url = 'https://www.floods.it/public/DatiStoriciBis/DSdownloadBis.php?Arg=Trento%20Ponte%20S%20Lorenzo&Type=Portate&Anno={}'
import urllib.request
import os
import zipfile
if not os.path.exists(data_dir):
os.makedirs(data_dir)
for year in years:
f = file_str.format(year)
urllib.request.urlretrieve(url.format(year), f)
with zipfile.ZipFile(f, "r") as zip_ref:
zip_ref.extractall(data_dir)
# In[37]:
import pandas as pd
import re
y= '2000'
for root, dirs, files in os.walk(data_dir):
for file in files:
if ".csv" in file:
df = pd.read_csv(root+'/'+file, skiprows=6)
df.columns = ['data', 'portata']
y = re.findall(r'\d+', root)[0]
df = df[(df.portata > 750) & (df.data > y+'-06-01') & (df.data < y+'-08-31') ]
if df.shape[0] > 0:
print(y)
print(df.shape)
#append the file name to the list
#print(os.path.join(root,file))
# In[ ]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment