get the delta of the nearest experation ATM option - thinkscript

i wanna display the delta of call and put options for nearest experation of the underlaying symbol thats open in the chart.
def atmCallOption = GetATMOption(GetUnderlyingSymbol(), GetNextExpirationOption(),
OptionClass.CALL);
def atmPUTOption = GetATMOption(GetUnderlyingSymbol(), GetNextExpirationOption(),
OptionClass.PUT);
plot callDelta = Delta(atmCallOption);
plot putDelta = Delta(atmPUTOption);

Related

How can I retrieve my raster data from PostGIS database in Django project and calculate my value of the raster at Given location

I have the raster data stored in my database. I want to get that raster data back in my Django and try to find the value at that certain pixel.
My code
class dataviewView(views.View):
def post(self, request):
data = json.loads(request.body)
name = data['name']
lat = data['lat']
long = data['long']
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint(lat,long)
if ndvimodel.objects.filter(name = name).exists():
p1 = ndvimodel.objects.all()
for raster_data in p1:
rasterdata = raster_data.rast
print(type(rasterdata))
But I am unable to get that raster content. How can I solve these issues
Access to raster.bands[0].data() will return numpy array from the first band, then access to raster.geotransform. After yo can use
mx, my = geom.GetX(), geom.GetY()
px = int((mx - gt[0]) / gt[1])
py = int((my - gt[3]) / gt[5])
intval = raster.bands[0].data()[px, py]

Rotation between two frame similar to interactive markers

What do I want to do?
I work with a Franka Emika Panda and use the "cartesian_impedance_example_controller" with its "equilibrium_pose" topic to move the panda arm.
I want to use a command to rotate the arm along its axes of the "panda_rightfinger" joint axes (axis of interactive marker seen in picture). The roation only happens around the axis and happens by pressing a specific button.
(Right finger frame with the interactive marker around it and panda_link0 frame on the left)
How do I do it?
The rotation quaternion gets created by a function that uses following script:
axis = {
"roll": 0,
"pitch": 0,
"yaw": 0
}
def pyr_producer(self, gesture_msg):
global axis
axis[gesture_msg.cls] += 1 * 0.01
return list(axis.values())
def get_quaternion(self, gesture_msg):
roll, pitch, yaw = pyr_producer(gesture_msg)
q_rot = tf.transformations.quaternion_from_euler(roll, pitch, yaw)
return Quaternion(*q_rot)
Afterwards, this rotation quaterion will be used by another script and gets published to the corresponding equilibrium_pose topic.
This part of the script calculates the rotation:
eq_pose: the new pose that will be used for the topic
current_goal_pose: the pose that contains the actual rotation
last_goal_pose: the pose that contains the last rotation
eq_pose.pose.position = last_goal_pose.pose.position
eq_pose.pose.orientation = orientation_producer.get_quaternion(goal_pose.gesture)
# calculate the relative quaternion from the last pose to the new pose
# (see http://wiki.ros.org/tf2/Tutorials/Quaternions)
# add relative rotation quaternion to the new equilibrium orientation by multiplying
q_equilibrium = [eq_pose.pose.orientation.x, eq_pose.pose.orientation.y,
eq_pose.pose.orientation.z, eq_pose.pose.orientation.w]
q_2 = [current_goal_pose.pose.orientation.x, current_goal_pose.pose.orientation.y,
current_goal_pose.pose.orientation.z, current_goal_pose.pose.orientation.w]
# Negate w value for inverse
q_1_inv = [last_goal_pose.pose.orientation.x, last_goal_pose.pose.orientation.y,
last_goal_pose.pose.orientation.z, (-1)*last_goal_pose.pose.orientation.w]
q_relative = tf.transformations.quaternion_multiply(q_2, q_1_inv)
q_equilibrium = tf.transformations.quaternion_multiply(q_relative, q_equilibrium)
eq_pose.pose.orientation.x = q_equilibrium[0]
eq_pose.pose.orientation.y = q_equilibrium[1]
eq_pose.pose.orientation.z = q_equilibrium[2]
eq_pose.pose.orientation.w = q_equilibrium[3]
# update last pose
last_goal_pose = current_goal_pose
# Only publish poses when there is an interaction
eq_publisher.publish(eq_pose)
The eq_pose gets generated by this part:
def franka_state_callback(msg):
global eq_pose
global initial_eq_pose_found
# the initial pose has to be retrieved only once
if initial_eq_pose_found:
return
initial_quaternion = \
tf.transformations.quaternion_from_matrix(
np.transpose(np.reshape(msg.O_T_EE,
(4, 4))))
initial_quaternion = initial_quaternion / np.linalg.norm(initial_quaternion)
eq_pose.pose.orientation.x = initial_quaternion[0]
eq_pose.pose.orientation.y = initial_quaternion[1]
eq_pose.pose.orientation.z = initial_quaternion[2]
eq_pose.pose.orientation.w = initial_quaternion[3]
eq_pose.pose.position.x = msg.O_T_EE[12]
eq_pose.pose.position.y = msg.O_T_EE[13]
eq_pose.pose.position.z = msg.O_T_EE[14]
initial_eq_pose_found = True
rospy.loginfo("Initial panda pose found: " + str(initial_eq_pose_found))
rospy.loginfo("Initial panda pose: " + str(eq_pose))
if __name__ == "__main__":
state_sub = rospy.Subscriber("/panda/franka_state_controller/franka_states", FrankaState, franka_state_callback)
while not initial_eq_pose_found:
rospy.sleep(1)
state_sub.unregister()
What actually happens
The rotation itself works, but only happens around the "panda_link0" axis, which is the fixed position of the panda foot. The rotation should be the same like the one around the interactive marker in the interactive marker example.
Final Question
So I want to know, how to calculate the quaternions for this rotation?
I am quite new to robotics and hope my description was clear.
Okay, I just found my mistake, as expected, it was very easy:
The multiplication of quaternions is not cummutative. With respect to that, I just had to change the calculation of the quaternion from
q_equilibrium = tf.transformations.quaternion_multiply(q_relative, q_equilibrium)
to
q_equilibrium = tf.transformations.quaternion_multiply(q_equilibrium,q_relative)

Draggable point in matplotlib - How to retrieve point coordinates

I would like to be able to move a point (matplotlib.patches.Ellipse) along a vertical line. To do so, I'm calling the Dragable rectangle class (http://matplotlib.org/1.3.1/users/event_handling.html) inside a PySide QtGui.QWidget.
The dragging of my ellipse works fine, but I'm stuck in how to retrieve the final y-coordinate of the ellipse when I release the mouse button (I want to have a QLabel next to the plot that contains this y-coordinate). From on_release I have its final position:
def on_release(self, event):
if DraggablePoint.lock is not self:
return
self.point.newYcoordinate = self.point.center[1]
self.press = None
DraggablePoint.lock = None
# draw everything but the selected point and store the pixel buffer
canvas = self.point.figure.canvas
axes = self.point.axes
self.point.set_animated(True)
canvas.draw()
self.background = canvas.copy_from_bbox(self.point.axes.bbox)
# now redraw just the point
axes.draw_artist(self.point)
# and blit just the redrawn area
canvas.blit(axes.bbox)
but how can I connect this to the text of my QLabel (and obtain that this label is updated each time the ellipse is moved)?
self.FlexibleValue = patches.Ellipse(xy=(0.5, 0.5), width=0.2, height=0.2, edgecolor='r', facecolor='r', lw=2)
self.axesResp.add_patch(self.FlexibleValue)
self.dragValue = DraggablePoint(self.FlexibleValue)
self.dragValue.connect()
by adding a signal as tcaswell suggested:
def on_release(self, event):
...
self.signal.updatedSignal.emit(str(self.point.newYcoordinate))
and then retrieving the y-coordinate:
self.dragValue.signal.updatedSignal.connect(self.updatedValue)
with:
def updatedValue(self, newValue):
self.labelValue.setText(newValue)
and:
class UpdatedSignal(QtCore.QObject):
updatedSignal = QtCore.Signal(str)

Aligning Label in Frame Tkinter

I am new to Python and even newer to Tkinter.
I am currently practicing how to use Frames and Labels and
the problem I am encountering is, when I put Labels on a frame with some buttons next to each label,
the alignment is not good to look at.
Here is the code:
from Tkinter import *
class GUI():
def __init__(self):
self.namelist = ["Mark","Anna","Jason","Lenna","Leo","Zucharich","Robinson","AReallyLongNameThatMightExist"]
self.canvas = Canvas(width=1200,height=700)
self.canvas.pack(expand=YES,fill=BOTH)
def Friends(self):
controlframe = Frame(self.canvas)
controlframe.place(x=600,y=300)
#Frame for showing names of friends
for x in self.namelist:
frame = Frame(controlframe)
frame.pack()
Name = Label(frame,text="%s "%x).pack(side=LEFT)
chatButton = Button(frame,text="Chat").pack(side=LEFT)
delButton = Button(frame,text="Delete").pack(side=LEFT)
setcloseButton = Button(frame,text="Set Close").pack(side=LEFT)
setgroupButton = Button(frame,text="Set Group").pack(side=LEFT)
mainloop()
GUI = GUI()
GUI.Friends()
What should I do so that the alignment of the Label(=name) and the button is equal to the other ones so that they will form a shape of a rectangle and not some zigzag?
It is almost always better in Tk to use the grid geometry manager. It is much more flexible once you come to understand how it works. Converting your example to use grid solves your problem as shown below but you should experiment with it a bit. Try removing the 'sticky="W"' from the label for instance and see that the centering of the widgets within the row or column can be controlled. To get your frame responding to resizes sensibly you should investigate the columnconfigure and rowconfigure options for the grid geometry management as well.
from Tkinter import *
class GUI():
def __init__(self):
self.namelist = ["Mark","Anna","Jason","Lenna",
"Leo","Zucharich","Robinson",
"AReallyLongNameThatMightExist"]
self.canvas = Canvas(width=1200,height=700)
self.canvas.pack(expand=YES,fill=BOTH)
def Friends(self):
frame = Frame(self.canvas)
frame.place(x=600,y=300)
#Frame for showing names of friends
row = 0
for x in self.namelist:
label = Label(frame,text="%s "%x)
chatButton = Button(frame,text="Chat")
delButton = Button(frame,text="Delete")
setcloseButton = Button(frame,text="Set Close")
setgroupButton = Button(frame,text="Set Group")
label.grid(row=row, column=0, sticky="W")
chatButton.grid(row=row, column=1)
delButton.grid(row=row, column=2)
setcloseButton.grid(row=row, column=3)
setgroupButton.grid(row=row, column=4)
row = row + 1
mainloop()
GUI = GUI()
GUI.Friends()

How do I label units in a ReportLab Lineplot?

Can anyone tell me the attribute to set to label the units on a LinePlot in ReportLab? Also, if you know how to set a title, that would be ultimately super helpful.
drawing = Drawing(50,50)
data = [(tuple(zip(matfile['chan'].item([6],matfile['chan'].item()[7].item()[0])))]
lp = LinePlot()
lp.data = data
lp.????? = (str(matfile['chan'].item()[3]), str(matfile['chan'].item()[2]))
drawing.add(lp)
elements.append(drawing)
This is actually going to be inside a loop - I load a .mat file and there's about 50 channels, and I am going to plot almost all of them. Separately. But first I need to get a handle on assigning the labels (title text, which will be the same as the channel, then the units for the axes...) X Axis label should always be 'Seconds', Y axis label will vary... sometimes a %, sometimes a pressure or temperature or speed, etc.
I have no idea how to do THAT, but I ended up using framing tables and I cobbled together something.I did not succeed in rotating the text for the y axis label.
for channel in channels:
drawing = Drawing(0,0)
data = [(tuple(zip(matfile[channel].item()[6],matfile[channel].item()[7].item()[0])))]
lp = LinePlot()
lp.data = data
lp.width = 6*inch
lp.height = 3.25*inch
stylesheet = getSampleStyleSheet()
y_label = Paragraph(str(matfile[channel].item()[2]), stylesheet['Normal'])
drawing.add(lp)
plot_table = [['',str(channel)],
[y_label, drawing],
['',matfile[channel].item()[3]]]
t_framing_table = Table(plot_table)
t_framing_table._argH[1] = lp.height + .5*inch
t_framing_table._argW[1] = lp.width
elements.append(t_framing_table)
if break_page:
elements.append(PageBreak())
break_page = False
else:
break_page = True