In [238]:
# Reload when code changed:
%load_ext autoreload
%autoreload 2
%pwd
import sys
path = "../"
sys.path.append(path)
#os.path.abspath("../")
In [239]:
import os
import core
import importlib
importlib.reload(core)
import pandas as pd
import numpy as np
print(core.__file__)
pd.__version__
Out[239]:
In [240]:
root_directory = "../" #os.getcwd()
workspace_directory = root_directory + '/workspaces'
resource_directory = root_directory + '/resources'
In [241]:
workspaces = {}
# Holds all loaded workspaces
In [242]:
default_workspace = core.WorkSpace(name='default',
parent_directory=workspace_directory,
resource_directory=resource_directory)
workspaces['default'] = default_workspace
In [243]:
# Import data
default_workspace.import_default_data()
print('DATA')
# Step 0 data filter
default_workspace.set_data_filter(step=0, filter_type='include_list', filter_name='STATN', data=['a', 'b', 'c'])
print(0)
# Step 1 data filter
subset = 'default_subset'
default_workspace.set_data_filter(step=1, subset=subset, filter_type='include_list', filter_name='STATN', data=['a', 'b', 'c'])
print(1)
# Check indicator data filter
indicator = 'din_winter'
filter_settings = {'12s': {'DEPTH_INTERVAL':[20, 50],
'DEPTH_TOLERANCE': 10}}
default_workspace.set_indicator_settings_data_filter(indicator=indicator,
filter_settings=filter_settings,
step=2,
subset=subset)
print(2)
In [ ]:
In [ ]:
In [ ]:
In [244]:
mw_workspace = default_workspace.make_copy_of_workspace('mw', overwrite=True)
workspaces['mw'] = mw_workspace
mww = mw_workspace
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [245]:
mw_workspace = core.WorkSpace(name='mw',
parent_directory=workspace_directory,
resource_directory=resource_directory)
workspaces['mw'] = default_workspace
mww = mw_workspace
mww.load_all_data()
Out[245]:
In [246]:
mww.import_default_data(force=False)
Out[246]:
In [247]:
# Step 0 data filter
mww.set_data_filter(step=0, filter_type='include_list', filter_name='STATN', data=['a', 'b', 'c'])
print(0)
# Step 1 data filter
subset = 'default_subset'
mww.set_data_filter(step=1, subset=subset, filter_type='include_list', filter_name='STATN', data=['a', 'b', 'c'])
print(1)
# Check indicator data filter
indicator = 'din_winter'
filter_settings = {'12s': {'DEPTH_INTERVAL':[20, 50],
'DEPTH_TOLERANCE': 10}}
mww.set_indicator_settings_data_filter(indicator=indicator,
filter_settings=filter_settings,
step=2,
subset=subset)
print(2)
In [248]:
mww.copy_subset('default_subset', 'test_subset_1')
Out[248]:
In [270]:
# Step 0 data filter
mww.set_data_filter(step=0, filter_type='include_list', filter_name='STATN', data=['FLADEN', 'SKALKORGARNA', 'VALÖ'])
mww.set_data_filter(step=0, filter_type='include_list', filter_name='MYEAR', data=['2016'])
print(0)
# Step 1 data filter
subset = 'test_subset_1'
mww.set_data_filter(step=1, subset=subset, filter_type='include_list', filter_name='STATN', data=['FLADEN', 'SKALKORGARNA'])
mww.set_data_filter(step=1, subset=subset, filter_type='include_list', filter_name='MYEAR', data=['2016'])
print(1)
# Water body station filter
water_body = 'Yttre Brofjorden'
add_stations = ['FLADEN']
mww.set_water_body_station_filter(station_list=add_stations, subset=subset, water_body=water_body, include=True)
print(2)
# Indicator data filter
indicator = 'din_winter'
filter_settings = {'12s': {'DEPH_INTERVAL':[20, 50],
'DEPH_TOLERANCE': 10}}
mww.set_indicator_settings_data_filter(indicator=indicator,
filter_settings=filter_settings,
step=2,
subset=subset)
print(3)
In [ ]:
In [333]:
mww.apply_data_filter(step=0)
mww.apply_data_filter(step=1, subset=subset)
mww.apply_water_body_station_filter(subset=subset, water_body=water_body)
mww.apply_indicator_data_filter(step=2, subset=subset, indicator=indicator, water_body=water_body)
In [ ]:
In [ ]:
In [363]:
# Step 0
data_step_0 = mww.get_filtered_data(step=0)
len(data_step_0)
Out[363]:
In [364]:
# Step 1
data_step_1 = mww.get_filtered_data(step=1, subset=subset)
len(data_step_1)
Out[364]:
In [365]:
# Step 2 water_body
data_step_2_water_body = mww.get_filtered_data(step=2, subset=subset, water_body=water_body)
len(data_step_2_water_body)
Out[365]:
In [367]:
# Step 2 indicator
data_step_2_indicator = mww.get_filtered_data(step=2, subset=subset, water_body=water_body, indicator=indicator)
len(data_step_2_indicator)
Out[367]:
In [368]:
data_step_2_indicator
Out[368]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [340]:
b = mww.index_handler.booleans
In [341]:
print(len(np.where(b['step_0']['boolean'])[0]))
In [342]:
print(len(np.where(b['step_0'][subset]['boolean'])[0]))
In [343]:
print(len(np.where(b['step_0'][subset]['step_1']['boolean'])[0]))
In [344]:
print(len(np.where(b['step_0'][subset]['step_1']['step_2']['boolean'])[0]))
In [345]:
print(len(np.where(b['step_0'][subset]['step_1']['step_2'][water_body]['boolean'])[0]))
In [346]:
print(len(np.where(b['step_0'][subset]['step_1']['step_2'][water_body][indicator]['boolean'])[0]))
In [ ]:
In [347]:
b['step_0']['test_subset_1']['step_1']['step_2']['Yttre Brofjorden']['din_winter'].keys()
Out[347]:
In [348]:
df0 = mww.get_data_filter_object(step=0)
df1 = mww.get_data_filter_object(step=1, subset=subset)
wbf = mww.get_water_body_station_filter(subset=subset)
if2 = mww.get_indicator_settings_data_filter_object(step=2, subset=subset, indicator=indicator)
In [349]:
print(df0.all_filters)
print(df0.get_include_list_filter('MYEAR'))
print(df0.get_include_list_filter('STATN'))
In [350]:
print(df1.all_filters)
print(df1.get_include_list_filter('MYEAR'))
print(df1.get_include_list_filter('STATN'))
In [351]:
print(water_body)
print('+')
print(wbf.get_list(water_body=water_body))
In [352]:
df = mww.index_handler.data_handler_object.all_data
df1_bool = df1.get_filter_boolean_for_df(df=df)
wb_bool = wbf.get_filter_boolean_for_df(df=df, water_body=water_body)
In [353]:
np.where(df1_bool)
Out[353]:
In [354]:
np.where(wb_bool)
Out[354]:
In [355]:
np.where(df1_bool & wb_bool)
Out[355]:
In [356]:
set(df['STATN'][df1_bool])
Out[356]:
In [357]:
set(df['STATN'][wb_bool])
Out[357]:
In [358]:
include_stations = ['FLADEN']
exclude_stations = []
b_inc_wb = (df['SEA_AREA_NAME'] == water_body)
b_inc_statn = (df['STATN'].isin(include_stations))
b_exc_statn = ~(df['STATN'].isin(exclude_stations ))
boolean = ((df['SEA_AREA_NAME'] == water_body) | \
(df['STATN'].isin(include_stations))) & \
(~df['STATN'].isin(exclude_stations ))
In [359]:
print(set(df['STATN'][b_inc_wb]))
print(set(df['STATN'][b_inc_statn]))
# print(set(df['STATN'][b_exc_statn]))
print('-'*50)
print(set(df['STATN'][boolean]))
In [360]:
set(df['STATN'][boolean])
Out[360]:
In [361]:
set(df['STATN'][boolean])
Out[361]:
In [326]:
wbf
Out[326]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: