I currently am trying to use
paraview.simple.Histogram(Input, params)
as
paraview.simple.Histogram(q, BinCount = 30)
in the shell where q is a variable data set from my "out.e" ExodusII file. I'm getting the error
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'q' is not defined
I've tried to search the literature on python shell scripting in Paraview but it seems to be eluding me. I know this is a quick fix. Thanks
Try this instead:
Histogram(SelectInputArray="q", BinCount=30)
This assumes you currently have the reader as the active object in the Pipeline browser.
I was able to answer this problem using the following.
outset = Reader(FileName=['/dir/out.e'])
and for the Histogram
histogram1_1 = Histogram(Input=outset)
histogram1_1.SelectInputArray = ['CELLS', 'q']
histogram1_1.BinCount = 30
Note for anyone who comes into this issue, the TRACE option in the Python Shell will build a script for you when you do anything in the GUI.
Related
I'm developing Python scripts for the automated grading of assignments using CanvasAPI, an API wrapper in Python for the Canvas learning management platform. In studying the documentation, I can successfully issue curl commands in Python for a few parameters. For example, this conversion below is for grading a single submission:
Curl command per the Canvas API docs:
PUT /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id
with
submission[posted_grade]
Turns into this via the CanvasAPI Python wrapper:
edit(submission={'posted_grade': 'grade'})
Where I'm running into difficulties is the more complex parameter for rubrics. Using the same PUT request as above, the syntax in the documentation is as follows:
rubric_assessment[criterion_id][points]
For which I have:
edit(rubric_assessment[{'id': 'criterion_9980'},{'points', '37'}])
However, I get the following error:
Traceback (most recent call last):
File "C:\Users\danie\AppData\Local\Temp\atom_script_tempfiles\2021528-29488-1eagfyw.k8hw", line 39, in <module>
submission = assignment.get_submission(10370)
File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\site-packages\canvasapi\assignment.py", line 203, in get_submission
response = self._requester.request(
File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\site-packages\canvasapi\requester.py", line 255, in request
raise ResourceDoesNotExist("Not Found")
canvasapi.exceptions.ResourceDoesNotExist: Not Found
I suspect I'm fouling up the syntax somewhere along the line. Any suggestions? All help much appreciated.
I'm trying to code a Slack-Bot which is asking for lunch and is taking orders for lunch.
I'm working with this tutorial.
My problem is: I'm trying to run my script in CMD (yes, windows!) but I receive this error:
C:\Users\Dave\PycharmProjects\lunchbot>python lunchbot.py
Traceback (most recent call last):
File "lunchbot.py", line 167, in <module>
if slack_client.rtm_connect(with_team_state=False):
TypeError: rtm_connect() got an unexpected keyword argument 'with_team_state'
This is the part of the code that's not working correctly:
if __name__ == "__main__":
if slack_client.rtm_connect(with_team_state=False):
print("Lunchbot is ready to go!")
starterbot_id = slack_client.api_call("auth.test")["user_id"]
while True:
command, channel = parse_bot_commands(slack_client.rtm_read())
if command:
handle_command(command, channel)
time.sleep(RTM_READ_DELAY)
else:
print("No connection.")
What actually confuses me is every time I'm trying to run this code in my IDE everything is fine. Does anybody have an idea of what could be wrong?
There is a known issue with the websocket-client and Slack. It's buggy and has been a problem for some time now. I wonder if your Pycharm environment is pointing to a different version and hence why it is working.
I would try to force the value of the websocket-client with a known working version.
websocket-client==0.40.0 for example:
I have a pyROOT script where I use TChain::AddFriend to combine two TTrees:
from ROOT import TFile, gDirectory
myfile = TFile("e.root")
mychain = gDirectory.Get("elec_gen")
entries = mychain.GetEntriesFast()
friendFile = TFile("mu.root")
friendChain = gDirectory.Get("muon_gen")
mychain.AddFriend("muon_gen")
elec_gen_evtNum = mychain.evtNum
muon_gen_evtNum = mychain.muon_gen.evtNum
When I run this I get:
$ python friendTest.py
Traceback (most recent call last):
File "friendTest.py", line 12, in <module>
muon_gen_evtNum = mychain.muon_gen.evtNum
AttributeError: 'TTree' object has no attribute 'muon_gen'
With the last line commented-out it runs fine. So it appears I am not accessing the leaves of the friend tree (muon_gen) correctly. How do I access them?
I also tried combining the TTrees using:
mychain.AddFriend("muon_gen","mu.root")
but this produces the same error.
I had a similar question, and found an answer (well, workaround) on the ROOT forum:
https://root-forum.cern.ch/t/accessing-a-friend-ttree-using-pyroot/25513
although no solution was presented using TFriend.
Instead, RobS found a workaround for his own question of just loading the two TFile and TTree separately and running LoadTree() and GetEvent() on each TChain
I read in the howto documentation to install Trigger, but when I test in python environment, I get the error below:
>>> from trigger.netdevices import NetDevices
>>> nd = NetDevices()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 913, in __init__
with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 767, in __init__
production_only=production_only, with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 83, in _populate
# device_data = _munge_source_data(data_source=data_source)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 73, in _munge_source_data
# return loader.load_metadata(path, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/loader.py", line 163, in load_metadata
raise RuntimeError('No data loaders succeeded. Tried: %r' % tried)
RuntimeError: No data loaders succeeded. Tried: [<trigger.netdevices.loaders.filesystem.XMLLoader object at 0x7f550a1ed350>, <trigger.netdevices.loaders.filesystem.JSONLoader object at 0x7f550a1ed210>, <trigger.netdevices.loaders.filesystem.SQLiteLoader object at 0x7f550a1ed250>, <trigger.netdevices.loaders.filesystem.CSVLoader object at 0x7f550a1ed290>, <trigger.netdevices.loaders.filesystem.RancidLoader object at 0x7f550a1ed550>]
Does anyone have some idea how to fix it?
The NetDevices constructor is apparently trying to find a "metadata source" that isn't there.
Firstly, you need to define the metadata. Second, your code should handle the exception where none is found.
I'm the lead developer of Trigger. Check out the the doc Working with NetDevices. It is probably what you were missing. We've done some work recently to improve the quality of the setup/install docs, and I hope that this is more clear now!
If you want to get started super quickly, you can feed Trigger a CSV-formatted NetDevices file, like so:
test1-abc.net.example.com,juniper
test2-abc.net.example.com,cisco
Just put that in a file, e.g. /tmp/netdevices.csv and then set the NETDEVICES_SOURCE environment variable:
export NETDEVICES_SOURCE=/tmp/netdevices.csv
And then fire up python and continue on with your examples and you should be good to go!
I found that the default of /etc/trigger/netdevices.xml wasn't listed in the setup instructions. It did indicate to copy from the trigger source folder:
cp conf/netdevices.json /etc/trigger/netdevices.json
But, I didn't see how to specify this instead of the default NETDEVICES_SOURCE on the installation page. But, as soon as I had a file that NETDEVICES_SOURCE pointed to in my /etc/trigger folder, it worked.
I recommend this to get the verifying functionality examples to work right away with minimal fuss:
cp conf/netdevices.xml /etc/trigger/netdevices.xml
Using Ubuntu 14.04 with Python 2.7.3
Basically, I want to read the CPU temperature with Python. Please explain in layman's terms as I have never done this on Windows before nor have I had to work with wmi.
This is what I have at the moment:
import wmi
w = wmi.WMI(namespace="root\wmi")
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
print temperature_info.CurrentTemperature
(I got this code from this thread: Accessing CPU temperature in python)
However, on running the script, I get this error:
Traceback (most recent call last):
File "C:\Users\Ryan\Desktop\SerialSystemMonitor", line 4, in <module>
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
File "C:\Python27\lib\site-packages\wmi.py", line 819, in query
handle_com_error ()
File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
x_wmi: <x_wmi: Unexpected COM Error (-2147217396, 'OLE error 0x8004100c', None, None)>
What can I do to get this to work?
According to the MSDN page on WMI Error Constants, the error you have received is:
WBEM_E_NOT_SUPPORTED
2147749900 (0x8004100C)
Feature or operation is not supported.
Presumably, then, your CPU does not provide temperature information through WMI. If your CPU doesn't expose this information, you're probably out of luck, at least as far as a straightforward solution in Python goes.
I assume you've tried the other option given in the answer you linked, using Win32_TemperatureProbe(); if you haven't, try it.
Just execute as Admin. It's work for me.