SkillAgentSearch skills...

CleanRfield

cleanRfield: This package is a compilation of functions to clean and filter observations from yield monitors or other agricultural spatial point data. Yield monitors are prone to error, and filtering the observations or removing observations from near field boundaries can improve estimates of whole-field yield, combine speed, grain moisture, or other parameters. In this package, users can easily select filters thresholding for one or more traits and prepare a smaller dataset to make decisions.

Install / Use

/learn @filipematias23/CleanRfield
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

cleanRfield: A tool for cleaning and filtering data spatial points from crop yield maps in R.

This package is a compilation of functions to clean and filter observations from yield monitors or other agricultural spatial point data. Yield monitors are prone to error, and filtering the observations or removing observations from near field boundaries can improve estimates of whole-field yield, combine speed, grain moisture, or other parameters of interest. In this package, users can easily select filters for one or more traits and prepare a smaller dataset to make decisions.

This tutorial assumes that readers have a basic understanding of spatial data, including projections and coordinate reference systems. If you need a refresher on this topic, we recommend reading this blog post for deciding between projected and unprojected data and this post for understanding the basics of coordinate reference systems.

<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/CleanRField_large.jpg" width="40%" height="40%"> </p> <div id="menu" />

Resources

Installation

1. First steps

2. Cropping or selecting regions

3. Sampling point data

4. Making rasters

5. Building shape boundaries

6. Buffering the field boundaries

7. Filtering using data values

8. Filtering using standard deviation values

9. Evaluating multiple fields on parallel

10. Making Maps

11. Saving files

12. Working with .csv or .txt files

13. Interpolating yield maps

Contact

<div id="instal" />

Install R and RStudio.

<br />

Now install R/cleanRfield using the install_github() function from devtools package. If necessary, use the argument type="source".

install.packages("devtools")
devtools::install_github("filipematias23/cleanRfield")
<br /> <p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/cleanRfield_R.jpg"> </p> <br />

Menu

<div id="p1" />

1. First steps

Calling necessary packages:

library(terra)
library(cleanRfield)

Start this tutorial by downloading the example EX1 here and the field boundary here. This tutorial will use the function vect() from package terra to read and upload the data to RStudio (see provided code).

EX1 is a yield map from a soybean field, stored as a point shapefile. Yield monitor observations were originally collected in the north-central US using a combine yield monitor, and observations were geographically shifted to protect the landowner’s privacy. This data set include three attributes:

  • Speed (miles per hour): speed of the combine at the time the observation was recorded
  • Dry_Yield (bushels per acre): yield at that observation’s location as recorded by the yield monitor, adjusted to a 13% moisture basis
  • Adj_Moist (percent): indicates what moisture level the original wet yield measurements were adjusted to when calculating dry yield

The field boundary is a shapefile layer with three (3) polygons that delineate the boundaries of the sample field EX1.

### Opening Sample Field 1 ###

par(mfrow=c(1,2))

EX1<-vect("EX1.shp")
plot(EX1, main="Data Point")

EX1.Shape<-vect("EX1_boundary.shp")
plot(EX1.Shape, main="Field Boundary")

par(mfrow=c(1,1))
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter1.jpg" width="70%" height="70%"> </p>

Menu

<div id="p2" />

2. Cropping or selecting targeted field

Users can subset the data by drawing boundaries around a field or subset of fields. Function cropField. Depending on your computer and the size of your data set, this step may take a few seconds. This function works better using a popup window, not RStudio's integrated viewing pane, so we've included code for opening that new window.

#Open an extra plot window 
x11() 
# "Use cursor to select 4 points around polygon (1) in the plots window."
EX1.C<-cropField(field = EX1, nPolygon = 1, nPoint = 4)
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter2.jpg" width="70%" height="70%"> </p>
plot(EX1.C$shape,main="Drawing Shape")
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter3.jpg" width="70%" height="70%"> </p>
# Using the shape drawn above to crop data:
EX1.C<-cropField(field = EX1, shape = EX1.C$shape) 
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter4.jpg" width="70%" height="70%"> </p>
# All data will be selected using the full boundary as shape:
EX1.C1<-cropField(field = EX1, shape = EX1.Shape) 
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter5.jpg" width="70%" height="70%"> </p>

The newest version of RStudio (2021.09.2) has updated the plot viewing pane. If you are using the newest RStudio, you may need run an additional line of code to open the point-and-click cropping functionality in a pop-out window instead of the integrated plot viewing pane.

#Open an extra plot window 
x11() 
# "Use cursor to select 4 points around polygon (1) in the plots window."
EX1.C<-cropField(field = EX1, nPolygon = 1, nPoint = 4)

Menu

<div id="p3" />

3. Sampling point data

Users can sample random points in the data. Function sampleField.

# Sampling 5%:
EX1.S<-sampleField(field = EX1, size = 0.05) 
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter6.jpg" width="70%" height="70%"> </p>
# Sampling 10% under a small shape:
EX1.S<-sampleField(field = EX1,shape = EX1.C$shape, size = 0.1) 
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter7.jpg" width="70%" height="70%"> </p>
# Sampling 10% under a full shape:
EX1.S<-sampleField(field = EX1,shape = EX1.Shape, size = 0.1) 
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter8.jpg" width="70%" height="70%"> </p>

Menu

<div id="p4" />

4. Making rasters

Function rasterField.Data points can be used to create raster files. Use either the provided code for unprojected data or projected data-- you will not need to run both sets of code. Any positive number can be chosen as the resolution, but choosing too high of a resolution will result in a raster file that oversimplifies the shape of the field, and choosing too low of a resolution can cause the runtime to be to long and/or cause the parts of the field between combine passes to be excluded from the final field shape.

# Check projection to observe 'LENGTHUNIT': 
crs(EX1)

# Unprojected Data (non or NA): use resolution around 0.00008 to create a raster for "Dry_Yield":
EX1.R<-rasterField(field = EX1,
                   trait = c("Dry_Yield"),
                   res = 0.00008)
                   
# Projected Data (e.g., +units=m or +units=us-ft): use resolution around 5 to 20 to create a raster for "Dry_Yield":
EX1.R<-rasterField(field = EX1,
                   trait = c("Dry_Yield"),
                   res = 20)                   
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter9.jpg" width="70%" height="70%"> </p>
# Making raster only for the small shape:
EX1.R<-rasterField(field = EX1,
                    shape = EX1.C$shape,
                    trait = c("Dry_Yield"),
                    res = 0.00008) # Attention: for projected data use res=20 (e.g., +units=m or +units=us-ft).
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter10.jpg" width="70%" height="70%"> </p>
# Multilayer raster for two or more traits:
EX1.R<-rasterField(field = EX1,
                   trait = c("Dry_Yield","Speed"),
                   res = 0.00008) # Attention: for projected data use res=20 (e.g., +units=m or +units=us-ft).
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter11.jpg" width="70%" height="70%"> </p>
# Different raster color visualizations:
library(RColorBrewer)
par(mfrow=c(2,3))
plot(EX1.R$Dry_Yield)
plot(EX1.R$Dry_Yield,col = heat.colors(10))
plot(EX1.R$Dry_Yield,col = topo.colors(10))
plot(EX1.R$Dry_Yield,col = brewer.pal(11, "RdYlGn"))
plot(EX1.R$Dry_Yield,col = brewer.pal(9, "BuGn"))
plot(EX1.R$Dry_Yield,col = brewer.pal(9, "Greens"))
par(mfrow=c(1,1))
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/filter11col.jpeg"> </p>

Menu

<div id="p5" />

5. Building shape boundaries

Users can manually draw field boundaries or use the ras

View on GitHub
GitHub Stars42
CategoryDevelopment
Updated1mo ago
Forks3

Languages

R

Security Score

90/100

Audited on Feb 25, 2026

No findings