How to create paraview slice - paraview

I want to make Paraview slice in normal z direction (0,0,1) in python shell.
paraview.simple.Slice(*input, **params)
what should be input in paraview.simple.Slice to get a slice at particular location

Here's an example script:
from paraview import simple as pvs
dataProducer = pvs.Wavelet()
slicer = pvs.Slice(Input=dataProducer, SliceType="Plane")
slicer.SliceType.Origin = [0, 0, 0]
slicer.SliceType.Normal = [0, 0, 1]
# To render the result, do this:
Show(slicer)
Render()
You can also you Tools | Start Trace to generate Python trace for actions you perform in the UI.

Related

Blender 2.77: How to I create a path for an object to follow with latitude, longitude, & altitude (in feet) coordinates in csv format?

I have a csv of lat., long., and altitude data from flight 24.
I want to make a path for an object to follow in blender, but the path has to be generated from the above data.
I also want to import a 3D-model of the place where the aircraft flew over.
The problem is I need to use blender 2.77 because the another add-on I want to use only supports v. 2.77. Add-ons like blender-osm and blender-gis only supports the most up to date version of blender.
Lets say you have x y z coordinates for each point of a path then you can easily able to create a path curve using bpy. Here is an example:
import bpy
def create_curve(coords_list):
crv = bpy.data.curves.new('crv', 'CURVE')
crv.dimensions = '3D'
spline = crv.splines.new(type='NURBS')
spline.points.add(len(coords_list) - 1)
for p, new_co in zip(spline.points, coords_list):
p.co = (new_co + [1.0])
obj = bpy.data.objects.new('object_name', crv)
bpy.data.scenes[0].collection.objects.link(obj)
cords_list = [
[0,0,0],
[1, 0, 1],
[2, 0, -1],
[0, 0, 2]
]
create_curve(cords_list)
Output:

Fail to use Screen('Preference') in PsychToolbox for MATLAB

In PsychToolbox for MATLAB, I try to put
Screen('Preference', 'SyncTestSettings', maxStddev = 0.001, minSamples = 50, maxDeviation = 0.1, maxDuration = 5);
in the MATLAB command window, but it keeps to tell me:
Error in function Preference: Extra input argument described
Error using Screen
Usage:
oldPreferenceValue = Screen('Preference', preferenceName,
[newPreferenceValue])
I was confused. The document given by PsychToolbox is:
[maxStddev, minSamples, maxDeviation, maxDuration] = Screen('Preference',
'SyncTestSettings' [, maxStddev=0.001 secs][, minSamples=50][,
maxDeviation=0.1][, maxDuration=5 secs]);
Is there anything I misunderstand the document? And what is the correct command?
(My MATLAB is R2021a, and PsychToolbox is 3.0.17.12)
What you are trying to accomplish can be done with the following command:
Screen('Preference', 'SyncTestSettings', 0.001, 50, 0.1, 5)
You have to provide these values in the correct order. If you wanted to skip over a value (i.e., leave it as is) then use
[]
like so:
Screen('Preference', 'SyncTestSettings', 0.001, [], 0.1, 5)

Basemap plus 3d graph

Hello Stackoverflow forks,
I'm a enthusiastic python learner.
I have studied python to visualiza my personal project about population density.
I have gone through tutorials about matplotlib and basemap in python.
I came across with the idea about
mapping my 3dimensional graph on top of the basemap which allows me to use geographycal coordinate information.
Can anyone let me know how I could use basemap as a base plane for the 3dimensional graph?
Please let me know which tutorial or references I could go with for developing this.
Best,
Thank you always Stackoverflow forks.
The basemap documentation has a small section on 3D plotting. Here's a simple script to get you started:
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
plt.close('all')
fig = plt.figure()
ax = fig.gca(projection='3d')
extent = [-127, -65, 25, 51]
# make the map and axis.
m = Basemap(llcrnrlon=extent[0], llcrnrlat=extent[2],
urcrnrlon=extent[1], urcrnrlat=extent[3],
projection='cyl', resolution='l', fix_aspect=False, ax=ax)
ax.add_collection3d(m.drawcoastlines(linewidth=0.25))
ax.add_collection3d(m.drawcountries(linewidth=0.25))
ax.add_collection3d(m.drawstates(linewidth=0.25))
ax.view_init(azim = 230, elev = 15)
ax.set_xlabel(u'Longitude (°E)', labelpad=10)
ax.set_ylabel(u'Latitude (°N)', labelpad=10)
ax.set_zlabel(u'Altitude (ft)', labelpad=20)
# values to plot - change as needed. Plots 2 dots, one at elevation 0 and another 100.
# also draws a line between the two.
x, y = m(-85.4808, 32.6099)
ax.plot3D([x, x], [y, y], [0, 100], color = 'green', lw = 0.5)
ax.scatter3D(x, y, 100, s = 5, c = 'k', zorder = 4)
ax.scatter3D(x, y, 0, s = 2, c = 'k', zorder = 4)
ax.set_zlim(0., 400.)
plt.show()

Turn on specific LED using NeoPixel module for Espruino?

I am trying to turn on a specific LED using the NeoPixel module. How it works is really easy: Parse it a 2D array of RGB colors. Here's an example:
require("neopixel").write(NodeMCU.B2, [[255, 0, 0], [0, 255, 0], [0, 0, 255]]);
That will turn on the first three LEDs with red, green, and blue. I want to have a function, where I can do something like:
function single(number, color) {
require("neopixel").write(NodeMCU.B2, number, color);
}
single(0, [255, 0, 0]);
single(1, [0, 255, 0]);
single(2, [0, 0, 255]);
Which would do the exact same as above. Now you might ask: Why would you want that? Well:
I want it to remember the last "configuration" of LEDs, so I can update it over time
If I want to turn off all my 100+ LEDs and just turn on the last few (or the ones in the middle), I wouldn't have to parse the write() function 100+ LEDs, where most of them are black
Is something like that possible, or would I have to do some magic in order to remember the last LED configuration?
Yes, totally - it's worth looking at the neopixel docs at http://www.espruino.com/WS2811 as they suggest you use an array to
store the current state.
Once you have that array - called arr here - you can use the .set method to set the 3 elements at the right position (3x the number, because RGB), and then can resend the whole array.
var arr = new Uint8ClampedArray(NUM_OF_LEDS*3);
function single(number, color) {
arr.set(color, number*3);
require("neopixel").write(NodeMCU.B2, arr);
}

Node attributes in for loops, NetworkX

I'm trying to model voting dynamics on networks, and would like to be able to create a graph in NetworkX where I can iterate the voter process on nodes, having their colour change corresponding to their vote 'labels'.
I've managed to get this code to let me see the attributes for each node, but how do I go about using those in a for loop to designate colour?
H = nx.Graph()
H.add_node(1,vote='labour')
H.add_node(2,vote='labour')
H.add_node(3,vote='conservative')
h=nx.get_node_attributes(H,'vote')
h.items()
Gives me the result:
[(1, 'labour'), (2, 'labour'), (3, 'conservative')]
I've got a for loop to do this type of colour coding based on the node number as follows, but haven't managed to make it work for my 'vote' status.
S=nx.star_graph(10)
colour_map=[]
for node in S:
if node % 2 ==0:
colour_map.append('blue')
else: colour_map.append('yellow')
nx.draw(S, node_color = colour_map,with_labels = True)
plt.show()
You can iterate the node attributes with H.nodes(data=True) which returns the node name and the node attributes in a dictionary. Here's a full example using your graph.
import networkx as nx
import matplotlib.pyplot as plt
H = nx.Graph()
H.add_node(1, vote='labour')
H.add_node(2, vote='labour')
H.add_node(3, vote='conservative')
color_map = []
for node, data in H.nodes(data=True):
if data['vote'] == 'labour':
color_map.append(0.25) # blue color
elif data['vote'] == 'conservative':
color_map.append(0.7) # yellow color
nx.draw(H, vmin=0, vmax=1, cmap=plt.cm.jet, node_color=color_map, with_labels=True)
plt.show()
This code will draw a different layout of nodes each time you run it (some layouts, as e.g. draw_spring, are available here).
Regarding colors, I use 0.25 for blue and 0.7 for yellow. Note that I use the jet matplotlib colormap and that I set vmin=0 and vmax=1 so that the color values are absolute (and not relative to eachother).
Output of the code above:
UPDATE:
I wasn't aware that you could simply use color names in matplotlib. Here's the updated for loop:
for node, data in H.nodes(data=True):
if data['vote'] == 'labour':
color_map.append("blue")
elif data['vote'] == 'conservative':
color_map.append("yellow")
And the updated draw command:
nx.draw(H, node_color=color_map, with_labels=True)
Note that this way you get different shades of blue and yellow than in the image above.