In [1]:
# Reload when code changed:
%load_ext autoreload
%autoreload 2
%pwd
import sys
import os
path = "../"
sys.path.append(path)
#os.path.abspath("../")
print(os.path.abspath(path))


D:\Utveckling\git\ekostat_calculator

In [2]:
import os 
import core
import importlib
importlib.reload(core) 
try:
    logging.shutdown()
    importlib.reload(logging)
except:
    pass
import pandas as pd
import numpy as np
import json
import time
import re

from event_handler import EventHandler
print(core.__file__)
pd.__version__


..\core\__init__.py
Out[2]:
'0.19.2'

In [3]:
user_id_1 = 'user_1'
user_id_2 = 'user_2'
user_1_ws_1 = 'mw1'
print(path)
paths = {'user_id': user_id_1, 
         'workspace_directory': path + '/workspaces', 
         'resource_directory': path + '/resources', 
         'log_directory': path + '/log', 
         'test_data_directory': path + '/test_data'}


../

In [25]:
workspace_uuid = '327bbf4f-f367-4d85-80f4-e9151907eadc'
subset_uuid = 'ac45fef1-3042-44f4-bdca-e121d1d93f45'

In [26]:
# ekos = EventHandler(**paths)
# ekos.action_workspace_load_default_data(workspace_uuid)

In [27]:
ekos = EventHandler(**paths)
ekos.action_load_data(workspace_uuid)


2018-07-18 07:24:59,848	event_handler.py	77	__init__	DEBUG	Start EventHandler: event_handler
2018-07-18 07:25:03,921	event_handler.py	2375	load_workspace	DEBUG	Trying to load new workspace "327bbf4f-f367-4d85-80f4-e9151907eadc" with alias "New test workspace"
2018-07-18 07:25:04,013	logger.py	85	add_log	DEBUG	
2018-07-18 07:25:04,014	logger.py	86	add_log	DEBUG	========================================================================================================================
2018-07-18 07:25:04,014	logger.py	87	add_log	DEBUG	### Log added for log_id "ac45fef1-3042-44f4-bdca-e121d1d93f45" at locaton: ..\workspaces\327bbf4f-f367-4d85-80f4-e9151907eadc\log\subset_ac45fef1-3042-44f4-bdca-e121d1d93f45.log
2018-07-18 07:25:04,014	logger.py	88	add_log	DEBUG	------------------------------------------------------------------------------------------------------------------------
2018-07-18 07:25:04,073	logger.py	85	add_log	DEBUG	
2018-07-18 07:25:04,075	logger.py	86	add_log	DEBUG	========================================================================================================================
2018-07-18 07:25:04,078	logger.py	87	add_log	DEBUG	### Log added for log_id "default_subset" at locaton: ..\workspaces\327bbf4f-f367-4d85-80f4-e9151907eadc\log\subset_default_subset.log
2018-07-18 07:25:04,080	logger.py	88	add_log	DEBUG	------------------------------------------------------------------------------------------------------------------------
====================================================================================================
ac45fef1-3042-44f4-bdca-e121d1d93f45
..//workspaces/327bbf4f-f367-4d85-80f4-e9151907eadc/log
subset
----------------------------------------------------------------------------------------------------
====================================================================================================
default_subset
..//workspaces/327bbf4f-f367-4d85-80f4-e9151907eadc/log
subset
----------------------------------------------------------------------------------------------------
2018-07-18 07:25:04,273	logger.py	85	add_log	DEBUG	
2018-07-18 07:25:04,277	logger.py	86	add_log	DEBUG	========================================================================================================================
2018-07-18 07:25:04,279	logger.py	87	add_log	DEBUG	### Log added for log_id "327bbf4f-f367-4d85-80f4-e9151907eadc" at locaton: ..\workspaces\327bbf4f-f367-4d85-80f4-e9151907eadc\log\workspace_327bbf4f-f367-4d85-80f4-e9151907eadc.log
2018-07-18 07:25:04,282	logger.py	88	add_log	DEBUG	------------------------------------------------------------------------------------------------------------------------
2018-07-18 07:25:04,284	event_handler.py	2393	load_workspace	INFO	Workspace "327bbf4f-f367-4d85-80f4-e9151907eadc" with alias "New test workspace loaded."
====================================================================================================
327bbf4f-f367-4d85-80f4-e9151907eadc
..//workspaces/327bbf4f-f367-4d85-80f4-e9151907eadc/log
workspace
----------------------------------------------------------------------------------------------------
self.all_data 0
2018-07-18 07:25:04,704	workspaces.py	1569	load_all_data	DEBUG	Data has been loaded from existing all_data.pickle file.
Out[27]:
True

In [28]:
workspace = ekos.workspaces[workspace_uuid]
subset = workspace.get_subset_object(subset_uuid)
df = workspace.data_handler.all_data

In [ ]:
print(workspace.index_handler.booleans.keys())
print(workspace.index_handler.booleans['step_0'].keys())
print(workspace.index_handler.booleans['step_0'][subset_uuid].keys())
print(workspace.index_handler.booleans['step_0'][subset_uuid]['step_1'].keys())
b0 = workspace.index_handler.booleans['step_0']['boolean']

In [ ]:
print(set(df['MYEAR']))
print(set(df.loc[b0, 'MYEAR']))

In [ ]:
# Check filter 
ekos.apply_data_filter(workspace_uuid=workspace_uuid, 
                      step=0)
ekos.apply_data_filter(workspace_uuid=workspace_uuid, 
                       subset_uuid=subset_uuid, 
                       step=1)

In [29]:
ih = core.index_handler.new_IndexHandler(workspace_object=workspace, data_handler_object=workspace.data_handler)

In [30]:
ih._get_filter_level('step_0')


Out[30]:
{'boolean': None, 'step_0': {}}

In [31]:
ih._add_filter_level('step_0')


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-31-9f5411c57cd8> in <module>()
----> 1 ih._add_filter_level('step_0')

D:\Utveckling\git\ekostat_calculator\core\index_handler.py in _add_filter_level(self, key)
     88         """ 
     89         if key not in self.levels:
---> 90             raise
     91 
     92         if key == self.levels[0]:

RuntimeError: No active exception to reraise

In [ ]:
class Level(dict):
    def __init__(self, 
                 level=None, 
                 name=None, 
                 boolean=None, 
                 parent_object=None):
        self.level = level
        self.name = name
        self.boolean = boolean
        self.parent_object = parent_object

In [16]:
levels = ['data_0', 'subset', 'data_1', 'water_body', 'indicator']
parent = dict(zip(levels[1:], levels[:-1]))
def _get_parent_level(key):
    return parent.get(key, None)

In [17]:
def get_level_info(level, name):
    return {'level': level, 
            'name': name, 
            'boolean': None, 
            'parent_level': _get_parent_level(level)}

In [90]:
all_data = {} 
def add_boolean(filter_object=None, 
                df=None, 
                **kwargs): 
    given_levels = [] 
    for level in levels:
        if level in kwargs:
            given_levels.append(level)
    # Check if sufficient information 
    if given_levels != levels[:len(given_levels)]:
        print('NO')
        return False
    
    # Fix boolean 
    boolean = 5
    
    
    data = all_data
    for level in given_levels: 
        name = kwargs[level]
        
        if name not in data:
            data[name] = {} 
            data = data[name]
        
        if 'booelan' not in data:
            data['boolean'] = boolean 
            
        
        
        
        
        
        
        
        
        
        
#         level_dict = {'level': level, 
#                       'name': name, 
#                       'boolean': boolean, 
#                       'next_level': {}}
        
#         if data.get('level') == _get_parent_level(level): 
#             data = data['next_level']
            
#         elif not data: 
#             data = level_dict
#             data = data['next_level']

In [93]:
all_data = {}
add_boolean(data_1='data_1', data_0='data_0', subset='sub1')
add_boolean(data_1='data_1', data_0='data_0', subset='sub2')

In [94]:
all_data


Out[94]:
{'boolean': 5,
 'data_0': {'boolean': 5, 'sub1': {'boolean': 5, 'data_1': {'boolean': 5}}},
 'sub2': {'boolean': 5, 'data_1': {'boolean': 5}}}

In [95]:
print(all_data.keys())
print(all_data['data_0'].keys())
print(all_data['data_0']['sub1'].keys())
print(all_data['data_0']['sub1']['data_1'].keys())


dict_keys(['data_0', 'boolean', 'sub2'])
dict_keys(['boolean', 'sub1'])
dict_keys(['boolean', 'data_1'])
dict_keys(['boolean'])

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [21]:
all_data['fgsagfsa']['parent_dict'].keys()


Out[21]:
dict_keys([True, 'fgsagfsa'])

In [138]:
all_data.keys()


Out[138]:
dict_keys([True, 'fgsagfsa'])

In [8]:
def set_boolean_info(level=None, 
                    name=None, 
                    boolean=None, 
                    parent_dict=None, 
                    **kwargs):
    return

In [9]:
data0 = set_boolean_info(level='data_0', 
                         name='data_0', 
                         boolean=1, 
                         parent_dict=False) 


sub1 = set_boolean_info(level='subset', 
                        name='ac45fef1-3042-44f4-bdca-e121d1d93f45', 
                        boolean=2, 
                        parent_dict=data0)

data1 = set_boolean_info(level='data_1', 
                        name='data_1', 
                        boolean=3, 
                        parent_dict=sub1)

wb1 = set_boolean_info(level='water_body', 
                        name='wb1', 
                        boolean=5, 
                        parent_dict=data1)

wb2 = set_boolean_info(level='water_body', 
                        name='wb2', 
                        boolean=10, 
                        parent_dict=data1)

In [ ]:


In [10]:
def get_combined_boolean(info_dict): 
    boolean = info_dict['boolean']
    if info_dict['parent_dict'] == False:
        return boolean
    else:
#         print(info_dict.keys())
        boolean += get_combined_boolean(info_dict['parent_dict'])
        return boolean

In [11]:
get_combined_boolean(wb1)


Out[11]:
11

In [ ]:


In [ ]:


In [56]:
indicator_din_winter = 'din_winter'
indicator_bqi = 'bqi' 
indicator_oxygen = 'oxygen'

type_area = False
viss_eu_cd = 'SE582000-115270'

In [57]:
sf_din_winter = ekos.get_settings_filter_object(workspace_uuid=workspace_uuid, 
                                               subset_uuid=subset_uuid,
                                               indicator=indicator_din_winter, 
                                               filter_type='data')

sf_bqi = ekos.get_settings_filter_object(workspace_uuid=workspace_uuid, 
                                               subset_uuid=subset_uuid,
                                               indicator=indicator_bqi, 
                                               filter_type='data')

sf_oxygen = ekos.get_settings_filter_object(workspace_uuid=workspace_uuid, 
                                               subset_uuid=subset_uuid,
                                               indicator=indicator_oxygen, 
                                               filter_type='data')

In [15]:
sf_oxygen.get_viss_eu_cd_list()


Out[15]:
['SE555545-124332',
 'SE561030-122821',
 'SE562000-123800',
 'SE562450-122751',
 'SE563000-123351',
 'SE581260-113220',
 'SE581700-113000',
 'SE581740-114820',
 'SE582000-115270',
 'SE591800-181360',
 'SE592000-184700',
 'SE592290-181600',
 'SE658352-163189']

In [48]:
sf_bqi.get_value(type_area='2', 
                 variable='DEPH_INTERVAL', 
                 water_body=False, 
                 return_series=False)


return_value [[5, 20], [20, 500]]
Out[48]:
[[5, 20], [20, 500]]

In [49]:
sf_din_winter.get_value(type_area='2', 
                 variable='DEPH_INTERVAL', 
                 water_body=False, 
                 return_series=False)


return_value [[0, 10]]
Out[49]:
[0, 10]

In [41]:
df = sf_bqi.settings.df.copy(deep=True)
suf = sf_bqi.settings.suf
num = sf_bqi.settings.num 
var = sf_bqi.settings.var

print(suf)
print(num)
print(var)


2
DEPH_INTERVAL

In [46]:
df.loc[(df['TYPE_AREA_NUMBER']=='2') | \
       (df['TYPE_AREA_NUMBER']=='4'), var]


Out[46]:
2      5-20
3    20-500
6      5-20
7    20-500
Name: DEPH_INTERVAL, dtype: object

In [44]:
df.loc[(df['TYPE_AREA_NUMBER']==num) & \
       (df['VISS_EU_CD'] == 'unspecified'), var]


Out[44]:
2      5-20
3    20-500
Name: DEPH_INTERVAL, dtype: object

In [25]:
sf_bqi.settings.value_series


Out[25]:
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
0    5-20
Name: DEPH_INTERVAL, dtype: object

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [298]:


In [ ]:


In [299]:


In [ ]:


In [ ]:


In [300]:
sf = ekos.get_settings_filter_object(workspace_uuid=workspace_uuid, 
                                                                           subset_uuid=subset_uuid,
                                                                           indicator=indicator, 
                                                                           filter_type='data')

In [301]:
print(len(sf.settings.df.columns))
print(len(sf.settings.columns_in_file))


20
20

In [304]:
sf.settings.df


Out[304]:
DEPH_INTERVAL DEPH_TOLERANCE GM_EQR_LIMIT GM_VALUE_LIMIT HG_EQR_LIMIT HG_VALUE_LIMIT MIN_NR_VALUES MIN_NR_YEARS MONTH_LIST MP_EQR_LIMIT ... PB_EQR_LIMIT PB_VALUE_LIMIT POS_RADIUS_TOLERANCE REF_VALUE_LIMIT SALINITY MAX TIME_DELTA_TOLERANCE TYPE_AREA_NUMBER TYPE_AREA_SUFFIX VISS_EU_CD WATERBODY_NAME
0 0-10 5 0.66 -0.77778*s+30 0.8 -0.64815*s+25 3 3 12;1;2;3 0.44 ... 0.28 -1.8148*s+70 0.1 -0.51852*s+20 27 3 1 n unspecified NaN
1 0-10 5 0.67 -0.7875*s+22.5 0.8 -0.656*s+18.75 3 3 12;1;2;3 0.44 ... 0.29 -1.838*s+52.5 0.1 -0.525*s+15 20 3 1 s unspecified NaN
2 0-10 5 0.66 -0.77778*s+30 0.8 -0.64815*s+25 3 3 12;1;2;3 0.44 ... 0.28 -1.8148*s+70 0.1 -0.51852*s+20 27 3 2 unspecified NaN
3 0-10 5 0.66 -0.77778*s+30 0.8 -0.64815*s+25 3 3 12;1;2;3 0.44 ... 0.28 -1.8148*s+70 0.1 -0.51852*s+20 27 3 3 unspecified NaN
4 0-10 5 0.67 -0.7875*s+22.5 0.8 -0.656*s+18.75 3 3 12;1;2;3 0.44 ... 0.29 -1.838*s+52.5 0.1 -0.525*s+15 20 3 4 unspecified NaN
5 0-10 5 0.67 0.1875*s+2.25 0.8 0.1563*s+1.88 3 3 12;1;2;3 0.44 ... 0.29 0.4375*s+5.25 0.1 0.125*s+1.5 20 3 5 unspecified NaN
6 0-10 5 0.67 0.1875*s+2.25 0.8 0.1563*s+1.88 3 3 12;1;2;3 0.44 ... 0.29 0.4375*s+5.25 0.1 0.125*s+1.5 20 3 6 unspecified NaN
7 0-10 5 0.67 -7.3929*s+55.5 0.8 -6.1618*s+46.2 3 3 12;1;2 0.45 ... 0.29 -17.25*s+130 0.1 -4.928*s+37 7 3 7 unspecified NaN
8 0-10 5 0.67 -7.3929*s+55.5 0.8 -6.1618*s+46.2 3 3 12;1;2 0.45 ... 0.29 -17.25*s+130 0.1 -4.928*s+37 7 3 8 unspecified NaN
9 0-10 5 0.67 -7.3929*s+55.5 0.8 -6.1618*s+46.2 3 3 12;1;2 0.45 ... 0.29 -17.25*s+130 0.1 -4.928*s+37 7 3 9 unspecified NaN
10 0-10 5 0.66 0*s+3.75 0.81 0*s+3.125 3 3 12;1;2 0.45 ... 0.28 0*s+8.75 0.1 0*s+2.5 7 3 10 unspecified NaN
11 0-10 5 0.66 0*s+3.75 0.81 0*s+3.125 3 3 12;1;2 0.45 ... 0.28 0*s+8.75 0.1 0*s+2.5 7 3 11 unspecified NaN
12 0-10 5 0.66 -1.625*s+13.5 0.8 -1.354*s+11.25 3 3 12;1;2 0.44 ... 0.29 -3.792*s+31.5 0.1 -1.0833*s+9 6 3 12 s unspecified NaN
13 0-10 5 0.67 -1.125*s+10.5 0.8 -0.9375*s+8.75 3 3 12;1;2 0.44 ... 0.29 -2.625*s+24.5 0.1 -0.75*s+7 6 3 12 n unspecified NaN
14 0-10 5 0.66 -1.625*s+13.5 0.8 -1.354*s+11.25 3 3 12;1;2 0.44 ... 0.29 -3.792*s+31.5 0.1 -1.0833*s+9 6 3 13 unspecified NaN
15 0-10 5 0.66 -1.625*s+13.5 0.8 -1.354*s+11.25 3 3 12;1;2 0.44 ... 0.29 -3.792*s+31.5 0.1 -1.0833*s+9 6 3 14 unspecified NaN
16 0-10 5 0.67 -1.125*s+10.5 0.8 -0.9375*s+8.75 3 3 12;1;2 0.44 ... 0.29 -2.625*s+24.5 0.1 -0.75*s+7 6 3 15 unspecified NaN
17 0-10 5 0.67 -0.6*s+7.5 0.8 -0.5*s+6.25 3 3 11;12;1;2 0.44 ... 0.29 -1.4*s+17.5 0.1 -0.4*s+5 5 3 16 unspecified NaN
18 0-10 5 0.67 -0.6*s+7.5 0.8 -0.5*s+6.25 3 3 11;12;1;2 0.44 ... 0.29 -1.4*s+17.5 0.1 -0.4*s+5 5 3 17 unspecified NaN
19 0-10 5 0.66 -0.3*s+7.5 0.8 -0.25*s+6.25 3 3 11;12;1;2 0.44 ... 0.28 -0.7*s+17.5 0.1 -0.2*s+5 5 3 18 unspecified NaN
20 0-10 5 0.66 -0.3*s+7.5 0.8 -0.25*s+6.25 3 3 11;12;1;2 0.44 ... 0.28 -0.7*s+17.5 0.1 -0.2*s+5 5 3 19 unspecified NaN
21 0-10 5 0.67 -1.14*s+12 0.8 -0.95*s+10 3 3 11;12;1;2 0.44 ... 0.29 -2.66*s+28 0.1 -0.76*s+8 5 3 20 unspecified NaN
22 0-10 5 0.67 -1.14*s+12 0.8 -0.95*s+10 3 3 11;12;1;2 0.44 ... 0.29 -2.66*s+28 0.1 -0.76*s+8 5 3 21 unspecified NaN
23 0-10 5 0.67 -2*s+13.5 0.8 -1.667*s+11.25 3 3 11;12;1;2 0.44 ... 0.29 -4.667*s+31.5 0.1 -1.333*s+9 3 3 22 unspecified NaN
24 0-10 5 0.67 -2*s+13.5 0.8 -1.667*s+11.25 3 3 11;12;1;2 0.44 ... 0.29 -4.667*s+31.5 0.1 -1.333*s+9 3 3 23 unspecified NaN
25 0-10 5 0.67 -1.125*s+10.5 0.8 -0.9375*s+8.75 3 3 12;1;2 0.44 ... 0.29 -2.625*s+24.5 0.1 -0.75*s+7 6 3 24 unspecified NaN
26 0-10 5 0.67 -0.7875*s+22.5 0.8 -0.656*s+18.75 3 3 12;1;2;3 0.44 ... 0.29 -1.838*s+52.5 0.1 -0.525*s+15 20 3 25 unspecified NaN

27 rows × 21 columns


In [303]:
set_data = {viss_eu_cd:{'DEPH_INTERVAL': [[10, 20]]}}
sf.set_values(set_data)


set_values
['DEPH_INTERVAL', 'MONTH_LIST']
3
Interval column
Value to set for water body (viss_eu_cd) "SE582000-115270" and variable "DEPH_INTERVAL": ['10-20']
21
Index(['DEPH_INTERVAL', 'DEPH_TOLERANCE', 'GM_EQR_LIMIT', 'GM_VALUE_LIMIT',
       'HG_EQR_LIMIT', 'HG_VALUE_LIMIT', 'MIN_NR_VALUES', 'MIN_NR_YEARS',
       'MONTH_LIST', 'MP_EQR_LIMIT', 'MP_VALUE_LIMIT', 'PB_EQR_LIMIT',
       'PB_VALUE_LIMIT', 'POS_RADIUS_TOLERANCE', 'REF_VALUE_LIMIT',
       'SALINITY MAX', 'TIME_DELTA_TOLERANCE', 'TYPE_AREA_NUMBER',
       'TYPE_AREA_SUFFIX', 'VISS_EU_CD', 'WATERBODY_NAME'],
      dtype='object')
20
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-303-fbc761246531> in <module>()
      1 set_data = {viss_eu_cd:{'DEPH_INTERVAL': [[10, 20]]}}
----> 2 sf.set_values(set_data)

D:\Utveckling\git\ekostat_calculator\core\filters.py in set_values(self, value_dict)
   1158         """
   1159         self.settings.set_values(value_dict, self.allowed_variables)
-> 1160         self.settings.save_file()
   1161 
   1162 

D:\Utveckling\git\ekostat_calculator\core\filters.py in save_file(self, file_path)
    525         print(self.df.columns)
    526         print(len(self.columns_in_file))
--> 527         self.df.columns = self.columns_in_file
    528 
    529         self.df.to_csv(file_path, sep='\t', encoding='cp1252', index=False)

C:\Continuum\Anaconda3\envs\EKOSTAT_tool\lib\site-packages\pandas\core\generic.py in __setattr__(self, name, value)
   2755         try:
   2756             object.__getattribute__(self, name)
-> 2757             return object.__setattr__(self, name, value)
   2758         except AttributeError:
   2759             pass

pandas\src\properties.pyx in pandas.lib.AxisProperty.__set__ (pandas\lib.c:46249)()

C:\Continuum\Anaconda3\envs\EKOSTAT_tool\lib\site-packages\pandas\core\generic.py in _set_axis(self, axis, labels)
    446 
    447     def _set_axis(self, axis, labels):
--> 448         self._data.set_axis(axis, labels)
    449         self._clear_item_cache()
    450 

C:\Continuum\Anaconda3\envs\EKOSTAT_tool\lib\site-packages\pandas\core\internals.py in set_axis(self, axis, new_labels)
   2800             raise ValueError('Length mismatch: Expected axis has %d elements, '
   2801                              'new values have %d elements' %
-> 2802                              (old_len, new_len))
   2803 
   2804         self.axes[axis] = new_labels

ValueError: Length mismatch: Expected axis has 21 elements, new values have 20 elements

In [266]:
len(sf.settings.columns)


Out[266]:
20

In [265]:
len(sf.settings.columns_in_file)


Out[265]:
20

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [165]:
df = pd.read_csv('D:/Utveckling/git/ekostat_calculator/workspaces/40e11bb1-49fb-4eb3-bb2b-4d5b9f520b2c/subsets/a15e6f23-5f78-4e78-b3fa-d9cc14e88f93/step_2/settings/indicator_settings/oxygen_test.set', sep='\t', encoding='cp1252')
df = pd.read_csv('D:/Utveckling/git/ekostat_calculator/workspaces/40e11bb1-49fb-4eb3-bb2b-4d5b9f520b2c/subsets/a15e6f23-5f78-4e78-b3fa-d9cc14e88f93/step_2/settings/indicator_settings/BQI.set', sep='\t', encoding='cp1252')
df = df.fillna('')

In [166]:
df.head()


Out[166]:
Indicator Type_Area_number Type_Area_suffix VISS_EU_CD level_DEPH_INTERVAL_int tolerance_MIN_NR_YEARS_int tolerance_MIN_NR_VALUES_int filter_MONTH_LIST_int ref_HG_value_limit_float ref_GM_value_limit_float ref_MP_value_limit_float ref_PB_value_limit_float ref_max BQIm ref_HG_EQR_limit_float ref_GM_EQR_llimit_float ref_MP_EQR_llimit_float ref_PB_EQR_limit_float Param QualityElement
0 BQI 1 unspecified 5-20 3 5 5;6 13.9 10.3 6.9 3.4 15.7 0.89 0.66 0.44 0.22 BQI Bottom fauna
1 BQI 1 unspecified 20-500 3 5 5;6 15.7 12.0 8.0 4.0 17.6 0.89 0.68 0.45 0.23 BQI Bottom fauna
2 BQI 2 unspecified 5-20 3 5 5;6 13.9 10.3 6.9 3.4 15.7 0.89 0.66 0.44 0.22 BQI Bottom fauna
3 BQI 2 unspecified 20-500 3 5 5;6 15.7 12.0 8.0 4.0 17.6 0.89 0.68 0.45 0.23 BQI Bottom fauna
4 BQI 3 unspecified 5-20 3 5 5;6 13.9 10.3 6.9 3.4 15.7 0.89 0.66 0.44 0.22 BQI Bottom fauna

In [167]:
viss_eu_cd = 'SE582000-115270'
#viss_eu_cd = 'SE592000-184700'
viss_eu_cd = 'SE570900-121060'
type_area = ekos.mapping_objects['water_body'].get_type_area_for_water_body(viss_eu_cd, include_suffix=True).replace('-', '')
water_body_name = ekos.mapping_objects['water_body'].get_display_name(water_body=viss_eu_cd)
print('type_area:', type_area)
print('viss_eu_cd:', viss_eu_cd)
print('water_body_name:', water_body_name)


type_area: 1s
viss_eu_cd: SE570900-121060
water_body_name: Balgöarkipelagen

In [168]:
s = df.loc[((df['Type_Area_number'].astype(str) + df['Type_Area_suffix'])==type_area) & (df['VISS_EU_CD']=='unspecified')].copy()
if not len(s):
    type_area = re.findall('\d+', type_area)[0]
    s = df.loc[((df['Type_Area_number'].astype(str) + df['Type_Area_suffix'])==type_area) & (df['VISS_EU_CD']=='unspecified')].copy()

In [169]:
s['VISS_EU_CD'] = viss_eu_cd
s['WATERBODY_NAME'] = water_body_name

In [170]:
type(s)


Out[170]:
pandas.core.frame.DataFrame

