You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Note:** The `Libcfitsio` submodule has been moved to [CFITSIO.jl](https://github.com/JuliaAstro/CFITSIO.jl) and will be deprecated in a future release.
15
-
16
-
17
14
## Usage
18
15
19
16
For more in-depth usage and examples, see [the documentation](http://juliaastro.github.io/FITSIO.jl/stable/).
A [Julia](http://julialang.org) package for reading and writing Flexible Image Transport System (FITS) files, based on the [cfitsio](http://heasarc.gsfc.nasa.gov/fitsio/) library.
6
4
7
-
A [Julia](http://julialang.org) package for reading and writing
8
-
Flexible Image Transport System (FITS) files, based on the
The `Libcfitsio` submodule has been moved to [CFITSIO.jl](https://github.com/JuliaAstro/CFITSIO.jl) and will be deprecated in a future release.
16
-
17
-
# Installation
7
+
## Installation
18
8
19
9
`FITSIO.jl` can be installed using the built-in package manager:
20
10
@@ -26,7 +16,7 @@ pkg> add FITSIO
26
16
DocTestFilters = r"File: [a-zA-Z0-9/._]+"
27
17
```
28
18
29
-
# Quick start
19
+
##Quick start
30
20
31
21
The simplest way to write and read an image from a FITS file is by using the functions [`FITSIO.fitswrite`](@ref) and [`FITSIO.fitsread`](@ref).
32
22
@@ -47,16 +37,19 @@ julia> FITSIO.fitsread(fname, 1, 1:2, 1) # read a section of HDU number 1
47
37
1
48
38
3
49
39
```
40
+
50
41
This is not the most performant way, as the file is opened and closed on every invocation. However, this abstracts away the complexity.
42
+
51
43
!!! warn
52
44
Currently, `fitswrite` overwrites an existing file, so this should be used with caution. In the future, this may allow
53
45
appending to an existing file.
54
46
55
-
# Usage
47
+
##Usage
56
48
57
49
In this example, we write to and read from a fits file.
58
50
59
51
We create a new temporary file using the `FITS` constructor:
52
+
60
53
```jldoctest example
61
54
julia> fname, _ = mktemp(); # create a temporary file for this example
62
55
@@ -70,12 +63,10 @@ No HDUs.
70
63
julia> length(f) # shows the number of HDUs in the file
71
64
0
72
65
```
66
+
73
67
In this example, we have used the file mode `"w"`, which will overwrite any existing file with the same name. To append to an existing file instead, we use the mode `"r+"`, and to open a file for reading, we may specify the mode `"r"`.
74
68
75
-
A FITS file consists of one or more header-data units (HDUs),
76
-
concatenated one after the other. The `FITS` object therefore is
77
-
represented as a collection of these HDUs. Each HDU can contain image data, or table data (either binary or
78
-
ASCII-formatted). Since we have just created a new file, there are no HDUs currently in the file.
69
+
A FITS file consists of one or more header-data units (HDUs), concatenated one after the other. The `FITS` object therefore is represented as a collection of these HDUs. Each HDU can contain image data, or table data (either binary or ASCII-formatted). Since we have just created a new file, there are no HDUs currently in the file.
79
70
80
71
## Image
81
72
@@ -223,6 +214,7 @@ Variable length columns are not supported by the `Tables.jl` interface, and `Tab
223
214
In this section, we re-use the file that we had created in the eariler section, which contains an image HDU and a table HDU.
224
215
225
216
We may read the header of an HDU as
217
+
226
218
```jldoctest example
227
219
julia> header = read_header(imghdu)
228
220
SIMPLE = T / file does conform to FITS standard
@@ -240,6 +232,7 @@ FITSHeader
240
232
julia> length(header) # number of keys
241
233
8
242
234
```
235
+
243
236
This reads the entire header from the HDU into memory. The header object behaves like a dictionary that may be queried using its keys:
244
237
245
238
```jldoctest example
@@ -276,7 +269,9 @@ julia> read_key(imghdu, 3) # query by key index
276
269
julia> get_comment(header, "NAXIS")
277
270
"number of data axes"
278
271
```
272
+
279
273
We may modify the header in memory as
274
+
280
275
```jldoctest example
281
276
julia> header["NEWKEY"] = 10; # change or add a keyword
Manipulating a header only changes it in memory until it is written to disk. The header object in memory is not connected to the fits file. To write some header keywords in the new extension, pass a [`FITSHeader`](@ref) instance as a keyword: `write(f, data; header=header)`
293
288
294
-
295
289
## Iterating over the HDUs
296
290
297
291
We may iterate over the fits file to access individual HDUs.
@@ -310,6 +304,7 @@ Close the file to write the in-memory FITS file to disk.
310
304
```jldoctest example
311
305
julia> close(f)
312
306
```
307
+
313
308
FITS objects are also closed automatically when garbage collected.
0 commit comments