import numpy import bpy import math import time filebase = 'Pegasus2500-7000_SN' # 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 level of the surface so we can keep all the planes at the # same level #medflux = 400.0*math.sqrt(numpy.median(data[:,3])+minf+1.0) medflux = numpy.nanmedian(data[:,3]) # Method 1 : 6.0 seconds #start = time.time() #for i in range(0,data.shape[0],100): # #print(i,data.shape[0]) # xp = data[i,0] # yp = data[i,1] # flux = data[i,3] # # bpy.ops.object.text_add() # ob=bpy.context.object # ob.data.body = str(flux) # ob.location = (xp,yp,0.0) #end = time.time() #print(end-start) # Method 2 - 4 seconds #start = time.time() #for i in range(0,data.shape[0],50): # #print(i,data.shape[0]) # xp = data[i,0] # yp = data[i,1] # # Convert flux to a 2 d.p. string, multiply by 100 to have nice values # zp = data[i,3] - medflux # flux = "{:.2f}".format(data[i,3]*100.0) # myFontCurve = bpy.data.curves.new(type="FONT",name="i") # myFontOb = bpy.data.objects.new("i",myFontCurve) # myFontOb.data.body = flux # myFontOb.location = (xp,yp,0.0) # bpy.context.scene.objects.link(myFontOb) # bpy.context.scene.update() # #end = time.time() #print(end-start) # Method 3 - correct offsets # We advance through the vertices by index. This means that when we get # to the top and start from the bottom, we must skip the next few columns. # We could advance in steps of one, but only actually create text every # stepth value. That way we'd be guaranteed to reach values in the toplist # and then we can increase the step by the correct amount fo skip the # required number of columns (sizey*step). toplist = [] for i in range(sizey-1,sizex*sizey,sizey): toplist.append(i) i = 0 step = 2 # 5 for really high resolution, 10 for speed obs = 0 start = time.time() while i < data.shape[0]: #print(i) # If index is an exact multiple of the step, create the text if (i % step) == 0: xp = data[i,0] yp = data[i,1] # Convert flux to a 2 d.p. string, multiply by 100 to have nice values zp = data[i,3]*3.0 #- medflux flux = "{:.0f}".format(data[i,3]*3.0) # Format to a 0 d.p. string myFontCurve = bpy.data.curves.new(type="FONT",name='text_'+str(i)) myFontOb = bpy.data.objects.new('text_'+str(i),myFontCurve) myFontOb.data.body = flux myFontOb.location = (xp,yp,zp) myFontOb.scale = ((3.0,3.0,3.0)) bpy.context.scene.objects.link(myFontOb) obs = obs + 1 print(i,obs) i = i + 1 if i in toplist: i = i + (sizey*step) bpy.context.scene.update() end = time.time() print(end-start)