In [171]:
df2 = df.append(s)

In [172]:
wbm = ekos.mapping_objects['water_body']

In [173]:
wbm.get_display_name(water_body=viss_eu_cd)


Out[173]:
'Balgöarkipelagen'

In [174]:
df2.tail()


Out[174]:
Indicator Param QualityElement Type_Area_number Type_Area_suffix VISS_EU_CD WATERBODY_NAME filter_MONTH_LIST_int level_DEPH_INTERVAL_int ref_GM_EQR_llimit_float ref_GM_value_limit_float ref_HG_EQR_limit_float ref_HG_value_limit_float ref_MP_EQR_llimit_float ref_MP_value_limit_float ref_PB_EQR_limit_float ref_PB_value_limit_float ref_max BQIm tolerance_MIN_NR_VALUES_int tolerance_MIN_NR_YEARS_int
29 BQI BQI Bottom fauna 24 unspecified NaN 5;6 5-60 0.30 3.0 0.77 7.7 0.20 2.0 0.10 1.3 14.0 5 3
30 BQI BQI Bottom fauna 25 unspecified NaN 5;6 5-20 0.66 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
31 BQI BQI Bottom fauna 25 unspecified NaN 5;6 20-500 0.68 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
0 BQI BQI Bottom fauna 1 SE570900-121060 Balgöarkipelagen 5;6 5-20 0.66 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
1 BQI BQI Bottom fauna 1 SE570900-121060 Balgöarkipelagen 5;6 20-500 0.68 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3

In [195]:
print(viss_eu_cd)
print()

matching_columns = ['WATERBODY_NAME', 'tolerance_MIN_NR_YEARS_int', 
                    'tolerance_BOTTOM_WATER_int', 'MONTH_LIST_int', 
                    'filter_DEPH_INTERVAL_int']

for viss in set(df2['VISS_EU_CD']):
    if viss =='unspecified':
        continue 
    type_area = ekos.mapping_objects['water_body'].get_type_area_for_water_body(viss, include_suffix=True).replace('-', '')
    type_area_series = df2.loc[((df2['Type_Area_number'].astype(str) + df2['Type_Area_suffix'])==type_area) & (df2['VISS_EU_CD']=='unspecified')].copy()
    if not len(type_area_series):
        type_area = re.findall('\d+', type_area)[0] 
        type_area_series = df2.loc[((df2['Type_Area_number'].astype(str) + df2['Type_Area_suffix'])==type_area) & (df2['VISS_EU_CD']=='unspecified')].copy()
    viss_series = df2.loc[df2['VISS_EU_CD']==viss_eu_cd, :]
    for col in matching_columns:
        if col not in viss_series.columns:
            continue
        if list(viss_series[col].values) != list(type_area_series[col].values):
            print('+', viss, type_area)


SE570900-121060

+ SE570900-121060 1

In [220]:
df2.loc[df2['Type_Area_number']==1, :]


Out[220]:
Indicator Param QualityElement Type_Area_number Type_Area_suffix VISS_EU_CD WATERBODY_NAME filter_MONTH_LIST_int level_DEPH_INTERVAL_int ref_GM_EQR_llimit_float ref_GM_value_limit_float ref_HG_EQR_limit_float ref_HG_value_limit_float ref_MP_EQR_llimit_float ref_MP_value_limit_float ref_PB_EQR_limit_float ref_PB_value_limit_float ref_max BQIm tolerance_MIN_NR_VALUES_int tolerance_MIN_NR_YEARS_int
0 BQI BQI Bottom fauna 1 unspecified NaN 5;6 5-20 0.66 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
1 BQI BQI Bottom fauna 1 unspecified NaN 5;6 20-500 0.68 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
0 BQI BQI Bottom fauna 1 SE570900-121060 Balgöarkipelagen 5;6 5-20 0.66 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
1 BQI BQI Bottom fauna 1 SE570900-121060 Balgöarkipelagen 5;6 20-500 0.68 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3

In [ ]:


In [ ]:


In [217]:
df3 = df2.copy(deep=True)
df3.reset_index(inplace=True)

In [218]:
viss_eu_cd_boolean = df3['VISS_EU_CD']==viss_eu_cd

In [ ]:


In [219]:
import numpy as np
df3.drop(np.where(viss_eu_cd_boolean)[0])


Out[219]:
index Indicator Param QualityElement Type_Area_number Type_Area_suffix VISS_EU_CD WATERBODY_NAME filter_MONTH_LIST_int level_DEPH_INTERVAL_int ... ref_GM_value_limit_float ref_HG_EQR_limit_float ref_HG_value_limit_float ref_MP_EQR_llimit_float ref_MP_value_limit_float ref_PB_EQR_limit_float ref_PB_value_limit_float ref_max BQIm tolerance_MIN_NR_VALUES_int tolerance_MIN_NR_YEARS_int
0 0 BQI BQI Bottom fauna 1 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
1 1 BQI BQI Bottom fauna 1 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
2 2 BQI BQI Bottom fauna 2 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
3 3 BQI BQI Bottom fauna 2 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
4 4 BQI BQI Bottom fauna 3 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
5 5 BQI BQI Bottom fauna 3 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
6 6 BQI BQI Bottom fauna 4 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
7 7 BQI BQI Bottom fauna 4 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
8 8 BQI BQI Bottom fauna 5 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
9 9 BQI BQI Bottom fauna 5 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
10 10 BQI BQI Bottom fauna 6 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
11 11 BQI BQI Bottom fauna 6 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
12 12 BQI BQI Bottom fauna 7 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
13 13 BQI BQI Bottom fauna 8 unspecified NaN 5;6 5-60 ... 3.5 0.75 10.5 0.17 2.3 0.08 1.6 14.0 5 3
14 14 BQI BQI Bottom fauna 9 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
15 15 BQI BQI Bottom fauna 10 unspecified NaN 5;6 5-60 ... 4.0 0.78 9.3 0.22 2.7 0.11 1.8 12.0 5 3
16 16 BQI BQI Bottom fauna 11 unspecified NaN 5;6 5-60 ... 4.0 0.80 8.0 0.27 2.7 0.13 1.8 10.0 5 3
17 17 BQI BQI Bottom fauna 12 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
18 18 BQI BQI Bottom fauna 13 unspecified NaN 5;6 5-60 ... 3.0 0.75 9.0 0.17 2.0 0.08 1.3 12.0 5 3
19 19 BQI BQI Bottom fauna 14 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
20 20 BQI BQI Bottom fauna 15 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
21 21 BQI BQI Bottom fauna 16 unspecified NaN 5;6 5-500 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
22 22 BQI BQI Bottom fauna 17 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
23 23 BQI BQI Bottom fauna 18 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
24 24 BQI BQI Bottom fauna 19 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
25 25 BQI BQI Bottom fauna 20 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
26 26 BQI BQI Bottom fauna 21 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
27 27 BQI BQI Bottom fauna 22 unspecified NaN 5;6 5-500 ... 2.0 0.58 7.5 0.10 1.3 0.05 0.9 13.0 5 3
28 28 BQI BQI Bottom fauna 23 unspecified NaN 5;6 5-500 ... 1.5 0.57 6.3 0.09 1.0 0.05 0.7 11.0 5 3
29 29 BQI BQI Bottom fauna 24 unspecified NaN 5;6 5-60 ... 3.0 0.77 7.7 0.20 2.0 0.10 1.3 14.0 5 3
30 30 BQI BQI Bottom fauna 25 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
31 31 BQI BQI Bottom fauna 25 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3

32 rows × 21 columns


In [215]:
df3


Out[215]:
index Indicator Param QualityElement Type_Area_number Type_Area_suffix VISS_EU_CD WATERBODY_NAME filter_MONTH_LIST_int level_DEPH_INTERVAL_int ... ref_GM_value_limit_float ref_HG_EQR_limit_float ref_HG_value_limit_float ref_MP_EQR_llimit_float ref_MP_value_limit_float ref_PB_EQR_limit_float ref_PB_value_limit_float ref_max BQIm tolerance_MIN_NR_VALUES_int tolerance_MIN_NR_YEARS_int
0 0 BQI BQI Bottom fauna 1 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
1 1 BQI BQI Bottom fauna 1 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
2 2 BQI BQI Bottom fauna 2 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
3 3 BQI BQI Bottom fauna 2 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
4 4 BQI BQI Bottom fauna 3 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
5 5 BQI BQI Bottom fauna 3 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
6 6 BQI BQI Bottom fauna 4 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
7 7 BQI BQI Bottom fauna 4 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
8 8 BQI BQI Bottom fauna 5 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
9 9 BQI BQI Bottom fauna 5 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
10 10 BQI BQI Bottom fauna 6 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
11 11 BQI BQI Bottom fauna 6 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
12 12 BQI BQI Bottom fauna 7 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
13 13 BQI BQI Bottom fauna 8 unspecified NaN 5;6 5-60 ... 3.5 0.75 10.5 0.17 2.3 0.08 1.6 14.0 5 3
14 14 BQI BQI Bottom fauna 9 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
15 15 BQI BQI Bottom fauna 10 unspecified NaN 5;6 5-60 ... 4.0 0.78 9.3 0.22 2.7 0.11 1.8 12.0 5 3
16 16 BQI BQI Bottom fauna 11 unspecified NaN 5;6 5-60 ... 4.0 0.80 8.0 0.27 2.7 0.13 1.8 10.0 5 3
17 17 BQI BQI Bottom fauna 12 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
18 18 BQI BQI Bottom fauna 13 unspecified NaN 5;6 5-60 ... 3.0 0.75 9.0 0.17 2.0 0.08 1.3 12.0 5 3
19 19 BQI BQI Bottom fauna 14 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
20 20 BQI BQI Bottom fauna 15 unspecified NaN 5;6 5-60 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
21 21 BQI BQI Bottom fauna 16 unspecified NaN 5;6 5-500 ... 4.0 0.76 10.7 0.19 2.7 0.10 1.8 14.0 5 3
22 22 BQI BQI Bottom fauna 17 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
23 23 BQI BQI Bottom fauna 18 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
24 24 BQI BQI Bottom fauna 19 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
25 25 BQI BQI Bottom fauna 20 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
26 26 BQI BQI Bottom fauna 21 unspecified NaN 5;6 5-500 ... 4.0 0.77 10.0 0.21 2.7 0.10 1.8 13.0 5 3
27 27 BQI BQI Bottom fauna 22 unspecified NaN 5;6 5-500 ... 2.0 0.58 7.5 0.10 1.3 0.05 0.9 13.0 5 3
28 28 BQI BQI Bottom fauna 23 unspecified NaN 5;6 5-500 ... 1.5 0.57 6.3 0.09 1.0 0.05 0.7 11.0 5 3
29 29 BQI BQI Bottom fauna 24 unspecified NaN 5;6 5-60 ... 3.0 0.77 7.7 0.20 2.0 0.10 1.3 14.0 5 3
30 30 BQI BQI Bottom fauna 25 unspecified NaN 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
31 31 BQI BQI Bottom fauna 25 unspecified NaN 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3
32 0 BQI BQI Bottom fauna 1 SE570900-121060 Balgöarkipelagen 5;6 5-20 ... 10.3 0.89 13.9 0.44 6.9 0.22 3.4 15.7 5 3
33 1 BQI BQI Bottom fauna 1 SE570900-121060 Balgöarkipelagen 5;6 20-500 ... 12.0 0.89 15.7 0.45 8.0 0.23 4.0 17.6 5 3

34 rows × 21 columns


In [ ]:


In [ ]:


In [188]:
import codecs
hp = {}
with codecs.open('D:/Utveckling/git/ekostat_calculator/resources/mappings/indicator_settings_homogeneous_parameters.txt') as fid: 
    for line in fid:
        line = line.strip()
        if line:
            indicator, par = [item.strip() for item in line.split('\t')]
            if not hp.get(indicator):
                hp[indicator] = []
            hp[indicator].append(par)

In [189]:
hp


Out[189]:
{'bqi': ['month_list'],
 'ntot_winter': ['month_list'],
 'oxygen': ['month_list']}

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: