Skip to content

Commit

Permalink
Remove intermediate variables
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteDlp committed Dec 6, 2023
1 parent 5795e42 commit 3449a4f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 65 deletions.
111 changes: 49 additions & 62 deletions R/defStormsDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,35 @@ getDataFromCsvFile <- function(filename, fields, basin, seasons, unitConversion,
# Initialize template structure
templateArray = array(NaN, dim=c(row,len))

Check warning on line 441 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L441

Added line #L441 was not covered by tests


# Mandatory fields
names <- array(NaN, dim=len)
seasons <- array(NaN, dim=len)
isotimes <- templateArray
longitude <- templateArray
latitude <- templateArray
msw <- templateArray
data <- list(
names = array(NaN, dim=len),
seasons = array(NaN, dim=len),
isotimes = templateArray,
longitude = templateArray,
latitude = templateArray,
msw = templateArray

Check warning on line 451 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L445-L451

Added lines #L445 - L451 were not covered by tests
)

# Optional fields
sshs <- templateArray # TODO Remove later
rmw <- templateArray
pressure <- templateArray
poci <- templateArray
# TODO Remove later
if("sshs" %in% names(fields)){
data$sshs <- templateArray

Check warning on line 456 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L455-L456

Added lines #L455 - L456 were not covered by tests
}

if("rmw" %in% names(fields)){
data$rmw <- templateArray

Check warning on line 460 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L459-L460

Added lines #L459 - L460 were not covered by tests
}

if("pressure" %in% names(fields)){
data$pressure <- templateArray

Check warning on line 464 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L463-L464

Added lines #L463 - L464 were not covered by tests
}

if("poci" %in% names(fields)){
data$poci <- templateArray

Check warning on line 468 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L467-L468

Added lines #L467 - L468 were not covered by tests
}



for(i in 1:len){

Check warning on line 473 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L473

Added line #L473 was not covered by tests

Expand All @@ -465,102 +481,73 @@ getDataFromCsvFile <- function(filename, fields, basin, seasons, unitConversion,
end = cumulativeIndex[i]

Check warning on line 481 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L481

Added line #L481 was not covered by tests

# Fill data

names[i] <- dataBaseFiltered[start, fields["names"]]
seasons[i] <- as.numeric(dataBaseFiltered[start, fields["seasons"]])
isotimes[,i] <- c(dataBaseFiltered[start:end, fields["isoTime"]], rep(NaN, row-countObs[i]))
longitude[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["lon"]], rep(NaN, row-countObs[i])))
latitude[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["lat"]], rep(NaN, row-countObs[i])))
data$names[i] <- dataBaseFiltered[start, fields["names"]]
data$seasons[i] <- as.numeric(dataBaseFiltered[start, fields["seasons"]])
data$isotimes[,i] <- c(dataBaseFiltered[start:end, fields["isoTime"]], rep(NaN, row-countObs[i]))
data$longitude[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["lon"]], rep(NaN, row-countObs[i])))
data$latitude[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["lat"]], rep(NaN, row-countObs[i])))

Check warning on line 488 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L484-L488

Added lines #L484 - L488 were not covered by tests

if (unitConversion["msw"] == "mph2ms") {
msw[,i] <- as.numeric(c(mph2ms(as.numeric(dataBaseFiltered[start:end, fields["msw"]])), rep(NaN, row-countObs[i])))
data$msw[,i] <- as.numeric(c(mph2ms(as.numeric(dataBaseFiltered[start:end, fields["msw"]])), rep(NaN, row-countObs[i])))
} else if (unitConversion["msw"] == "knt2ms") {
msw[,i] <- as.numeric(c(knt2ms(as.numeric(dataBaseFiltered[start:end, fields["msw"]])), rep(NaN, row-countObs[i])))
data$msw[,i] <- as.numeric(c(knt2ms(as.numeric(dataBaseFiltered[start:end, fields["msw"]])), rep(NaN, row-countObs[i])))
} else if (unitConversion["msw"] == "kmh2ms") {
msw[,i] <- as.numeric(c(kmh2ms(as.numeric(dataBaseFiltered[start:end, fields["msw"]])), rep(NaN, row-countObs[i])))
data$msw[,i] <- as.numeric(c(kmh2ms(as.numeric(dataBaseFiltered[start:end, fields["msw"]])), rep(NaN, row-countObs[i])))

Check warning on line 495 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L490-L495

Added lines #L490 - L495 were not covered by tests
} else {
msw[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["msw"]], rep(NaN, row-countObs[i])))
data$msw[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["msw"]], rep(NaN, row-countObs[i])))

Check warning on line 497 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L497

Added line #L497 was not covered by tests
}

# TODO Remove later
if ("sshs" %in% names(fields)) {
sshs[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["sshs"]], rep(NaN, row-countObs[i])))
data$sshs[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["sshs"]], rep(NaN, row-countObs[i])))

Check warning on line 502 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L501-L502

Added lines #L501 - L502 were not covered by tests
}

if ("rmw" %in% names(fields)) {
if (unitConversion["rmw"] == "nm2km") {
rmw[,i] <- as.numeric(c(nm2km(as.numeric(dataBaseFiltered[start:end, fields["rmw"]])), rep(NaN, row-countObs[i])))
data$rmw[,i] <- as.numeric(c(nm2km(as.numeric(dataBaseFiltered[start:end, fields["rmw"]])), rep(NaN, row-countObs[i])))

Check warning on line 507 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L505-L507

Added lines #L505 - L507 were not covered by tests
} else {
rmw[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["rwm"]], rep(NaN, row-countObs[i])))
data$rmw[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["rwm"]], rep(NaN, row-countObs[i])))

Check warning on line 509 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L509

Added line #L509 was not covered by tests
}
}

if ("pressure" %in% names(fields)) {
if (unitConversion["pressure"] == "mb2pa") {
pressure[,i] <- as.numeric(c(mb2pa(as.numeric(dataBaseFiltered[start:end, fields["pressure"]])), rep(NaN, row-countObs[i])))
data$pressure[,i] <- as.numeric(c(mb2pa(as.numeric(dataBaseFiltered[start:end, fields["pressure"]])), rep(NaN, row-countObs[i])))

Check warning on line 515 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L513-L515

Added lines #L513 - L515 were not covered by tests

} else if (unitConversion["pressure"] == "b2pa") {
pressure[,i] <- as.numeric(c(b2pa(as.numeric(dataBaseFiltered[start:end, fields["pressure"]])), rep(NaN, row-countObs[i])))
data$pressure[,i] <- as.numeric(c(b2pa(as.numeric(dataBaseFiltered[start:end, fields["pressure"]])), rep(NaN, row-countObs[i])))

Check warning on line 518 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L517-L518

Added lines #L517 - L518 were not covered by tests

} else if (unitConversion["pressure"] == "psi2pa") {
pressure[,i] <- as.numeric(c(psi2pa(as.numeric(dataBaseFiltered[start:end, fields["pressure"]])), rep(NaN, row-countObs[i])))
data$pressure[,i] <- as.numeric(c(psi2pa(as.numeric(dataBaseFiltered[start:end, fields["pressure"]])), rep(NaN, row-countObs[i])))

Check warning on line 521 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L520-L521

Added lines #L520 - L521 were not covered by tests

} else if (unitConversion["pressure"] == "atm2pa") {
pressure[,i] <- as.numeric(c(atm2pa(as.numeric(dataBaseFiltered[start:end, fields["pressure"]])), rep(NaN, row-countObs[i])))
data$pressure[,i] <- as.numeric(c(atm2pa(as.numeric(dataBaseFiltered[start:end, fields["pressure"]])), rep(NaN, row-countObs[i])))

Check warning on line 524 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L523-L524

Added lines #L523 - L524 were not covered by tests

} else {
pressure[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["pressure"]], rep(NaN, row-countObs[i])))
data$pressure[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["pressure"]], rep(NaN, row-countObs[i])))

Check warning on line 527 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L527

Added line #L527 was not covered by tests
}
}

if ("poci" %in% names(fields)) {
if (unitConversion["poci"] == "mb2pa") {
poci[,i] <- as.numeric(c(mb2pa(as.numeric(dataBaseFiltered[start:end, fields["poci"]])), rep(NaN, row-countObs[i])))
data$poci[,i] <- as.numeric(c(mb2pa(as.numeric(dataBaseFiltered[start:end, fields["poci"]])), rep(NaN, row-countObs[i])))

Check warning on line 533 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L531-L533

Added lines #L531 - L533 were not covered by tests

} else if (unitConversion["poci"] == "b2pa") {
poci[,i] <- as.numeric(c(b2pa(as.numeric(dataBaseFiltered[start:end, fields["poci"]])), rep(NaN, row-countObs[i])))
data$poci[,i] <- as.numeric(c(b2pa(as.numeric(dataBaseFiltered[start:end, fields["poci"]])), rep(NaN, row-countObs[i])))

Check warning on line 536 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L535-L536

Added lines #L535 - L536 were not covered by tests

} else if (unitConversion["poci"] == "psi2pa") {
poci[,i] <- as.numeric(c(psi2pa(as.numeric(dataBaseFiltered[start:end, fields["poci"]])), rep(NaN, row-countObs[i])))
data$poci[,i] <- as.numeric(c(psi2pa(as.numeric(dataBaseFiltered[start:end, fields["poci"]])), rep(NaN, row-countObs[i])))

Check warning on line 539 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L538-L539

Added lines #L538 - L539 were not covered by tests

} else if (unitConversion["poci"] == "atm2pa") {
poci[,i] <- as.numeric(c(atm2pa(as.numeric(dataBaseFiltered[start:end, fields["poci"]])), rep(NaN, row-countObs[i])))
data$poci[,i] <- as.numeric(c(atm2pa(as.numeric(dataBaseFiltered[start:end, fields["poci"]])), rep(NaN, row-countObs[i])))

Check warning on line 542 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L541-L542

Added lines #L541 - L542 were not covered by tests

} else {
poci[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["poci"]], rep(NaN, row-countObs[i])))
data$poci[,i] <- as.numeric(c(dataBaseFiltered[start:end, fields["poci"]], rep(NaN, row-countObs[i])))

Check warning on line 545 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L545

Added line #L545 was not covered by tests
}
}

}

# Collect data
data <- list(
names = names,
seasons = seasons,
isotimes = isotimes,
longitude = longitude,
latitude = latitude,
msw = msw
)

# TODO Remove later
if("sshs" %in% names(fields)){
data$sshs <- sshs
}

if("rmw" %in% names(fields)){
data$rmw <- rmw
}

if("pressure" %in% names(fields)){
data$pressure <- pressure
}

if("poci" %in% names(fields)){
data$poci <- poci
}


return(data)

Check warning on line 551 in R/defStormsDataset.R

View check run for this annotation

Codecov / codecov/patch

R/defStormsDataset.R#L551

Added line #L551 was not covered by tests

}
Expand Down
4 changes: 2 additions & 2 deletions man/getDataFromCsvFile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/stormsDataset-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3449a4f

Please sign in to comment.