In [1]:
import hkvfewspy as fewspy
from datetime import datetime
import altair as alt
alt.data_transformers.enable('json')
%matplotlib inline
In [2]:
# set client
pi = fewspy.Pi()
pi.setClient(wsdl='http://localhost:8100/FewsPiService?wsdl')
In [3]:
# get filters
filters = pi.getFilters()
filter_id = filters.f_meteo_historie['id']
In [4]:
# get parameters
parameters = pi.getParameters(filter_id)
parameter_ids = [parameters.P_meting['id'], parameters.E_meting['id']]
parameter_ids
Out[4]:
['P.meting', 'E.meting']
In [5]:
# get locations
locations = pi.getLocations(filterId=filter_id, setFormat='gdf')
locations.plot()
Out[5]:
<matplotlib.axes._subplots.AxesSubplot at 0x9fab860>
In [6]:
locations.head()
Out[6]:
locationId shortName x y geometry
KNMIUUR6210 KNMIUUR6210 Valkenburg 88625.0 466577.0 POINT (4.416660451604394 52.18333260826056)
KNMIUUR6235 KNMIUUR6235 De_Kooy 114381.0 547900.0 POINT (4.783319272350027 52.91666123973935)
KNMIUUR6240 KNMIUUR6240 Schiphol 112672.0 479294.0 POINT (4.766662139364787 52.29999262522522)
KNMIUUR6249 KNMIUUR6249 Berkhout 127350.0 517350.0 POINT (4.978692374471717 52.64294238118446)
KNMIUUR6257 KNMIUUR6257 Wijk_aan_Zee 101545.0 501657.0 POINT (4.59998723847303 52.4999964020235)
In [7]:
# selecteer stion Schiphol en Berkhout
location_ids = locations.locationId.iloc[2:4].tolist()
location_ids
Out[7]:
['KNMIUUR6240', 'KNMIUUR6249']
In [8]:
start_date = datetime(2018,1,2)
end_date = datetime(2018,9,19)

Zie beneden voor tekst en uitleg waarom we gebruik moeten maken van de 'oude' getTimeSeriesForFilter2 functie

In [9]:
# define object to create SOAP list
array_of_string = pi.client.get_type('ns0:ArrayOfString')
# get timeseries
df = pi.getTimeSeriesForFilter2(filterId = filter_id,
                                parameterIds = array_of_string(parameter_ids), 
                                locationIds = array_of_string(location_ids), 
                                startTime = start_date, 
                                endTime = end_date, 
                                setFormat = 'df')
warning: 'header' has no attribute 'qualifierId'
warning: 'header' has no attribute 'qualifierId'
warning: 'header' has no attribute 'qualifierId'
warning: 'header' has no attribute 'qualifierId'
In [10]:
data = df.reset_index()
data.head()
Out[10]:
date moduleInstanceId qualifierId parameterId units locationId stationName flag value
0 2018-01-01 01:00:00+01:00 ImportScalarHistWiwb E.meting mm KNMIUUR6240 Schiphol 0.0 0.100
1 2018-01-01 01:00:00+01:00 ImportScalarHistWiwb E.meting mm KNMIUUR6249 Berkhout 0.0 0.100
2 2018-01-02 00:00:00+01:00 ImportScalarHistWiwb P.meting mm KNMIUUR6240 Schiphol 0.0 0.000
3 2018-01-02 00:00:00+01:00 ImportScalarHistWiwb P.meting mm KNMIUUR6249 Berkhout 0.0 0.000
4 2018-01-02 00:10:00+01:00 ImportScalarHistWiwb P.meting mm KNMIUUR6240 Schiphol 0.0 0.011
In [11]:
alt.Chart(data).mark_line().encode(
    x='yearmonthdatehours(date):T', # aggregate from 10 minute values to hourly values
    y=alt.Y('value:Q', axis=alt.Axis(title='millimeter')),
    color='stationName',
    column='parameterId'
).interactive(bind_y=False) # includes scroll zoom and drag on x-axis
Out[11]:
In [12]:
# same data different chart
alt.Chart(data).mark_rect().encode(
    x=alt.X('month(date):N', axis=alt.Axis(title='Month of the year'), scale=alt.Scale(rangeStep=50)),
    y=alt.Y('value', bin=alt.Bin(maxbins=40), axis=alt.Axis(title='mm')),
    color=alt.Color('average(value):Q', scale=alt.Scale(scheme='greenblue'), legend=alt.Legend(title="millimeters")),
    row='parameterId',
    column='stationName'
).configure_view(height=150)
Out[12]:

De FEWS 2017.02 stand-alone versie heeft alleen een basis SOAP web-service.
De verbeterde SOAP en de gehele REST web-services zijn alleen toegankelijk wanneer het bestand FewsPiServices.war is toegevoegd aan Tomcat met behulp van een direct-database koppeling

Dus banaf 2017.02 is het niet mogelijk om de verbeterde SOAP of REST web-interface aan te bieden in een stand-alone FEWS instantie.

Met de basis SOAP web-service kan er bijvoorbeeld niet gefilterd worden op de moduleInstanceIds en zijn sommige functies niet beschikbaar

Onderstaande kan dus niet..

In [ ]:
# query = pi.setQueryParameters(prefill_defaults=True)
# query.parameterIds(parameter_id)
# query.moduleInstanceIds(['ImportScalarHistWiwb'])
# query.locationIds(location_ids)
# query.startTime(start_date)
# query.endTime(end_date)
# query.clientTimeZone('Europe/Amsterdam')
# query.query
In [ ]:
# df = pi.getTimeSeries(queryParameters=query, setFormat='df', print_response=True)
In [ ]:
# df.head()