| Title: | Cosmic Microwave Background Data Analysis |
|---|---|
| Description: | Tools for handling and analysing spherical data on a HEALPix grid, with applications to cosmic microwave background maps. Supports reading FITS files, converting between spherical and Cartesian coordinates and HEALPix ordering schemes, selecting sky regions, sampling pixels, and visualising maps. Implements empirical covariance, correlation and variogram estimation, covariance model fitting, angular power spectrum estimation, and distributional and entropy-based comparisons of spherical data. The package and its methods are described by Fryer, Li and Olenko (2020) <doi:10.32614/RJ-2020-012>. |
| Authors: | Daniel Fryer [aut, cre] (ORCID: <https://orcid.org/0000-0001-6032-0522>), Andriy Olenko [aut] (ORCID: <https://orcid.org/0000-0002-0917-7000>), Ming Li [aut] (ORCID: <https://orcid.org/0000-0002-1218-2804>), Yuguang Wang [aut] |
| Maintainer: | Daniel Fryer <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.5 |
| Built: | 2026-10-28 23:31:33 UTC |
| Source: | https://github.com/cran/rcosmo |
th ancestor pixelGives the pixel at resolution that contains ,
where is specified at resolution (notice
it does not depend on ).
ancestor(p, k)ancestor(p, k)
p |
A pixel index specified in nested order. |
k |
A generation of an ancestor pixel. |
A numeric vector of nested pixel indices at resolution , identifying the ancestors containing the input pixels.
ancestor(4,2) ancestor(17,2)ancestor(4,2) ancestor(17,2)
Compare attributes to decide if two CMBDataFrames are compatible
areCompatibleCMBDFs(cmbdf1, cmbdf2, compare.pix = FALSE)areCompatibleCMBDFs(cmbdf1, cmbdf2, compare.pix = FALSE)
cmbdf1 |
|
cmbdf2 |
|
compare.pix |
A boolean. If TRUE then cmbdf1 and cmbdf2 must share the same pixel indices to be considered compatible |
If the CMBDataFrames do not have compatible attributes then
a message is printed indicating the attributes that do not match.
To suppress this use the suppressMessages function
A single logical value, TRUE if both objects have the same nside and ordering, and also the same pixel indices when compare.pix = TRUE; otherwise FALSE. Incompatibilities are reported with a suppressible message.
a <- CMBDataFrame(nside = 2, ordering = "ring", coords = "cartesian") b <- CMBDataFrame(nside = 1, ordering = "nested", coords = "spherical") areCompatibleCMBDFs(a,b) suppressMessages(areCompatibleCMBDFs(a,b))a <- CMBDataFrame(nside = 2, ordering = "ring", coords = "cartesian") b <- CMBDataFrame(nside = 1, ordering = "nested", coords = "spherical") areCompatibleCMBDFs(a,b) suppressMessages(areCompatibleCMBDFs(a,b))
CMBDataFrame
Safely converts a data.frame to a CMBDataFrame. The
rows of the data.frame are assumed to be in the HEALPix order
given by ordering, and at the HEALPix resolution given
by nside. Coordinates, if present, are assumed to correspond to
HEALPix pixel centers. The coordinates must be named either x,y,z
(cartesian) or theta, phi (spherical colatitude and longitude respectively).
If df is a HPDataFrame then
it is possible that df has attribute healpixCentered = TRUE,
in which case as.CMBDataFrame will perform HEALPix centering of
coordinates.
as.CMBDataFrame(df, ordering, nside, spix, drop.coords = FALSE)as.CMBDataFrame(df, ordering, nside, spix, drop.coords = FALSE)
df |
Any |
ordering |
character string that specifies the ordering scheme ("ring" or "nested") |
nside |
an integer |
spix |
an integer vector that specifies the HEALPix pixel index
corresponding to each row of |
drop.coords |
A logical. If |
A CMBDataFrame
## Example 1: Create df with no coords, then create CMBDataFrames cmbdf and ## df2 with spherical coords df <- data.frame(I=rnorm(12)) df cmbdf <- as.CMBDataFrame(df,ordering= "ring", nside=1) summary(cmbdf) pix(cmbdf) coords(cmbdf) df2 <- coords(cmbdf, new.coords = "spherical") df2 ## Example 2: Create CMBDataFrames for first 10 Healpix centers df <- data.frame(I=rnorm(10)) df cmbdf <- as.CMBDataFrame(df,ordering= "ring", nside=2, spix=1:10) summary(cmbdf) pix(cmbdf)## Example 1: Create df with no coords, then create CMBDataFrames cmbdf and ## df2 with spherical coords df <- data.frame(I=rnorm(12)) df cmbdf <- as.CMBDataFrame(df,ordering= "ring", nside=1) summary(cmbdf) pix(cmbdf) coords(cmbdf) df2 <- coords(cmbdf, new.coords = "spherical") df2 ## Example 2: Create CMBDataFrames for first 10 Healpix centers df <- data.frame(I=rnorm(10)) df cmbdf <- as.CMBDataFrame(df,ordering= "ring", nside=2, spix=1:10) summary(cmbdf) pix(cmbdf)
CMBWindow is assumed convex.Initially any CMBWindow is not assumed convex.
The assumedConvex
attribute can be change for any CMBWindow.
assumedConvex(win, assume.convex)assumedConvex(win, assume.convex)
win |
a CMBWindow object |
assume.convex |
optionally change the assumedConvex attribute to TRUE or FALSE |
A logical value giving the convexity assumption when assume.convex is omitted; otherwise the CMBWindow with its convexity attribute updated.
win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) assumedConvex(win1) win2 <- assumedConvex(win1, assume.convex = TRUE) assumedConvex(win2) assumedConvex(win1) <- TRUE assumedConvex(win1)win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) assumedConvex(win1) win2 <- assumedConvex(win1, assume.convex = TRUE) assumedConvex(win2) assumedConvex(win1) <- TRUE assumedConvex(win1)
The function checks object's attribute assumedUniquePix. The attribute is True if the object was assumed to have rows that correspond to unique HEALPix pixel indices.
assumedUniquePix(obj)assumedUniquePix(obj)
obj |
Any object. |
A boolean. This is TRUE if obj
is a CMBDataFrame or a HPDataFrame whose
rows were assumed to correspond to unique HEALPix pixel indices.
hp1 <- HPDataFrame(I=rnorm(5), nside = 1, spix = c(1,1,2,2,3)) pix(hp1) coords(hp1, new.coords = "cartesian") assumedUniquePix(hp1) sky <- CMBDataFrame(nside = 32, coords = "cartesian", ordering = "nested") sky.s <- CMBDataFrame(sky, sample.size = 100) hpdf <- HPDataFrame(sky.s, auto.spix = TRUE) assumedUniquePix(hpdf)hp1 <- HPDataFrame(I=rnorm(5), nside = 1, spix = c(1,1,2,2,3)) pix(hp1) coords(hp1, new.coords = "cartesian") assumedUniquePix(hp1) sky <- CMBDataFrame(nside = 32, coords = "cartesian", ordering = "nested") sky.s <- CMBDataFrame(sky, sample.size = 100) hpdf <- HPDataFrame(sky.s, auto.spix = TRUE) assumedUniquePix(hpdf)
The base-resolution comprises twelve pixels. baseNeighbours returns
a map from the base pixel index bp to the vector of base pixels
that are neighbours of bp, in counterclockwise order of
direction: S,SE,E,NE,N,NW,W,SW. The presence of -1 indicates
that the corresponding direction is empty.
baseNeighbours(bp)baseNeighbours(bp)
bp |
The base pixel index |
A numeric vector of eight neighbouring base pixel indices in the order S, SE, E, NE, N, NW, W, SW. Missing neighbours are coded as -1. Returns NULL for an index outside 1 to 12.
## Return neighbours of base pixel 1 baseNeighbours(1) ## There is no base pixel 14, so baseNeighbours returns NULL baseNeighbours(14)## Return neighbours of base pixel 1 baseNeighbours(1) ## There is no base pixel 14, so baseNeighbours returns NULL baseNeighbours(14)
cbind for CMBDataFramesAdd a new column or columns (vector, matrix or data.frame)
to a CMBDataFrame. Note that method dispatch
occurs on the first argument. So, the CMBDataFrame must
be the first argument
## S3 method for class 'CMBDataFrame' cbind(..., deparse.level = 1)## S3 method for class 'CMBDataFrame' cbind(..., deparse.level = 1)
... |
(generalized) vectors or matrices. Columns to bind. |
deparse.level |
Integer controlling the construction of labels in the case of non-matrix-like arguments. |
See the documentation for cbind
A CMBDataFrame containing the combined columns, with HEALPix metadata and pixel indices retained from the single CMBDataFrame input.
cmbdf <- CMBDataFrame(nside = 1, ordering = "nested", coords = "spherical") cmbdf2 <- cbind(cmbdf, myData = rep(1, 12)) cmbdf2cmbdf <- CMBDataFrame(nside = 1, ordering = "nested", coords = "spherical") cmbdf2 <- cbind(cmbdf, myData = rep(1, 12)) cmbdf2
CMBWindowsThis function returns the empirical chi-squared statistic for intensities
observations from two CMBWindows of the specified
CMBDataFrame. The functions employs the function chi2.empirical and uses histogram
counts of intensities for computations.
chi2CMB(cmbdf, win1, win2, intensities = "I")chi2CMB(cmbdf, win1, win2, intensities = "I")
cmbdf |
A |
win1 |
|
win2 |
|
intensities |
A |
Estimated Chi-squared statistic for observations in two
CMBWindows. For small sample sizes and many zero counts
Chi-squared statistic is inefficient.
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) win2 <- CMBWindow(theta = c(pi/2, pi, pi/2), phi = c(0, 0, pi/2)) chi2CMB(cmbdf, win1, win2)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) win2 <- CMBWindow(theta = c(pi/2, pi, pi/2), phi = c(0, 0, pi/2)) chi2CMB(cmbdf, win1, win2)
Gives four pixels at resolution that are contained in ,
where is a pixel specified at resolution (notice it does not
depend on ).
children(p)children(p)
p |
A pixel index specified in nested order. |
A numeric vector of four nested pixel indices at resolution , identifying the children of pixel p.
children(11)children(11)
The function CMBDat creates objects of class CMBDat.
These are lists containing header information and other metadata as well
as an element called data, whose columns may include, for example, the
intensity (I), polarisation (Q, U), PMASK and TMASK. It also may contain an
mmap object that points to the CMB map data table in the FITS
file.
CMBDat(filename, mmap = FALSE, spix)CMBDat(filename, mmap = FALSE, spix)
filename |
The path to the fits file. |
mmap |
A boolean indicating whether to use memory mapping. |
spix |
The sample pixels (rows) to read from the FITS file binary data table (optional) |
A list containing header information and other metadata
as well as an element called data where:
If mmap = FALSE then a data.frame is
included, named data, whose columns may include, for
example, the intensity (I), polarisation (Q, U), PMASK and TMASK.
If mmap = TRUE then a mmap object is returned
that points to the CMB map data table in the FITS file.
filename <- system.file("extdata", "CMB_testmap.fits", package = "rcosmo") cmbdat <- CMBDat(filename, spix = 1:10) class(cmbdat) cmbdat$nside cmbdat$ordering head(cmbdat$data)filename <- system.file("extdata", "CMB_testmap.fits", package = "rcosmo") cmbdat <- CMBDat(filename, spix = 1:10) class(cmbdat) cmbdat$nside cmbdat$ordering head(cmbdat$data)
The function CMBDataFrame creates objects of class CMBDataFrame.
These are a special type of data.frame that carry metadata
about, e.g., the HEALPix ordering scheme, coordinate system, and nside parameter.
CMBDataFrame( CMBData, coords, win, include.polar = FALSE, include.masks = FALSE, spix, sample.size, nside, ordering, I, ... )CMBDataFrame( CMBData, coords, win, include.polar = FALSE, include.masks = FALSE, spix, sample.size, nside, ordering, I, ... )
CMBData |
Can be a string location of FITS file,
another |
coords |
Can be "spherical," "cartesian", or unspecified (HEALPix only). |
win |
optional |
include.polar |
TRUE if polarisation data is required, otherwise FALSE. |
include.masks |
TRUE if TMASK and PMASK are required, otherwise FALSE. |
spix |
Optional vector of sample pixel indices, or a path to a file
containing comma delimited sample pixel indices. The ordering scheme is
given by |
sample.size |
If a positive integer is given, a simple random
sample of size equal to sample.size will be taken from CMBData. If
spix is specified then |
nside |
Optionally specify the nside parameter manually nside= |
ordering |
Specifies the desired HEALPix ordering scheme
("ring" or "nested") for the output CMBDataFrame.
If |
I |
A vector of intensities to be included
if |
... |
Optional names data columns of length nrow(CMBData) to add to the CMBDataFrame. |
A CMBDataFrame whose row.names attribute contains
HEALPix indices.
## Construct a small synthetic sky map. df <- CMBDataFrame(nside = 16, I = rnorm(12 * 16 ^ 2), ordering = "nested") ## Take a random sample. df.sample <- CMBDataFrame(df, sample.size = 80) plot(df.sample) ## Select pixels by index. df.subset <- CMBDataFrame(df, spix = c(2,4,6)) ## Inspect the map and the selected pixel indices. summary(df) pix(df.subset)## Construct a small synthetic sky map. df <- CMBDataFrame(nside = 16, I = rnorm(12 * 16 ^ 2), ordering = "nested") ## Take a random sample. df.sample <- CMBDataFrame(df, sample.size = 80) plot(df.sample) ## Select pixels by index. df.subset <- CMBDataFrame(df, spix = c(2,4,6)) ## Inspect the map and the selected pixel indices. summary(df) pix(df.subset)
The function CMBWindow creates objects of class CMBWindow.
It is either a polygon or a disc type.
CMBWindow(..., r, set.minus = FALSE, assume.convex = FALSE)CMBWindow(..., r, set.minus = FALSE, assume.convex = FALSE)
... |
these arguments are compulsory and must be labelled either x, y, z (cartesian) or theta, phi (spherical, colatitude and longitude respectively). Alternatively, a single data.frame may be passed in with columns labelled x, y, z or theta, phi. |
r |
if a disc type window is required then this specifies the radius of the disc |
set.minus |
when |
assume.convex |
when |
If r is unspecified then the rows of ... correspond to
counter-clockwise ordered vertices defining a spherical polygon
lying entirely within one open hemisphere on the unit sphere.
Counter-clockwise is understood from the perspective outside the
sphere, facing the hemisphere that contains the polygon, looking
toward the origin. Note that there must be at least 3 rows (vertices)
to define a polygon (we exclude bygones).
On the other hand,
if r is specified then ... must specify just one row, and this
row is taken to be the center of a disc of radius r
A data frame of class CMBWindow containing vertex coordinates for a polygon, or centre coordinates and radius r for a disc. Attributes record the coordinate system, window type and convexity assumption.
win <- CMBWindow(theta = c(pi/2,pi/2,pi/3, pi/3), phi = c(0,pi/3,pi/3,0)) plot(win) ## Create a disc type window win1<- CMBWindow(x=0,y=3/5,z=4/5,r=0.8, set.minus =TRUE) plot(win1) ## Apply a disc type window to CMBDataFrame cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") window(cmbdf) <- CMBWindow(x=0,y=3/5,z=4/5,r=0.8, set.minus =TRUE) plot(cmbdf)win <- CMBWindow(theta = c(pi/2,pi/2,pi/3, pi/3), phi = c(0,pi/3,pi/3,0)) plot(win) ## Create a disc type window win1<- CMBWindow(x=0,y=3/5,z=4/5,r=0.8, set.minus =TRUE) plot(win1) ## Apply a disc type window to CMBDataFrame cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") window(cmbdf) <- CMBWindow(x=0,y=3/5,z=4/5,r=0.8, set.minus =TRUE) plot(cmbdf)
Detailed descriptions and and examples can be found in documentation for specific
coords functions coords.CMBDataFrame, coords.CMBWindow,
coords.HPDataFrame, coords.data.frame
coords(x, ...)coords(x, ...)
x |
An object. |
... |
Unused arguments. |
A character string naming the coordinate system when it is queried, or an object of the input class with converted coordinates when a new system is supplied. See the individual methods for supported classes.
coords.CMBDataFrame
coords.CMBWindow
coords.HPDataFrame
coords.data.frame
CMBDataFrame
If new.coords is unspecified then
this function returns the coordinate system used in the CMBDataFrame
cmbdf.
The coordinate system is either "cartesian" or "spherical".
If a new coordinate system is specified, using e.g.
new.coords = "spherical", then this function instead
returns a new CMBDataFrame whose coordinates are of the specified
type. The original CMBDataFrame, cmbdf, is unaffected.
If you would like to change cmbdf without creating a new
variable, then use coords<-.CMBDataFrame (see
examples below).
## S3 method for class 'CMBDataFrame' coords(x, new.coords, ...)## S3 method for class 'CMBDataFrame' coords(x, new.coords, ...)
x |
A CMBDataFrame, |
new.coords |
Specifies the new coordinate system ("spherical" or "cartesian") if a change of coordinate system is desired. |
... |
Unused arguments. |
If new.coords is unspecified, then the name of the coordinate system
of cmbdf is returned. Otherwise a new CMBDataFrame is returned
equivalent to cmbdf but having the desired change of coordinates
## Create df with no coords, then create df2 with cartesian coords df <- CMBDataFrame(nside = 16) df coords(df) df2 <- coords(df, new.coords = "cartesian") coords(df2) ## Change the coords of df directly (to spherical) coords(df) <- "spherical" coords(df)## Create df with no coords, then create df2 with cartesian coords df <- CMBDataFrame(nside = 16) df coords(df) df2 <- coords(df, new.coords = "cartesian") coords(df2) ## Change the coords of df directly (to spherical) coords(df) <- "spherical" coords(df)
CMBWindow
This function returns the coordinate system used in a
CMBWindow. The coordinate system is either
"cartesian" or "spherical"
## S3 method for class 'CMBWindow' coords(x, new.coords, ...)## S3 method for class 'CMBWindow' coords(x, new.coords, ...)
x |
a CMBWindow, |
new.coords |
specifies the new coordinate system ("spherical" or "cartesian") if a change of coordinate system is desired |
... |
Unused arguments. |
If a new coordinate system is specified, using e.g. new.coords = "spherical", the coordinate system of the CMBWindow will be converted
If new.coords is unspecified, then the name of the coordinate system
of win is returned. Otherwise a new CMBWindow is returned
equivalent to win but having the desired change of coordinates
## Create win with sperical coords, then change it to win1 with cartesian coords win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) coords(win) win1 <- coords(win, new.coords = "cartesian") coords(win1) ## Change back to spherical coordinates coords(win1) <- "spherical" coords(win1)## Create win with sperical coords, then change it to win1 with cartesian coords win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) coords(win) win1 <- coords(win, new.coords = "cartesian") coords(win1) ## Change back to spherical coordinates coords(win1) <- "spherical" coords(win1)
This does not affect the original object unless new coordinate system is directly assigned.
## S3 method for class 'data.frame' coords(x, new.coords, ...)## S3 method for class 'data.frame' coords(x, new.coords, ...)
x |
a data.frame with columns labelled x, y, z (for cartesian) or theta, phi (for spherical colatitude and longitude respectively) |
new.coords |
specifies the new coordinate system ("spherical" or "cartesian"). |
... |
Unused arguments. |
A new data.frame whose coordinates are as specified by
new.coords
## Create df with no coords, then create df2 with spherical coords df <- data.frame(x = c(1,0,0), y = c(0,1,0), z = c(0,0,1)) df df2 <- coords(df, new.coords = "spherical") df2 ## The function coords does not affect the original object. ## To change the coords assign a new value ("spherical or "cartesian") coords(df, new.coords = "spherical") df coords(df) <- "spherical" df## Create df with no coords, then create df2 with spherical coords df <- data.frame(x = c(1,0,0), y = c(0,1,0), z = c(0,0,1)) df df2 <- coords(df, new.coords = "spherical") df2 ## The function coords does not affect the original object. ## To change the coords assign a new value ("spherical or "cartesian") coords(df, new.coords = "spherical") df coords(df) <- "spherical" df
HPDataFrame
Add or change coordinates in a HPDataFrame.
This does not affect the argument object hpdf.
Instead it returns a new HPDataFrame
with the desired coordinates. To change hpdf
directly see coords<-.HPDataFrame.
## S3 method for class 'HPDataFrame' coords(x, new.coords, healpixCentered = FALSE, ...)## S3 method for class 'HPDataFrame' coords(x, new.coords, healpixCentered = FALSE, ...)
x |
a HPDataFrame, |
new.coords |
specifies the new coordinate system ("spherical" or "cartesian") |
healpixCentered |
boolean. If TRUE then columns x,y,z
or theta, phi will be ignored and removed if present.
This forces the coordinates to be found from HEALPix
pixel indices only. Then the HEALPixCentered
attribute of |
... |
Unused arguments. |
If columns exist labelled x,y,z (cartesian) or theta, phi
(colatitude and longitude respectively), then these will be
treated as the coordinates of hpdf and converted
accordingly.
If columns x,y,z or theta,phi are not present then the healpix
pixel indices as given by pix(hpdf) are used for
assigning coordinates.
A HPDataFrame with columns x,y,z (cartesian)
or theta, phi (colatitude and longitude respectively)
df <- HPDataFrame(I = rep(0,12), nside = 1) coords(df, new.coords = "cartesian") # Notice that df is unchanged df # Instead, change df directly coords(df) <- "spherical" ## specify cartesian coordinates then convert to spherical hp1 <- HPDataFrame(x = c(1,0,0), y = c(0,1,0), z = c(0,0,1), nside = 1, auto.spix = TRUE) hp1 <- coords(hp1, new.coords = "spherical") ## Instead, ignore/drop existing coordinates and use HEALPix only hp2 <- HPDataFrame(x = c(1,0,0), y = c(0,1,0), z = c(0,0,1), nside = 1, auto.spix = TRUE) hp2 <- coords(hp1, new.coords = "spherical", healpixCentered = TRUE)df <- HPDataFrame(I = rep(0,12), nside = 1) coords(df, new.coords = "cartesian") # Notice that df is unchanged df # Instead, change df directly coords(df) <- "spherical" ## specify cartesian coordinates then convert to spherical hp1 <- HPDataFrame(x = c(1,0,0), y = c(0,1,0), z = c(0,0,1), nside = 1, auto.spix = TRUE) hp1 <- coords(hp1, new.coords = "spherical") ## Instead, ignore/drop existing coordinates and use HEALPix only hp2 <- HPDataFrame(x = c(1,0,0), y = c(0,1,0), z = c(0,0,1), nside = 1, auto.spix = TRUE) hp2 <- coords(hp1, new.coords = "spherical", healpixCentered = TRUE)
This function provides an empirical correlation function for data
in a CMBDataFrame or data.frame. It assumes that data are from a stationary spherical
random field and the correlation depends only on a geodesic distance between locations.
Output is a binned correlation.
corrCMB( cmbdf, num.bins = 10, sample.size, max.dist = pi, breaks, equiareal = TRUE, calc.max.dist = FALSE )corrCMB( cmbdf, num.bins = 10, sample.size, max.dist = pi, breaks, equiareal = TRUE, calc.max.dist = FALSE )
cmbdf |
is a |
num.bins |
specifies the number of bins |
sample.size |
optionally specify the size of a simple random sample to take before calculating correlation. This may be useful if the full correlation computation is too slow. |
max.dist |
an optional number between 0 and pi specifying the
maximum geodesic distance to use for calculating correlation. Only
used if |
breaks |
optionally specify the breaks manually using a
vector giving the break points between cells. This vector
has length |
equiareal |
if TRUE then the bins have equal spherical area. If false then the bins have equal annular widths. Default is TRUE. |
calc.max.dist |
if TRUE then the |
#' An object of the class CMBCorrelation that is a modification of variog
from the package geoR with variogram values replaced by correlation.
The attribute "breaks" contains the break points used to create bins.
The result has num.bins + 1 values since the first value at distance 0 is not
counted as a bin.
a vector with distances.
a vector with estimated correlation values at distances given in u.
number of pairs in each bin
standard deviation of the values in each bin
limits defining the interval spanned by each bin
a logical vector indicating whether the number of pairs in each bin is greater or equal to the value in the argument pairs.min
variance of the data
parameters of the mean part of the model fitted by ordinary least squares
echoes the option argument
maximum distance between pairs allowed in the correlation calculations
number of data
direction for which the correlation was computed
the function call
geoR package,variog, variogramCMB, covCMB
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") corcmb <- corrCMB(cmbdf, max.dist = pi/2, num.bins = 6) corcmbset.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") corcmb <- corrCMB(cmbdf, max.dist = pi/2, num.bins = 6) corcmb
This function provides an empirical covariance function for data
in a CMBDataFrame or data.frame. It assumes that data are from a stationary spherical
random field and the covariance depends only on a geodesic distance between locations.
Output is a binned covariance.
covCMB( cmbdf, num.bins = 10, sample.size, max.dist = pi, breaks, equiareal = TRUE, calc.max.dist = FALSE )covCMB( cmbdf, num.bins = 10, sample.size, max.dist = pi, breaks, equiareal = TRUE, calc.max.dist = FALSE )
cmbdf |
is a |
num.bins |
specifies the number of bins |
sample.size |
optionally specify the size of a simple random sample to take before calculating covariance. This may be useful if the full covariance computation is too slow. |
max.dist |
an optional number between 0 and pi specifying the
maximum geodesic distance to use for calculating covariance. Only
used if |
breaks |
optionally specify the breaks manually using a
vector giving the break points between cells. This vector
has length |
equiareal |
if TRUE then the bins have equal spherical area. If false then the bins have equal annular widths. Default is TRUE. |
calc.max.dist |
if TRUE then the |
An object of the class CMBCovariance that is a modification of variog
from the package geoR with variogram values replaced by covariances.
The attribute "breaks" contains the break points used to create bins.
The result has num.bins + 1 values since the first value, the sample
variance, is not counted as a bin.
a vector with distances.
a vector with estimated covariance values at distances given in u.
number of pairs in each bin
standard deviation of the values in each bin
limits defining the interval spanned by each bin
a logical vector indicating whether the number of pairs in each bin is greater or equal to the value in the argument pairs.min
variance of the data
parameters of the mean part of the model fitted by ordinary least squares
echoes the option argument
maximum distance between pairs allowed in the covariance calculations
number of data
direction for which the covariance was computed
the function call
geoR package, variog, variogramCMB, corrCMB
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") Cov <- covCMB(cmbdf, max.dist = pi/2, num.bins = 6) Covset.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") Cov <- covCMB(cmbdf, max.dist = pi/2, num.bins = 6) Cov
This function computes the covariances given the separation distance of locations.
Options for different covariance functions on spheres are available. The function
extends the function cov.spatial for additional
covariance models on spheres.
covmodelCMB( obj, cov.model = "matern", cov.pars = stop("no cov.pars argument provided"), kappa = 0.5 )covmodelCMB( obj, cov.model = "matern", cov.pars = stop("no cov.pars argument provided"), kappa = 0.5 )
obj |
Vector of distances between pairs of spatial locations. |
cov.model |
A type of the correlation function. Available choices are: "matern", "exponential","spherical", "powered.exponential", "cauchy", "gencauchy", "pure.nugget", "askey", "c2wendland", "c4wendland", "sinepower", "multiquadric". Default is "matern" |
cov.pars |
A vector with two covariance parameters. The first parameter corresponds to the variance sigma^2. The second parameter corresponds to the range phi of the correlation function. |
kappa |
A smoothness parameter of the correlation function. |
The function returns the value of the covariance C(h) at the distance h.
The covariance function has the form
The parameters of the covariance are positive numbers sigma^2, phi
and kappa.
Expressions for the correlation functions which are not included in the package geoR:
Additional information can be found in the section Details in
cov.spatial.
Values of a covariance function for the given distances.
geoR package, cov.spatial
T. Gneiting. Strictly and non-strictly positive definite functions on spheres. Bernoulli 19 (2013), no. 4, 1327-1349.
## Compute Askey variogram at x = pi/4 1 - covmodelCMB(pi/4, cov.pars = c(1, pi), kappa = 3, cov.model = "askey" ) ## Plot of the Askey covariance function v1.f <- function(x, ...) {covmodelCMB(x, ...)} curve( v1.f(x, cov.pars = c(1, 0.03), kappa = 3, cov.model = "askey"), from = 0, to = 0.1, xlab = "distance", ylab = expression(cov(h)), lty = 2, main = "covariance")## Compute Askey variogram at x = pi/4 1 - covmodelCMB(pi/4, cov.pars = c(1, pi), kappa = 3, cov.model = "askey" ) ## Plot of the Askey covariance function v1.f <- function(x, ...) {covmodelCMB(x, ...)} curve( v1.f(x, cov.pars = c(1, 0.03), kappa = 3, cov.model = "askey"), from = 0, to = 0.1, xlab = "distance", ylab = expression(cov(h)), lty = 2, main = "covariance")
This function provides a covariance estimate using the values of the estimated power spectra.
covPwSp(PowerSpectra, Ns)covPwSp(PowerSpectra, Ns)
PowerSpectra |
A data frame which first column lists values of multipole moments and the second column gives the corresponding values of CMB power spectra. |
Ns |
A number of points in which the covariance estimate is computed on the interval [-1,1] |
A data frame which first column is 1-d grid starting at -1+1/Ns and finishing at 1 with the step 2/Ns. The second column is the values of estimated covariances on this grid.
Formula (2.1) in Baran A., Terdik G. Power spectrum estimation of spherical random fields based on covariances. Annales Mathematicae et Informaticae 44 (2015) pp. 15–22.
Power Spectra data are from Planck Legacy Archive https://www.cosmos.esa.int/web/planck/pla
if (requireNamespace("gsl", quietly = TRUE)) { spectrum <- data.frame(l = 1:5, power = exp(-(1:5))) Cov_est <- covPwSp(spectrum, Ns = 100) plot(acos(Cov_est$t), Cov_est$Estimated_Cov, type = "l", xlab = "Angular distance", ylab = "Estimated covariance") }if (requireNamespace("gsl", quietly = TRUE)) { spectrum <- data.frame(l = 1:5, power = exp(-(1:5))) Cov_est <- covPwSp(spectrum, Ns = 100) plot(acos(Cov_est$t), Cov_est$Estimated_Cov, type = "l", xlab = "Angular distance", ylab = "Estimated covariance") }
Plot the HEALPix pixel boundaries at nside
displayPixelBoundaries( nside, eps = pi/90, col = "gray", lwd = 1, ordering, incl.labels = 1:(12 * nside^2), nums.col = col, nums.size = 1, font = 2, depth_test = "always", ... )displayPixelBoundaries( nside, eps = pi/90, col = "gray", lwd = 1, ordering, incl.labels = 1:(12 * nside^2), nums.col = col, nums.size = 1, font = 2, depth_test = "always", ... )
nside |
the HEALPix nside parameter (integer number |
eps |
controls the smoothness of the plot, smaller eps implies more samples |
col |
the colour of plotted boundary lines |
lwd |
the thickness of the plotted boundary lines |
ordering |
optionally specify an ordering scheme from which to plot HEALPix pixel numbers. Can be either "ring" or "nested" |
incl.labels |
If |
nums.col |
specifies the colour of pixel numbers
if |
nums.size |
specifies the size of pixel numbers
if |
font |
A numeric font number from 1 to 5,
used if |
depth_test |
The depth test to be applied.
This controls how resistant the plotted
object is to being obscured. See |
... |
arguments passed to |
Produces a plot of the HEALPix pixel boundaries.
displayPixelBoundaries(1, eps = pi/90, col = "red") displayPixelBoundaries(2, eps = pi/90, col = "green")displayPixelBoundaries(1, eps = pi/90, col = "red") displayPixelBoundaries(2, eps = pi/90, col = "green")
Display the pixels spix at resolution by colouring
in the grandchildren of spix at resolution
displayPixels( boundary.j, j, plot.j = 5, spix, boundary.col = "gray", boundary.lwd = 1, incl.labels = 1:(12 * 4^boundary.j), col = "blue", size = 3 )displayPixels( boundary.j, j, plot.j = 5, spix, boundary.col = "gray", boundary.lwd = 1, incl.labels = 1:(12 * 4^boundary.j), col = "blue", size = 3 )
boundary.j |
The resolution to display boundaries at. If this is missing then boundaries will not be plotted. |
j |
The resolution that spix are specified at. |
plot.j |
The resolution to plot grandchildren at |
spix |
Integer vector. The pixel indices to display. These must be in nested order. |
boundary.col |
The boundary colour. |
boundary.lwd |
The boundary line width. |
incl.labels |
Integer vector of pixel indices to label at resolution j. |
col |
The colour to make the grandchildren. |
size |
The size to make the grandchildren. |
No meaningful return value; called for its side effect of drawing pixels and optional boundaries in the current rgl scene.
## Example 1 ## Plot base pixels 1,2,3 by colouring their grandchildren at resolution ## 5 (by default). No pixel boundaries. displayPixels(j=0, spix=c(1,2,3)) ## Plot base pixels 1,2,3 display and their boundaries (boundary.j=0) displayPixels(0,0, spix=c(1,2,3)) ## Plot base pixels 1,2,3 by colouring their grandchildren at resolution 2 displayPixels(0,0, plot.j = 2, spix=c(1,2,3)) ## Example 2 demoNeighbours <- function(p,j) { neighbours(p, j) displayPixels(boundary.j = j, j = j, plot.j = 5, spix = neighbours(p, j), boundary.col = "gray", boundary.lwd = 1, incl.labels = neighbours(p, j), col = "blue", size = 3) rcosmo::displayPixelBoundaries(nside = 1, col = "blue", lwd = 3) } demoNeighbours(1,2)## Example 1 ## Plot base pixels 1,2,3 by colouring their grandchildren at resolution ## 5 (by default). No pixel boundaries. displayPixels(j=0, spix=c(1,2,3)) ## Plot base pixels 1,2,3 display and their boundaries (boundary.j=0) displayPixels(0,0, spix=c(1,2,3)) ## Plot base pixels 1,2,3 by colouring their grandchildren at resolution 2 displayPixels(0,0, plot.j = 2, spix=c(1,2,3)) ## Example 2 demoNeighbours <- function(p,j) { neighbours(p, j) displayPixels(boundary.j = j, j = j, plot.j = 5, spix = neighbours(p, j), boundary.col = "gray", boundary.lwd = 1, incl.labels = neighbours(p, j), col = "blue", size = 3) rcosmo::displayPixelBoundaries(nside = 1, col = "blue", lwd = 3) } demoNeighbours(1,2)
The function downloadCMBMap downloads CMB maps from
https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/matrix_cmb.html.
downloadCMBMap(foreground = "smica", nside = 1024, destfile, release = 2)downloadCMBMap(foreground = "smica", nside = 1024, destfile, release = 2)
foreground |
A string naming the foreground separation method pipeline. Please choose one of "COMMANDER", "NILC", "SEVEM" or "SMICA" (not case sensitive). |
nside |
An integer. The nside parameter (resolution) required.
The available options are |
destfile |
A required character string with an explicit path and file name for the downloaded file. No default destination is used. Tilde-expansion is performed. |
release |
An integer. Indicates the Planck map release to download. Currently only 2 and 3 are supported. |
CMB maps have been produced by the COMMANDER, NILC, SEVEM, and SMICA pipelines, respectively.
For each pipeline, the intensity maps are provided at Nside = 2048, at 5 arcmin resolution, and the polarization maps are provided at Nside = 1024 at 10 arcmin resolution.
The integer status code from utils::download.file,
returned invisibly (0 indicates success). The FITS map is saved to
destfile and can be read with CMBDataFrame.
Planck Public Data Release 2 Maps https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/matrix_cmb.html
Other fits maps can also be downloaded
using the general command download.file.
## Requires internet access and downloads a large FITS file. if (interactive()) { dest <- tempfile(fileext = ".fits") downloadCMBMap(foreground = "smica", nside = 1024, destfile = dest) sky <- CMBDataFrame(dest, spix = 1:10) unlink(dest) }## Requires internet access and downloads a large FITS file. if (interactive()) { dest <- tempfile(fileext = ".fits") downloadCMBMap(foreground = "smica", nside = 1024, destfile = dest) sky <- CMBDataFrame(dest, spix = 1:10) unlink(dest) }
The function downloadCMBPS downloads
CMB power spectra components from
https://www.cosmos.esa.int/web/planck/pla.
downloadCMBPS(link = 1, destfile, save = TRUE)downloadCMBPS(link = 1, destfile, save = TRUE)
link |
The link code (an integer from 1 to 6) for the URL to download the file. See code details in this help file. |
destfile |
A character string with an explicit path and file name.
Required when |
save |
A boolean indicating whether to save or not (since the downloaded data is returned anyway). |
link = 1: Best-fit LCDM CMB power spectra
from the baseline Planck
TT, TE, EE+lowE+lensing (2 <= ell <= 2508).
link = 2: Baseline high-ell
Planck TT power spectra (2 <= ell <= 2508).
link = 3: Baseline high-ell
Planck EE power spectra (2 <= ell <= 1996).
link = 4: Baseline high-ell
Planck TE power spectra (2 <= ell <= 1996).
link = 5: Low-ell
Planck EB power spectra (2 <= ell <= 29).
link = 6: Low-ell
Planck BB power spectra (2 <= ell <= 29).
A data frame returned invisibly, containing multipoles in column
L and the selected power spectrum and uncertainty columns described
above. When save = TRUE, it is also written to destfile.
Planck Legacy Archive https://www.cosmos.esa.int/web/planck/pla
## Requires internet access. if (interactive()) { dest <- tempfile(fileext = ".txt") spectrum <- downloadCMBPS(link = 6, destfile = dest) unlink(dest) spectrum <- downloadCMBPS(link = 1, save = FALSE) plot(spectrum$L, spectrum$TT, type = "l") }## Requires internet access. if (interactive()) { dest <- tempfile(fileext = ".txt") spectrum <- downloadCMBPS(link = 6, destfile = dest) unlink(dest) spectrum <- downloadCMBPS(link = 1, save = FALSE) plot(spectrum$L, spectrum$TT, type = "l") }
This function returns an estimated entropy for the specified
CMBDataFrame column intensities and CMBWindow
region. The functions employs the function entropy and uses histogram
counts of intensities for computations. All arguments of the standard
entropy can be used.
entropyCMB(cmbdf, win, intensities = "I", method)entropyCMB(cmbdf, win, intensities = "I", method)
cmbdf |
A |
win |
|
intensities |
A |
method |
A method to estimate entropy, see entropy |
Estimated Shannon entropy for observations in CMBWindow
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) entropyCMB(cmbdf, win1)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) entropyCMB(cmbdf, win1)
This function returns an estimated exceedance probability for the specified
CMBDataFrame column intensities, threshold level
and CMBWindow region.
exprob(cmbdf, win, alpha, intensities = "I")exprob(cmbdf, win, alpha, intensities = "I")
cmbdf |
A |
win |
|
alpha |
A numeric threshold level. |
intensities |
The name of the column in |
Estimated threshold exceedance probability
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) exprob(cmbdf, win1, alpha = mean(cmbdf$I))set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) exprob(cmbdf, win1, alpha = mean(cmbdf$I))
This function returns n largest extreme values for the specified
CMBDataFrame column intensities and
CMBWindow region.
extrCMB(cmbdf, win, n, intensities = "I")extrCMB(cmbdf, win, n, intensities = "I")
cmbdf |
A |
win |
|
n |
An integer value. |
intensities |
A |
A CMBDataFrame with n largest extreme values
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) extremes <- extrCMB(cmbdf, win1, 5) extremesset.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) extremes <- extrCMB(cmbdf, win1, 5) extremes
This function returns an area of the spherical region
where measured values
are above of the specified threshold level .
fmf(cmbdf, alpha, intensities = "I")fmf(cmbdf, alpha, intensities = "I")
cmbdf |
A |
alpha |
A numeric threshold level. |
intensities |
A |
The area of the exceedance region
Leonenko N., Olenko A. (2014) Sojourn measures of Student and Fisher-Snedecor random fields. Bernoulli, 20:1454-1483.
n <- 64 cmbdf <- CMBDataFrame(nside=n, I = rnorm(12*n^2), coords = "cartesian", ordering = "nested") fmf(cmbdf, 0, 4) fmf(cmbdf, 2, 4) win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) cmbdf.win <- window(cmbdf, new.window = win) fmf(cmbdf.win, 0, 4)n <- 64 cmbdf <- CMBDataFrame(nside=n, I = rnorm(12*n^2), coords = "cartesian", ordering = "nested") fmf(cmbdf, 0, 4) fmf(cmbdf, 2, 4) win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) cmbdf.win <- window(cmbdf, new.window = win) fmf(cmbdf.win, 0, 4)
This function computes values of the sample Renyi function. Returns
the estimated values of for taking values on a grid.
For large data sets could be rather time consuming.
fRen( cmbdf, q.min = 1.01, q.max = 10, N = 20, k.box = log2(nside(cmbdf)) - 3, intensities = "I" )fRen( cmbdf, q.min = 1.01, q.max = 10, N = 20, k.box = log2(nside(cmbdf)) - 3, intensities = "I" )
cmbdf |
A |
q.min |
Left endpoint of the interval to compute the Renyi function. The default value is 1.01, |
q.max |
Right endpoint of the interval to compute the Renyi function. The default value is 10 |
N |
Number of points to compute the Renyi function. The default value is 20. |
k.box |
A dyadic decomposition level in computing the Renyi function,
see the references in Details. The default value is |
intensities |
A CMBDataFrame column with measured values |
Data frame which first column is the sampling grid
of values. Another column
consists of values of the sample Renyi function computed
on the grid using the th level dyadic decomposition
of the unit ball.
(1) Leonenko, N., and Shieh, N. 2013. Rényi function for multifractal random fields. Fractals 21, Article No. 1350009.
(2) http://mathworld.wolfram.com/RenyiEntropy.html
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") Tq <- fRen(cmbdf, N = 5, k.box = 1) plot(Tq$q, Tq$tq, xlab = "q", ylab = "Renyi function")set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") Tq <- fRen(cmbdf, N = 5, k.box = 1) plot(Tq$q, Tq$tq, xlab = "q", ylab = "Renyi function")
Convert latitude (lat) and longitude (lon) to spherical
coordinates (theta, phi) with theta in and
phi in . All values lat, lon, theta, phi
are assumed to be in radians.
geo2sph(...)geo2sph(...)
... |
A data.frame with columns lat and lon, or named vectors of lat and lon. |
A data.frame with columns theta and phi.
geo <- data.frame( lat = c(0, pi/3, pi/2), lon = c(0, pi/3, pi)) geo sph <- geo2sph(geo) sphgeo <- data.frame( lat = c(0, pi/3, pi/2), lon = c(0, pi/3, pi)) geo sph <- geo2sph(geo) sph
Get an angle between two directions defined by arcs on the unit sphere
geoAngle(p1)geoAngle(p1)
p1 |
A |
Let and denote the rows of p1.
Then the returned object is an angle in radians beween two arcs determined by #'the pairs #'of spherical points (p1[1,], p1[2,]) and (p1[2,], p1[3,])
respectively.
p1 <- data.frame(diag(3)) p1 colnames(p1) <- c("x", "y", "z") geoAngle(p1) geo <- data.frame( lat = c(30, 0, 20), lon = c(30, 60, 10))*(pi/180) geo p2 <- geo2sph(geo) p2 geoAngle(p2)p1 <- data.frame(diag(3)) p1 colnames(p1) <- c("x", "y", "z") geoAngle(p1) geo <- data.frame( lat = c(30, 0, 20), lon = c(30, 60, 10))*(pi/180) geo p2 <- geo2sph(geo) p2 geoAngle(p2)
Detailed descriptions and and examples can be found in documentation for specific
geoArea functions geoArea.CMBDataFrame, geoArea.HPDataFrame,
geoArea.CMBWindow
geoArea(x)geoArea(x)
x |
An object. |
A numeric scalar giving the area covered by the object on the unit sphere, in steradians.
geoArea.CMBDataFrame
geoArea.HPDataFrame
geoArea.CMBWindow
CMBDataFrame
Gives the surface on the unit sphere
that is encompassed by all pixels in cmbdf
## S3 method for class 'CMBDataFrame' geoArea(x)## S3 method for class 'CMBDataFrame' geoArea(x)
x |
a CMBDataFrame. |
The sum of the areas of all pixels (rows) in x.
## At low resolution, a few data points can ## occupy a large pixel area, e.g.: cmbdf <- CMBDataFrame(nside = 1, spix = c(1,2,3)) pix(cmbdf) ## The total number of Healpix points at nside=1 equals 12. As cmbdf has 3 Healpix ## it occupies pi = 1/4*(surface area of unit sphere) geoArea(cmbdf) plot(cmbdf, size = 5, hp.boundaries = 1)## At low resolution, a few data points can ## occupy a large pixel area, e.g.: cmbdf <- CMBDataFrame(nside = 1, spix = c(1,2,3)) pix(cmbdf) ## The total number of Healpix points at nside=1 equals 12. As cmbdf has 3 Healpix ## it occupies pi = 1/4*(surface area of unit sphere) geoArea(cmbdf) plot(cmbdf, size = 5, hp.boundaries = 1)
CMBWindow
Geodesic area of a CMBWindow
## S3 method for class 'CMBWindow' geoArea(x)## S3 method for class 'CMBWindow' geoArea(x)
x |
A CMBWindow. |
The spherical area inside the CMBWindow x.
## A window that covers 1/8 of the unit sphere is constructed and its area is ## pi/2 = 1/8*(surface area of unit sphere) win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) geoArea(win)## A window that covers 1/8 of the unit sphere is constructed and its area is ## pi/2 = 1/8*(surface area of unit sphere) win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) geoArea(win)
HPDataFrame
Gives the surface on the unit sphere
that is encompassed by all pixels in x.
## S3 method for class 'HPDataFrame' geoArea(x)## S3 method for class 'HPDataFrame' geoArea(x)
x |
A HPDataFrame. |
The sum of the areas of all pixels (rows) in x.
## Generate random I for HPDataFrame hp1 <- HPDataFrame(I=rnorm(5), nside = 1, spix = c(1,1,2,2,3)) pix(hp1) ## The total number of Healpix points at nside=1 equals 12. As hp1 has five ## I values at 3 Healpix points, then the occupied area is ## pi = 1/4*(surface area of unit sphere) geoArea(hp1) plot(hp1, size = 5, hp.boundaries = 1)## Generate random I for HPDataFrame hp1 <- HPDataFrame(I=rnorm(5), nside = 1, spix = c(1,1,2,2,3)) pix(hp1) ## The total number of Healpix points at nside=1 equals 12. As hp1 has five ## I values at 3 Healpix points, then the occupied area is ## pi = 1/4*(surface area of unit sphere) geoArea(hp1) plot(hp1, size = 5, hp.boundaries = 1)
Get geodesic distance between points on the unit sphere
geoDist(p1, p2, include.names = FALSE)geoDist(p1, p2, include.names = FALSE)
p1 |
A |
p2 |
Same as p1. |
include.names |
Boolean. If TRUE then the row and
column names of the returned matrix will be taken from
the points in |
Let denote the number of rows of p1
and let denote the number of rows of p2.
Then the returned object is an by matrix
whose entry in position is the geodesic distance
from the th row of p1 to the
th row of p2.
p1 <- data.frame(diag(3)) colnames(p1) <- c("x", "y", "z") p1 p2 <- data.frame(x=c(1,0), y=c(0,3/5), z=c(0,4/5)) p2 geoDist(p1, p2, include.names = FALSE)p1 <- data.frame(diag(3)) colnames(p1) <- c("x", "y", "z") p1 p2 <- data.frame(x=c(1,0), y=c(0,3/5), z=c(0,4/5)) p2 geoDist(p1, p2, include.names = FALSE)
CMBDataFrame
Get the FITS headers from a CMBDataFrame
header(cmbdf)header(cmbdf)
cmbdf |
a CMBDataFrame. |
The FITS headers belonging to the FITS file from which cmbdf data was imported
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") header(cmbdf)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") header(cmbdf)
The function checks object's attribute healpixCentered. The attribute is
TRUE if the object was assumed to have rows that correspond to
unique HEALPix pixel indices.
healpixCentered(obj)healpixCentered(obj)
obj |
Any object. |
A boolean. This is TRUE if obj
is a CMBDataFrame or a HPDataFrame whose
coordinates were assumed to correspond to HEALPix pixel center
locations.
hp1 <- HPDataFrame(I=rnorm(5), nside = 1, spix = c(1,1,2,2,3)) pix(hp1) coords(hp1, new.coords = "cartesian") healpixCentered(hp1) sky <- CMBDataFrame(nside = 32, coords = "cartesian", ordering = "nested") sky.s <- CMBDataFrame(sky, sample.size = 100) hpdf <- HPDataFrame(sky.s, auto.spix = TRUE) healpixCentered(hpdf)hp1 <- HPDataFrame(I=rnorm(5), nside = 1, spix = c(1,1,2,2,3)) pix(hp1) coords(hp1, new.coords = "cartesian") healpixCentered(hp1) sky <- CMBDataFrame(nside = 32, coords = "cartesian", ordering = "nested") sky.s <- CMBDataFrame(sky, sample.size = 100) hpdf <- HPDataFrame(sky.s, auto.spix = TRUE) healpixCentered(hpdf)
HPDataFrames are a type of data.frame designed to carry
data located on the unit sphere. Each row of a HPDataFrame
is associated with a HEALPix pixel index. The HPDataFrame
also holds an attribute called nside which stores the
HEALPix Nside parameter (i.e., the resolution of the HEALPix grid
that is being used).
Unlike CMBDataFrame, HPDataFrames may have
repeated pixel indices. They are made this way so that
multiple data points falling within a given pixel
can be stored in different rows of any given HPDataFrame.
HPDataFrame( ..., nside, ordering = "nested", auto.spix = FALSE, spix, assumedUniquePix = FALSE, delete.duplicates = FALSE, save.dots = FALSE, save.duplicate.indices = FALSE )HPDataFrame( ..., nside, ordering = "nested", auto.spix = FALSE, spix, assumedUniquePix = FALSE, delete.duplicates = FALSE, save.dots = FALSE, save.duplicate.indices = FALSE )
... |
Data. Can be named vectors or a data.frame. May include columns (x,y,z) or (theta, phi) representing Cartesian or spherical coordinates of points on the unit sphere. |
nside |
Integer number |
ordering |
The HEALPix ordering scheme ("ring" or "nested"). |
auto.spix |
Boolean. If TRUE then spix will be found from
the coordinates provided in the data. That is, each row of
data will be assigned the pixel index of its closest HEALPix
pixel center. There must be columns x,y,z for cartesian or
theta, phi for spherical colatitude and longitude respectively.
If |
spix |
A vector of HEALPix pixel indices indicating the
pixel locations of the data. Note that |
assumedUniquePix |
A boolean. Sets the |
delete.duplicates |
Boolean. If TRUE then rows corresponding to duplicate pixel indices will be dropped from the returned HPDataFrame, and assumedUniquePix will be set to TRUE. |
save.dots |
A logical. If |
save.duplicate.indices |
A logical. If |
HPDataFrame with auto.spix = TRUE can be used to transform any
spherical data (not necessarily CMB) to the Healpix representation, see
Example 3 below.
A data frame of class HPDataFrame containing the supplied observations and any coordinate columns. HEALPix pixel indices are stored in the pix attribute; further attributes record nside, ordering and whether indices are assumed unique.
hp <- HPDataFrame(I = c(1, 2, 3), nside = 1, spix = c(1, 1, 2)) pix(hp) assumedUniquePix(hp) coords(hp, new.coords = "cartesian") ## Assign pixels automatically from three distinct locations. hp.unique <- HPDataFrame(x = c(1, 0, 0), y = c(0, 1, 0), z = c(0, 0, 1), auto.spix = TRUE) pix(hp.unique) assumedUniquePix(hp.unique)hp <- HPDataFrame(I = c(1, 2, 3), nside = 1, spix = c(1, 1, 2)) pix(hp) assumedUniquePix(hp) coords(hp, new.coords = "cartesian") ## Assign pixels automatically from three distinct locations. hp.unique <- HPDataFrame(x = c(1, 0, 0), y = c(0, 1, 0), z = c(0, 0, 1), auto.spix = TRUE) pix(hp.unique) assumedUniquePix(hp.unique)
Find the pixel index of a given pixel with
index ibp in base pixel bp.
ibp2p(ibp, bp, j)ibp2p(ibp, bp, j)
ibp |
The pixel index within base pixel bp, at resolution j, in nested order. |
bp |
The base pixel index |
j |
The resolution parameter nside = 2^j |
A numeric vector of full-sky nested pixel indices at resolution j, combining the within-base indices and base pixel indices.
ibp2p(1, 1, 2) ibp2p(1, 2, 2)ibp2p(1, 1, 2) ibp2p(1, 2, 2)
Check if an object is of class CMBDat
is.CMBDat(cmbdf)is.CMBDat(cmbdf)
cmbdf |
Any R object |
TRUE if cmbdf is a CMBDat object, otherwise FALSE
filename <- system.file("extdata", "CMB_testmap.fits", package = "rcosmo") cmbdat <- CMBDat(filename, spix = 1:10) is.CMBDat(cmbdat)filename <- system.file("extdata", "CMB_testmap.fits", package = "rcosmo") cmbdat <- CMBDat(filename, spix = 1:10) is.CMBDat(cmbdat)
Check if an object is of class CMBDataFrame
is.CMBDataFrame(cmbdf)is.CMBDataFrame(cmbdf)
cmbdf |
Any R object |
TRUE if cmbdf is a CMBDataFrame, otherwise FALSE
df <- CMBDataFrame(nside = 16) is.CMBDataFrame(df) df2 <- coords(df, new.coords = "cartesian") is.CMBDataFrame(df2)df <- CMBDataFrame(nside = 16) is.CMBDataFrame(df) df2 <- coords(df, new.coords = "cartesian") is.CMBDataFrame(df2)
Check if an object is a CMBWindow
is.CMBWindow(win)is.CMBWindow(win)
win |
any object |
TRUE or FALSE depending if win is a CMBWindow
win <- CMBWindow(x=0,y=3/5,z=4/5,r=0.8, set.minus = TRUE) is.CMBWindow(win)win <- CMBWindow(x=0,y=3/5,z=4/5,r=0.8, set.minus = TRUE) is.CMBWindow(win)
HPDataFrame
Check if an object is of class HPDataFrame
is.HPDataFrame(hpdf)is.HPDataFrame(hpdf)
hpdf |
Any R object |
TRUE if hpdf is a HPDataFrame, otherwise FALSE
df <- CMBDataFrame(nside = 16) is.HPDataFrame(df) df <- HPDataFrame(I = rep(0,12), nside = 1) is.HPDataFrame(df)df <- CMBDataFrame(nside = 16) is.HPDataFrame(df) df <- HPDataFrame(I = rep(0,12), nside = 1) is.HPDataFrame(df)
This function adds a line with the variogram model fitted by the function
variofitCMB to a current variogram plot. The function modifies
lines.variomodel.variofit from the package geoR
for additional covariance models on spheres.
linesCMB(x, max.dist, scaled = FALSE, ...)linesCMB(x, max.dist, scaled = FALSE, ...)
x |
An object of the class |
max.dist |
A maximum distance to draw the variogram line. The default is
|
scaled |
logical. If TRUE the sill in the plot is 1. |
... |
other plotting parameters passed to |
The function adds a line with fitted variogram model to a plot. It is used
to compare empirical variograms against fitted models returned by
variofitCMB.
Available models are: "matern", "exponential", "spherical", "powered.exponential", "cauchy", "gencauchy", "pure.nugget", "askey", "c2wendland", "c4wendland", "sinepower", "multiquadric".
A line with a fitted variogram model is added to a plot.
geoR package, lines.variomodel.variofit,
covmodelCMB, variofitCMB
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") varcmb <- variogramCMB(cmbdf, max.dist = pi/2, num.bins = 6) ols <- variofitCMB(varcmb, ini.cov.pars = c(1, 0.5), cov.model = "matern", weights = "equal", messages = FALSE) plot(varcmb) linesCMB(ols, lty = 2)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") varcmb <- variogramCMB(cmbdf, max.dist = pi/2, num.bins = 6) ols <- variofitCMB(varcmb, ini.cov.pars = c(1, 0.5), cov.model = "matern", weights = "equal", messages = FALSE) plot(varcmb) linesCMB(ols, lty = 2)
Get the maximum geodesic distance either between all points in a data.frame pairwise, or between all points in a data.frame and one target point.
maxDist(df, point)maxDist(df, point)
df |
A |
point |
An optional target point on the unit sphere
in cartesian coordinates, in which case all distances are
calculated between |
If point is specified: the longest geodesic
distance from point to the
points specified by the rows of df.
If point is not specified: the longest geodesic
distance pairwise between points in df.
## Using a CMBDataFrame with HEALPix coordinates only cmbdf <- CMBDataFrame(nside = 1, spix = c(1,5,12), ordering = "ring") plot(cmbdf, hp.boundaries = 1, col = "blue", size = 5) p <- c(0,0,1) maxDist(cmbdf, p) # no need to have coordinates ## Using a HPDataFrame with HEALPix coordinates only hp <- HPDataFrame(nside = 1, I = rep(0,3), spix = c(1,5,12) ) maxDist(hp, p) # notice no need to have coordinates ## Using a data.frame with cartesian coordinates coords(hp) <- "cartesian" df <- data.frame(x = hp$x, y = hp$y, z = hp$z) maxDist(df, p) ## Using a data.frame with spherical coordinates coords(hp) <- "spherical" df <- data.frame(theta = hp$theta, phi = hp$phi) maxDist(df, p) ## max distance between points in cmdf maxDist(cmbdf)## Using a CMBDataFrame with HEALPix coordinates only cmbdf <- CMBDataFrame(nside = 1, spix = c(1,5,12), ordering = "ring") plot(cmbdf, hp.boundaries = 1, col = "blue", size = 5) p <- c(0,0,1) maxDist(cmbdf, p) # no need to have coordinates ## Using a HPDataFrame with HEALPix coordinates only hp <- HPDataFrame(nside = 1, I = rep(0,3), spix = c(1,5,12) ) maxDist(hp, p) # notice no need to have coordinates ## Using a data.frame with cartesian coordinates coords(hp) <- "cartesian" df <- data.frame(x = hp$x, y = hp$y, z = hp$z) maxDist(df, p) ## Using a data.frame with spherical coordinates coords(hp) <- "spherical" df <- data.frame(theta = hp$theta, phi = hp$phi) maxDist(df, p) ## max distance between points in cmdf maxDist(cmbdf)
CMBWindow
Get the maximum distance between all points
in a CMBWindow
maxWindowDist(x)maxWindowDist(x)
x |
A CMBWindow object. |
The maximum distance between window's points.
## win is a equilateral spherical triangle which sides are pi/2 win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) maxWindowDist(win)## win is a equilateral spherical triangle which sides are pi/2 win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) maxWindowDist(win)
Get the minimum geodesic distance either between all points in a data.frame pairwise, or between all points in a data.frame and one target point.
minDist(df, point)minDist(df, point)
df |
A |
point |
An optional target point on the unit sphere
in cartesian coordinates, in which case all distances are
calculated between |
If point is specified: the shortest
distance from point to the
points specified by the rows of df.
If point is not specified: the shortest
distance pairwise between points in df.
## Using a CMBDataFrame with HEALPix coordinates only cmbdf <- CMBDataFrame(nside = 1, spix = c(1,5,12), ordering = "ring") plot(cmbdf, hp.boundaries = 1, col = "blue", size = 5) p <- c(0,0,1) minDist(cmbdf, p) # no need to have coordinates ## Using a HPDataFrame with HEALPix coordinates only hp <- HPDataFrame(nside = 1, I = rep(0,3), spix = c(1,5,12) ) minDist(hp, p) # notice no need to have coordinates ## Using a data.frame with cartesian coordinates coords(hp) <- "cartesian" df <- data.frame(x = hp$x, y = hp$y, z = hp$z) minDist(df, p) ## Using a data.frame with spherical coordinates coords(hp) <- "spherical" df <- data.frame(theta = hp$theta, phi = hp$phi) minDist(df, p) ## min distance between points in cmdf minDist(cmbdf)## Using a CMBDataFrame with HEALPix coordinates only cmbdf <- CMBDataFrame(nside = 1, spix = c(1,5,12), ordering = "ring") plot(cmbdf, hp.boundaries = 1, col = "blue", size = 5) p <- c(0,0,1) minDist(cmbdf, p) # no need to have coordinates ## Using a HPDataFrame with HEALPix coordinates only hp <- HPDataFrame(nside = 1, I = rep(0,3), spix = c(1,5,12) ) minDist(hp, p) # notice no need to have coordinates ## Using a data.frame with cartesian coordinates coords(hp) <- "cartesian" df <- data.frame(x = hp$x, y = hp$y, z = hp$z) minDist(df, p) ## Using a data.frame with spherical coordinates coords(hp) <- "spherical" df <- data.frame(theta = hp$theta, phi = hp$phi) minDist(df, p) ## min distance between points in cmdf minDist(cmbdf)
Return the neighbouring pixels to a given pixel
that is specified at resolution , in the nested order.
neighbours(p, j)neighbours(p, j)
p |
Pixel index p at resolution j. |
j |
The resolution parameter with nside = 2^j. |
A numeric vector of neighbouring pixel indices in nested order at resolution j; directions without a neighbour are omitted. For j > 0, the vector also includes p itself. For a vector of input pixels, a list of these vectors is returned.
## Return the neighbouring pixels for base pixel 1 neighbours(1, 0) ## Plot the neighbouring pixels for base pixel 1 demoNeighbours <- function(p,j) { neighbours(p, j) displayPixels(boundary.j = j, j = j, plot.j = j+3, spix = neighbours(p, j), boundary.col = "gray", boundary.lwd = 1, incl.labels = neighbours(p, j), col = "blue", size = 3) rcosmo::displayPixelBoundaries(nside = 1, col = "blue", lwd = 3) } demoNeighbours(1,2) demoNeighbours(1,0)## Return the neighbouring pixels for base pixel 1 neighbours(1, 0) ## Plot the neighbouring pixels for base pixel 1 demoNeighbours <- function(p,j) { neighbours(p, j) displayPixels(boundary.j = j, j = j, plot.j = j+3, spix = neighbours(p, j), boundary.col = "gray", boundary.lwd = 1, incl.labels = neighbours(p, j), col = "blue", size = 3) rcosmo::displayPixelBoundaries(nside = 1, col = "blue", lwd = 3) } demoNeighbours(1,2) demoNeighbours(1,0)
Convert from "nested" to "ring" ordering
nest2ring computes the HEALPix pixel index
in the "ring" ordering scheme from the pixel index
in the "nested" ordering scheme.
nest2ring(nside, pix)nest2ring(nside, pix)
nside |
is the HEALPix nside parameter. |
pix |
is the set or subset of pixel indices at nside. If pix is left blank then all pixels are converted. |
the output is the corresponding set of pixel in the ring ordering scheme.
# compute HEALPix indices in the ring ordering scheme nside <- 8 pix <-c(1,2,23) nest2ring(nside,pix)# compute HEALPix indices in the ring ordering scheme nside <- 8 pix <-c(1,2,23) nest2ring(nside,pix)
Finds the closest HEALPix pixel center to a given target point,
specified in Cartesian coordinates, using an efficient nested search
algorithm. HEALPix indices are all assumed to be in the "nested"
ordering scheme.
nestSearch(target, nside, index.only = FALSE, save.dots = FALSE)nestSearch(target, nside, index.only = FALSE, save.dots = FALSE)
target |
A data.frame, matrix or vector of Cartesian (x,y,z) coordinates for the target point. If a data.frame is used then spherical coordinates can be specified with row names theta and phi. |
nside |
An integer, the target resolution at which the resulting pixels are returned. |
index.only |
A boolean indicating whether to return only the pixel index (TRUE), or cartesian coordinates as well (FALSE). |
save.dots |
A logical. A If |
if index.only = TRUE then the output will be a HEALPix index.
If index.only FALSE then the output is the list containing the HEALPix index
and Cartesian coordinate vector of the HEALPix point closest to target
at resolution nside.
## Find the closest HEALPix pixel center at resolution j=2 for ## the point (0.6,0.8,0) point <- c(0.6,0.8,0) j <- 2 cpoint <- nestSearch(point, nside = 2^j) ## Plot the closest pixel center in blue and the point (0.6,0.8,0) in red displayPixels(j, j, plot.j=j, spix=c(cpoint$pix), size=5, incl.labels =FALSE) rgl::plot3d(point[1], point[2], point[3], col="red", size = 5, add = TRUE) ## Repeat the above for 4 points in a data.frame points <- data.frame(x = c(1,0,0,0.6), y = c(0,1,0,0.8), z = c(0,0,1,0)) points j <- 2 cpoints <- nestSearch(points, nside = 2^j) ## Plot the closest pixel center in blue and the point (0.6,0.8,0) in red displayPixels(j, j, plot.j=j, spix=c(cpoints$pix), size=5, incl.labels =FALSE) rgl::plot3d(points[,1], points[,2], points[,3], col="red", size = 5, add = TRUE)## Find the closest HEALPix pixel center at resolution j=2 for ## the point (0.6,0.8,0) point <- c(0.6,0.8,0) j <- 2 cpoint <- nestSearch(point, nside = 2^j) ## Plot the closest pixel center in blue and the point (0.6,0.8,0) in red displayPixels(j, j, plot.j=j, spix=c(cpoint$pix), size=5, incl.labels =FALSE) rgl::plot3d(point[1], point[2], point[3], col="red", size = 5, add = TRUE) ## Repeat the above for 4 points in a data.frame points <- data.frame(x = c(1,0,0,0.6), y = c(0,1,0,0.8), z = c(0,0,1,0)) points j <- 2 cpoints <- nestSearch(points, nside = 2^j) ## Plot the closest pixel center in blue and the point (0.6,0.8,0) in red displayPixels(j, j, plot.j=j, spix=c(cpoints$pix), size=5, incl.labels =FALSE) rgl::plot3d(points[,1], points[,2], points[,3], col="red", size = 5, add = TRUE)
Detailed descriptions and and examples can be found in documentation for specific
nside functions nside.CMBDataFrame, nside.HPDataFrame
nside(x)nside(x)
x |
An object. |
A numeric scalar giving the HEALPix nside parameter. The corresponding full-sky grid contains 12*nside^2 pixels.
nside.CMBDataFrame
nside.HPDataFrame
This function returns the HEALPix Nside parameter of a CMBDataFrame
## S3 method for class 'CMBDataFrame' nside(x)## S3 method for class 'CMBDataFrame' nside(x)
x |
A |
The HEALPix Nside parameter.
df <- CMBDataFrame(nside = 16) nside(df)df <- CMBDataFrame(nside = 16) nside(df)
HPDataFrame
This function returns the HEALPix Nside parameter
of a HPDataFrame
## S3 method for class 'HPDataFrame' nside(x)## S3 method for class 'HPDataFrame' nside(x)
x |
A |
The HEALPix Nside parameter.
df <- HPDataFrame(I = rep(0,12), nside = 1) nside(df)df <- HPDataFrame(I = rep(0,12), nside = 1) nside(df)
Map numeric values to a colour map
numeric2col( num, colmap = grDevices::terrain.colors(100), breaks.length = length(colmap) )numeric2col( num, colmap = grDevices::terrain.colors(100), breaks.length = length(colmap) )
num |
A numeric vector. The numbers which will be mapped to colours. |
colmap |
A colour map. See |
breaks.length |
A single integer. Controls the number of
breaks in the discretisation of |
A character vector of colours, one for each element of num, selected from colmap according to the discretised numeric values.
ns <- 16 sky <- CMBDataFrame(I = rnorm(12*ns^2), nside = ns) plot(sky, col = numeric2col(sky$I))ns <- 16 sky <- CMBDataFrame(I = rnorm(12*ns^2), nside = ns) plot(sky, col = numeric2col(sky$I))
Detailed descriptions and and examples can be found in documentation for specific
ordering functions ordering.CMBDataFrame, ordering.HPDataFrame
ordering(x, ...)ordering(x, ...)
x |
An object. |
... |
Extra arguments. |
A character string, "nested" or "ring", when queried, or an object of the input class reordered to the requested scheme.
ordering.CMBDataFrame
ordering.HPDataFrame
This function returns the HEALPix ordering scheme from a CMBDataFrame. The ordering scheme is either "ring" or "nested".
## S3 method for class 'CMBDataFrame' ordering(x, new.ordering, ...)## S3 method for class 'CMBDataFrame' ordering(x, new.ordering, ...)
x |
A |
new.ordering |
Specifies the new ordering ("ring" or "nest") if a change of ordering scheme is desired. |
... |
Unused arguments. |
If a new ordering is specified, using e.g. new.ordering = "ring", the ordering scheme of the CMBDataFrame will be converted.
The name of the HEALPix ordering scheme that is used in the CMBDataFrame x.
df <- CMBDataFrame(nside = 1, ordering = "nested") ordering(df) df1 <- ordering(df, new.ordering = "ring") ordering(df1)df <- CMBDataFrame(nside = 1, ordering = "nested") ordering(df) df1 <- ordering(df, new.ordering = "ring") ordering(df1)
This function returns the HEALPix ordering scheme from a HPDataFrame.
The ordering scheme is either "ring" or "nested". If a new ordering
is specified, using e.g. new.ordering = "ring", the
ordering scheme of the HPDataFrame will be converted.
## S3 method for class 'HPDataFrame' ordering(x, new.ordering, ...)## S3 method for class 'HPDataFrame' ordering(x, new.ordering, ...)
x |
a |
new.ordering |
Specifies the new ordering ("ring" or "nest") if a change of ordering scheme is desired. |
... |
Unused arguments. |
The name of the HEALPix ordering scheme that is used in the HPDataFrame x, or a new HPDataFrame with the desired new.ordering
df <- HPDataFrame(I = rep(0,12), nside = 1, ordering = "nested") ordering(df) df1 <- ordering(df, new.ordering = "ring") ordering(df1)df <- HPDataFrame(I = rep(0,12), nside = 1, ordering = "nested") ordering(df) df1 <- ordering(df, new.ordering = "ring") ordering(df1)
The base pixel to which pixel belongs at resolution
p2bp(p, j)p2bp(p, j)
p |
The pixel index at resolution j, in nested order. |
j |
The resolution parameter nside = 2^j |
A numeric vector of base pixel indices from 1 to 12, identifying the base pixel containing each input pixel.
p2bp(5, 0) p2bp(5, 1)p2bp(5, 0) p2bp(5, 1)
Convert a pixel index to its index within
the base pixel to which belongs
p2ibp(p, j)p2ibp(p, j)
p |
The pixel index at resolution j, in nested order. |
j |
The resolution parameter nside = 2^j |
A numeric vector giving the nested index of each input pixel within its base pixel at resolution j.
p2ibp(6, 0) p2ibp(6, 1)p2ibp(6, 0) p2ibp(6, 1)
Gives the pixel at resolution that contains ,
where is specified at resolution (notice it does
not depend on ).
parent(p)parent(p)
p |
A pixel index specified in nested order. |
A numeric vector of nested pixel indices at resolution , identifying the parent containing each input pixel.
parent(4) parent(5)parent(4) parent(5)
Detailed descriptions and and examples can be found in documentation for specific
pix functions pix.CMBDataFrame, pix.HPDataFrame
pix(x, ...)pix(x, ...)
x |
An object. |
... |
Extra arguments. |
A numeric vector of HEALPix pixel indices when queried, or an object of the input class with updated pixel indices when new indices are supplied.
pix.CMBDataFrame
pix.HPDataFrame
CMBDataFrame
If new.pix is unspecified then this function returns the vector of
HEALPix pixel indices from a CMBDataFrame. If new.pix is specified then
this function returns a new CMBDataFrame with the same number of rows
as cmbdf, but with pix attribute new.pix. Thus,
new.pix must have length equal to nrow(cmbdf).
## S3 method for class 'CMBDataFrame' pix(x, new.pix, ...)## S3 method for class 'CMBDataFrame' pix(x, new.pix, ...)
x |
A CMBDataFrame. |
new.pix |
Optional vector of pixel indices with
length equal to |
... |
Unused arguments. |
The vector of HEALPix pixel indices or, if new.pix is specified, a new CMBDataFrame.
df <- CMBDataFrame(nside = 16, sample.size = 10, ordering = "nested") pix(df)df <- CMBDataFrame(nside = 16, sample.size = 10, ordering = "nested") pix(df)
HPDataFrame
If new.pix is unspecified then this function returns the vector of
HEALPix pixel indices from a HPDataFrame. If new.pix is specified then
this function returns a new HPDataFrame with the same number of rows
as x, but with pix attribute new.pix. Thus,
new.pix must have length equal to nrow(x).
## S3 method for class 'HPDataFrame' pix(x, new.pix, ...)## S3 method for class 'HPDataFrame' pix(x, new.pix, ...)
x |
a |
new.pix |
optional vector of pixel indices with
length equal to |
... |
Unused arguments. |
The vector of HEALPix pixel indices (integers) or, if new.pix is specified, a new HPDataFrame.
df <- HPDataFrame(I = rep(0,12), nside = 1) pix(df)df <- HPDataFrame(I = rep(0,12), nside = 1) pix(df)
Convert HEALPix pixel indices to cartesian or spherical coordinates
pix2coords(nside, coords = "cartesian", ordering = "nested", spix)pix2coords(nside, coords = "cartesian", ordering = "nested", spix)
nside |
the nside parameter (integer number |
coords |
'cartesian' or 'spherical' coordinates |
ordering |
'ring' or 'nested' ordering |
spix |
optional integer or vector of sample pixel indices |
a data.frame with columns 'x', 'y', 'z' (cartesian) or 'theta', 'phi' (spherical)
pix2coords(nside=1, spix=c(2,5)) pix2coords(nside=1, coords = "spherical", spix=c(2,5))pix2coords(nside=1, spix=c(2,5)) pix2coords(nside=1, coords = "spherical", spix=c(2,5))
Get the area of a single HEALPix pixel
pixelArea(nsideObject)pixelArea(nsideObject)
nsideObject |
|
the area of a single HEALPix pixel
at the nside resolution of nsideObject
df1 <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") pixelArea(df1)df1 <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") pixelArea(df1)
Find all pixels in a higher resolution that fall within the specified pixel area at a lower resolution. All pixels are assumed to be in nested ordering.
pixelWindow(j1, j2, pix.j1)pixelWindow(j1, j2, pix.j1)
j1 |
An integer. The lower resolution, with j1 =< j2.
Note that |
j2 |
An integer. The upper resolution. |
pix.j1 |
An integer. The pixel index at resolution j1 within which
all pixels from resolution j2 will be returned. |
All pixels in resolution j2 that fall within the pixel pix.j1 specified at resolution j1
pixelWindow(3, 3, 2) pixelWindow(3, 4, 2) pixelWindow(3, 5, 2)pixelWindow(3, 3, 2) pixelWindow(3, 4, 2) pixelWindow(3, 5, 2)
Plots sample (empirical) correlation function. Uses plot.variogram from
geoR package.
## S3 method for class 'CMBCorrelation' plot(x, ...)## S3 method for class 'CMBCorrelation' plot(x, ...)
x |
An object of class CMBCorrelation. |
... |
Extra arguments as in |
Produces a plot with the sample correlation function.
geoR package, corrCMB, variog,
plot.variogram
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") corcmb <- corrCMB(cmbdf, max.dist = pi/2, num.bins = 6) plot(corcmb)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") corcmb <- corrCMB(cmbdf, max.dist = pi/2, num.bins = 6) plot(corcmb)
Plots sample (empirical) covariance function. Uses plot.variogram from
geoR package.
## S3 method for class 'CMBCovariance' plot(x, ...)## S3 method for class 'CMBCovariance' plot(x, ...)
x |
An object of class CMBCovariance. |
... |
Extra arguments as in |
Produces a plot with the sample covariance function.
#'@references geoR package, covCMB, variog,
plot.variogram
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") Cov <- covCMB(cmbdf, max.dist = pi/2, num.bins = 6) plot(Cov)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") Cov <- covCMB(cmbdf, max.dist = pi/2, num.bins = 6) plot(Cov)
This function produces a plot from a CMBDataFrame.
## S3 method for class 'CMBDataFrame' plot( x, intensities = "I", add = FALSE, sample.size, type = "p", size = 1, box = FALSE, axes = FALSE, aspect = FALSE, col, back.col = "black", labels, hp.boundaries = 0, hpb.col = "gray", depth_test = "less", lab_depth_test = "always", ... )## S3 method for class 'CMBDataFrame' plot( x, intensities = "I", add = FALSE, sample.size, type = "p", size = 1, box = FALSE, axes = FALSE, aspect = FALSE, col, back.col = "black", labels, hp.boundaries = 0, hpb.col = "gray", depth_test = "less", lab_depth_test = "always", ... )
x |
A |
intensities |
The name of a column that specifies CMB intensities.
This is only used if |
add |
If TRUE then this plot will be added to any existing plot.
Note that if |
sample.size |
Optionally specifies the size of a simple random sample to take before plotting. This can make the plot less computationally intensive. |
type |
A single character indicating the type of item to plot. Supported types are: 'p' for points, 's' for spheres, 'l' for lines, 'h' for line segments from z = 0, and 'n' for nothing. |
size |
The size of plotted points. |
box |
Whether to draw a box. |
axes |
Whether to draw axes. |
aspect |
Either a logical indicating whether to adjust the aspect ratio, or a new ratio. |
col |
Specify the colour(s) of the plotted points. |
back.col |
Optionally specifies the background colour of the plot. This argument is passed to rgl::bg3d. |
labels |
Optionally specify a vector of labels to plot,
such as words or vertex indices. If this is specified then
|
hp.boundaries |
Integer. If greater than 0 then HEALPix
pixel boundaries at |
hpb.col |
Colour for the |
depth_test |
The depth test to be applied to the
plotted points. This controls how resistant the plotted
object is to being obscured. See |
lab_depth_test |
The |
... |
Arguments passed to rgl::plot3d. |
A plot of the CMB data
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") plot(cmbdf)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") plot(cmbdf)
CMBWindow
Visualise a CMBWindow
## S3 method for class 'CMBWindow' plot( x, add = TRUE, type = "l", col = "red", size = 2, box = FALSE, axes = FALSE, aspect = FALSE, back.col, depth_test = "always", ... )## S3 method for class 'CMBWindow' plot( x, add = TRUE, type = "l", col = "red", size = 2, box = FALSE, axes = FALSE, aspect = FALSE, back.col, depth_test = "always", ... )
x |
A CMBWindow. |
add |
if TRUE then this plot will be added to any existing plot.
Note that if |
type |
a single character indicating the type of item to plot. Supported types are: 'p' for points, 's' for spheres, 'l' for lines, 'h' for line segments from z = 0, and 'n' for nothing. |
col |
specify the colour(s) of the plotted points |
size |
the size of plotted points |
box |
whether to draw a box |
axes |
whether to draw axes |
aspect |
either a logical indicating whether to adjust the aspect ratio, or a new ratio. |
back.col |
specifies the background colour of the plot. This argument is passed to rgl::bg3d. |
depth_test |
The depth test to be applied.
This controls how resistant the plotted
object is to being obscured.
See |
... |
arguments passed to rgl::plot3d |
No meaningful return value; called for its side effect of drawing the window in the current rgl scene.
win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) win2 <- CMBWindow(theta = c(2*pi/3,3*pi/4,3*pi/4, 2*pi/3), phi = c(pi/4,pi/4,pi/3,pi/3)) plot(win1) plot(win2)win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) win2 <- CMBWindow(theta = c(2*pi/3,3*pi/4,3*pi/4, 2*pi/3), phi = c(pi/4,pi/4,pi/3,pi/3)) plot(win1) plot(win2)
This function produces a plot from a HPDataFrame.
If columns x,y,z (cartesian) or theta,phi (colatitude and longitude
respectively) are present in x, then
these will be used as coordinates for plotting. Otherwise, the
HEALPix indices as in pix(x) will be used. If HEALPix
indices are used and multiple rows correspond to a single pixel
index, then beware that values may be obfuscated in the plot,
and all locations are pixel centers.
## S3 method for class 'HPDataFrame' plot( x, intensities = "I", add = FALSE, sample.size, type = "p", size = 1, box = FALSE, axes = FALSE, aspect = FALSE, col = "blue", back.col = "black", labels, hp.boundaries = 0, hpb.col = "gray", depth_test = "less", lab_depth_test = "always", ... )## S3 method for class 'HPDataFrame' plot( x, intensities = "I", add = FALSE, sample.size, type = "p", size = 1, box = FALSE, axes = FALSE, aspect = FALSE, col = "blue", back.col = "black", labels, hp.boundaries = 0, hpb.col = "gray", depth_test = "less", lab_depth_test = "always", ... )
x |
A HPDataFrame. |
intensities |
The column name for the data in |
add |
if TRUE then this plot will be added to any existing plot.
Note that if |
sample.size |
optionally specifies the size of a simple random sample to take before plotting. This can make the plot less computationally intensive |
type |
a single character indicating the type of item to plot. Supported types are: 'p' for points, 's' for spheres, 'l' for lines, 'h' for line segments from z = 0, and 'n' for nothing. |
size |
the size of plotted points |
box |
whether to draw a box |
axes |
whether to draw axes |
aspect |
either a logical indicating whether to adjust the aspect ratio, or a new ratio. |
col |
specify the colour(s) of the plotted points |
back.col |
optionally specifies the background colour of the plot. This argument is passed to rgl::bg3d. |
labels |
optionally specify a vector of labels to plot,
such as words or vertex indices. If this is specified then
|
hp.boundaries |
integer. If greater than 0 then HEALPix
pixel boundaries at |
hpb.col |
colour for the |
depth_test |
The depth test to be applied to the plotted points. This controls how resistant the plotted object is to being obscured. This controls how resistant the plotted |
lab_depth_test |
The |
... |
arguments passed to rgl::plot3d |
A plot of the data locations according to coordinate columns or HEALPix index
hpdf <- HPDataFrame(I = rep(0,12), nside = 1) plot(hpdf, size = 5, col = "yellow", back.col = "black", hp.boundaries = 1)hpdf <- HPDataFrame(I = rep(0,12), nside = 1) plot(hpdf, size = 5, col = "yellow", back.col = "black", hp.boundaries = 1)
Plots sample (empirical) variogram. Uses plot.variogram from
geoR package.
See plot.variogram for usage and arguments.
Produces a plot with the sample variogram.
geoR package, variogramCMB, variog,
plot.variogram
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") varcmb <- variogramCMB(cmbdf, max.dist = pi/2, num.bins = 6) plot(varcmb)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") varcmb <- variogramCMB(cmbdf, max.dist = pi/2, num.bins = 6) plot(varcmb)
For specified measurements from CMBDataFrame this function
produces scatterplots and binned means versus theta and phi angles.
plotAngDis(cmbdf, intensities = "I")plotAngDis(cmbdf, intensities = "I")
cmbdf |
A |
intensities |
The name of a column of |
2x2 plot. The first row shows scatterplots. The second row gives barplots of the corresponding means computed over bins. The first column corresponds to the values of theta and the second one is for psi.
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") plotAngDis(cmbdf)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") plotAngDis(cmbdf)
Plots theoretical covariance functions from the list defined in covmodelCMB
plotcovmodelCMB( cov.model = "matern", sigmasq = 1, phi = pi, kappa = 0.5, from = 0, to = pi, ... )plotcovmodelCMB( cov.model = "matern", sigmasq = 1, phi = pi, kappa = 0.5, from = 0, to = pi, ... )
cov.model |
A type of the correlation function. Available choices are: "matern", "exponential","spherical", "powered.exponential", "cauchy", "gencauchy", "pure.nugget", "askey", "c2wendland", "c4wendland", "sinepower", "multiquadric". The default is "matern" |
sigmasq |
The variance parameter as documented in |
phi |
The range parameter as documented in |
kappa |
A smoothness parameter of the correlation function. The default is 0.5. |
from |
A lower range of the plotting region. The default is |
to |
An upper range of the plotting region. The default is |
... |
optional plotting parameters. |
Produces a plot with the theoretical covariance function.
plotcovmodelCMB("matern", sigmasq = 5) plotcovmodelCMB("askey", phi = pi/4, to = pi/2, kappa = 4)plotcovmodelCMB("matern", sigmasq = 5) plotcovmodelCMB("askey", phi = pi/4, to = pi/2, kappa = 4)
Plots theoretical variogram functions from the list defined in covmodelCMB
plotvariogram( cov.model = "matern", sigmasq = 1, phi = pi, kappa = 0.5, from = 0, to = pi, ... )plotvariogram( cov.model = "matern", sigmasq = 1, phi = pi, kappa = 0.5, from = 0, to = pi, ... )
cov.model |
A type of the variogram function. Available choices are: "matern", "exponential","spherical", "powered.exponential", "cauchy", "gencauchy", "pure.nugget", "askey", "c2wendland", "c4wendland", "sinepower", "multiquadric". The default is "matern" |
sigmasq |
The variance parameter as documented in |
phi |
The range parameter as documented in |
kappa |
A smoothness parameter of the variogram function. The default is 0.5. |
from |
A lower range of the plotting region. The default is |
to |
An upper range of the plotting region. The default is |
... |
optional plotting parameters. |
Produces a plot with the theoretical variogram.
plotvariogram("matern", sigmasq = 5) plotvariogram("askey", phi = pi/4, to = pi/2, kappa = 4)plotvariogram("matern", sigmasq = 5) plotvariogram("askey", phi = pi/4, to = pi/2, kappa = 4)
This function computes the practical range for covariance functions on spheres.
The function extends practicalRange from the
package geoR to additional covariance models on spheres.
practicalRangeCMB(cov.model, phi, kappa = 0.5, correlation = 0.05, ...)practicalRangeCMB(cov.model, phi, kappa = 0.5, correlation = 0.05, ...)
cov.model |
A type of the correlation function. Available choices are: "matern", "exponential","spherical", "powered.exponential", "cauchy", "gencauchy", "pure.nugget", "askey", "c2wendland", "c4wendland", "sinepower", "multiquadric". |
phi |
The range parameter as documented in |
kappa |
A smoothness parameter of the correlation function. |
correlation |
A correlation threshold (default is 0.05) |
... |
other optimisation parameters |
The practical(effective) range for a covariance function is the distance at which
a covariance function first time reaches the specified value correlation. For
covariance functions on spheres the practical range does not exceed , the
distance beyond which a covariance function is not defined. For the covariance
functions "spherical", "askey", "c2wendland", "c4wendland" their practical ranges
are equal to lengths of their support.
Value of the practical range for the covariance function specified in covmodelCMB
geoR package, practicalRange, covmodelCMB
practicalRangeCMB(cov.model = "sinepower", phi = 0.1, kappa = 0.5) practicalRangeCMB(cov.model = "askey", phi = 0.1, kappa = 0.5)practicalRangeCMB(cov.model = "sinepower", phi = 0.1, kappa = 0.5) practicalRangeCMB(cov.model = "askey", phi = 0.1, kappa = 0.5)
This function neatly prints the contents of a CMBDataFrame.
## S3 method for class 'CMBDataFrame' print(x, ...)## S3 method for class 'CMBDataFrame' print(x, ...)
x |
A |
... |
arguments passed to |
Prints contents of the CMB data frame to the console.
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") print(cmbdf)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") print(cmbdf)
HPDataFrame
This function neatly prints the contents of a HPDataFrame.
## S3 method for class 'HPDataFrame' print(x, ...)## S3 method for class 'HPDataFrame' print(x, ...)
x |
A HPDataFrame. |
... |
arguments passed to |
Prints contents of the HPDataFrame to the console.
df <- HPDataFrame(I = rep(0,12), nside = 1, ordering = "nested") print(df) dfdf <- HPDataFrame(I = rep(0,12), nside = 1, ordering = "nested") print(df) df
This function provides an angular power spectra estimate using the values of the sample correlations. The approach is based on Lawson-Hanson algorithm for non-negative least squares.
pwSpCorr(corcmb, lmax = 20 * length(corcmb$u))pwSpCorr(corcmb, lmax = 20 * length(corcmb$u))
corcmb |
An object of the class CMBCorrelation. |
lmax |
A number of angular power spectra components to estimate |
A data frame which first column is 1-d grid of l values
from 0 to lmax. The second column is
estimated angular power spectra components on this grid.
Formula (2.1) in Baran A., Terdik G. Power spectrum estimation of spherical random fields based on covariances. Annales Mathematicae et Informaticae 44 (2015) pp. 15–22.
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") corcmb <- corrCMB(cmbdf, max.dist = pi, num.bins = 8) pw <- pwSpCorr(corcmb, lmax = 10) pwset.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") corcmb <- corrCMB(cmbdf, max.dist = pi, num.bins = 8) pw <- pwSpCorr(corcmb, lmax = 10) pw
CMBWindow
This function is a modification of standard qqnorm functions to work
with CMBWindow regions.
qqnormWin(cmbdf, win, intensities = "I")qqnormWin(cmbdf, win, intensities = "I")
cmbdf |
A |
win |
|
intensities |
A |
qqnormWin returns a normal QQ plot of for the specified
CMBDataFrame column intensities and CMBWindow
region. The function automatically adds a line of a “theoretical” normal
quantile-quantile plot.
A list with quantile components x and y and a normal QQ plot with QQ line
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) qqnormWin(cmbdf, win1)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) qqnormWin(cmbdf, win1)
CMBWindowsThis function is a modification of standard qqplot functions to work
with CMBWindow regions.
qqplotWin(cmbdf, win1, win2, intensities = "I")qqplotWin(cmbdf, win1, win2, intensities = "I")
cmbdf |
A |
win1 |
|
win2 |
|
intensities |
A |
qqplotWin produces a QQ plot of quantiles of observations in
two CMBWindows against each other for
the specified CMBDataFrame column
intensities. The function automatically adds a diagonal line.
A list with quantile components x and y and a QQ plot with a diagonal line
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) win2 <- CMBWindow(theta = c(pi/2, pi, pi/2), phi = c(0, 0, pi/2)) qqplotWin(cmbdf, win1, win2)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) win2 <- CMBWindow(theta = c(pi/2, pi, pi/2), phi = c(0, 0, pi/2)) qqplotWin(cmbdf, win1, win2)
This function returns an estimated q-statistic for the specified column
intensities in a CMBDataFrame and the list of
CMBWindows.
qstat(cmbdf, listwin, intensities = "I")qstat(cmbdf, listwin, intensities = "I")
cmbdf |
A |
listwin |
A list of |
intensities |
A |
The q-statistics is used to measure spatial stratified heterogeneity
and takes values in [0, 1]. It gives the percent of the variance of
intensities explained by the stratification. 0 corresponds to no spatial
stratified heterogeneity, 1 to perfect spatial stratified heterogeneity.
Estimated q-statistics for observations in a list of CMBWindows
Wang, J.F, Zhang, T.L, Fu, B.J. (2016). A measure of spatial stratified heterogeneity. Ecological Indicators. 67: 250–256.
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) win2 <- CMBWindow(theta = c(pi/2, pi, pi/2), phi = c(0, 0, pi/2)) qstat(cmbdf, list(win1, win2))set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") win1 <- CMBWindow(theta = c(0, pi/2, pi/2), phi = c(0, 0, pi/2)) win2 <- CMBWindow(theta = c(pi/2, pi, pi/2), phi = c(0, 0, pi/2)) qstat(cmbdf, list(win1, win2))
rbind for CMBDataFramesAdd a new row or rows to a CMBDataFrame.
All arguments passed to ... must be CMBDataFrames.
If the CMBDataFrame arguments have overlapping pixel
indices then all but one of the non-unique rows will be
deleted unless unsafe = TRUE. If unsafe = TRUE
then a HPDataFrame will be returned instead
of a CMBDataFrame.
## S3 method for class 'CMBDataFrame' rbind(..., deparse.level = 1, unsafe = FALSE)## S3 method for class 'CMBDataFrame' rbind(..., deparse.level = 1, unsafe = FALSE)
... |
A number of CMBDataFrames |
deparse.level |
See documentation
for |
unsafe |
A boolean. If the CMBDataFrame arguments have
overlapping pixel
indices then all but one of the non-unique rows will be
deleted unless |
A CMBDataFrame containing the combined rows and windows, with overlapping pixel indices deduplicated. If unsafe = TRUE, returns an HPDataFrame retaining duplicate pixels instead. All inputs must have matching nside and ordering.
See the documentation for rbind
df <- CMBDataFrame(nside = 1, I = 1:12) df.123 <- CMBDataFrame(df, spix = c(1,2,3)) df.123 df.234 <- CMBDataFrame(df, spix = c(2,3,4)) df.234 df.1234 <- rbind(df.123, df.234) df.1234 class(df.1234) # A CMBDataFrame pix(df.1234) df.123234 <- rbind(df.123, df.234, unsafe = TRUE) df.123234 class(df.123234) # A HPDataFrame pix(df.123234)df <- CMBDataFrame(nside = 1, I = 1:12) df.123 <- CMBDataFrame(df, spix = c(1,2,3)) df.123 df.234 <- CMBDataFrame(df, spix = c(2,3,4)) df.234 df.1234 <- rbind(df.123, df.234) df.1234 class(df.1234) # A CMBDataFrame pix(df.1234) df.123234 <- rbind(df.123, df.234, unsafe = TRUE) df.123234 class(df.123234) # A HPDataFrame pix(df.123234)
Handling and Analysing Spherical, Healpix and Cosmic Microwave Background data on a HEALPix grid.
The package rcosmo offers various tools for
Downloading and transforming Cosmic Microwave Background radiation (CMB) and spherical data
Working with Hierarchical Equal Area isoLatitude Pixelation of a sphere (Healpix)
Spherical geometry
Statistical analysis of CMB and spherical data
Visualisation of Healpix data
Most of rcosmo features were developed for CMB,
but it can also be used for other spherical data. It contains
tools for transforming spherical data in cartesian and geographic
coordinates to the Healpix representation.
Current updates are available through URL: https://github.com/frycast/rcosmo
https://github.com/frycast/rcosmo/issues
Daniel Fryer [email protected], Andriy Olenko [email protected], Ming Li [email protected], Yuguang Wang.
Useful links:
CMBDataFrame
Get the arcmin resolution from a CMBDataFrame
resolution(cmbdf)resolution(cmbdf)
cmbdf |
a CMBDataFrame. |
The arcmin resolution as specified by the FITS file where the data was sourced
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") resolution(cmbdf)set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") resolution(cmbdf)
ring2nest converts HEALPix pixel indices in the 'ring' ordering scheme
to HEALPix pixel indices in the 'nested' ordering scheme.
ring2nest(nside, pix)ring2nest(nside, pix)
nside |
is the HEALPix nside parameter (integer number |
pix |
is a vector of HEALPix pixel indices, in the 'ring' ordering scheme. |
the output is a vector of HEALPix pixel indices in the 'nested' ordering scheme.
## Convert (1,2,23) from ring to nest at nside = 8 nside <- 8 pix <-c(1,2,23) ring2nest(nside,pix)## Convert (1,2,23) from ring to nest at nside = 8 nside <- 8 pix <-c(1,2,23) ring2nest(nside,pix)
CMBDataFrame
This function returns a CMBDataFrame which size equals to sample.size,
whose rows comprise a simple random sample of the rows
from the input CMBDataFrame.
sampleCMB(cmbdf, sample.size)sampleCMB(cmbdf, sample.size)
cmbdf |
a |
sample.size |
the desired sample size. |
A CMBDataFrame which size equals to sample.size,
whose rows comprise a simple random sample of the rows
from the input CMBDataFrame.
df <- CMBDataFrame(nside = 16, I = rnorm(12 * 16 ^ 2), ordering = "nested") df.sample <- sampleCMB(df, sample.size = 100) df.sampledf <- CMBDataFrame(nside = 16, I = rnorm(12 * 16 ^ 2), ordering = "nested") df.sample <- sampleCMB(df, sample.size = 100) df.sample
The siblings of pixel are defined as the
children of the parent of . Note this is resolution independent.
siblings(p)siblings(p)
p |
Pixel index in nested order. |
An integer vector of four nested pixel indices sharing the same parent as p, including p itself.
siblings(11) siblings(12)siblings(11) siblings(12)
The function sphericalHarmonics computes
the spherical harmonic values
for the given 3D Cartesian coordinates.
sphericalHarmonics(L, m, xyz)sphericalHarmonics(L, m, xyz)
L |
The degree of spherical harmonic (L=0,1,2,...) |
m |
The order number of the degree-L spherical harmonic (m=-L,-L+1,...,L-1,L) |
xyz |
Dataframe for given points in 3D cartesian coordinates |
values of spherical harmonics
See https://en.wikipedia.org/wiki/Table_of_spherical_harmonics
It uses equation (7) in Hesse, K., Sloan, I. H., & Womersley, R. S. (2010). Numerical integration on the sphere. In Handbook of Geomathematics (pp. 1185-1219). Springer Berlin Heidelberg,
but instead of the order k=1,...,2L+1 in the book we use m=k-L-1.
## Calculate spherical harmonic value at ## the point (0,1,0) with L=5, m=2 point<-data.frame(x=0,y=1,z=0) sphericalHarmonics(5,2,point) ## Calculate spherical harmonic values at ## the point (1,0,0), (0,1,0), (0,0,1) with L=5, m=2 points<-data.frame(diag(3)) sphericalHarmonics(5,2,points)## Calculate spherical harmonic value at ## the point (0,1,0) with L=5, m=2 point<-data.frame(x=0,y=1,z=0) sphericalHarmonics(5,2,point) ## Calculate spherical harmonic values at ## the point (1,0,0), (0,1,0), (0,0,1) with L=5, m=2 points<-data.frame(diag(3)) sphericalHarmonics(5,2,points)
CMBDataFrame
This function produces a summary from a CMBDataFrame.
## S3 method for class 'CMBDataFrame' summary(object, intensities = "I", ...)## S3 method for class 'CMBDataFrame' summary(object, intensities = "I", ...)
object |
A |
intensities |
the name of a column specifying CMB intensities (or potentially another numeric quantity of interest) |
... |
Unused arguments. |
A summary includes window's type and area, total area covered by observations, and main statistics for intensity values
ns <- 16 df <- CMBDataFrame(I = rnorm(12*ns^2), nside = ns, ordering = "nested") win1 <- CMBWindow(x=0,y=3/5,z=4/5,r=0.8) df.sample1 <- window(df, new.window = win1) summary(df)ns <- 16 df <- CMBDataFrame(I = rnorm(12*ns^2), nside = ns, ordering = "nested") win1 <- CMBWindow(x=0,y=3/5,z=4/5,r=0.8) df.sample1 <- window(df, new.window = win1) summary(df)
CMBWindow
This function produces a summary from a CMBWindow
## S3 method for class 'CMBWindow' summary(object, ...)## S3 method for class 'CMBWindow' summary(object, ...)
object |
A CMBWindow. |
... |
Unused arguments. |
A summary includes window's type and area
win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) summary(win) win1<- CMBWindow(x=0,y=3/5,z=4/5,r=0.8, set.minus = TRUE) summary(win1)win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) summary(win) win1<- CMBWindow(x=0,y=3/5,z=4/5,r=0.8, set.minus = TRUE) summary(win1)
HPDataFrame
This function produces a summary from a HPDataFrame.
## S3 method for class 'HPDataFrame' summary(object, intensities = "I", ...)## S3 method for class 'HPDataFrame' summary(object, intensities = "I", ...)
object |
A HPDataFrame. |
intensities |
the name of a column specifying intensities (or potentially another numeric quantity of interest) |
... |
Unused arguments. |
A summary includes window's type and area, total area covered by observations, and main statistics for intensity values
ns <- 2 hpdf <- HPDataFrame(I = rnorm(12*ns^2), nside = 2, ordering = "nested") win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) hpdf.win <- window(hpdf, new.window = win) summary(hpdf.win)ns <- 2 hpdf <- HPDataFrame(I = rnorm(12*ns^2), nside = 2, ordering = "nested") win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) hpdf.win <- window(hpdf, new.window = win) summary(hpdf.win)
CMBWindow
Triangulate a polygonal CMBWindow
triangulate(win)triangulate(win)
win |
a CMBWindow object |
a list of CMBWindow polygons or minus.polygons,
each having 3 vertices and representing a triangle.
If winType of win does not include
"minus" then these triangles have
pairwise disjoint interiors and their union
is equal to the original polygon,
win.
Otherwise, if winType of win
does include "minus" the triangles are
the same as for the non-minus type above, but have "minus" types.
## Example 1 win <- CMBWindow(theta = c(2*pi/3,3*pi/4,3*pi/4, 2*pi/3), phi = c(pi/4,pi/4,pi/3,pi/3)) win plot(win) win1 <- triangulate(win) win1 summary(win1[[1]]) plot(win1[[1]], add= FALSE, col="green") plot(win1[[2]], col="blue") ## Example 2: triangilation minus-type polygon win <- CMBWindow(theta = c(pi/5,pi/3,pi/4, pi/3, pi/5), phi = c(pi/5,pi/5, pi/4 ,pi/3,pi/3), set.minus =TRUE) win plot(win) summary(win) win1 <- triangulate(win) win1 plot(win1[[1]], add= FALSE, col="green") plot(win1[[2]], col="blue") plot(win1[[3]], col="yellow") summary(win1[[1]]) summary(win1[[2]]) summary(win1[[3]])## Example 1 win <- CMBWindow(theta = c(2*pi/3,3*pi/4,3*pi/4, 2*pi/3), phi = c(pi/4,pi/4,pi/3,pi/3)) win plot(win) win1 <- triangulate(win) win1 summary(win1[[1]]) plot(win1[[1]], add= FALSE, col="green") plot(win1[[2]], col="blue") ## Example 2: triangilation minus-type polygon win <- CMBWindow(theta = c(pi/5,pi/3,pi/4, pi/3, pi/5), phi = c(pi/5,pi/5, pi/4 ,pi/3,pi/3), set.minus =TRUE) win plot(win) summary(win) win1 <- triangulate(win) win1 plot(win1[[1]], add= FALSE, col="green") plot(win1[[2]], col="blue") plot(win1[[3]], col="yellow") summary(win1[[1]]) summary(win1[[2]]) summary(win1[[3]])
This function estimates variogram parameters by fitting a parametric model
from covmodelCMB to a sample variogram. The function extends
variofit from the package geoR
to additional covariance models on spheres.
variofitCMB( vario, ini.cov.pars, cov.model, fix.nugget = FALSE, nugget = 0, fix.kappa = TRUE, kappa = 0.5, simul.number = NULL, max.dist = vario$max.dist, weights, minimisation.function, limits = geoR::pars.limits(), messages, ... )variofitCMB( vario, ini.cov.pars, cov.model, fix.nugget = FALSE, nugget = 0, fix.kappa = TRUE, kappa = 0.5, simul.number = NULL, max.dist = vario$max.dist, weights, minimisation.function, limits = geoR::pars.limits(), messages, ... )
vario |
An object of the class |
ini.cov.pars |
A vector with initial values for the variogram parameters. The first parameter corresponds to the variance sigma^2. The second parameter corresponds to the range phi of the correlation function. |
cov.model |
A type of the variogram function. Available choices are: "matern", "exponential","spherical", "powered.exponential", "cauchy", "gencauchy", "pure.nugget", "askey", "c2wendland", "c4wendland", "sinepower", "multiquadric". The default is "matern" |
fix.nugget |
logical. Indicates whether the nugget variance should be regarded as fixed or be estimated. The default is FALSE. |
nugget |
A value for the nugget parameter. Regarded as a fixed values if
|
fix.kappa |
logical. Indicates whether the parameter kappa should be regarded as fixed or be estimated. The default is TRUE. |
kappa |
A value for the smoothness parameter. Regarded as a fixed values if
|
simul.number |
number of simulation. Used if |
max.dist |
A maximum distance to fit a variogram model. The default is
|
weights |
Weights used in the loss function in the minimization algorithm. |
minimisation.function |
Minimization function ("optim", "nlm", "nls") to estimate the parameters. |
limits |
Lower and upper limits for the model parameters used
in the numerical minimisation by |
messages |
logical. Indicates whether or not status messages are printed on the screen. |
... |
other minimisation parameters |
The parameter values of a variogram function from covmodelCMB are
found by numerical optimization using one of the functions: optim,
nlm and nls.
The function extends variofit from the package geoR
to additional variogram models on spheres. Available models are: "matern",
"exponential", "spherical", "powered.exponential", "cauchy", "gencauchy",
"pure.nugget", "askey", "c2wendland", "c4wendland", "sinepower", "multiquadric".
Additionally it rescales an empirical variogram to the range [0,1] before
numerical optimisation and then transforms all obtained results to the original
scale. If ini.cov.pars are not provided then the 5x5 grid
(seq(0,max(vario$v),l=5), seq(0,vario$max.dist,l=5))
of initial values of sigma^2 and phi is used.
An object of the class variomodel and variofit, see
variofit
geoR package, variofit, covmodelCMB
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") varcmb <- variogramCMB(cmbdf, max.dist = pi/2, num.bins = 6) ols <- variofitCMB(varcmb, ini.cov.pars = c(1, 0.5), cov.model = "matern", weights = "equal", messages = FALSE) olsset.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") varcmb <- variogramCMB(cmbdf, max.dist = pi/2, num.bins = 6) ols <- variofitCMB(varcmb, ini.cov.pars = c(1, 0.5), cov.model = "matern", weights = "equal", messages = FALSE) ols
This function provides an empirical variogram for data in a
CMBDataFrame or data.frame. It assumes that data are from a
stationary spherical random field and the covariance depends only on a
geodesic distance between locations. Output is a binned variogram.
variogramCMB( cmbdf, num.bins = 10, sample.size, max.dist = pi, breaks, equiareal = TRUE, calc.max.dist = FALSE )variogramCMB( cmbdf, num.bins = 10, sample.size, max.dist = pi, breaks, equiareal = TRUE, calc.max.dist = FALSE )
cmbdf |
is a |
num.bins |
specifies the number of bins |
sample.size |
optionally specify the size of a simple random sample to take before calculating variogram. This may be useful if the full covariance computation is too slow. |
max.dist |
an optional number between 0 and pi specifying the
maximum geodesic distance to use for calculating covariance. Only
used if |
breaks |
optionally specify the breaks manually using a
vector giving the break points between cells. This vector
has length |
equiareal |
if TRUE then the bins have equal spherical area. If false then the bins have equal annular widths. Default is TRUE. |
calc.max.dist |
if TRUE then the |
An object of class variog specified in the package geoR.
The attribute "breaks" contains the break points used to create bins.
The result has num.bins + 1 values since the first value at distance 0 is not
counted as a bin.
a vector with distances.
a vector with estimated variogram values at distances given in u.
number of pairs in each bin
standard deviation of the values in each bin
limits defining the interval spanned by each bin
a logical vector indicating whether the number of pairs in each bin is greater or equal to the value in the argument pairs.min
variance of the data
parameters of the mean part of the model fitted by ordinary least squares
echoes the option argument
maximum distance between pairs allowed in the variogram calculations
number of data
direction for which the variogram was computed
the function call
geoR package, variog, covCMB, corrCMB
set.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") varcmb <- variogramCMB(cmbdf, max.dist = pi/2, num.bins = 6) varcmbset.seed(1) cmbdf <- CMBDataFrame(nside = 8, I = rnorm(12 * 8^2), ordering = "nested") varcmb <- variogramCMB(cmbdf, max.dist = pi/2, num.bins = 6) varcmb
Detailed descriptions and and examples can be found in documentation for specific
window functions window.CMBDataFrame, window.HPDataFrame,
window.data.frame
window(x, ...)window(x, ...)
x |
An object. |
... |
Extra arguments. |
The stored window (a CMBWindow, a list of windows, or NULL for full sky) when queried, or an object of the input class restricted to the requested sky region. See the individual methods.
window.CMBDataFrame
window.HPDataFrame
window.data.frame
CMBDat objectThis function returns a
data.frame containing the data in x restricted to the
CMBWindow new.window
## S3 method for class 'CMBDat' window(x, new.window, intersect = TRUE, ...)## S3 method for class 'CMBDat' window(x, new.window, intersect = TRUE, ...)
x |
a |
new.window |
A single |
intersect |
A boolean that determines
the behaviour when |
... |
Unused arguments. |
Windows that are tagged with set.minus (see CMBWindow)
are treated differently from other windows.
If the argument is a list of CMBWindows, then interious of all windows whose
winType does not include "minus" are united (let be their union) and
exteriors of all windows whose winType does include "minus" are intersected,
(let be their intersection). Then, provided that
intersect = TRUE (the default), the returned data.frame will
be the points of cmbdat$data in the the intersection of
and .
Otherwise, if intersect = FALSE, the returned data.frame
consists of the points of x$data in the union of
and .
Note that if (resp. ) is empty then the returned data.frame
will be the points of x in (resp. ).
A CMBDataFrame containing the data in x restricted to the
CMBWindow new.window
filename <- system.file("extdata", "CMB_testmap.fits", package = "rcosmo") cmbdat <- CMBDat(filename) win <- CMBWindow(x = 0, y = 0, z = 1, r = pi/2) cmbdat.win <- window(cmbdat, new.window = win) class(cmbdat.win)filename <- system.file("extdata", "CMB_testmap.fits", package = "rcosmo") cmbdat <- CMBDat(filename) win <- CMBWindow(x = 0, y = 0, z = 1, r = pi/2) cmbdat.win <- window(cmbdat, new.window = win) class(cmbdat.win)
CMBDataFrame
When new.window or in.pixels is unspecified this function returns the
CMBWindow attribute of a
CMBDataFrame. The return value is NULL if the window is full sky.
When new.window is specified this function instead returns
a new CMBDataFrame whose CMBWindow attribute is new.window
## S3 method for class 'CMBDataFrame' window(x, new.window, intersect = TRUE, in.pixels, in.pixels.res = 0, ...)## S3 method for class 'CMBDataFrame' window(x, new.window, intersect = TRUE, in.pixels, in.pixels.res = 0, ...)
x |
A |
new.window |
Optionally specify a new window
in which case a new CMBDataFrame is returned whose CMBWindow is new.window.
|
intersect |
A boolean that determines
the behaviour when |
in.pixels |
A vector of pixels at resolution
|
in.pixels.res |
An integer. Resolution
(i.e., |
... |
Unused arguments. |
Windows that are tagged with set.minus (see CMBWindow)
are treated differently from other windows.
If the argument new.window is a list of CMBWindows,
then interious of all windows whose
winType does not include "minus" are united (let be their union) and
exteriors of all windows whose winType does include "minus" are intersected,
(let be their intersection). Then, provided that
intersect = TRUE (the default), the returned CMBDataFrame will
be the points of cmbdf in the the intersection of and .
Otherwise, if intersect = FALSE, the returned CMBDataFrame
consists of the points of x in the union of
and .
Note that if (resp. ) is empty then the returned CMBDataFrame
will be the points of x in (resp. ).
The window attribute of x or, if new.window/in.pixels is specified,
a new CMBDataFrame.
## Example 1: Create a new CMBDataFrame with a window cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) cmbdf.win <- window(cmbdf, new.window = win) plot(cmbdf.win) window(cmbdf.win) ## Example 2: Change the window of an existing CMBDataFrame cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") window(cmbdf) <- win2 <- CMBWindow(theta = c(pi/6,pi/3,pi/3, pi/6), phi = c(0,0,pi/6,pi/6)) plot(cmbdf) ## Example 3: union of windows ## Create 2 windows win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) win2 <- CMBWindow(theta = c(2*pi/3,3*pi/4,3*pi/4, 2*pi/3), phi = c(pi/4,pi/4,pi/3,pi/3)) plot(win1) plot(win2) ## Create CMBDataFrame with points in the union of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win <- window(cmbdf, new.window = list(win1, win2), intersect = FALSE) plot(cmbdf.win) ## Example 4: intersection of windows ## Create 2 windows win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) win2 <- CMBWindow(theta = c(pi/4,pi/3,pi/3, pi/4), phi = c(pi/4,pi/4,pi/3,pi/3)) plot(win1) plot(win2) ## Create CMBDataFrame with points in the intersection of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win1 <- window(cmbdf, new.window = win1) cmbdf.win12 <- window(cmbdf.win1, new.window = win2) plot(cmbdf.win12) plot(win1) plot(win2) ## Example 5: intersection of windows with "minus" type ## Create 2 windows with "minus" type win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2), set.minus =TRUE) win2 <- CMBWindow(theta = c(pi/4,pi/3,pi/3, pi/4), phi = c(pi/4,pi/4,pi/3,pi/3), set.minus =TRUE) plot(win1) plot(win2) ## Create CMBDataFrame with points in the intersection of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win <- window(cmbdf, new.window = list(win1, win2)) plot(cmbdf.win) ## Example 6: intersection of windows with different types ##Create 2 windows, one with "minus" type win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) win2 <- CMBWindow(theta = c(pi/4,pi/3,pi/3, pi/4), phi = c(pi/4,pi/4,pi/3,pi/3), set.minus =TRUE) plot(win1) plot(win2) ## Create CMBDataFrame with points in the intersection of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win <- window(cmbdf, new.window = list(win1, win2), intersect = TRUE) plot(cmbdf.win) ## Example 7: union of windows with different types win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2), set.minus =TRUE) win2 <- CMBWindow(theta = c(pi/4,pi/3,pi/3, pi/4), phi = c(pi/4,pi/4,pi/3,pi/3)) plot(win1) plot(win2) ## Create CMBDataFrame with points in the union of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win <- window(cmbdf, new.window = list(win1, win2), intersect = FALSE) plot(cmbdf.win)## Example 1: Create a new CMBDataFrame with a window cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") win <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) cmbdf.win <- window(cmbdf, new.window = win) plot(cmbdf.win) window(cmbdf.win) ## Example 2: Change the window of an existing CMBDataFrame cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") window(cmbdf) <- win2 <- CMBWindow(theta = c(pi/6,pi/3,pi/3, pi/6), phi = c(0,0,pi/6,pi/6)) plot(cmbdf) ## Example 3: union of windows ## Create 2 windows win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) win2 <- CMBWindow(theta = c(2*pi/3,3*pi/4,3*pi/4, 2*pi/3), phi = c(pi/4,pi/4,pi/3,pi/3)) plot(win1) plot(win2) ## Create CMBDataFrame with points in the union of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win <- window(cmbdf, new.window = list(win1, win2), intersect = FALSE) plot(cmbdf.win) ## Example 4: intersection of windows ## Create 2 windows win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) win2 <- CMBWindow(theta = c(pi/4,pi/3,pi/3, pi/4), phi = c(pi/4,pi/4,pi/3,pi/3)) plot(win1) plot(win2) ## Create CMBDataFrame with points in the intersection of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win1 <- window(cmbdf, new.window = win1) cmbdf.win12 <- window(cmbdf.win1, new.window = win2) plot(cmbdf.win12) plot(win1) plot(win2) ## Example 5: intersection of windows with "minus" type ## Create 2 windows with "minus" type win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2), set.minus =TRUE) win2 <- CMBWindow(theta = c(pi/4,pi/3,pi/3, pi/4), phi = c(pi/4,pi/4,pi/3,pi/3), set.minus =TRUE) plot(win1) plot(win2) ## Create CMBDataFrame with points in the intersection of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win <- window(cmbdf, new.window = list(win1, win2)) plot(cmbdf.win) ## Example 6: intersection of windows with different types ##Create 2 windows, one with "minus" type win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) win2 <- CMBWindow(theta = c(pi/4,pi/3,pi/3, pi/4), phi = c(pi/4,pi/4,pi/3,pi/3), set.minus =TRUE) plot(win1) plot(win2) ## Create CMBDataFrame with points in the intersection of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win <- window(cmbdf, new.window = list(win1, win2), intersect = TRUE) plot(cmbdf.win) ## Example 7: union of windows with different types win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2), set.minus =TRUE) win2 <- CMBWindow(theta = c(pi/4,pi/3,pi/3, pi/4), phi = c(pi/4,pi/4,pi/3,pi/3)) plot(win1) plot(win2) ## Create CMBDataFrame with points in the union of win1 and win2 cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win <- window(cmbdf, new.window = list(win1, win2), intersect = FALSE) plot(cmbdf.win)
This function returns a
data.frame containing the data in x restricted to the
CMBWindow new.window
## S3 method for class 'data.frame' window(x, new.window, intersect = TRUE, ...)## S3 method for class 'data.frame' window(x, new.window, intersect = TRUE, ...)
x |
A data.frame. Must have columns labelled x,y,z specifying cartesian coordinates, or columns labelled theta, phi specifying colatitude and longitude respectively. |
new.window |
A single |
intersect |
A boolean that determines
the behaviour when |
... |
Unused arguments. |
Windows that are tagged with set.minus (see CMBWindow)
are treated differently from other windows.
If the argument is a list of CMBWindows, then interiors of all windows whose
winType does not include "minus" are united (let be their union) and
exteriors of all windows whose winType does include "minus" are intersected,
(let be their intersection). Then, provided that
intersect = TRUE (the default), the returned data.frame will
be the points of x in the the intersection of
and .
Otherwise, if intersect = FALSE, the returned data.frame
consists of the points of x in the union of
and .
Note that if (resp. ) is empty then the returned data.frame
will be the points of x in (resp. ).
A data.frame containing the data in x restricted to the
CMBWindow new.window
win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) cmbdf <- CMBDataFrame(nside = 4) df2 <- coords(cmbdf, new.coords = "cartesian") df <- as.data.frame(df2[,1:3]) df df.win <- window(df, new.window = win1) df.winwin1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) cmbdf <- CMBDataFrame(nside = 4) df2 <- coords(cmbdf, new.coords = "cartesian") df <- as.data.frame(df2[,1:3]) df df.win <- window(df, new.window = win1) df.win
HPDataFrame
This function returns a
HPDataFrame containing the data in hpdf restricted to the
CMBWindow new.window. If the HPDataFrame has columns x,y,z
or theta, phi then these will be used to determine locations
with priority over the HEALPix indices in pix(hpdf)
unless healpixCentered = TRUE is given. Note that
if healpixCentered = TRUE then columns x,y,z or theta, phi
will be discarded and replaced with pixel center locations.
## S3 method for class 'HPDataFrame' window(x, new.window, intersect = TRUE, healpixCentered = FALSE, ...)## S3 method for class 'HPDataFrame' window(x, new.window, intersect = TRUE, healpixCentered = FALSE, ...)
x |
A |
new.window |
Optional.
A single |
intersect |
A boolean that determines
the behaviour when |
healpixCentered |
A boolean. If the HPDataFrame has columns x,y,z
or theta, phi then these will be used to determine locations
with priority over the HEALPix indices in |
... |
Unused arguments. |
Windows that are tagged with set.minus (see CMBWindow)
are treated differently from other windows.
If the argument is a list of CMBWindows, then interiors of all windows whose
winType does not include "minus" are united (let be their union) and
exteriors of all windows whose winType does include "minus" are intersected,
(let be their intersection). Then, provided that
intersect = TRUE (the default), the returned data.frame will
be the points of df in the the intersection of
and .
Otherwise, if intersect = FALSE, the returned data.frame
consists of the points of df in the union of
and .
Note that if (resp. ) is empty then the returned data.frame
will be the points of df in (resp. ).
A HPDataFrame containing the data in x restricted to the
CMBWindow new.window. Or, if new.window is
unspecified, then the window attribute of x
is returned instead (and may be NULL).
ns <- 16 hpdf <- HPDataFrame(nside = ns, I = 1:(12*ns^2)) hpdf win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) plot(hpdf); plot(win1) hpdf.win <- window(hpdf, new.window = win1) plot(hpdf.win, col = "yellow", size = 4, add = TRUE) attributes(hpdf.win) window(hpdf.win) hpdf.winns <- 16 hpdf <- HPDataFrame(nside = ns, I = 1:(12*ns^2)) hpdf win1 <- CMBWindow(theta = c(0,pi/2,pi/2), phi = c(0,0,pi/2)) plot(hpdf); plot(win1) hpdf.win <- window(hpdf, new.window = win1) plot(hpdf.win, col = "yellow", size = 4, add = TRUE) attributes(hpdf.win) window(hpdf.win) hpdf.win
Get/change the winType (polygon or disk) of a CMBWindow.
If new.type is missing then the winType of win
is returned. Otherwise, a new window is returned with winType
equal to new.type. If you want to change the
winType of win directly, then use winType<-, see
the examples below.
winType(win, new.type)winType(win, new.type)
win |
a |
new.type |
optionally specify a new type. Use this to change between "polygon" and "minus.polygon" or to change between "disc" and "minus.disc" |
If new.type is missing then the winType of win
is returned. Otherwise a new window is returned with winType
equal to new.type
win <- CMBWindow(theta = c(pi/2,pi/2,pi/3, pi/3), phi = c(0,pi/3,pi/3,0)) winType(win) win1 <- CMBWindow(x=0,y=3/5,z=4/5,r=0.8) winType(win1) cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win1 <- window(cmbdf, new.window = win1) plot(cmbdf.win1) winType(win1) <- "minus.disc" winType(win1) cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win1 <- window(cmbdf, new.window = win1) plot(cmbdf.win1)win <- CMBWindow(theta = c(pi/2,pi/2,pi/3, pi/3), phi = c(0,pi/3,pi/3,0)) winType(win) win1 <- CMBWindow(x=0,y=3/5,z=4/5,r=0.8) winType(win1) cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win1 <- window(cmbdf, new.window = win1) plot(cmbdf.win1) winType(win1) <- "minus.disc" winType(win1) cmbdf <- CMBDataFrame(nside = 64, coords = "cartesian", ordering = "nested") cmbdf.win1 <- window(cmbdf, new.window = win1) plot(cmbdf.win1)