diff --git a/blackbody.py b/blackbody.py index eb37287..ed6f56e 100644 --- a/blackbody.py +++ b/blackbody.py @@ -2,6 +2,7 @@ import numpy as np import scipy.misc as spm +import imageio as imio #accretion disk log temperature profile (R^{-3/4}) LOGSHIFT = 0.823959216501 # 3/4 log(3) @@ -25,7 +26,7 @@ def intensity(T): return 1./( np.exp(29622.4 / T.clip(1.)) - 1) -ramp = spm.imread('data/colourtemp.jpg')[0,:,:]/255. +ramp = imio.imread('data/colourtemp.jpg')[0,:,:]/255. rampsz = ramp.shape[0] diff --git a/tracer.py b/tracer.py index 59a3bb2..773739f 100755 --- a/tracer.py +++ b/tracer.py @@ -4,6 +4,7 @@ import matplotlib.pyplot as plt import scipy.ndimage as ndim import scipy.misc as spm +import imageio as imio import random,sys,time,os import datetime @@ -278,9 +279,9 @@ figure = plt.gcf() ax = plt.gca() - + ax.cla() - + gscale = 1.1*np.linalg.norm(CAMERA_POS) ax.set_xlim((-gscale,gscale)) ax.set_ylim((-gscale,gscale)) @@ -290,8 +291,8 @@ ax.plot([CAMERA_POS[2],LOOKAT[2]] , [CAMERA_POS[0],LOOKAT[0]] , color='0.05', linestyle='-') - - + + figure.gca().add_artist(g_diskout) figure.gca().add_artist(g_diskin) figure.gca().add_artist(g_horizon) @@ -313,7 +314,7 @@ def rgbtosrgb(arr): arr[mask] **= 1/2.4 arr[mask] *= 1.055 arr[mask] -= 0.055 - arr[-mask] *= 12.92 + arr[~mask] *= 12.92 # convert from srgb to linear rgb @@ -323,12 +324,12 @@ def srgbtorgb(arr): arr[mask] += 0.055 arr[mask] /= 1.055 arr[mask] **= 2.4 - arr[-mask] /= 12.92 + arr[~mask] /= 12.92 logger.debug("Loading textures...") if SKY_TEXTURE == 'texture': - texarr_sky = spm.imread('textures/bgedit.jpg') + texarr_sky = imio.imread('textures/bgedit.jpg') # must convert to float here so we can work in linear colour texarr_sky = texarr_sky.astype(float) texarr_sky /= 255.0 @@ -345,9 +346,9 @@ def srgbtorgb(arr): texarr_disk = None if DISK_TEXTURE == 'texture': - texarr_disk = spm.imread('textures/adisk.jpg') + texarr_disk = imio.imread('textures/adisk.jpg') if DISK_TEXTURE == 'test': - texarr_disk = spm.imread('textures/adisktest.jpg') + texarr_disk = imio.imread('textures/adisktest.jpg') if texarr_disk is not None: # must convert to float here so we can work in linear colour texarr_disk = texarr_disk.astype(float) @@ -519,7 +520,7 @@ def tonumpyarray(mp_arr): indices = [q*i + min(i,r) for i in range(NTHREADS+1)] for i in range(NTHREADS): - schedules.append(chunks[ indices[i]:indices[i+1] ]) + schedules.append(chunks[ indices[i]:indices[i+1] ]) @@ -607,7 +608,7 @@ def showprogress(messtring,i,queue): ETA = 0 mes = "%d%%, %s remaining. Chunk %d/%d, %s"%( - int(100*progress), + int(100*progress), format_time(ETA), chnkcounters[i], len(schedules[i]), @@ -640,7 +641,7 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running #number of chunk pixels numChunk = chunk.shape[0] - #useful constant arrays + #useful constant arrays ones = np.ones((numChunk)) ones3 = np.ones((numChunk,3)) UPFIELD = np.outer(ones,np.array([0.,1.,0.])) @@ -719,7 +720,7 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running k4 = RK4f( y + rkstep*k3, h2) increment = rkstep/6. * (k1 + 2*k2 + 2*k3 + k4) - + velocity += increment[:,3:6] point += increment[:,0:3] @@ -753,7 +754,7 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running diskmask = np.logical_and(mask_crossing,mask_distance) if (diskmask.any()): - + #actual collision point by intersection lambdaa = - point[:,1]/velocity[:,1] colpoint = point + lambdaa[:,np.newaxis] * velocity @@ -776,7 +777,7 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running elif DISK_TEXTURE_INT == DT_TEXTURE: phi = np.arctan2(colpoint[:,0],point[:,2]) - + uv = np.zeros((numChunk,2)) uv[:,0] = ((phi+2*np.pi)%(2*np.pi))/(2*np.pi) @@ -923,7 +924,7 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running while True: refreshcounter+=1 time.sleep(0.1) - + output.parsemessages() if not DISABLE_DISPLAY and (refreshcounter%40 == 0): @@ -963,11 +964,11 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running if AIRY_BLOOM: logger.debug("-computing Airy disk bloom...") - + #blending bloom #colour = total_colour_buffer_preproc + 0.3*blurd #0.2*dbg_grid + 0.8*dbg_finvec - + #airy disk bloom colour_bloomd = np.copy(total_colour_buffer_preproc) @@ -979,13 +980,13 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running radd = 0.00019825 * RESOLUTION[0] / np.arctan(TANFOV) # the user is allowed to rescale the resolution, though - radd*=AIRY_RADIUS + radd*=AIRY_RADIUS # the pixel size of the kernel: # 25 pixels radius is ok for 5.0 bright source pixel at 1920x1080, so... - # remembering that airy ~ 1/x^3, so if we want intensity/x^3 < hreshold => + # remembering that airy ~ 1/x^3, so if we want intensity/x^3 < hreshold => # => max_x = (intensity/threshold)^1/3 - # so it scales with + # so it scales with # - the cube root of maximum intensity # - linear in resolution @@ -994,9 +995,9 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running kern_radius = 25 * np.power( np.amax(colour_bloomd) / 5.0 , 1./3.) * RESOLUTION[0]/1920. logger.debug("--(radius: %3f, kernel pixel radius: %3f, maximum source brightness: %3f)", radd, kern_radius, mxint) - + colour_bloomd = bloom.airy_convolve(colour_bloomd,radd) - + colour_bloomd = colour_bloomd.reshape((numPixels,3)) @@ -1010,7 +1011,7 @@ def raytrace_schedule(i,schedule,total_shared,q): # this is the function running if BLURDO: logger.debug("-computing wide gaussian blur...") - + #hipass = np.outer(sqrnorm(total_colour_buffer_preproc) > BLOOMCUT, np.array([1.,1.,1.])) * total_colour_buffer_preproc blurd = np.copy(total_colour_buffer_preproc)