如何在R代码中将小于0的栅格值替换为NA [英] How to Replace Raster Values Less than 0 to NA in R code

查看:616
本文介绍了如何在R代码中将小于0的栅格值替换为NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Landsat影像来计算净辐射. 在转换后的反射率栅格图层中,负值非常低(例如:-0.000003).我想确保我的反射率为0-1,以减少将来计算中的误差.

I am working with Landsat imagery to calculate net radiation. There are very low negative values (ex: -0.000003) that are in my converted reflectance raster layers. I want to make sure that my reflectances are 0 - 1 in order to reduce error in my future calculations.

如何在R中将小于0的栅格值替换为"NA".类似于栅格计算功能.我不确定如何提供示例,但是我敢肯定你们中的一个可以帮助我,是吗?

How can I replace raster values less than 0 to "NA" in R. Similar to a raster calc function. I'm unsure how to provide an example, but I'm certain one of you could help me, yes?

这是我从Bastiaanssen等人得出的反射率方程. (1998)

Here is my equation for the reflectivity derived from Bastiaanssen et al. (1998)

假设pb1表示Landsat波段1的反射率,pi = 3.14 ...,lb1 =波段1的辐射度,ESUN =波段1的大气层值,dr =一年中某天的相对地球太阳距离.

Assuming, the pb1 indicates the reflectance for band 1 of Landsat, pi = 3.14..., lb1 = radiance for band 1, ESUN = exoatmospheric value for band 1, dr = the relative earth sun distance for the day of year.

#Calculate reflectivity per band. QC: Always 0 to 1
pb1 = (pi * lb1)/(ESUN1 * cos(solzen) * dr)

创建此栅格后,我要做的就是将小于0的pb1值设置为NA.

After this raster is created, all I want to do is set the pb1 values that are less than 0 to NA.

帮助?

推荐答案

library(raster)

values(pb1)[values(pb1) < 0] = NA

或者,按照@jbaums的建议:

Or, as suggested by @jbaums:

pb1[pb1 < 0] <- NA

如果要保留原始栅格对象,请记住在运行上面的代码之前将原始栅格分配给新的对象名称.

If you want to keep the original raster object, remember to assign the original raster to a new object name before running the code above.

这篇关于如何在R代码中将小于0的栅格值替换为NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