-
Notifications
You must be signed in to change notification settings - Fork 4
Parser added #2
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
Merged
Merged
Parser added #2
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| module Reproject | ||
|
|
||
| greet() = print("Hello World!") | ||
| using FITSIO, WCS | ||
|
|
||
| include("parsers.jl") | ||
|
|
||
| end # module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """ | ||
| parse_input_data(input_data::ImageHDU) | ||
| parse_input_data(input_data::String, hdu_in) | ||
| parse_input_data(input_data::FITS, hdu_in) | ||
|
|
||
| Parse input data and returns an Array and WCS object. | ||
|
|
||
| # Arguments | ||
| - `input_data`: image to reproject which can be name of a FITS file, | ||
| an ImageHDU or a FITS file. | ||
| - `hdu_in`: used to set HDU to use when more than one HDU is present. | ||
| """ | ||
| function parse_input_data(input_data::ImageHDU) | ||
| return read(input_data), WCS.from_header(read_header(input_data, String))[1] | ||
| end | ||
|
|
||
| function parse_input_data(input_data::String, hdu_in) | ||
| return parse_input_data(FITS(input_data), hdu_in) | ||
| end | ||
|
|
||
| function parse_input_data(input_data::FITS, hdu_in) | ||
| return parse_input_data(input_data[hdu_in]) | ||
| end | ||
|
|
||
|
|
||
| # TODO: extend support for passing FITSHeader when FITSHeader to WCSTransform support is possible. | ||
|
|
||
|
|
||
| """ | ||
| parse_output_projection(output_projection::WCSTransform, shape_out) | ||
| parse_output_projection(output_projection::ImageHDU; shape_out) | ||
| parse_output_projection(output_projection::String, hdu_number) | ||
| parse_output_projection(output_projection::FITS, hdu_number) | ||
|
|
||
| Parse output projection and returns a WCS object and shape of output. | ||
|
|
||
| # Arguments | ||
| - `output_projection`: WCS information about the image to be reprojected which can be | ||
| name of a FITS file, an ImageHDU or WCSTransform. | ||
| - `shape_out`: shape of the output image. | ||
| - `hdu_number`: specifies HDU number when file name is given as input. | ||
| """ | ||
| function parse_output_projection(output_projection::WCSTransform, shape_out) | ||
| if length(shape_out) == 0 | ||
| throw(DomainError(shape_out, "The shape of the output image should not be an empty tuple")) | ||
| end | ||
|
|
||
| return output_projection, shape_out | ||
| end | ||
|
|
||
| function parse_output_projection(output_projection::ImageHDU, shape_out) | ||
| wcs_out = WCS.from_header(read_header(output_projection, String))[1] | ||
| if shape_out === nothing | ||
| shape_out = size(output_projection) | ||
| end | ||
| if length(shape_out) == 0 | ||
| throw(DomainError(shape_out, "The shape of the output image should not be an empty tuple")) | ||
| end | ||
| return wcs_out, shape_out | ||
| end | ||
|
|
||
| function parse_output_projection(output_projection::String, hdu_number) | ||
| parse_output_projection(FITS(output_projection), hdu_number) | ||
| end | ||
|
|
||
| function parse_output_projection(output_projection::FITS, hdu_number) | ||
| wcs_out = WCS.from_header(read_header(output_projection[hdu_number], String))[1] | ||
|
|
||
| if output_projection[hdu_number] isa ImageHDU | ||
| shape_out = size(output_projection[hdu_number]) | ||
| else | ||
| throw(ArgumentError("Given FITS file doesn't have ImageHDU")) | ||
| end | ||
|
|
||
| return wcs_out, shape_out | ||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| using Reproject: parse_input_data, parse_output_projection | ||
| @testset "input parser" begin | ||
| fname = tempname() * ".fits" | ||
| f = FITS(fname, "w") | ||
| inhdr = FITSHeader(["FLTKEY", "INTKEY", "BOOLKEY", "STRKEY", "COMMENT", | ||
| "HISTORY"], | ||
| [1.0, 1, true, "string value", nothing, nothing], | ||
| ["floating point keyword", | ||
| "", | ||
| "boolean keyword", | ||
| "string value", | ||
| "this is a comment", | ||
| "this is a history"]) | ||
|
|
||
| indata = reshape(Float32[1:100;], 5, 20) | ||
| write(f, indata; header=inhdr) | ||
|
|
||
| @testset "ImageHDU type" begin | ||
| result = parse_input_data(f[1]) | ||
| @test result[1] isa Array | ||
| @test result[2] isa WCSTransform | ||
| end | ||
|
|
||
| @testset "Single HDU FITS file" begin | ||
| result = parse_input_data(f, 1) | ||
| @test result[1] isa Array | ||
| @test result[2] isa WCSTransform | ||
| end | ||
| close(f) | ||
|
|
||
| @testset "String filename input" begin | ||
| result = parse_input_data(fname, 1) | ||
| @test result[1] isa Array | ||
| @test result[2] isa WCSTransform | ||
| end | ||
|
|
||
| f = FITS(fname, "w") | ||
| write(f, indata; header=inhdr) | ||
| write(f, indata; header=inhdr) | ||
|
|
||
| @testset "Multiple HDU FITS file" begin | ||
| result = parse_input_data(f, 2) | ||
| @test result[1] isa Array | ||
| @test result[2] isa WCSTransform | ||
|
|
||
| close(f) | ||
| result = parse_input_data(fname, 1) | ||
| @test result[1] isa Array | ||
| @test result[2] isa WCSTransform | ||
| end | ||
| end | ||
|
|
||
| @testset "output parser" begin | ||
| fname = tempname() * ".fits" | ||
| f = FITS(fname, "w") | ||
| inhdr = FITSHeader(["FLTKEY", "INTKEY", "BOOLKEY", "STRKEY", "COMMENT", | ||
| "HISTORY"], | ||
| [1.0, 1, true, "string value", nothing, nothing], | ||
| ["floating point keyword", | ||
| "", | ||
| "boolean keyword", | ||
| "string value", | ||
| "this is a comment", | ||
| "this is a history"]) | ||
|
|
||
| indata = reshape(Float32[1:100;], 5, 20) | ||
| write(f, indata; header=inhdr) | ||
|
|
||
| @testset "ImageHDU type" begin | ||
| result = parse_output_projection(f[1], (12,12)) | ||
| @test result[1] isa WCSTransform | ||
| @test result[2] isa Tuple | ||
| @test_throws DomainError parse_output_projection(f[1], ()) | ||
| end | ||
| close(f) | ||
|
|
||
| @testset "String filename" begin | ||
| result = parse_output_projection(fname, 1) | ||
| @test result[1] isa WCSTransform | ||
| @test result[2] isa Tuple | ||
| end | ||
|
|
||
| wcs = WCSTransform(2; | ||
| cdelt = [-0.066667, 0.066667], | ||
| ctype = ["RA---AIR", "DEC--AIR"], | ||
| crpix = [-234.75, 8.3393], | ||
| crval = [0., -90], | ||
| pv = [(2, 1, 45.0)]) | ||
|
|
||
| @testset "WCSTransform input" begin | ||
| result = parse_output_projection(wcs, (12,12)) | ||
| @test result[1] isa WCSTransform | ||
| @test result[2] isa Tuple | ||
| @test_throws DomainError parse_output_projection(wcs, ()) | ||
| end | ||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| using Reproject | ||
| using Test | ||
| using Conda, PyCall | ||
| using FITSIO, WCS | ||
|
|
||
| ENV["PYTHON"]="" | ||
| Conda.add_channel("astropy") | ||
| Conda.add("reproject") | ||
| rp = pyimport("reproject") | ||
|
|
||
| @testset "Reproject.jl" begin | ||
| # Write your own tests here. | ||
| include("parsers.jl") | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.