The MAgPIE class is a data format for cellular MAgPIE data with a close
relationship to the array data format. is.magpie
tests if x
is
an MAgPIE-object, as.magpie
transforms x
to an MAgPIE-object
(if possible).
An object that should be either tested or transformed as/to an MAgPIE-object.
additional arguments supplied for the conversion to a MAgPIE
object. Allowed arguments for arrays and dataframes are spatial
and
temporal
both expecting a vector of dimension or column numbers which
contain the spatial or temporal information. By default both arguments are
set to NULL which means that the as.magpie
will try to detect
automatically the temporal and spatial dimensions. The arguments will just
overwrite the automatic detection. If you want to specify that the data does
not contain a spatial or temporal dimension you can set the corresponding
argument to 0. In addition as.magpie
for data.frames is also
expecting an argument called datacol
which expects a number stating
which is the first column containing data. This argument should be used if
the dimensions are not detected corretly, e.g. if the last dimension column
contains years which are then detected as values and therefore interpreted
as first data column. In addition an argument tidy=TRUE
can be used
to indicate that the data.frame structure is following the rules of tidy
data (last column is the data column all other columns contain dimension
information). This information will help the conversion.
Objects can be created by calls of the form
new("magpie", data, dim, dimnames, ...)
. MAgPIE objects have three
dimensions (cells,years,datatype) and the dimensionnames of the first
dimension have the structure "REGION.cellnumber". MAgPIE-objects behave the
same like array-objects with 2 exceptions: 1.Dimensions of the object
will not collapse (e.g. x[1,1,1]
will remain 3D instead of becoming
1D) 2.It is possible to extract full regions just by typing
x["REGIONNAME",,]
.
Please mind following standards: Header must not contain any purely numeric entries, but combinations of characters and numbers are allowed (e.g. "bla","12" is forbidden, wheras "bla","b12" is allowed) Years always have the structure "y" + 4-digit number, e.g. "y1995" Regions always have the structure 3 capital letters, e.g. "AFR" or "GLO" This standards are necessary to allow the scripts to detect headers, years and regions properly and to have a distinction to other data.
read.magpie
, write.magpie
,
getRegions
, getYears
, getNames
,
getCPR
, ncells
, nyears
,
ndata
# NOT RUN {
showClass("magpie")
data(population_magpie)
# returning PAO and PAS for 2025
population_magpie["PA",2025,,pmatch="left"]
# returning CPA for 2025
population_magpie["PA",2025,,pmatch="right"]
# returning CPA PAO and PAS for 2025
population_magpie["PA",2025,,pmatch=TRUE]
# returning PAS and 2025
population_magpie["PAS",2025,]
# returning everything but values for PAS or values for 2025
population_magpie["PAS",2025,,invert=TRUE]
# }
Run the code above in your browser using DataLab