我正在使用Julia版本0.6.2并在第15行遇到错误,说明RemoteRef未定义。但是,当我尝试定义它时,例如RemoteRef{Channel{Any}}(x,y,z)
我仍然得到同样的错误。 @spawn
用于稍后将其链接到另一个函数中,fetch()
也用于代码中以将其链接回来。这曾用于版本0.4.7但我正在尝试更新代码。
我尝试手动将RemoteRef添加到repository.Refs列表,但这似乎不起作用。
任何人都可以对这个问题有任何见解吗?谢谢。
Pkg.add("DataFrames")
Pkg.clone("git://github.com/wkearn/RasterIO.jl")
Pkg.build("RasterIO")
using DataFrames
using RasterIO
output_file = "point_irradiance.asc"
dtm_file = "///dtm.tif"
dsm_file = "///dsm.tif"
buildings_file = "///build.asc"
extent_file = "///extent.dat"
lamps_file = "////pen_light.csv"
lamp_easting = 3
lamp_northing = 4
lamp_height = 2
@everywhere function lightdist(xdist,ydist,zdist)
xyzdist = sqrt(xdist^2+ydist^2+zdist^2)
return (1/(xyzdist^2))
end
function create_point_irradiance()
# Read in locations of street maps
lamps = convert(Matrix, readtable(lamps_file))
extent = convert(Matrix, DataFrames.readtable(extent_file))
xindex = collect(extent[1,1]:1:(extent[1,2]-1))
yindex = collect(extent[1,4]:-1:(extent[1,3]+1))
xindexmax, = size(xindex)
yindexmax, = size(yindex)
nlamps, = size(lamps)
nlamps = nlamps
nprocs = 3
chunk = div(nlamps, nprocs)
references = Array(RemoteRef, nprocs)
for core in 1:nprocs
if (core == 1)
from = 1
else
from = (chunk * (core - 1)) + 1
end
if (core == nprocs)
to = nlamps
else
to = chunk * core
end
references[core] = @spawn calculate_shadow(lamps[from:to, :], dtm_file, dsm_file, buildings_file, xindex, yindex, xindexmax, yindexmax, lamp_easting, lamp_northing, lamp_height)
end
point_irradiance = fill(0.0, (yindexmax, xindexmax))
for core in 1:nprocs
point_irradiance += fetch(references[core])
end
writedlm(output_file, point_irradiance, " ")
function add_headers(f::IOStream)
return string("NCOLS ", xindexmax, "\n",
"NROWS ", yindexmax, "\n",
"XLLCORNER ", extent[1,1], "\n",
"YLLCORNER ", extent[1,3], "\n",
"CELLSIZE 2 \n",
"NODATA_VALUE -9999\n",
readall(f))
end
content = open(add_headers, output_file);
f = open(output_file, "w")
write(f, content)
close(f)
end
@everywhere function calculate_shadow(lamps, dtm_file, dsm_file, buildings_file, xindex, yindex, xindexmax, yindexmax, lamp_easting, lamp_northing, lamp_height)
ext = 100
lamp_ext = 100
absorbance = 0.1
sensor_ht = 2.5
dtmR = RasterIO.openraster(dtm_file, UInt32(0))
dtm = transpose(RasterIO.fetch(dtmR, 1))
RasterIO.closeraster(dtmR)
dsmR = RasterIO.openraster(dsm_file, UInt32(0))
dsm = transpose(RasterIO.fetch(dsmR, 1))
RasterIO.closeraster(dsmR)
buildingsR = RasterIO.openraster(buildings_file, convert(UInt32, 0))
buildings = transpose(RasterIO.fetch(buildingsR, 1))
RasterIO.closeraster(buildingsR)
# Produce raster of structures (buildings, trees, hedges, etc)
surf = dsm - dtm
buildings = [if (buildings[ydim, xdim] == 0)
0
else
surf[ydim, xdim]
end
for ydim =1:yindexmax, xdim=1:xindexmax]
hard_surf = dtm + buildings
soft_surf = surf - buildings
# release memory
dsm = 0
surf = 0
buildings = 0
point_irradiance = fill(0.0, size(hard_surf))
for lamp in 1:size(lamps, 1)
x = lamps[lamp,lamp_easting]
y = lamps[lamp,lamp_northing]
z = lamps[lamp,lamp_height]
Xmax = xindex[xindexmax, 1]
Xmin = xindex[1, 1]
Ymin = yindex[yindexmax, 1]
Ymax = yindex[1, 1]
if ((x <= (Xmax+ext)) & (x>= (Xmin-ext)) & (y<=(Ymax+ext)) & (y>=(Ymin-ext)))
row = find(yindex .== min(max(y,Ymin),Ymax))[1]
col = find(xindex .== max(min(x,Xmax),Xmin))[1]
col_min = max(col-ext,1)
col_max = min(col+ext, xindexmax)
col_lamp = col-col_min
row_min = max(row-ext, 1)
row_max = min(row+ext, yindexmax)
row_lamp = row-row_min
nrows = row_max-row_min
ncols = col_max-col_min
hard_block = hard_surf[row_min:(row_min + nrows - 1),col_min:(col_min + ncols - 1)]
soft_block = soft_surf[row_min:(row_min + nrows - 1),col_min:(col_min + ncols - 1)]
terrain_block = dtm[row_min:(row_min + nrows - 1),col_min:(col_min + ncols - 1)]
point_irrad = fill(0.0, size(hard_block))
if (ncols==200&nrows==200)
for xx in 1:ncols
for yy in 1:nrows
xdist = col_lamp-xx
ydist = row_lamp-yy
xydist = sqrt(xdist^2+ydist^2)
zdist = (terrain_block[row_lamp,col_lamp]+z)-(terrain_block[yy,xx]+sensor_ht)
xyzdist = sqrt(xydist^2+zdist^2)
dist = floor(xydist+0.5)
if (xydist<=lamp_ext)
if (zdist>0)
shadow = 1
shading = 0
if(dist>0)
for d in 1:dist
if (hard_block[round(Int, yy+(ydist)*(d/dist)),round(Int, xx+(xdist)*(d/dist))] >= (terrain_block[yy,xx]+sensor_ht+(d/dist)*zdist))
shadow = 0
end
if(soft_block[round(Int, yy+(ydist)*(d/dist)),round(Int, (xx+(xdist)*(d/dist)))] >= (terrain_block[yy,xx]+sensor_ht+(d/dist)*zdist))
shading = shading + xyzdist/xydist
end
end
end
res = (1/(10^(absorbance*shading)))*shadow*lightdist(xdist,ydist,zdist)
real_y = yy + row_min - 1
real_x = xx + col_min - 1
point_irradiance[real_y, real_x] = point_irradiance[real_y, real_x] + ((1/(10^(absorbance*shading)))*shadow*lightdist(xdist,ydist,zdist))
end
end
end
end
end
end
end
return point_irradiance
end
@time create_point_irradiance()