Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make raw encoding really not doing anything; fix a bug of creating te… #47

Merged
merged 1 commit into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Codings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@ struct BlosclzCoding <: AbstractBigArrayCoding end
struct GzipCoding <: AbstractBigArrayCoding end
struct ZstdCoding <: AbstractBigArrayCoding end

const DEFAULT_CODING = RawCoding
const DEFAULT_CODING = GzipCoding

function encode(data::Array, coding::Type{RawCoding})
reinterpret(UInt8, data[:])
reinterpret(UInt8, data[:]) |> Vector
end

function decode(data::Vector{UInt8}, coding::Type{RawCoding})
return data
end

function encode(data::Array, coding::Type{ZstdCoding})
#Libz.deflate(reinterpret(UInt8, data[:]))
transcode(ZstdCompressor, reinterpret(UInt8, vec(data)) |> Vector)
end

Expand Down
17 changes: 13 additions & 4 deletions src/Infos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export InfoScale

const ENCODING_MAP = Dict{String,Any}(
# note that the raw encoding in cloud storage will be automatically gzip encoded!
"raw" => GzipCoding,
"raw" => RawCoding,
"jpeg" => JPEGCoding,
"blosclz" => BlosclzCoding,
"gzip" => GzipCoding,
Expand Down Expand Up @@ -89,7 +89,7 @@ function Base.Dict(self::InfoScale)
end
end
d[:size] = [get_volume_size(self)...]
d[:voxelOffset] = [Tuple(get_voxel_offset(self))...]
d[:voxel_offset] = [Tuple(get_voxel_offset(self))...]
return d
end

Expand Down Expand Up @@ -120,8 +120,17 @@ end
end

@inline function get_encoding(self::InfoScale) self.encoding end
@inline function set_encoding!(self::InfoScale, encoding::DataType)
self.encoding = encoding
end

"""
set_encoding!(self::InfoScale, encoding::Symbol)

@inline function set_encoding!(self::InfoScale, encoding::Symbol)
the encoding map is:
$(ENCODING_MAP)
"""
@inline function set_encoding!(self::InfoScale, encoding::String)
self.encoding = ENCODING_MAP[encoding]
end

Expand Down Expand Up @@ -328,7 +337,7 @@ end
@inline function get_encoding(self::Info, mip::Integer=1)
InfoScales.get_encoding( get_scales(self)[mip] )
end
@inline function set_encoding!(self::Info, encoding::DataType)
@inline function set_encoding!(self::Info, encoding::Union{String, DataType})
for scale in get_scales(self)
InfoScales.set_encoding!(scale, encoding)
end
Expand Down
7 changes: 4 additions & 3 deletions src/backends/BinDicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ struct BinDict <: AbstractBigArrayBackend
end
end

@inline function Base.show(self::BinDict)
println("BinDict in ", get_path(self))
@inline function Base.show(io::IO, self::BinDict)
write(io, "BinDict in " * get_path(self))
end

@inline function get_path(self::BinDict)
Expand All @@ -42,7 +42,7 @@ end
end

@inline function Base.setindex!( self::BinDict, value::Array, key::AbstractString )
data = reinterpret(UInt8, value[:])
data = reinterpret(UInt8, value[:]) |> Vector
fileName = joinpath( get_path(self), key )
write(fileName, data)
end
Expand All @@ -63,3 +63,4 @@ end


end # module

3 changes: 2 additions & 1 deletion src/modes/sequential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function setindex_sequential!( ba::BigArray{D,T,N}, buf::Array{T,N},
chunkGlobalRange, globalRange, rangeInChunk, rangeInBuffer = adjust_volume_boundary(ba,
chunkGlobalRange, globalRange, rangeInChunk, rangeInBuffer)
@inbounds chk = buf[rangeInBuffer]
ba.kvStore[ joinpath(mipLevelName, cartesian_range2string(chunkGlobalRange)) ] = encode( chk, C)
ba.kvStore[ joinpath(mipLevelName, cartesian_range2string(chunkGlobalRange)) ] =
encode( chk, C)
end
end

Expand Down
5 changes: 3 additions & 2 deletions src/type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ end
function BigArray(layerPath::AbstractString; mip::Int=1, fillMissing::Bool=DEFAULT_FILL_MISSING,
mode::Symbol=DEFAULT_MODE)
if isdir(layerPath) || startswith(layerPath, "file://")
layerPath = replace(layerPath, "file://"=>"/", count=1)
d = BinDict(layerPath)
elseif startswith(layerPath, "gs://")
d = GSDict(layerPath)
Expand All @@ -35,7 +36,7 @@ end
@inline function BigArray(d::AbstractBigArrayBackend; mip::Int=1,
fillMissing::Bool=DEFAULT_FILL_MISSING,
mode::Symbol=DEFAULT_MODE)
info = d["info"] |> Info
info = d["info"] |> Info
return BigArray(d, info, mip, fillMissing, mode)
end

Expand Down Expand Up @@ -93,7 +94,7 @@ function BigArray(info::Info{T,N}; mip::Integer=1,
datasetDir = joinpath(layerDir, string(Infos.get_key(info, 1)))
mkdir(layerDir)
mkdir(datasetDir)
d = BinDict(datasetDir)
d = BinDict(layerDir)

# write the info as file
write(joinpath(layerDir, "info"), JSON.json(Dict(info)))
Expand Down