add L7.qmd

This commit is contained in:
2026-05-26 13:43:04 +08:00
parent 982f26736f
commit 29daf1b240
16 changed files with 672764 additions and 2 deletions
+1 -1
View File
@@ -34,4 +34,4 @@ website:
- text: Codes - text: Codes
url: https://git.drwater.net/{{< var projtype >}}/{{< var reponame >}}/src/branch/{{< var branch >}} url: https://git.drwater.net/{{< var projtype >}}/{{< var reponame >}}/src/branch/{{< var branch >}}
- text: Issue - text: Issue
url: https://git.drwater.net/manuscript/{{< var reponame >}}/issues url: https://git.drwater.net/{{< var projtype >}}/{{< var reponame >}}/issues
+1 -1
View File
@@ -33,4 +33,4 @@ website:
- text: Codes - text: Codes
url: https://git.drwater.net/{{< var projtype >}}/{{< var reponame >}}/src/branch/{{< var branch >}} url: https://git.drwater.net/{{< var projtype >}}/{{< var reponame >}}/src/branch/{{< var branch >}}
- text: Issue - text: Issue
url: https://git.drwater.net/manuscript/{{< var reponame >}}/issues url: https://git.drwater.net/{{< var projtype >}}/{{< var reponame >}}/issues
+170
View File
@@ -0,0 +1,170 @@
---
title: "RWEP L7- Data Transform"
---
# Data Source
```{r}
dailylanddf <- readr::read_csv("../data/chinawq/daily_land.csv")
metadatadf <- readxl::read_xls("../data/chinawq/metadata_and_statistics.xls")
monthlylanddf <- readr::read_csv("../data/chinawq/monthly_ocean.csv")
weeklylanddf <- readr::read_csv("../data/chinawq/weekly_land.csv")
```
```{r}
require(tidyverse)
dailylanddf
dailylanddf |>
select(.data$MonitoringLocationIdentifier, .data$LongitudeMeasure_WGS84)
dailylanddf |>
select("MonitoringLocationIdentifier", "LongitudeMeasure_WGS84")
dailylanddf |>
select(1:3)
dailylanddf |>
rename(x = 1) |>
rename(y = 2)
```
# 内置function
```{r}
dailylanddf |>
select(1:3) |>
rename_all(\(x) c("a", "b", "c")) |>
rename_all(\(x) paste0(x, "_new"))
dailylanddf |>
select(1:3) |>
rename_all(~ c("a", "b", "c")) |>
rename_all(~ paste0(., "_new"))
dailylanddf |>
select(1:3) |>
rename_all(~ c("x", "y", "z"))
```
```{r}
fulldatadf <- readr::read_csv("../data/chinawq/full_dataset.csv")
datadf <- fulldatadf |>
select(lon = 2, lat = 3, date = 4, varname = 5, value = 6) |>
mutate(value = as.numeric(value)) |>
tidyr::pivot_wider(names_from = varname, values_from = value)
saveRDS(datadf, "../data/chinawq/datadf.rds")
```
# 统计
## 统计每月的DO的平均值
```{r}
datadf <- readRDS("../data/chinawq/datadf.rds")
datadf |>
select(1:7) |>
mutate(month = month(date)) |>
select(lon, lat, month, date, everything()) |>
group_by(month) |>
summarize(DO_mean = mean(DO, na.rm = TRUE), DO_sd = sd(DO, na.rm = TRUE)) |>
ggplot(aes(x = month, y = DO_mean)) +
geom_point() +
geom_smooth(method = "loess") +
geom_errorbar(aes(ymin = DO_mean - DO_sd, ymax = DO_mean + DO_sd))
```
```{r}
datadf |>
select(1:7) |>
mutate(month = month(date)) |>
mutate(year = year(date)) |>
select(lon, lat, year, month, date, everything()) |>
summarize(
DO_mean = mean(DO, na.rm = TRUE),
DO_sd = sd(DO, na.rm = TRUE),
.by = c(year, month)
) |>
ggplot(aes(x = month, y = DO_mean)) +
geom_point() +
geom_smooth(method = "loess") +
geom_errorbar(aes(ymin = DO_mean - DO_sd, ymax = DO_mean + DO_sd)) +
facet_wrap(~year)
```
```{r}
datadf |>
select(1:7) |>
mutate(month = month(date)) |>
mutate(year = year(date)) |>
select(-lon, -lat, -date) |>
group_by(year, month) |>
summarize_all(\(x) mean(x, na.rm = TRUE))
```
## nest
```{r}
for (isite in 1:10) {
m <- datadf |>
select(1:7) |>
tidyr::nest(wqdf = -c(lon, lat)) |>
pull(wqdf) |>
nth(isite) |>
lm(formula = DO ~ pH, data = _)
slope <- coef(m)[2]
print(slope)
}
```
## purrr::map
```{r}
datadf |>
select(1:7) |>
tidyr::nest(wqdf = -c(lon, lat)) |>
slice(1:10) |>
mutate(
m = purrr::map(
wqdf,
\(x) {
lm(formula = DO ~ pH, data = x)
}
)
) |>
mutate(slope = purrr::map_dbl(m, \(x) coef(x)[2])) |>
mutate(
p = purrr::map(wqdf, \(x) {
x |>
ggplot(aes(x = pH, y = DO)) +
geom_smooth(method = "lm") +
geom_point()
})
) |>
pull(p) |>
patchwork::wrap_plots() +
patchwork::plot_layout(ncol = 2)
```
@@ -0,0 +1 @@
UTF-8
Binary file not shown.
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff