Skip to content

Commit

Permalink
modify save functionality to accomodate path = nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthlal25 committed Aug 19, 2020
1 parent 32644f2 commit 98aa01e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/collection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ function ccds(f,
processed_images = map(zip(locations, image_iterator)) do (location, output)
processed_image = f(output)
if save
# if path is nothing and still the file is being saved, the location of input file is used
if path isa Nothing
path = dirname(location)
end
save_path = generate_filename(location, path, save_prefix, save_suffix, save_delim, ext)
writefits(save_path, processed_image)
end
Expand Down Expand Up @@ -368,6 +372,10 @@ function filenames(f,
processed_images = map(zip(locations, path_iterator)) do (location, output)
processed_image = f(output)
if save
# if path is nothing and still the file is being saved, the location of input file is used
if path isa Nothing
path = dirname(location)
end
save_path = generate_filename(location, path, save_prefix, save_suffix, save_delim, ext)
writefits(save_path, processed_image)
end
Expand All @@ -381,10 +389,10 @@ end
"""
arrays(f,
collection;
save = any(!isnothing, (save_prefix, path, save_suffix)),
path = nothing,
save_prefix = nothing,
save_suffix = nothing,
save = any(!isnothing, (save_prefix, path, save_suffix)),
save_delim = "_",
ext = r"fits(\\.tar\\.gz)?"i,
kwargs...)
Expand Down Expand Up @@ -416,10 +424,10 @@ Mapping version of `arrays` function is interfaced on iterative version of `arra
"""
function arrays(f,
collection;
save = any(!isnothing, (save_prefix, path, save_suffix)),
path = nothing,
save_prefix = nothing,
save_suffix = nothing,
save = any(!isnothing, (save_prefix, path, save_suffix)),
save_delim = "_",
ext = r"fits(\.tar\.gz)?"i,
kwargs...)
Expand All @@ -429,6 +437,10 @@ function arrays(f,
processed_images = map(zip(locations, array_iterator)) do (location, output)
processed_image = f(output)
if save
# if path is nothing and still the file is being saved, the location of input file is used
if path isa Nothing
path = dirname(location)
end
save_path = generate_filename(location, path, save_prefix, save_suffix, save_delim, ext)
writefits(save_path, processed_image)
end
Expand Down
37 changes: 35 additions & 2 deletions test/collection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
@test arr1 == arr2
end

@testset "image-generators" begin
@testset "ccds-generators" begin
# setting initial data
dir = joinpath(@__DIR__, "data")
df = fitscollection(dir)
Expand All @@ -85,7 +85,7 @@ end
end
end

@testset "saving-image" begin
@testset "saving-ccds" begin
dir = joinpath(@__DIR__, "data")
savedir = @__DIR__
collection = fitscollection(dir)
Expand Down Expand Up @@ -119,6 +119,17 @@ end

# remove the files generated during tests
rm.(collection1[:, :path])

# testing save functionality with path = nothing, i.e. at same location as of the input file
new_saved_data = ccds(collection; save_prefix = "save_without_path") do data
data
end
collection2 = fitscollection(dir)
@test first(size(collection2)) == 4

# removing data generated during testion
rm.(joinpath(dir, "save_without_path_M6707HH.fits"))
rm.(joinpath(dir, "save_without_path_M35070V.fits"))
end

@testset "saving-filename" begin
Expand Down Expand Up @@ -153,6 +164,17 @@ end

# removing data generated during testing
rm.(collection1[:, :path])

# testing save functionality with path = nothing, i.e. at same location as of the input file
new_saved_data = filenames(collection; save_prefix = "save_without_path") do filename
CCDData(filename)
end
collection2 = fitscollection(dir)
@test first(size(collection2)) == 4

# removing data generated during testion
rm.(joinpath(dir, "save_without_path_M6707HH.fits"))
rm.(joinpath(dir, "save_without_path_M35070V.fits"))
end

@testset "saving-arrays" begin
Expand Down Expand Up @@ -187,6 +209,17 @@ end

# removing data generated during testing
rm.(collection1[:, :path])

# testing save functionality with path = nothing, i.e. at same location as of the input file
new_saved_data = arrays(collection; save_prefix = "save_without_path") do data
data
end
collection2 = fitscollection(dir)
@test first(size(collection2)) == 4

# removing data generated during testion
rm.(joinpath(dir, "save_without_path_M6707HH.fits"))
rm.(joinpath(dir, "save_without_path_M35070V.fits"))
end

@testset "helper" begin
Expand Down

0 comments on commit 98aa01e

Please sign in to comment.