How to permanently round values in a raster layer, matrix, or array, to write to a new file using r studio?Extract Value from Raster Stack Layer Determined by Different Raster's Pixel ValueWhy do I get different results in plotting a NetCDF layer with “image(x,y,z)” and “plot (raster)” using R-package Raster?Extracting rasters from multiple NetCDF files based on date values in PythonExport raster names from raster stack to NetCDF file in RHow to loop through multiple RasterBrick to create one large RasterBrick?Summarizing values across polygons, for each layer in Raster Stack - How to merge values with shapefile?writing a raster stack on disk with writeRaster in R changes the range of the values for each layerExtract values from a netCDF file with an unstructured grid, at given coordinates and timesSubstitute pixels values of all layers in a raster stackHow to loop extraction of values from multiple raster files?
Error when running ((x++)) as root
What's is the easiest way to purchase a stock and hold it
Would a "ring language" be possible?
Divisor Rich and Poor Numbers
Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?
multicol package causes underfull hbox
Largest memory peripheral for Sinclair ZX81?
How many Dothraki are left as of Game of Thrones S8E5?
how to create an executable file for an AppleScript?
Why does the setUID bit work inconsistently?
How does this piece of code determine array size without using sizeof( )?
Gambler's Fallacy Dice
How to get all possible paths in 0/1 matrix better way?
Is it standard to have the first week's pay indefinitely withheld?
I recently started my machine learning PhD and I have absolutely no idea what I'm doing
Driving a school bus in the USA
Former Employer just sent me an IP Agreement
Is it a good idea to teach algorithm courses using pseudocode?
Are there any symmetric cryptosystems based on computational complexity assumptions?
How do we explain the use of a software on a math paper?
Why is choosing a suitable thermodynamic potential important?
Why are stats in Angband written as 18/** instead of 19, 20...?
How would fantasy dwarves exist, realistically?
Should all adjustments be random effects in a mixed linear effect?
How to permanently round values in a raster layer, matrix, or array, to write to a new file using r studio?
Extract Value from Raster Stack Layer Determined by Different Raster's Pixel ValueWhy do I get different results in plotting a NetCDF layer with “image(x,y,z)” and “plot (raster)” using R-package Raster?Extracting rasters from multiple NetCDF files based on date values in PythonExport raster names from raster stack to NetCDF file in RHow to loop through multiple RasterBrick to create one large RasterBrick?Summarizing values across polygons, for each layer in Raster Stack - How to merge values with shapefile?writing a raster stack on disk with writeRaster in R changes the range of the values for each layerExtract values from a netCDF file with an unstructured grid, at given coordinates and timesSubstitute pixels values of all layers in a raster stackHow to loop extraction of values from multiple raster files?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to round either round a 3 dimensional matrix or several raster layers that will be made into a 3 dimensional matrix to 2 decimal places to make a new netcdf file that will take up less memory.
Using the round function as such:
newmatrix <- round(oldmatrix, 2)
only seems to round values superficially for display. Opening newmatrix and extracting values from it after adding it to a new file returns the unrounded values from oldmatrix. This is despite the fact that values extracted from newmatrix before adding it to a new file will be rounded to 2 decimal places as is supposed to be. The same thing happens if I round off the raster layers before creating a new matrix with them.
What function can I use to permanently round off my matrix's or raster's values to write to a new file rounded?
r netcdf
add a comment |
I am trying to round either round a 3 dimensional matrix or several raster layers that will be made into a 3 dimensional matrix to 2 decimal places to make a new netcdf file that will take up less memory.
Using the round function as such:
newmatrix <- round(oldmatrix, 2)
only seems to round values superficially for display. Opening newmatrix and extracting values from it after adding it to a new file returns the unrounded values from oldmatrix. This is despite the fact that values extracted from newmatrix before adding it to a new file will be rounded to 2 decimal places as is supposed to be. The same thing happens if I round off the raster layers before creating a new matrix with them.
What function can I use to permanently round off my matrix's or raster's values to write to a new file rounded?
r netcdf
add a comment |
I am trying to round either round a 3 dimensional matrix or several raster layers that will be made into a 3 dimensional matrix to 2 decimal places to make a new netcdf file that will take up less memory.
Using the round function as such:
newmatrix <- round(oldmatrix, 2)
only seems to round values superficially for display. Opening newmatrix and extracting values from it after adding it to a new file returns the unrounded values from oldmatrix. This is despite the fact that values extracted from newmatrix before adding it to a new file will be rounded to 2 decimal places as is supposed to be. The same thing happens if I round off the raster layers before creating a new matrix with them.
What function can I use to permanently round off my matrix's or raster's values to write to a new file rounded?
r netcdf
I am trying to round either round a 3 dimensional matrix or several raster layers that will be made into a 3 dimensional matrix to 2 decimal places to make a new netcdf file that will take up less memory.
Using the round function as such:
newmatrix <- round(oldmatrix, 2)
only seems to round values superficially for display. Opening newmatrix and extracting values from it after adding it to a new file returns the unrounded values from oldmatrix. This is despite the fact that values extracted from newmatrix before adding it to a new file will be rounded to 2 decimal places as is supposed to be. The same thing happens if I round off the raster layers before creating a new matrix with them.
What function can I use to permanently round off my matrix's or raster's values to write to a new file rounded?
r netcdf
r netcdf
asked Mar 23 at 17:21
Cooper SpringerCooper Springer
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
NetCDF doesn't have a fixed precision format that would save space in the way you are expecting. (See here for data types). The usual way of saving space is to encode as a short integer and set the variable attributes scale_factor
and add_offset
.
In your case, you would multiply by 100, convert to short, and have scale_factor=0.01
. Doing this in R is probably a lot of work, but nco utility would handle it in a few lines.
Let's say you have a variable called rh
.
ncap2 -v -s 'rh=short(100*rh)' in.nc out.nc
ncatted -O -h -a add_offset,rh,o,f,0 out.nc
ncatted -O -h -a scale_factor,rh,o,f,0.01 out.nc
If you are looking to save memory when reading a variable into R, you might be disappointed as it will just be converted back into a float upon reading.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316416%2fhow-to-permanently-round-values-in-a-raster-layer-matrix-or-array-to-write-to%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
NetCDF doesn't have a fixed precision format that would save space in the way you are expecting. (See here for data types). The usual way of saving space is to encode as a short integer and set the variable attributes scale_factor
and add_offset
.
In your case, you would multiply by 100, convert to short, and have scale_factor=0.01
. Doing this in R is probably a lot of work, but nco utility would handle it in a few lines.
Let's say you have a variable called rh
.
ncap2 -v -s 'rh=short(100*rh)' in.nc out.nc
ncatted -O -h -a add_offset,rh,o,f,0 out.nc
ncatted -O -h -a scale_factor,rh,o,f,0.01 out.nc
If you are looking to save memory when reading a variable into R, you might be disappointed as it will just be converted back into a float upon reading.
add a comment |
NetCDF doesn't have a fixed precision format that would save space in the way you are expecting. (See here for data types). The usual way of saving space is to encode as a short integer and set the variable attributes scale_factor
and add_offset
.
In your case, you would multiply by 100, convert to short, and have scale_factor=0.01
. Doing this in R is probably a lot of work, but nco utility would handle it in a few lines.
Let's say you have a variable called rh
.
ncap2 -v -s 'rh=short(100*rh)' in.nc out.nc
ncatted -O -h -a add_offset,rh,o,f,0 out.nc
ncatted -O -h -a scale_factor,rh,o,f,0.01 out.nc
If you are looking to save memory when reading a variable into R, you might be disappointed as it will just be converted back into a float upon reading.
add a comment |
NetCDF doesn't have a fixed precision format that would save space in the way you are expecting. (See here for data types). The usual way of saving space is to encode as a short integer and set the variable attributes scale_factor
and add_offset
.
In your case, you would multiply by 100, convert to short, and have scale_factor=0.01
. Doing this in R is probably a lot of work, but nco utility would handle it in a few lines.
Let's say you have a variable called rh
.
ncap2 -v -s 'rh=short(100*rh)' in.nc out.nc
ncatted -O -h -a add_offset,rh,o,f,0 out.nc
ncatted -O -h -a scale_factor,rh,o,f,0.01 out.nc
If you are looking to save memory when reading a variable into R, you might be disappointed as it will just be converted back into a float upon reading.
NetCDF doesn't have a fixed precision format that would save space in the way you are expecting. (See here for data types). The usual way of saving space is to encode as a short integer and set the variable attributes scale_factor
and add_offset
.
In your case, you would multiply by 100, convert to short, and have scale_factor=0.01
. Doing this in R is probably a lot of work, but nco utility would handle it in a few lines.
Let's say you have a variable called rh
.
ncap2 -v -s 'rh=short(100*rh)' in.nc out.nc
ncatted -O -h -a add_offset,rh,o,f,0 out.nc
ncatted -O -h -a scale_factor,rh,o,f,0.01 out.nc
If you are looking to save memory when reading a variable into R, you might be disappointed as it will just be converted back into a float upon reading.
answered Mar 25 at 6:33
Robert DavyRobert Davy
35319
35319
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316416%2fhow-to-permanently-round-values-in-a-raster-layer-matrix-or-array-to-write-to%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown