<jupyter_start><jupyter_text>Load directories<jupyter_code>root_directory = "../" #os.getcwd()
workspace_directory = root_directory + '/workspaces' 
resource_directory = root_directory + '/resources'
alias = 'lena'
user_id = 'test_user' #kanske ska vara off_line user?<jupyter_output><empty_output><jupyter_text>Initiate EventHandler<jupyter_code>ekos = EventHandler(root_directory)
# Remove all workspaces belonging to test user 
# ekos.remove_test_user_workspaces()
# remove selected workspace
workspace_uuid = ekos.get_unique_id_for_alias(user_id, 'lena_indicator')
#ekos.delete_workspace(user_id = user_id, unique_id = workspace_uuid, permanently=True)<jupyter_output><empty_output><jupyter_text>LOAD WORKSPACE  Load default workspace<jupyter_code>#default_workspace = core.WorkSpace(alias = 'default_workspace', 
#                                   unique_id = 'default_workspace', 
#                                   parent_directory=workspace_directory,
#                                   resource_directory=resource_directory, 
#                                   user_id = 'default')
#default_workspace.step_0.print_all_paths()
#default_workspace.import_default_data()<jupyter_output><empty_output><jupyter_text>Add new workspace  Only use this if you are not working with an already created workspace<jupyter_code>#ekos.copy_workspace(user_id = user_id, source_alias = 'default_workspace', target_alias = 'lena_indicator')
workspace_alias = 'lena_indicator'<jupyter_output><empty_output><jupyter_text>Load existing workspace<jupyter_code>ekos.load_workspace(user_id, alias = workspace_alias)
#Här får jag ibland felmeddelande core has no attribute ParameterMapping 
workspace_uuid = ekos.get_unique_id_for_alias(user_id, workspace_alias)
print(workspace_uuid)<jupyter_output>147f5d47-773c-43f0-b337-57208718d0cf<jupyter_text>Copy files from default workspace to make a clone<jupyter_code>#ekos.import_default_data(user_id, workspace_alias = workspace_alias)<jupyter_output>2018-03-26 15:07:46,967	event_handler.py	938	import_default_data	DEBUG	Trying to load default data in workspace "147f5d47-773c-43f0-b337-57208718d0cf" with alias "lena_indicator"
2018-03-26 15:07:48,013	workspaces.py	972	import_default_data	DEBUG	Default data has been copied to workspace raw data folder.<jupyter_text>Load all data in workspace<jupyter_code>ekos.load_data(user_id = user_id, unique_id = workspace_uuid)
w = ekos.get_workspace(user_id, unique_id = workspace_uuid, alias = workspace_alias)
len(w.data_handler.get_all_column_data_df())<jupyter_output>2018-04-03 19:02:14,237	workspaces.py	1395	load_all_data	DEBUG	data has been loaded from existing all_data.txt file.
2018-04-03 19:02:14,237	event_handler.py	919	get_workspace	DEBUG	Getting workspace "147f5d47-773c-43f0-b337-57208718d0cf" with alias "lena_indicator"<jupyter_text>Step 0   Set first data filter<jupyter_code>f0 = w.get_data_filter_object(step=0) 
f0.include_list_filter

#include_WB = ['Norrbottens skärgårds kustvatten']#,
                #'N S M Bottenhavets kustvatten'] 
include_stations = [] 
#exclude_WB = ['Norrbottens skärgårds kustvatten'] 
include_years = [] 

#w.set_data_filter(step=0, filter_type='include_list', filter_name='WATERBODY_NAME', data=include_WB)
w.set_data_filter(step=0, filter_type='include_list', filter_name='STATN', data=include_stations) 
#w.set_data_filter(step=0, filter_type='exclude_list', filter_name='WATERBODY_NAME', data=exclude_WB) 
w.set_data_filter(step=0, filter_type='include_list', filter_name='MYEAR', data=include_years)
f0.include_list_filter<jupyter_output><empty_output><jupyter_text>Apply first data filter<jupyter_code>w.apply_data_filter(step = 0) # This sets the first level of data filter in the IndexHandler<jupyter_output>add filter for step: step_0, type area: None, indicator: None, level: None<jupyter_text>Extract filtered data<jupyter_code>data_after_first_filter = w.get_filtered_data(step=0) # level=0 means first filter 
print('{} rows matching the filter criteria'.format(len(data_after_first_filter)))<jupyter_output>2018-04-03 19:02:21,963	workspaces.py	1271	get_filtered_data	DEBUG	STEP: step_0<jupyter_text>Step 1 load subset data<jupyter_code>#ekos.copy_subset(user_id, 
#                 workspace_alias=workspace_alias, 
#                 workspace_uuid=None, 
#                 subset_source_alias='default_subset', 
#                 subset_source_uuid='default_subset', 
#                 subset_target_alias='A')<jupyter_output><empty_output><jupyter_text>Step 1 Set subset filter<jupyter_code>subset_uuid = ekos.get_unique_id_for_alias(user_id, workspace_alias = workspace_alias, subset_alias = 'A')
print(w.get_subset_list())

f1 = w.get_data_filter_object(subset = subset_uuid, step=1) 
print(f1.include_list_filter)

w.apply_data_filter(subset = subset_uuid, step = 1)

df_step1 = w.get_filtered_data(step = 1, subset = subset_uuid)
print(df_step1.columns)<jupyter_output>2018-04-03 19:02:25,776	workspaces.py	1271	get_filtered_data	DEBUG	STEP: step_1<jupyter_text>Step 2<jupyter_code>w.get_step_object(step = 2, subset = subset_uuid).load_indicator_settings_filters()

w.get_step_object(step = 2, subset = subset_uuid).indicator_data_filter_settings
#ref_set = w.get_step_object(step = 2, subset = subset_uuid).indicator_ref_settings['din_winter']
#ref_set.settings.ref_columns
#ref_set.settings.df[ref_set.settings.ref_columns]
dinw_filter_set = w.get_step_object(step = 2, subset = subset_uuid).get_indicator_data_filter_settings('din_winter')
dinw_filter_set.settings.df
dinw_filter_set = w.get_step_object(step = 2, subset = subset_uuid).get_indicator_ref_settings('din_winter')
dinw_filter_set.settings.refvalue_column[0]
r = dinw_filter_set.get_value(variable = dinw_filter_set.settings.refvalue_column[0], type_area = '1s')[0]
if type(r) is str:
    print('ja det är en sträng')
type(r)
wb_list = df_step1.VISS_EU_CD.unique()
print('number of waterbodies in step 1: {}'.format(len(wb_list)))
typeA_list = [row.split('-')[0].strip().lstrip('0') for row in df_step1.WATER_TYPE_AREA.unique()]
print('number of type areas in step 1: {}'.format(len(typeA_list)))

#list(zip(typeA_list, df_step1.WATER_TYPE_AREA.unique()))<jupyter_output>number of waterbodies in step 1: 310
number of type areas in step 1: 27<jupyter_text>Apply indicator filter<jupyter_code>for type_area in typeA_list:
    w.apply_indicator_data_filter(step = 2, 
                              subset = subset_uuid, 
                              indicator = 'din_winter',
                              type_area = type_area)
#print(len(w.index_handler.booleans['step_0'][subset_uuid]['step_1']['step_2'].keys()))
#w.index_handler.booleans['step_0'][subset_uuid]['step_1']['step_2'].keys()
wb =  'SE654470-222700'
type_area = '2'#'01s - Västkustens inre kustvatten'
#w.index_handler.booleans['step_0'][subset_uuid]['step_1']['step_2'][type_area]['din_winter']['boolean']
#temp_df = w.get_filtered_data(step = 2, subset = subset_uuid, indicator = 'din_winter', water_body = 'SE654470-222700')
#temp_df.loc[(temp_df['MONTH'].isin([11, 12, 1, 2])) & (temp_df['VISS_EU_CD'].isin(['SE654470-222700']))][['MONTH', 'WATER_BODY_NAME', 'VISS_EU_CD', 'WATER_TYPE_AREA']]

print(w.get_filtered_data(step = 2, subset = subset_uuid, type_area = type_area, indicator = 'din_winter').MONTH.unique())
#[['MONTH', 'WATER_BODY_NAME', 'VISS_EU_CD']]

print(w.get_filtered_data(step = 2, subset = subset_uuid, type_area = type_area, indicator = 'din_winter').DEPH.min(),
w.get_filtered_data(step = 2, subset = subset_uuid, type_area = type_area, indicator = 'din_winter').DEPH.max())

w.get_filtered_data(step = 2, subset = subset_uuid, type_area = type_area).WATER_TYPE_AREA.unique()
water_body = wb
temp_df = w.get_filtered_data(step = 2, subset = subset_uuid, indicator = 'din_winter', type_area = type_area)[['SDATE','MONTH', 'WATER_BODY_NAME', 'VISS_EU_CD', 'WATER_TYPE_AREA', 'DIN','SALT_CTD', 'SALT_BTL']].dropna(thresh=7)
print('Waterbodys left: {}'.format(temp_df['WATER_BODY_NAME'].unique()))
temp_df.loc[temp_df['WATER_BODY_NAME'].isin(['Gullmarn centralbassäng'])]

w.get_available_indicators(subset= 'A', step=2)
w.cfg['indicators']
[item.strip() for item in w.cfg['indicators'].loc['din_winter'][0].split(', ')]<jupyter_output><empty_output><jupyter_text>Step 3 Load Indicator objects step 3....<jupyter_code>w.get_step_object(step = 3, subset = subset_uuid).calculate_indicator_status(subset_unique_id = subset_uuid, indicator_list = ['din_winter'])
w.get_step_object(step = 3, subset = subset_uuid).indicator_objects['din_winter'].get_water_body_indicator_df(water_body = wb)
w.get_step_object(step = 3, subset = subset_uuid).indicator_objects['din_winter'].get_ref_value(type_area = '1s', salinity = 25)
indicator= 'din_winter'
w.get_step_object(step = 3, subset = subset_uuid).get_indicator_data_filter_settings(indicator)
s = w.get_subset_object(subset_uuid).indicator_objects['din_winter']
s.get_filtered_data(subset = subset_uuid, step = 'step_2')
B2_NTOT_WINTER_SETTINGS = lv_workspace.get_subset_object('B').get_step_object('step_2').indicator_ref_settings['ntot_winter']
lv_workspace.get_subset_object('B').get_step_object('step_2').indicator_ref_settings['ntot_winter'].allowed_variables
# gör om till
# lv_workspace.get_indicator_ref_settings(step = , subset = , indicator = , waterbody/type)
# ger samma resultat som:
#lv_workspace.get_subset_object('B').get_step_object('step_2').indicator_ref_settings['ntot_winter'].settings.ref_columns

lv_workspace.get_subset_object('B').get_step_object('step_2').indicator_ref_settings['ntot_winter'].settings.get_value('EK G/M', 22)
#print(B2_NTOT_WINTER_SETTINGS)
#B2_NTOT_WINTER_SETTINGS.get_value('2', 'DEPTH_INTERVAL')
av = lv_workspace.get_subset_object('B').get_step_object('step_2').indicator_data_filter_settings['ntot_winter'].allowed_variables
lv_workspace.get_subset_object('B').get_step_object('step_2').indicator_data_filter_settings['ntot_winter'].settings.df[av]
lv_workspace.get_subset_object('B').get_step_object('step_2').indicator_data_filter_settings['ntot_winter'].settings.df

B2_NTOT_WINTER_SETTINGS.settings.mapping_water_body['N m Bottenvikens kustvatten']<jupyter_output><empty_output><jupyter_text>Set subset time and area filter<jupyter_code>f1_A = lv_workspace.get_data_filter_object(step=1, subset='A') 
f1_A.include_list_filter
lv_workspace.get_data_filter_info(step=1, subset='A') 
f1_A.exclude_list_filter
f0.include_list_filter<jupyter_output><empty_output><jupyter_text>Apply subset filter<jupyter_code>lv_workspace.apply_subset_filter(subset='A') # Not handled properly by the IndexHandler<jupyter_output><empty_output><jupyter_text>Extract filtered data<jupyter_code>data_after_subset_filter = lv_workspace.get_filtered_data(level=1, subset='A') # level=0 means first filter 
print('{} rows mathing the filter criteria'.format(len(data_after_subset_filter)))
data_after_subset_filter.head()
# show available waterbodies
lst = data_after_subset_filter.SEA_AREA_NAME.unique()
print('Waterbodies in subset:\n{}'.format('\n'.join(lst)))
import numpy as np
np.where(lv_workspace.index_handler.subset_filter)
f = lv_workspace.get_data_filter_object(step=1, subset='A') 

f.all_filters
f.exclude_list_filter
f.include_list_filter
s = lv_workspace.get_step_1_object('A')
s.data_filter.all_filters
f0 = lv_workspace.get_data_filter_object(step=0) 
f0.exclude_list_filter
f0.include_list_filter<jupyter_output><empty_output><jupyter_text>Quality factor Nutrients<jupyter_code>lv_workspace.initiate_quality_factors()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12000693180833549, 'fraction_numerical': 0.02998007105103544, 'mean_word_length': 7.430971512052593, 'pattern_counts': {'":': 0, '<': 70, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '19', 'dir': 'jupyter-structured-clean-dedup', 'id': '29418', 'license': 'MIT', 'n_tokens_mistral': 4489, 'n_tokens_neox': 4222, 'n_words': 613, 'path': 'notebooks/lv_notebook_Indicator.ipynb', 'repo_name': 'lvikt/ekostat_calculator', 'size': '11541'}