Skip to content

Commit 7b61d07

Browse files
authored
Merge pull request #39 from JuliaAstro/patch-1
Documentation and test updates
2 parents bc80090 + 26e94d4 commit 7b61d07

File tree

13 files changed

+176
-84
lines changed

13 files changed

+176
-84
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/" # Location of package manifests
6+
schedule:
7+
interval: "weekly"

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
- "1.3"
1919
- "1"
2020
- "nightly"
21-
os:
21+
os:
2222
- ubuntu-latest
2323
- macOS-latest
2424
- windows-latest
25-
arch:
25+
arch:
2626
- x64
2727
steps:
2828
- uses: actions/checkout@v2

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1212

1313
[compat]
1414
DataFrames = "0.21, 0.22, 1"
15-
FITSIO = "0.16.2"
15+
FITSIO = "0.16, 0.17"
1616
LazyStack = "0.0.7"
1717
ResumableFunctions = "0.5.1, 0.6"
1818
julia = "1.3"

docs/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ FITSIO = "525bcba6-941b-5504-bd06-fd0dc1a4d2eb"
44
Underscores = "d9a01c3f-67ce-4d8c-9b55-35f6e4050bb1"
55

66
[compat]
7-
Documenter = "0.27"
8-
FITSIO = "0.16.2"
7+
Documenter = "1"
8+
FITSIO = "0.16, 0.17"
99
Underscores = "2"

docs/make.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ makedocs(modules = [CCDReduction],
77
sitename = "CCDReduction.jl",
88
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
99
authors = "Siddharth Lal",
10-
strict = true,
11-
pages = pages
10+
pages = pages,
1211
)
1312

