In [1]:
%matplotlib inline
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import nivapy3 as nivapy
plt.style.use('ggplot')
In [2]:
# Connect to db
eng = nivapy.da.connect()
Filip has pointed out that annual nitrate concentrations for Swedish sites (as shown on the Explore Data page of the ICPW website) seem too low - well below the limit of detection for the lab performing the analysis. The lowest reported $NO_3^-$ values from the lab should be 10 µgN/l, which is 0.71 µeq/l.
This notebook performs a quick check to see whether the problem is with the raw data in our database, or with my data processing and analysis for the website.
In [3]:
# Get projects table
prj_grid = nivapy.da.select_resa_projects(eng)
prj_grid
In [4]:
# Select project
prj_df = prj_grid.get_selected_df()
prj_df
Out[4]:
In [5]:
# Get stations
stn_df = nivapy.da.select_resa_project_stations(prj_df, eng)
stn_df
Out[5]:
In [6]:
# Map
nivapy.spatial.quickmap(stn_df, popup='station_code')
Out[6]:
In [7]:
# Get available params
st_dt = '1990-01-01'
end_dt = '2012-12-31'
par_grid = nivapy.da.select_resa_station_parameters(stn_df,
st_dt,
end_dt,
eng)
par_grid
In [8]:
# Select NO3
par_df = par_grid.get_selected_df()
par_df
Out[8]:
In [9]:
# Get chem data
wc_df, dup_df = nivapy.da.select_resa_water_chemistry(stn_df,
par_df,
st_dt,
end_dt,
eng,
lod_flags=False)
# Get just surface samples
wc_df = wc_df.query('depth1 <= 1 and depth2 <= 1')
# Convert units to ueq/l
wc_df['NO3-N_µeq/l'] = wc_df['NO3-N_µg/l N']/14.
wc_df.head()
Out[9]:
In [10]:
# Get just data for Stensjön
sten_df = wc_df.query('station_code == "SE16"')
sten_df = sten_df[['sample_date', 'NO3-N_µeq/l']]
sten_df.set_index('sample_date', inplace=True)
# Resample to annual means
sten_df = sten_df.resample('A').median()
sten_df.index = sten_df.index.year
sten_df
Out[10]:
In [11]:
# Apply Sen's slope
res_df, sen_df = nivapy.stats.sens_slope(sten_df,
value_col='NO3-N_µeq/l',
index_col=sten_df.index)
res_df
Out[11]:
In [12]:
# Plot Sen's slope results
nivapy.plotting.plot_sens_slope(res_df, sen_df,
ylabel='NO3-N_µeq/l',
title='NO3-N at Stora Envättern')
This is the same as the plot on the website, so I think the code is working correctly. However, it is clear that our database has values well below 0.71 µeq/l. Looking at the raw data previously supplied to the ICPW programme, it looks as though the lowest values submitted are consistently 1 µeq/l (and not 10, which the the detection limit stated by Filip).