Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168699
Image: ubuntu2004
#### Get linear power ################## #lets make another column, and have it be the linear sum of the vertical and horizontal power columns import numpy as np log10 = lambda x: float(np.log10([x])) for row in my_data: total = 10*log10(10^(row[2]/10)+10^(row[3]/10)) row.append(total) ######################################## #### Adjust scale ###################### #we can't plot log numbers directly, because some of them are negative. #so add a constant to the data, determined by the data range vmax = max([row[2] for row in my_data]) vmin = min([row[2] for row in my_data]) hmax = max([row[3] for row in my_data]) hmin = min([row[3] for row in my_data]) tmax = max([row[4] for row in my_data]) tmin = min([row[4] for row in my_data]) allmax = max([vmax, hmax, tmax]) allmin = min([vmin, hmin, tmin]) #print([vmax, vmin, hmax, hmin, tmax, tmin]) #print([allmax, allmin]) adjusted_data = [] #print my_data for row in my_data: row = row[:] #make a new object - don't modify the original my_data #here we increase the data such that it's lowest point is 0 row[2] += -vmin row[3] += -hmin row[4] += -tmin #away from the origin by 10% of the total range of the data row[2] += (vmax - vmin)*0.1 row[3] += (hmax - hmin)*0.1 row[4] += (tmax - tmin)*0.1 adjusted_data.append(row) #print row #print adjusted_data ######################################## ### Convert to Cartesian ############### #convert to Cartesian, and make a list of 3-tuples pi = np.pi sin = np.sin cos = np.cos #convert spherical (in degrees) to cartesian def s2c(theta, phi, r): theta = theta*pi/180 phi = phi*pi/180 x = r*sin(theta)*cos(phi) y = r*sin(theta)*sin(phi) z = r*cos(theta) return (x,y,z) tuples = [] tuples_cart = [] for row in my_data: tuples.append((row[0],row[1],row[4])) tuples_cart.append(s2c(row[0],row[1],row[4])) ######################################## #### Sort into hemispheres ############# #now we must sort the data in the upper and lower hemispheres upper = [] lower = [] for item in tuples_cart: if item[2] >= 0: upper.append(item) else: lower.append(item) ########################################
print 'Here is the data plotted with elevation and azimuth as x and y: ' list_plot3d(tuples).show()
Here is the data plotted with elevation and azimuth as x and y:
print 'Here is the same data transformed into cartesian coordinates. The points seem correct in space, but no surface is present.' points(tuples_cart).show()
Here is the same data transformed into cartesian coordinates. The points seem correct in space, but no surface is present.
print 'Lets try to plot those points with list_plot3d. (gives error)' list_plot3d(tuples_cart).show()
Lets try to plot those points with list_plot3d. (gives error)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_12.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cHJpbnQgJ0xldHMgdHJ5IHRvIHBsb3QgdGhvc2UgcG9pbnRzIHdpdGggbGlzdF9wbG90M2QuIChnaXZlcyBlcnJvciknCmxpc3RfcGxvdDNkKHR1cGxlc19jYXJ0KS5zaG93KCk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpdnw1R5/___code___.py", line 3, in <module> exec compile(u'list_plot3d(tuples_cart).show()' + '\n', '', 'single') File "", line 1, in <module> File "/sagenb/sage_install/sage-4.7.2/local/lib/python2.6/site-packages/sage/plot/plot3d/list_plot3d.py", line 191, in list_plot3d return list_plot3d_tuples(v,interpolation_type,texture=texture, **kwds) File "/sagenb/sage_install/sage-4.7.2/local/lib/python2.6/site-packages/sage/plot/plot3d/list_plot3d.py", line 249, in list_plot3d_tuples raise ValueError, "Two points with same x,y coordinates and different z coordinates were given. Interpolation cannot handle this." ValueError: Two points with same x,y coordinates and different z coordinates were given. Interpolation cannot handle this.
print 'Lets try to plot only the lower hemisphere. (doesnt look right)' list_plot3d(lower)
Lets try to plot only the lower hemisphere. (doesnt look right)
print 'Lets try a points plot of the lower hemisphere.' points(lower)
Lets try a points plot of the lower hemisphere.