From 28d5845de0eb30fd3a8b74687a74e0c777443963 Mon Sep 17 00:00:00 2001 From: abhro <5664668+abhro@users.noreply.github.com> Date: Fri, 3 May 2024 06:20:37 -0400 Subject: [PATCH] Add repl language tags for examples (#195) --- docs/src/index.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index bf2f34b..08d353f 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -18,14 +18,14 @@ The interface is inspired by Erin Sheldon's `FITSIO.jl` can be installed using the built-in package manager -```julia +```julia-repl pkg> add FITSIO ``` ## Usage To open an existing file for reading: -```julia +```julia-repl julia> using FITSIO julia> f = FITS("file.fits") @@ -43,7 +43,7 @@ concatenated one after the other. The `FITS` object therefore is represented as a collection of these HDUs. Get information about the first HDU: -```julia +```julia-repl julia> f[1] File: file.fits HDU: 1 @@ -53,7 +53,7 @@ Datasize: (800, 800) ``` Iterate over HDUs in the file: -```julia +```julia-repl julia> for hdu in f; println(typeof(hdu)); end FITSIO.ImageHDU FITSIO.TableHDU @@ -63,7 +63,7 @@ FITSIO.TableHDU Each HDU can contain image data, or table data (either binary or ASCII-formatted). For image extensions, get the size of the image without reading it: -```julia +```julia-repl julia> ndims(f[1]) 2 @@ -76,7 +76,7 @@ julia> size(f[1], 2) Read an image from disk: -```julia +```julia-repl julia> data = read(f[1]); # read an image from disk julia> data = read(f[1], :, 790:end); # read just a subset of image @@ -84,7 +84,7 @@ julia> data = read(f[1], :, 790:end); # read just a subset of image Show info about a binary table: -```julia +```julia-repl julia> f[2] File: file.fits HDU: 2 @@ -97,19 +97,19 @@ Columns: Name Size Type TFORM Read a column from the table: -```julia - julia> data = read(f[2], "col1") +```julia-repl +julia> data = read(f[2], "col1") ``` Table HDUs implement the [Tables.jl](https://tables.juliadata.org/stable/) interface, so you can load them into other table types, like [DataFrames](https://dataframes.juliadata.org/stable/). -``` +```julia-repl julia> df = DataFrame(f[2]) ``` Variable length columns are not supported by the Tables.jl interface, and `Tables` methods will ignore them. Read the entire header into memory and get values from it: -```julia +```julia-repl julia> header = read_header(f[1]); # read the entire header from disk julia> length(header) # total number of records in header @@ -130,7 +130,7 @@ julia> get_comment(header, "NAXIS") # get comment for a given keyword Read just a single header record without reading the entire header: -```julia +```julia-repl julia> read_key(f[1], 4) # by position ("NAXIS1",800,"length of data axis 1") @@ -140,7 +140,7 @@ julia> read_key(f[1], "NAXIS1") # read by keyword Manipulate a header in memory: -```julia +```julia-repl julia> header["NEWKEY"] = 10 # change or add a keyword julia> set_comment!(header, "NEWKEY", "this is a comment") @@ -148,14 +148,14 @@ julia> set_comment!(header, "NEWKEY", "this is a comment") Close the file: -```julia +```julia-repl julia> close(f) ``` (`FITS` objects are also closed automatically when garbage collected.) Open a new file for writing: -```julia +```julia-repl julia> f = FITS("newfile.fits", "w"); ``` The second argument can be `"r"` (read-only; default), `"r+"` @@ -164,7 +164,7 @@ the same name is overwritten. Write an image to the file: -```julia +```julia-repl julia> data = reshape([1:100;], 5, 20) julia> write(f, data) # Write a new image extension with the data @@ -175,7 +175,7 @@ To write some header keywords in the new extension, pass a Overwrite image data in an existing file: -```julia +```julia-repl julia> f = FITS("newfile.fits", "r+") # Reopen the file in read-write mode julia> data = reshape([101:200;], 5, 20) # Prepare new image data julia> image_hdu = f[1] @@ -184,7 +184,7 @@ julia> write(image_hdu, data) # Overwrite the image Write a table to the file: -```julia +```julia-repl julia> data = Dict("col1"=>[1., 2., 3.], "col2"=>[1, 2, 3]); julia> write(f, data) # write a new binary table to a new extension @@ -193,7 +193,7 @@ julia> write(f, data) # write a new binary table to a new extension !!! tip "Compressed storage" Setting the file extension to `.gz` will automatically use GZIP compression and save on storage space. - ```julia + ```julia-repl julia> FITS("abc.fits", "w") do f # save the image uncompressed write(f, ones(200,200)) end @@ -211,7 +211,7 @@ julia> write(f, data) # write a new binary table to a new extension Alternately the compression algorithm might be specified in square brackets after the filename. Check the [CFITSIO website](https://heasarc.gsfc.nasa.gov/docs/software/fitsio/compression.html) for the details of this usage. - ```julia + ```julia-repl julia> FITS("abc.fits[compress R 100,100]", "w") do f # Rice algorithm with a 100 x 100 pixel tile size write(f, ones(200,200)) end @@ -221,4 +221,4 @@ julia> write(f, data) # write a new binary table to a new extension ``` !!! warn - Compression is "loss-less" for images with integer pixel values, and might be lossy for floating-point images. \ No newline at end of file + Compression is "loss-less" for images with integer pixel values, and might be lossy for floating-point images.