import numpy import bpy import math # Create thin lines. Plot flux as a function of baseline, one line per # declination pixel. filebase = 'M33AndMilkyWay' # Get the current frame frame = bpy.context.scene.frame_current filename = filebase+'_'+str(frame).zfill(3)+'.txt' # Read in the data from the correct file data = numpy.genfromtxt(filename) sizex = int(numpy.max(data[:,0]))+1 sizey = int(numpy.max(data[:,1]))+1 # Get the minimum flux minf = abs(numpy.nanmin(data[:,3])) # Prevent extreme values causing thing to go bad. Square root has # lower contrast at higher values so severely negative values can # cause the noise to be appear highly suppressed. if minf >= 0.05: minf = 0.05 # Correct the flux values all at once (faster and makes them easier to # work with later) data[:,3] = 200.0*numpy.sqrt(data[:,3]+minf) # Get the median flux level and apply it medflux = numpy.nanmedian(data[:,3]) data[:,3] = data[:,3] - medflux # Create one line mesh for each y (declination) pixel for y in range(0,sizey): print(y) me = bpy.data.meshes.new('Line_'+str(y)) # Create the vertices verts = [] for x in range(0,sizex): verts.append((x,y,0)) # Now fill in the faces j = 0 faces = [] while j < sizey: faces.append([j,j+1]) j = j + 1 # Create the mesh. Syntax is verts list, edge list, face list me.from_pydata(verts, [], faces) # Create the object obj = bpy.data.objects.new('Line_'+str(y), me) # Now we can move the vertex positions mesh = obj.data i = 0 vindex = 0 while i < data.shape[0]: yp = data[i,1] if (yp == y): xp = data[i,0] flux = data[i,3] mesh.vertices[vindex].co.x = xp mesh.vertices[vindex].co.y = yp mesh.vertices[vindex].co.z = flux vindex = vindex + 1 i = i + 1 #print(vindex) # Add the object to the current scene scene = bpy.context.scene scene.objects.link(obj)