Commit 8885b227 authored by andy.disch's avatar andy.disch
Browse files

initial commit

parent 9be010df
**/.venv/*
**/data/*
# -*- coding: utf-8 -*-
"""
Created on Thu May 20 12:25:08 2021
@author: user
"""
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
# import flow data
q_mes = pd.read_csv('./data/rafis_flowrate_liter_s.csv',sep=';', parse_dates=[0], float_precision='high')
q_mes.columns = ['time', 'value']
q_mes.set_index('time', inplace=True)
# remove special values
q_mes[q_mes < 0] = 0
#unit to m3/min for aggregation
q_mes = q_mes * 60 / 1000
#import rain data
r_mes = pd.read_csv('./data/rafis_precipitation_mm_h.csv',sep=';', parse_dates=[0], float_precision='high')
r_mes.columns = ['time', 'value']
r_mes.set_index('time', inplace=True)
# remove special values
r_mes[r_mes < 0] = 0
# unit to mm/min for aggregation
r_mes = r_mes / 60
# aggregate to daily values
q_mes_daily = q_mes.resample('D').sum() #unit: m3/d
r_mes_daily = r_mes.resample('D').sum() #unit: mm/d
#r_mes_daily = r_mes.resample('Y').sum()
# differentiation of rainfall events
rainy_day = r_mes_daily > 1 #unit:mm/d
# rain influenced day if there was a rainy day in the previous 2 days; "|" means "or"
rain_influenced_day = rainy_day.shift(-2) | rainy_day.shift(-1) | rainy_day
q_mes_no_rain = q_mes_daily[~rain_influenced_day] #"~" means "not"
q_mes_rain = q_mes_daily[rain_influenced_day]
# inhabitants = pd.read_csv('./data/population_russikon.csv', parse_dates=[0], usecols=[0, 5])
# inhabitants.columns = ['year', 'value']
# inhabitants.set_index('year', inplace=True)
# inhabitants = inhabitants.resample('Y').sum()
inhabitants = 5200 #population of corresponding catchment at Buchs (Dec.2020)
# calc wastewater
inhabitants_min = inhabitants * 0.180 #unit:m3/d
inhabitants_max = inhabitants * 0.180*2.5 #unit:m3/d
ax = q_mes_no_rain.plot.area(figsize=(16, 9))
q_mes_rain.plot(ax = ax, style='--', color='gainsboro')
r_mes_daily.plot(ax = ax, secondary_y=True, style='firebrick')
ax.right_ax.set_ylim(300, 0) #flipping the plot upside down
ax.axhspan(inhabitants_min, inhabitants_max, alpha=0.25, color='green')
ax.axhspan(0, inhabitants_min, alpha=0.25, color='red')
ax.axhspan(inhabitants_max, 16000, alpha=0.25, color='red')
ax.set_ylabel('Flow rate [m3/d]')
ax.right_ax.set_ylabel('Precipitation [mm/d]')
ax.get_legend().remove()
# import data
df = pd.read_csv('./data/BUFWNachtmini2019SevelenSchoe_data_only.csv', sep=';', parse_dates=[0], float_precision='high')
df.set_index('date', inplace=True)
df['TW'] = df['TW'].fillna(0)
# schoeller: textile industry
#qtot: sum of flow during 4 of the hours at night
#qdiff: substracting industrial discharge at these 4 hours --> basis inflow/infiltration (incl. Dry and wet weather runoffs)
#qtag: total amount of water flow per day
#qdifftag: total amount of water flow subtracting industrial discharge per day --> "daily life" wastewater flow
df
#Calculation of the variable proportion of extraneous water
df['qbasisFW'] = df['qdiff'] * 3600 * 6 / 1000 # unit: m3/d
# Population of Buchs according to https://www.buchs-sg.ch/kennzahlen and consumption per inhabitant of 180l/d
df['qSchmutz'] = 5200 * 0.180 # "daily life" foul sewage FS
df['qAlternativ'] = df['qbasisFW'] + df['qSchmutz'] # "daily life" foul sewage FS + basis inflow/infiltration
df['qDiff'] = df['qdifftag'] - df['qAlternativ'] # could be stormwater (direct) discharge (RDI) + additional I/I sources
# Calculation of the variable proportion of extraneous water according to weather conditions
df['qAlternativTW'] = df.loc[df['TW']==1.0, ['qAlternativ']] #dry weather
df['qAlternativRW'] = df.loc[df['TW']==0.0, ['qAlternativ']] #rain weather
df['qDiffTW'] = df.loc[df['TW']==1.0, ['qDiff']] #dry weather: should be close to 0 if no addtional I/I?
df['qDiffRW'] = df.loc[df['TW']==0.0, ['qDiff']] #wet weather: stormwater runoff?
plt.figure(figsize=(16, 6))
ax = sns.scatterplot(data=df, x='date', y='qDiff', hue='TW')
ax.scatter(x=df.index, y=df['qdifftag'], alpha=0.1, color='green')
ax.hlines(df['qDiffTW'].mean(), xmin='2019-01', xmax='2020-01', color=sns.color_palette("tab10")[1])
ax.hlines(df['qDiffRW'].mean(), xmin='2019-01', xmax='2020-01', color=sns.color_palette("tab10")[0])
plt.text('2019-05', 5000, str(df['qDiffTW'].mean()) + ' m3/d', bbox=dict(facecolor=sns.color_palette("tab10")[1]))
plt.text('2019-05', 6000, str(df['qDiffRW'].mean()) + ' m3/d', bbox=dict(facecolor=sns.color_palette("tab10")[0]))
plt.text('2019-08', 5000, str((df['qDiffTW']*100/df['qAlternativTW']).mean())+' %', bbox=dict(facecolor=sns.color_palette("tab10")[1]))
plt.text('2019-08', 6000, str((df['qDiffRW']*100/df['qAlternativRW']).mean())+' %', bbox=dict(facecolor=sns.color_palette("tab10")[0]))
ax.set_ylabel('Durchfluss [m3/d]')
ax.set_xlabel('')
#plt.savefig("data/output/Fremdwasser.jpg")
df['qDiffRW'][df['qDiffRW']<0] = 0
ax = df['qtag'].plot(style='--',color='gainsboro',label='daily flow')
df['qdifftag'].plot(color='grey',label='daily flow (without industrial discharge)')
df['qDiff'].plot(color='black',label='RDI+addtional sources?') #substruct FS('Schmutz') and basis infiltration ('qbasisFW')
df['qDiffRW'].plot.area(figsize=(16, 6),color='tab:blue',label='Rain direct flow (RDI)')
#df['qbasisFW'][df['qbasisFW']<0] = 0
#df['qbasisFW'].plot.area(ax=ax,color= 'green')
ax.set_ylabel('flow rate [m3/d]')
plt.legend()
#plt.savefig("Lutz_nightminimum.png")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment