In [1]:
%matplotlib inline
In [2]:
from IPython.display import display, HTML
In [3]:
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (14.0, 8.0)
In [4]:
import numpy as np
In [5]:
from aneris.control.factory import InterfaceFactory
In [6]:
from dtocean_core import start_logging
from dtocean_core.core import Core, AutoFileInput, AutoFileOutput
from dtocean_core.menu import DataMenu, ModuleMenu, ProjectMenu
from dtocean_core.pipeline import Tree
from dtocean_core.data import CoreMetaData
In [7]:
def html_list(x):
message = "<ul>"
for name in x:
message += "<li>{}</li>".format(name)
message += "</ul>"
return message
def html_dict(x):
message = "<ul>"
for name, status in x.iteritems():
message += "<li>{}: <b>{}</b></li>".format(name, status)
message += "</ul>"
return message
In [8]:
# Bring up the logger
start_logging()
In [9]:
new_core = Core()
data_menu = DataMenu()
project_menu = ProjectMenu()
module_menu = ModuleMenu()
pipe_tree = Tree()
In [10]:
project_title = "DTOcean"
new_project = project_menu.new_project(new_core, project_title)
In [11]:
options_branch = pipe_tree.get_branch(new_core, new_project, "System Type Selection")
variable_id = "device.system_type"
my_var = options_branch.get_input_variable(new_core, new_project, variable_id)
my_var.set_raw_interface(new_core, "Tidal Fixed")
my_var.read(new_core, new_project)
In [12]:
project_menu.initiate_pipeline(new_core, new_project)
In [13]:
names = module_menu.get_available(new_core, new_project)
message = html_list(names)
HTML(message)
Out[13]:
In [14]:
module_name = 'Hydrodynamics'
module_menu.activate(new_core, new_project, module_name)
hydro_branch = pipe_tree.get_branch(new_core, new_project, 'Hydrodynamics')
In [15]:
project_menu.initiate_dataflow(new_core, new_project)
In [16]:
new_core.inspect_level(new_project, "modules initial")
new_core.reset_level(new_project, preserve_level=True)
In [17]:
input_status = hydro_branch.get_input_status(new_core, new_project)
message = html_dict(input_status)
HTML(message)
Out[17]:
In [18]:
new_var_id = "device.turbine_performance"
new_var = hydro_branch.get_input_variable(new_core, new_project, new_var_id)
In [19]:
new_var.get_file_input_interfaces(new_core, include_auto=True)
Out[19]:
In [21]:
new_var.read_file(new_core,
new_project,
"test_data/tidal_performance.csv")
In [22]:
input_status = hydro_branch.get_input_status(new_core, new_project)
var_status = {new_var_id: input_status[new_var_id]}
message = html_dict(var_status)
HTML(message)
Out[22]:
In [23]:
new_var.get_value(new_core, new_project)
Out[23]:
In [24]:
new_var.write_file(new_core,
new_project,
"tidal_performance_copy.csv")
In [25]:
meta = CoreMetaData({"identifier": "test",
"structure": "test",
"title": "test",
"labels": ["a", "b"],
"units": ["kg", None]})
Create the Structure object and get the processed data format
In [26]:
data_obj = new_core.control.get_structure("TimeTable")
Build the fake AutoFileInput interface
In [27]:
interface_factory = InterfaceFactory(AutoFileInput)
AutoCls = interface_factory(meta, data_obj)
test = AutoCls()
Add the file path to the interface's ._path attribute and then call the AutoFileInput connect method
In [30]:
test._path = "test_data/date_test.csv"
In [31]:
test.connect()
Examine the data in the interface
In [32]:
test.data.result
Out[32]:
Try to load the result into the Structure
In [33]:
data_value = data_obj.get_data(test.data.result, meta)
data_value
Out[33]:
Build the fake AutoFileOutput interface
In [34]:
interface_factory = InterfaceFactory(AutoFileOutput)
AutoCls = interface_factory(meta, data_obj)
test = AutoCls()
Add the file path to the interface's ._path attribute and then call the AutoFileInput connect method
In [35]:
test._path = "date_test_copy.csv"
In [36]:
test.put_data("test", data_value)
In [37]:
test.connect()
In [ ]: