|
| 1 | +--- |
| 2 | +title: "ProFound: Beginner's Guide" |
| 3 | +author: "ProFound Package" |
| 4 | +date: "`r Sys.Date()`" |
| 5 | +output: rmarkdown::html_vignette |
| 6 | +vignette: > |
| 7 | + %\VignetteIndexEntry{ProFound: Beginner's Guide} |
| 8 | + %\VignetteEngine{knitr::rmarkdown} |
| 9 | + %\VignetteEncoding{UTF-8} |
| 10 | +--- |
| 11 | + |
| 12 | +```{r, include = FALSE} |
| 13 | +knitr::opts_chunk$set( |
| 14 | + collapse = TRUE, |
| 15 | + comment = "#>", |
| 16 | + eval = TRUE, |
| 17 | + fig.width = 7, |
| 18 | + fig.height = 7 |
| 19 | +) |
| 20 | +``` |
| 21 | + |
| 22 | +## What is ProFound? |
| 23 | + |
| 24 | +ProFound is an R package designed to **automatically detect and extract astronomical objects from images**. If you have an image (like a telescope observation), ProFound can: |
| 25 | + |
| 26 | +- Find all the stars, galaxies, or other objects in the image |
| 27 | +- Determine their locations and sizes |
| 28 | +- Measure their brightness |
| 29 | +- Separate overlapping objects |
| 30 | +- Create a catalogue you can analyse further |
| 31 | + |
| 32 | +Think of it as a "find all the things in this picture" tool, with sophisticated algorithms to handle real astronomical data. |
| 33 | + |
| 34 | +## When Would You Use ProFound? |
| 35 | + |
| 36 | +Typical use cases: |
| 37 | + |
| 38 | +- **Photometry**: Measuring the brightness of stars or galaxies |
| 39 | +- **Source catalogues**: Creating a list of all objects detected in a survey |
| 40 | +- **Image analysis**: Understanding what's in your astronomical images |
| 41 | +- **Pre-processing**: Preparing data before further analysis (like spectroscopy) |
| 42 | + |
| 43 | +## The Main Function: `profoundProFound()` |
| 44 | + |
| 45 | +The core of ProFound is the `profoundProFound()` function. Most of the time, this is the only function you need to know about. |
| 46 | + |
| 47 | +### Basic Usage |
| 48 | + |
| 49 | +The simplest form requires just an image: |
| 50 | + |
| 51 | +```{r eval=FALSE} |
| 52 | +library(ProFound) |
| 53 | +
|
| 54 | +# Run ProFound on an image |
| 55 | +result <- profoundProFound(image = my_image) |
| 56 | +``` |
| 57 | + |
| 58 | +That's it! ProFound will: |
| 59 | +1. Estimate the background sky level |
| 60 | +2. Find connected regions above a threshold |
| 61 | +3. Clean up the detections |
| 62 | +4. Measure properties of each object |
| 63 | +5. Return a list with all the results |
| 64 | + |
| 65 | +### What Do You Need to Input? |
| 66 | + |
| 67 | +**The image:** |
| 68 | +- Must be a 2D matrix or array of pixel values |
| 69 | +- Typically read from a FITS file (use `Rfits_read_image()` from the `Rfits` package) |
| 70 | +- Can be from any telescope or camera |
| 71 | + |
| 72 | +```{r eval=FALSE} |
| 73 | +library(Rfits) |
| 74 | +
|
| 75 | +# Read a FITS file |
| 76 | +fits_data <- Rfits_read_image("my_observation.fits") |
| 77 | +
|
| 78 | +# Run ProFound |
| 79 | +result <- profoundProFound(image = image) |
| 80 | +``` |
| 81 | + |
| 82 | +### Key Output: The Catalog |
| 83 | + |
| 84 | +The most useful output is `result$segstats`, a data frame containing detected objects and various useful properties, including: |
| 85 | + |
| 86 | +- `segID`: Unique ID for each object |
| 87 | +- `x`, `y`: Centre position (in pixels) |
| 88 | +- `N100`: Number of pixels in the object |
| 89 | +- `flux`: Total brightness (in ADU or counts) |
| 90 | +- `mag`: Magnitude (if `magzero` is set properly this will be in AB mag) |
| 91 | +- `R50`: Size of the object (radius containg 50% of the flux) |
| 92 | + |
| 93 | +```{r eval=FALSE} |
| 94 | +# View the catalog |
| 95 | +head(result$segstats) |
| 96 | +
|
| 97 | +# Access specific objects |
| 98 | +bright_objects = result$cat[result$cat$segstats$flux > 1000, ] |
| 99 | +``` |
| 100 | + |
| 101 | +## Common Parameters Explained |
| 102 | + |
| 103 | +ProFound has many parameters, but most have sensible defaults. Here are the ones you might adjust: |
| 104 | + |
| 105 | +### `skycut` and `pixcut` |
| 106 | + |
| 107 | +These control how aggressively ProFound detects objects: |
| 108 | + |
| 109 | +- **`skycut`** (default: 1.5): Detected objects must be this many times the sky noise above the background |
| 110 | +- **`pixcut`** (default: 3): Minimum number of connected pixels to count as an object |
| 111 | + |
| 112 | +*Lower values* = more detections (including fainter objects and noise) |
| 113 | +*Higher values* = fewer detections (only brightest objects) |
| 114 | + |
| 115 | +```{r eval=FALSE} |
| 116 | +# Detect fainter objects |
| 117 | +result_faint <- profoundProFound(image, skycut = 1, pixcut = 2) |
| 118 | +
|
| 119 | +# Detect only bright objects |
| 120 | +result_bright <- profoundProFound(image, skycut = 3, pixcut = 5) |
| 121 | +``` |
| 122 | + |
| 123 | +### `magzero` |
| 124 | + |
| 125 | +By default, ProFound reports brightness in raw counts (ADU). To convert to magnitudes: |
| 126 | + |
| 127 | +```{r eval=FALSE} |
| 128 | +# Tell ProFound the AB magnitude of a reference zero point |
| 129 | +result <- profoundProFound(image, magzero = 25) # Example: 25 mag zero point |
| 130 | +# Now result$cat$segstats will be in AB magnitudes |
| 131 | +``` |
| 132 | + |
| 133 | +### `mask` |
| 134 | + |
| 135 | +If certain parts of your image are bad (cosmic rays, detector artifacts), provide a mask: |
| 136 | + |
| 137 | +```{r eval=FALSE} |
| 138 | +# Create a mask: TRUE for good pixels, FALSE for bad pixels |
| 139 | +bad_pixels <- image$imDat < -100 # Example: very negative pixels are bad |
| 140 | +
|
| 141 | +result <- profoundProFound(image, mask = bad_pixels) |
| 142 | +# ProFound will ignore bad pixels |
| 143 | +``` |
| 144 | + |
| 145 | +### `gain` and `pixscale` |
| 146 | + |
| 147 | +For more accurate measurements: |
| 148 | + |
| 149 | +```{r eval=FALSE} |
| 150 | +# Tell ProFound the AB magnitude of a reference zero point |
| 151 | +# gain: electrons per ADU (from your detector specs) |
| 152 | +# pixscale: arcseconds per pixel (from your telescope/camera) |
| 153 | +result <- profoundProFound(image, magzero = 25, gain = 2.5, pixscale = 0.5) |
| 154 | +``` |
| 155 | + |
| 156 | +## A Complete Example |
| 157 | + |
| 158 | +```{r} |
| 159 | +library(ProFound) |
| 160 | +library(Rfits) |
| 161 | +
|
| 162 | +# 1. Read your image |
| 163 | +image = Rfits_read_image(system.file("extdata", 'VIKING/mystery_VIKING_Z.fits', |
| 164 | + package="ProFound")) |
| 165 | +
|
| 166 | +# 2. Create a simple mask (remove obvious bad pixels) |
| 167 | +mask <- image$imDat < -10 # Ignore very negative pixels |
| 168 | +
|
| 169 | +# 3. Run ProFound with sensible settings for detecting galaxies |
| 170 | +result <- profoundProFound( |
| 171 | + image = image, |
| 172 | + mask = mask, |
| 173 | + skycut = 1.5, # Moderate sensitivity |
| 174 | + pixcut = 3, # Require at least 3 connected pixels |
| 175 | + magzero = 26, # Convert to magnitudes |
| 176 | + pixscale = 0.3, # Pixel scale in arcsec |
| 177 | + plot = TRUE # Show diagnostic plots |
| 178 | +) |
| 179 | +
|
| 180 | +# 4. Examine the results |
| 181 | +cat_objects <- result$segstats |
| 182 | +
|
| 183 | +# How many objects did we detect? |
| 184 | +nrow(cat_objects) |
| 185 | +
|
| 186 | +# What's the brightest object? (Usually the first object with segID=1, but not always) |
| 187 | +brightest <- cat_objects[which.max(cat_objects$flux), ] |
| 188 | +
|
| 189 | +# Plot a histogram of magnitudes |
| 190 | +hist(cat_objects$mag, breaks = 50, |
| 191 | + main = "Magnitude Distribution", |
| 192 | + xlab = "Magnitude") |
| 193 | +``` |
| 194 | + |
| 195 | +Often the only bit people want to save is the *segstats* catalogue: |
| 196 | + |
| 197 | +```{r eval=FALSE} |
| 198 | +# Export the catalog |
| 199 | +write.csv(cat_objects, "/path/to/use/detected_objects.csv", row.names = FALSE) |
| 200 | +``` |
| 201 | + |
| 202 | +## Understanding the Segmentation Image |
| 203 | + |
| 204 | +ProFound also returns `result$segim`, a "segmentation image": |
| 205 | + |
| 206 | +- Each pixel is labelled with the ID of the object it belongs to |
| 207 | +- Value 0 = background (no object) |
| 208 | +- Value 1, 2, 3, ... = different detected objects |
| 209 | + |
| 210 | +```{r} |
| 211 | +# How many unique objects were detected? |
| 212 | +length(unique(as.integer(result$segim))) - 1L |
| 213 | +
|
| 214 | +# Which will be the same as |
| 215 | +dim(result$segstats) |
| 216 | +
|
| 217 | +# Visualize it |
| 218 | +magimage(result$segim, col = rainbow(max(result$segim))) |
| 219 | +``` |
| 220 | + |
| 221 | +## Troubleshooting |
| 222 | + |
| 223 | +### Too many detections (too much noise)? |
| 224 | + |
| 225 | +Increase `skycut` or `pixcut`: |
| 226 | + |
| 227 | +```{r} |
| 228 | +profoundProFound(image, skycut = 2.5, pixcut = 5, plot = TRUE) |
| 229 | +``` |
| 230 | + |
| 231 | +### Missing faint objects? |
| 232 | + |
| 233 | +Decrease `skycut` or `pixcut`: |
| 234 | + |
| 235 | +```{r} |
| 236 | +profoundProFound(image, skycut = 0.5, pixcut = 2, plot = TRUE) |
| 237 | +``` |
| 238 | + |
| 239 | +### Objects merged together? |
| 240 | + |
| 241 | +Lower de-blending tolerance: |
| 242 | + |
| 243 | +```{r} |
| 244 | +profoundProFound(image, tolerance = 1, plot = TRUE) |
| 245 | +``` |
| 246 | + |
| 247 | +### Wrong background estimate? |
| 248 | + |
| 249 | +Try a different sky estimation method: |
| 250 | + |
| 251 | +```{r} |
| 252 | +profoundProFound(image, skytype = "mean", plot = TRUE) |
| 253 | +``` |
| 254 | + |
| 255 | +## Next Steps |
| 256 | + |
| 257 | +- Check `?profoundProFound` for the full parameter list |
| 258 | +- Look at other vignettes for advanced topics (de-blending, photometry, etc.) |
| 259 | +- Run `profoundProFound(..., plot = TRUE)` to see diagnostic plots |
| 260 | +- Get advanced plots with plot method run on `profoundProFound` output, i.e. `plot(result)` |
| 261 | + |
| 262 | +Good luck with your analysis! |
0 commit comments