I am trying to simulate two FMUs with the one having inputs as CSV files by using the Master. What I have tried is the following:
from pyfmi import load_fmu
from pyfmi import Master
import pandas as pd
electricity_network = load_fmu(r"C:\Users\kosmy\Pandapower_Reduced.fmu")
pv = load_fmu(r"C:\Users\kosmy\Photovoltaics.Model.PVandWeather_simple.fmu")
load_file = r"C:\Users\kosmy\load_prof_sec_res.csv"
load = pd.read_csv(load_file)
models = [electricity_network, pv]
connections = [(pv, "P_MW", electricity_network, "P_pv1"),
(pv, "P_MW", electricity_network, "P_pv2")]
master_simulator = Master(models, connections)
input_object = [((electricity_network, 'P_load1'), load),
((electricity_network, 'P_load2'), load)]
res = master_simulator.simulate(final_time = 86400, input = input_object)
I am getting the following error:
Traceback (most recent call last):
File "C:\Users\kosmy\run_csv_pyfmi.py", line 29, in <module>
res = master_simulator.simulate(final_time = 86400, input = input_object)
File "src\pyfmi\master.pyx", line 1474, in pyfmi.master.Master.simulate
File "src\pyfmi\master.pyx", line 1369, in pyfmi.master.Master.specify_external_input
TypeError: tuple indices must be integers or slices, not tuple
Apparently, I do not give the correct format to the input, but I have not found an example demonstrating the correct format when using the Master.
Does anyone know how can I use the input in this case?
def load(t):
return 10, math.cos(t)
input_object = ([(electricity_network, 'P_load1'),(electricity_network, 'P_load2')],load)
another option is
data = np.transpose(np.vstack((t,u,v)))
input_object = (['InputVarI','InputVarP'],data)
error while creating a 2-tuple as input for model.simulate() of fmu model with pyfmi
Related
I am trying to calculate some climatic indexes using E-OBS daily data, and it requires some computation. I am using the xarray package for that. However, I am getting the following error message:
File "C:\Users\filip\anaconda3\envs\gis\lib\site-packages\xarray\backends\netCDF4_.py", line 486, in prepare_variable
nc4_var = self.ds.createVariable(
File "netCDF4\_netCDF4.pyx", line 2768, in netCDF4._netCDF4.Dataset.createVariable
File "netCDF4\_netCDF4.pyx", line 3857, in netCDF4._netCDF4.Variable.__init__
File "netCDF4\_netCDF4.pyx", line 1887, in netCDF4._netCDF4._ensure_nc_success
RuntimeError: NetCDF: Invalid argument
A minimum reproducible example would be:
import xarray as xr
prec = 'D:/inputs/eobs/rr_ens_mean_0.1deg_reg_v24.0e.nc'
ds_p = xr.open_dataset(prec)
pp = ds_p.resample({'time': 'YS'}).sum(min_count=1, keep_attrs=True)
pp_mean = pp.mean('time', keep_attrs=True)
temp = 'D:/inputs/eobs/tg_ens_mean_0.1deg_reg_v24.0e.nc'
ds_t = xr.open_dataset(temp)
tp = ds_t.resample({'time': 'YS'}).mean(keep_attrs=True)
tp_mean = tp.mean('time', keep_attrs=True)
ind = (pp_mean['rr'] / tp_mean['tg']) * 10
ind.to_netcdf('D:/outputs/eobs/ind.nc')
Could you try and see if you get the same error message? Am I doing something wrong?
I'm trying to query data with python in the owl file I created using the owlready library. But I get the following error. what would be the reason?
The code structure and received error are as follows.
from owlready2 import *
from urllib.request import urlopen
from rdflib.graph import Graph
onto = default_world.get_ontology("http://muratkilinc.com/ontologies/izmir.owl").load()
graph = default_world.as_rdflib_graph()
r = list(graph.query_owlready("""
PREFIX uni:<http://muratkilinc.com/ontologies/izmir.owl>
SELECT ?adi ?soyadi ?yas
WHERE
{
?turistler uni:yas ?yas.
?turistler uni:adi ?adi.
?turistler uni:soyadi ?soyadi.
FILTER(?yas > 35).
}"""))
results = default_world.as_rdflib_graph().query_owlready(r)
results = list(results)
print(results)
Error:
* Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available,
defaulting to slower Python implementation
Traceback (most recent call last):
File "c:/Users/BAUM-PC/Desktop/izmir/sparql.py", line 21, in <module>
results = list(results)
File "C:\Users\BAUM-PC\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\owlready2\rdflib_store.py", line 261, in query_owlready
File "C:\Users\BAUM-PC\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\rdflib\graph.py", line 1089, in query
query_object, initBindings, initNs, **kwargs))
File "C:\Users\BAUM-PC\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\rdflib\plugins\sparql\processor.py", line 74, in query
parsetree = parseQuery(strOrQuery)
File "C:\Users\BAUM-PC\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\rdflib\plugins\sparql\parser.py", line 1057, in parseQuery
q = expandUnicodeEscapes(q)
File "C:\Users\BAUM-PC\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\rdflib\plugins\sparql\parser.py", line 1048, in expandUnicodeEscapes
return expandUnicodeEscapes_re.sub(expand, q)
TypeError: expected string or bytes-like object
You have to skip second query and error message will skip
from owlready2 import *
from rdflib.graph import Graph
onto = default_world.get_ontology("http://muratkilinc.com/ontologies/izmir.owl").load()
graph = default_world.as_rdflib_graph()
r = list(graph.query_owlready("""
PREFIX uni:<http://muratkilinc.com/ontologies/izmir.owl>
SELECT ?adi ?soyadi ?yas
WHERE
{
?turistler uni:yas ?yas.
?turistler uni:adi ?adi.
?turistler uni:soyadi ?soyadi.
FILTER(?yas > 35).
}"""))
print(list(r))
It gives empty list - so it works without error message.
Empty list is different problem - with query, not with code - so you should ask new question.
I am trying to train a model for chatbot and created the following files.
Model configuration file config_spacy.json
{
"pipeline": "spacy_sklearn",
"path":"./models/nlu",
"data":"./data/data.json"
}`
Training file nlu_model.py
from rasa_nlu.training_data import load_data
from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.model import Trainer
from rasa_nlu import config
def train_nlu(data, config, model_dir):
training_data = load_data(data)
trainer = Trainer(RasaNLUModelConfig(config))
trainer.train(training_data)
model_directory = trainer.persist(model_dir, fixed_model_name = 'weathernlu')
if __name__ == '__main__':
train_nlu('./data/data.json','config_spacy.json','./models/nlu')
On running the file, I am getting the following error.
Traceback (most recent call last):
File "nlu_model.py", line 13, in
train_nlu('./data/data.json','config_spacy.json','./models/nlu')
File "nlu_model.py", line 8, in train_nlu
trainer = Trainer(RasaNLUModelConfig(config))
File "C:\anaconda3\lib\site-packages\rasa_nlu\config.py", line 103, in init
self.override(configuration_values)
File "C:\anaconda3\lib\site-packages\rasa_nlu\config.py", line 180, in override
self.dict.update(config)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
I searched a lot but I am unable to fix this error.
It could be a problem with the training data that you are using. Make sure there are a minimum of two intents with at least two examples in each so that the classifier can run correctly.
I think
trainer = Trainer(RasaNLUModelConfig(configs))
should be
trainer = Trainer(config.load(configs)), because load() contains read_yaml_file(filename) which you wont get by directly calling RasaNLUModelConfig(), correct me if I'm wrong, I'm also learning, :)
your final code should look like
def train_nlu(data, configs, model_dir):
training_data = load_data(data)
trainer = Trainer(config.load(configs))
trainer.train(training_data)
model_directory = trainer.persist(model_dir, fixed_model_name = 'weathernlu')
I'm using Zipline-1.1.1, Python3.4.6 to create a dynamic stock selector as follows:
from zipline.pipeline import Pipeline, engine
from zipline.pipeline.factors import AverageDollarVolume, Returns
def make_pipeline():
dollar_volume = AverageDollarVolume(window_length=1)
high_dollar_volume = dollar_volume.percentile_between(N, 100)
recent_returns = Returns(window_length=N, mask=high_dollar_volume)
low_returns = recent_returns.percentile_between(0, n)
high_returns = recent_returns.percentile_between(N, 100)
pipe_columns = {
'low_returns': low_returns,
'high_returns': high_returns,
'recent_returns': recent_returns,
'dollar_volume': dollar_volume
}
pipe_screen = (low_returns | high_returns)
pipe = Pipeline(columns=pipe_columns, screen=pipe_screen)
return pipe
I initialize a pipeline object with:
my_pipe = make_pipeline()
But when I try to populate the Pipeline, it fails with:
result = engine.PipelineEngine.run_pipeline(my_pipe, '2017-07-10', '2017-07-11')
Traceback (most recent call last):
File "<input>", line 1, in <module>
result = engine.PipelineEngine.run_pipeline(my_pipe, '2017-07-10', '2017-07-11')
TypeError: run_pipeline() missing 1 required positional argument: 'end_date'
I can't figure out what is wrong, any help is much appreciated.
If I understand correctly, you're using this library.
As far as I can see from that code, to be able to use run_pipeline method you have to instantiate on of pipeline engines before, e.g. SimplePipelineEngine. You need that because PipelineEngine is a class, even abstract class, not an object.
So you have to create an object of SimplePipelineEngine class and then call run_pipeline on it. You can do it this way:
your_engine = SimplePipelineEngine(get_loader=your_loader, calendar=your_calendar, asset_finder=your_asset_finder)
your_eninge.run_pipeline(my_pipe, '2017-07-10', '2017-07-11')
Of course you have to create your_loader etc. first.
Here is example of SimplePipelineEngine usage. I hope it will help.
I am trying to do some registration in python using the nipype package. It worked for basic registration:
from nipype.interfaces import fsl
from nipype.testing import example_data
flt = fsl.FLIRT(bins=640, cost_func='mutualinfo')
flt.inputs.in_file = 'myInput.img'
flt.inputs.reference = 'myReference.img'
flt.inputs.out_file = 'moved_subject.nii'
flt.inputs.out_matrix_file = 'subject_to_template.mat'
res = flt.run()
This yielded a successful registration. However, I am trying to apply this registration transformation to a non-brain image in the same space as the input MRI, using the outputted flt.inputs.out_matrix_file = 'subject_to_template.mat'.
I tried the following:
from nipype.interfaces import fsl
flt = fsl.FLIRT(bins=640, cost_func='mutualinfo')
flt.inputs.in_file = 'myNonBrainImage.img'
flt.inputs.reference = 'myReference.img'
flt.inputs.out_file = 'regNonBrain.nii'
flt.inputs.in_matrix_file = 'subject_to_template.mat'
flt.inputs.apply_xfm = True
res = flt.run()
Hoping that the flt.inputs.in_matrix_file and flt.inputs.apply_xfm = True flag would override standard registration and just use the matrix to register the additional image, but I got this error:
INFO:interface:stderr 2011-08-10T14:59:17.307116:Unrecognised option D
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/bin/python27/lib/python2.7/site-packages/nipype-0.4.1-py2.7.egg/nipype/interfaces/base.py", line 775, in run
runtime = self._run_interface(runtime)
File "/usr/bin/python27/lib/python2.7/site-packages/nipype-0.4.1-py2.7.egg/nipype/interfaces/base.py", line 1050, in _run_interface
self.raise_exception(runtime)
File "/usr/bin/python27/lib/python2.7/site-packages/nipype-0.4.1-py2.7.egg/nipype/interfaces/base.py", line 1027, in raise_exception
raise RuntimeError(message)
RuntimeError: Command:
flirt -in RF8869_3D_XRT_Dose_CT_A.img -ref clo010809T1Gd.img -out regDose.nii -omat /root/Desktop/Test Data/RF8869_3D_XRT_Dose_CT_A_flirt.mat -applyxfm -bins 640 -searchcost mutualinfo -init subject_to_template.mat
Standard output:
Standard error:
Unrecognised option D
Return code: 255
Interface FLIRT failed to run.
Do you know why and how can I solve this?
There is a space in directory/file name containing your images:
/root/Desktop/Test Data
Rename Test Data as Test_Data and it will work