1413
deploydocs(;

docs/src/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ This package provides tools for basic reduction methods of CCD images.
1414

1515
## Installation
1616

17-
From Julia enter Pkg mode
17+
From Julia enter Pkg mode (by pressing `]` in the Julia REPL)
1818

19-
```julia
20-
julia>]
19+
```julia-repl
20+
julia> ]
2121
22-
(1.3) pkg> add CCDReduction
22+
pkg> add CCDReduction
2323
```
2424

2525
## Usage

src/ccddata.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# abstract data type for CCDData
22
"""
3-
AbstractCCDData{T}
3+
abstract type AbstractCCDData{T} <: AbstractMatrix{T}
44
55
Supertype for `CCDData` based on `AbstractMatrix` interface.
66
@@ -20,6 +20,7 @@ Base.promote_rule(::Type{AbstractCCDData{T}}, ::Type{AbstractCCDData{V}}) where
2020

2121
# custom data type to hold ImageHDU
2222
"""
23+
CCDData <: AbstractCCDData
2324
CCDData(data::AbstractMatrix, [hdr::FITSHeader])
2425
2526
Struct to store `ImageHDU`, derived from [`AbstractCCDData`](@ref).
@@ -47,11 +48,8 @@ One can perform arithmetic operations on it as well:
4748
4849
```julia
4950
ccd1 = CCDData(zeros(4, 4))
50-
5151
ccd2 = CCDData(ones(4, 4))
52-
5352
sum_ccd1 = ccd1 + ccd2
54-
5553
sum_ccd2 = ccd2 + ccd1
5654
```
5755
@@ -93,7 +91,12 @@ function Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{CCDData}},
9391
ccd = find_ccd(bc)
9492
CCDData(similar(data(ccd), T, axes(bc)), hdr(ccd))
9593
end
96-
"`A = find_ccd(As)` returns the first CCDData among the arguments."
94+
95+
"""
96+
find_ccd(As)
97+
98+
Return the first CCDData among the arguments.
99+
"""
97100
find_ccd(bc::Base.Broadcast.Broadcasted) = find_ccd(bc.args)
98101
find_ccd(args::Tuple) = find_ccd(find_ccd(args[1]), Base.tail(args))
99102
find_ccd(x) = x

src/collection.jl

Lines changed: 83 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ end
4747
4848
Writes `data`/`ccd` in FITS format at `file_path`.
4949
50-
`FITSIO` takes over memory write in by `cfitsio`, which writes in row-major form, whereas when Julia gives that memory, it is assumed as column major.
51-
Therefore all data written by [`FITSIO.write`](http://juliaastro.github.io/FITSIO.jl/latest/api.html#Base.write-Tuple{FITS,Dict{String,V}%20where%20V}) is transposed. This function allows the user to write the data in a consistent way to FITS file by transposing before writing.
50+
`FITSIO` takes over memory write in by `cfitsio`, which writes in row-major
51+
form, whereas when Julia gives that memory, it is assumed as column major.
52+
Therefore all data written by
53+
[`FITSIO.write`](https://juliaastro.org/FITSIO.jl/stable/api/#Base.write-Tuple{FITS,%20Dict{String}})
54+
is transposed. This function allows the user to write the data in a consistent
55+
way to FITS file by transposing before writing.
5256
"""
5357
function writefits(file_path, data; header = nothing)
5458
d = ndims(data)
@@ -71,37 +75,56 @@ writefits(file_path, ccd::CCDData) = writefits(file_path, ccd.data; header = ccd
7175
exclude_dir=nothing,
7276
exclude_key=("", "HISTORY"))
7377
74-
Walk through `dir` collecting FITS files, scanning their headers, and culminating into a `DataFrame` that can be used with the generators for iterating over many files and processing them. If `recursive` is false, no subdirectories will be walked through.
78+
Walk through `dir` collecting FITS files, scanning their headers, and
79+
culminating into a `DataFrame` that can be used with the generators for
80+
iterating over many files and processing them. If `recursive` is false, no
81+
subdirectories will be walked through.
7582
76-
The table returned will contain the path to the file, the name of the file, and index of the corresponding HDU, and each FITS header column and value. If two FITS files have distinct columns, they will both appear in the table with `missing` in the appropriate rows.
83+
The table returned will contain the path to the file, the name of the file, and
84+
index of the corresponding HDU, and each FITS header column and value. If two
85+
FITS files have distinct columns, they will both appear in the table with
86+
`missing` in the appropriate rows.
7787
7888
!!! note "Duplicate Keys"
79-
In certain cases, there are multiple FITS headers with the same key, e.g., `COMMENT`. In these cases, only the first instance of the key-value pair will be stored.
80-
81-
If `abspath` is true, the path in the table will be absolute. If `keepext` is true, the name in the table will include the file extension, given by `ext`. `ext` will be used with `endswith` to filter for fits files compatible with `FITSIO.FITS`. `exclude` is a pattern that can be used with `occursin` to exclude certain filenames. For example, to exclude any files containing "sky",
89+
In certain cases, there are multiple FITS headers with the same key, e.g.,
90+
`COMMENT`. In these cases, only the first instance of the key-value pair
91+
will be stored.
92+
93+
If `abspath` is true, the path in the table will be absolute. If `keepext` is
94+
true, the name in the table will include the file extension, given by `ext`.
95+
`ext` will be used with `endswith` to filter for fits files compatible with
96+
`FITSIO.FITS`. `exclude` is a pattern that can be used with `occursin` to
97+
exclude certain filenames. For example, to exclude any files containing "sky",
8298
```julia
8399
fitscollection(...; exclude="sky")
84100
```
85-
to exclude exact filenames, [regex strings](https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1) will prove powerful
101+
to exclude exact filenames,
102+
[regex strings](https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1)
103+
will prove powerful
86104
```julia
87105
fitscollection(...; exclude=r"^tek001\d")
88106
```
89-
finally, using external tools like [Glob.jl](https://github.com/vtjnash/Glob.jl) allows further customization
107+
finally, using external tools like [Glob.jl](https://github.com/vtjnash/Glob.jl)
108+
allows further customization
90109
```julia
91110
using Glob
92111
fitscollection(...; exclude=fn"tek001*.fits") # same as regex match above
93112
```
94-
Similarly, `exclude_dir` allows excluding entire folders using pattern matching (e.g. skipping a backup folder `exclude_dir="backup"`).
95-
`exclude_key` allows excluding certain entries in the header unit of `ImageHDU` in FITS files (e.g. skipping `"HISTORY"` and `""` `exclude_key = ("HISTORY", "")`).
113+
Similarly, `exclude_dir` allows excluding entire folders using pattern matching
114+
(e.g. skipping a backup folder `exclude_dir="backup"`).
115+
`exclude_key` allows excluding certain entries in the header unit of `ImageHDU`
116+
in FITS files (e.g. skipping `"HISTORY"` and `""` `exclude_key = ("HISTORY", "")`).
96117
97-
For more information about the file matching and path deconstruction, see the extended help (`??fitscollection`)
118+
For more information about the file matching and path deconstruction, see the
119+
extended help (`??fitscollection`)
98120
# Extended Help
99121
100122
## Parts of a path
101123
102-
Let's look at some file paths starting from `"/data"`. Here are examples of how they would be parsed
124+
Let's look at some file paths starting from `"/data"`. Here are examples of how
125+
they would be parsed
103126
104-
```
127+
```plain
105128
root dir base ext
106129
[----][---][------][---]
107130
/data/test/tek0001.fits
@@ -111,7 +134,12 @@ Let's look at some file paths starting from `"/data"`. Here are examples of how
111134
/data/test/sci/tek0001.fits
112135
```
113136
114-
If `keepext` is `true`, `name=base * ext`, otherwise it is just `base`. If `abspath` is `true`, the path will be `root * dir * base * ext`, otherwise it will be `dir * base * ext`. These options allow flexility in creating a table that can be easily saved and loaded to avoid having to manually filter files. Especially consider how `abspath` can allow keeping tables that will transfer easily between computers or between data sources with common structures.
137+
If `keepext` is `true`, `name=base * ext`, otherwise it is just `base`. If
138+
`abspath` is `true`, the path will be `root * dir * base * ext`, otherwise it
139+
will be `dir * base * ext`. These options allow flexility in creating a table
140+
that can be easily saved and loaded to avoid having to manually filter files.
141+
Especially consider how `abspath` can allow keeping tables that will transfer
142+
easily between computers or between data sources with common structures.
115143
"""
116144
function fitscollection(basedir::String;
117145
recursive = true,
@@ -176,7 +204,8 @@ Iterates over `collection` using each `path` and `hdu` to load data into an `Arr
176204
collection = fitscollection("~/data/tekdata")
177205
data = arrays(collection) |> collect
178206
```
179-
This returns all image arrays present in `collection`. This can also be used via a for-loop
207+
This returns all image arrays present in `collection`.
208+
This can also be used via a for-loop
180209
```julia
181210
collection = fitscollection("~/data/tekdata")
182211
for arr in arrays(collection)
@@ -238,7 +267,8 @@ end
238267
239268
Generator for `CCDData`s of entries in data frame.
240269
241-
Iterates over `collection` using each `path` and `hdu` to load data into a [`CCDData`](@ref).
270+
Iterates over `collection` using each `path` and `hdu` to load data into a
271+
[`CCDData`](@ref).
242272
243273
# Examples
244274
```julia
@@ -271,7 +301,14 @@ end
271301
272302
Iterates over the `CCDData`s of the collection applying function `f` at each step.
273303
274-
The output from `f` can be saved using the appropriate keyword arguments. The `save_prefix` argument will add a prefix to each filename delimited by `save_delim`. `save_suffix` will add a suffix prior to the extension, which can be manually provided via `ext`, similar to [`fitscollection`](@ref). Files will be saved in the directory they are stored unless `path` is given. Finally, `save` will default to `true` if any of the previous arguments are set, but can be manually overridden (useful for testing). Files will be saved using [`CCDReduction.writefits`](@ref).
304+
The output from `f` can be saved using the appropriate keyword arguments. The
305+
`save_prefix` argument will add a prefix to each filename delimited by
306+
`save_delim`. `save_suffix` will add a suffix prior to the extension, which can
307+
be manually provided via `ext`, similar to [`fitscollection`](@ref). Files will
308+
be saved in the directory they are stored unless `path` is given. Finally,
309+
`save` will default to `true` if any of the previous arguments are set, but can
310+
be manually overridden (useful for testing). Files will be saved using
311+
[`CCDReduction.writefits`](@ref).
275312
276313
# Example
277314
```julia
@@ -280,15 +317,17 @@ processed_images = map(ccds(collection)) do img
280317
trim(img, (:, 1040:1059))
281318
end
282319
```
283-
The above generates `processed_images` which consists of trimmed versions of images present in `collection`.
320+
The above generates `processed_images` which consists of trimmed versions of
321+
images present in `collection`.
284322
285323
For saving the `processed_images` simultaneously with the operations performed
286324
```julia
287325
processed_images = map(ccds(collection; path = "~/data/tekdata", save_prefix = "trimmed")) do img
288326
trim(img, (:, 1040:1059))
289327
end
290328
```
291-
The trimmed images are saved as `trimmed_(original_name)` (FITS files) at `path = "~/data/tekdata"` as specified by the user.
329+
The trimmed images are saved as `trimmed_(original_name)` (FITS files) at
330+
`path = "~/data/tekdata"` as specified by the user.
292331
"""
293332
function ccds(f,
294333
collection;
@@ -332,7 +371,14 @@ end
332371
333372
Iterates over the file paths of the collection applying function `f` at each step.
334373
335-
The output from `f` can be saved using the appropriate keyword arguments. The `save_prefix` argument will add a prefix to each filename delimited by `save_delim`. `save_suffix` will add a suffix prior to the extension, which can be manually provided via `ext`, similar to [`fitscollection`](@ref). Files will be saved in the directory they are stored unless `path` is given. Finally, `save` will default to `true` if any of the previous arguments are set, but can be manually overridden (useful for testing). Files will be saved using [`CCDReduction.writefits`](@ref).
374+
The output from `f` can be saved using the appropriate keyword arguments. The
375+
`save_prefix` argument will add a prefix to each filename delimited by
376+
`save_delim`. `save_suffix` will add a suffix prior to the extension, which can
377+
be manually provided via `ext`, similar to [`fitscollection`](@ref). Files will
378+
be saved in the directory they are stored unless `path` is given. Finally,
379+
`save` will default to `true` if any of the previous arguments are set, but can
380+
be manually overridden (useful for testing). Files will be saved using
381+
[`CCDReduction.writefits`](@ref).
336382
337383
# Examples
338384
```julia
@@ -344,7 +390,8 @@ data = map(filenames(collection)) do path
344390
data
345391
end
346392
```
347-
The above generates `data` which consists of image arrays corresponding to 1st hdu of FITS file paths present in `collection`.
393+
The above generates `data` which consists of image arrays corresponding to 1st
394+
hdu of FITS file paths present in `collection`.
348395
For saving the `data` simultaneously with the operations performed
349396
```julia
350397
data = map(filenames(collection; path = "~/data/tekdata", save_prefix = "retrieved_from_filename")) do img
@@ -354,7 +401,8 @@ data = map(filenames(collection; path = "~/data/tekdata", save_prefix = "retriev
354401
data
355402
end
356403
```
357-
The retrieved data is saved as `retrieved_from_filename_(original_name)` (FITS files) at `path = "~/data/tekdata"` as specified by the user.
404+
The retrieved data is saved as `retrieved_from_filename_(original_name)`
405+
(FITS files) at `path = "~/data/tekdata"` as specified by the user.
358406
"""
359407
function filenames(f,
360408
collection;
@@ -398,7 +446,14 @@ end
398446
399447
Iterates over the image arrays of the collection applying function `f` at each step.
400448
401-
The output from `f` can be saved using the appropriate keyword arguments. The `save_prefix` argument will add a prefix to each filename delimited by `save_delim`. `save_suffix` will add a suffix prior to the extension, which can be manually provided via `ext`, similar to [`fitscollection`](@ref). Files will be saved in the directory they are stored unless `path` is given. Finally, `save` will default to `true` if any of the previous arguments are set, but can be manually overridden (useful for testing). Files will be saved using [`CCDReduction.writefits`](@ref).
449+
The output from `f` can be saved using the appropriate keyword arguments.
450+
The `save_prefix` argument will add a prefix to each filename delimited by
451+
`save_delim`. `save_suffix` will add a suffix prior to the extension, which can
452+
be manually provided via `ext`, similar to [`fitscollection`](@ref). Files will
453+
be saved in the directory they are stored unless `path` is given. Finally,
454+
`save` will default to `true` if any of the previous arguments are set, but can
455+
be manually overridden (useful for testing). Files will be saved using
456+
[`CCDReduction.writefits`](@ref).
402457
403458
# Examples
404459
```julia
@@ -407,14 +462,16 @@ processed_images = map(arrays(collection)) do arr
407462
trim(arr, (:, 1040:1059))
408463
end
409464
```
410-
The above generates `processed_images` which consists of trimmed versions of image arrays present in `collection`.
465+
The above generates `processed_images` which consists of trimmed versions of
466+
image arrays present in `collection`.
411467
For saving the `processed_images` simultaneously with the operations performed
412468
```julia
413469
processed_images = map(arrays(collection; path = "~/data/tekdata", save_prefix = "trimmed")) do img
414470
trim(img, (:, 1040:1059))
415471
end
416472
```
417-
The trimmed image arrays are saved as `trimmed_(original_name)` (FITS files) at `path = "~/data/tekdata"` as specified by the user.
473+
The trimmed image arrays are saved as `trimmed_(original_name)` (FITS files)
474+
at `path = "~/data/tekdata"` as specified by the user.
418475
"""
419476
function arrays(f,
420477
collection;

src/fits.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
66
Loads the given HDU as an `Array`, permuting the dimensions appropriately.
77
8-
FITSIO.jl takes over memory read in by cfitsio, which reads in row-major form, whereas when Julia takes that memory, it is assumed as column major.
9-
Therefore all data read by [`FITSIO.read`](http://juliaastro.github.io/FITSIO.jl/latest/api.html#Base.read-Tuple{ImageHDU}) is transposed. This function allows the user to read data in a consistent way to `Array` by transposing after reading.
8+
FITSIO.jl takes over memory read in by cfitsio, which reads in row-major form,
9+
whereas when Julia takes that memory, it is assumed as column major.
10+
Therefore all data read by
11+
[`FITSIO.read`](http://juliaastro.org/FITSIO.jl/latest/api.html#Base.read-Tuple{ImageHDU})
12+
is transposed. This function allows the user to read data in a consistent way to
13+
`Array` by transposing after reading.
1014
"""
1115
function getdata(hdu::ImageHDU)
1216
data = read(hdu)

0 commit comments

Comments
 (0)