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;








0















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?










share|improve this question




























    0















    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?










    share|improve this question
























      0












      0








      0








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 17:21









      Cooper SpringerCooper Springer

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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.






          share|improve this answer























            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
            );



            );













            draft saved

            draft discarded


















            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









            1














            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.






            share|improve this answer



























              1














              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.






              share|improve this answer

























                1












                1








                1







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 6:33









                Robert DavyRobert Davy

                35319




                35319





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현