-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportMorphology.R
48 lines (41 loc) · 1.17 KB
/
ImportMorphology.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
#Script for reading in the morphology data and transforming it from pixels to mm.
#
#Defined functions:
##ReadData:
###Reads in the file and ads a column wit the conversion factor
#
##ConvData:
###Converts all measurements from pixels to mm.
###Deletes the "five_mm" and "ConvFact" columns.
#
#Setting working directory, (change this if necesarry)
WorkDirectory <- "D:/Documents/MatechoiceColor2018/MorphologyPhotos"
#Defining function for reading in the data
ReadData <- function(wd){
setwd(wd)
pixels <- read.csv("measurements.txt", sep="\t")
pixels <- within(pixels, ConvFact <- five_mm/5)
return(pixels)
}
#Defining function for convertingfrom pixels to mm
ConvData <- function(pixels){
mm <- pixels
for (column in 2:ncol(pixels)){
print(column)
for (row in 1:nrow(pixels)){
print(row)
mm[row,column] <- pixels[row, column]/pixels[row,"ConvFact"]
}
}
mm <- mm[ , 1:7]
return(mm)
}
#Defining function for running the above functions in soccessive order.
Run <- function(wd){
pixels <- ReadData(wd)
mm <- ConvData(pixels)
return(mm)
}
#Runing the shit
PhotoMorphology <- Run(WorkDirectory)