Skip to contents

入门

lcz_ts() 功能允许您分析随时间变化与当地气候区 (LCZ) 相关的气温数据。在本教程中,我们将使用以下命令对 2019-2020 年柏林的气温进行每小时频率分析 lcz_data 来自 LCZ4r 封装。

library(LCZ4r)

# 获取您所在城市的LCZ地图
lcz_map <- lcz_get_map_euro(city = "Berlin")

# 从LCZ4r加载样本数据
data("lcz_data")

基本时间序列分析

让我们从基本分析开始 lcz_ts() 观察每小时的温度波动。

# 获取每月 LCZ 气温时间序列
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station",
       time.freq = "month",
       ylab = "Air temperature [°C]",
       xlab = "Date",
       title = "LCZ - Time Series",
       caption = "Source: LCZ4r, 2024.")
Monthly LCZ-air temperature time series for Berlin

柏林每月 LCZ 气温时间序列显示不同 LCZ 类别的季节性温度变化

使用plot_type 绘制选项

plot_type 论证中 lcz_ts() 提供多种可视化效果:

  • “basic_line”:简单的线图
  • “faceted_line”:按 LCZ 或车站划分的带面的线图
  • “热图”:用于可视化时间模式的热图
  • “warming_stripes”:代表温度随时间变化的条纹

以下是使用每种绘图类型的示例。

1. 基本线图

# 2019年9月每日气温
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station",
       time.freq = "day",
       year = 2019, month = 9,
       plot_type = "basic_line")
Basic line plot showing daily temperature variations in September 2019

显示 2019 年 9 月柏林每日气温变化的基本线图

2. 按车站划分的多面线图

# 2019年1月至3月各站点每日气温
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station", 
       time.freq = "hour",
       year = 2019, month = 1:3,
       plot_type = "facet_line", 
       facet = "station")
Faceted line plot showing temperature patterns across different meteorological stations

显示柏林不同气象站温度模式的多面线图(2019 年 1 月至 3 月)

3. 温度随时间变化的热图

# 2020年1月15日每小时气温,LCZ面
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station", 
       time.freq = "hour",
       year = 2020, month = 1, day = 15,
       plot_type = "heatmap", 
       facet = "LCZ")
Heatmap showing hourly temperature variations across LCZ classes

显示 2020 年 1 月 15 日不同 LCZ 类别每小时温度变化的热图

4. 保暖条纹

# 2020 年逐小时气温,以升温条纹的形式呈现
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station", 
       time.freq = "hour", 
       year = 2020, month = 1:12,
       plot_type = "warming_stripes",
       facet = "LCZ")
Warming stripes visualization showing temperature trends across LCZ classes

变暖条纹可视化显示 2020 年不同 LCZ 类别的温度趋势

使用“by”参数拆分数据

您可以按时间或空间类别(例如“年”、“月”、“季节”、“工作日”、“周末”、“年份季节”等)分割数据。

# 2020年各季节每日气温
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station", 
       time.freq = "day",
       year = 2020,
       plot_type = "basic_line", 
       by = "season")
Temperature variations across different seasons in 2020

2020年柏林不同季节气温变化

用“by”参数划分夜间和白天

您还可以按夜间和白天时段分割数据 by = "daylight".

# 2020年1月15日气温日变化
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station", 
       time.freq = "hour",
       year = 2020, month = 1, day = 15,
       plot_type = "heatmap", 
       by = "daylight")
Comparison of daytime and nighttime temperature patterns

2020年1月15日白天和夜间气温模式对比

将日光与月份结合起来

# 2020年1月15日和7月15日气温的日变化
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station", 
       time.freq = "hour",
       year = 2020, month = c(1, 7), day = 15,
       plot_type = "basic_line", 
       by = c("daylight", "monthyear"))
Comparison of diurnal temperature cycles in winter and summer

2020年冬季(一月)和夏季(七月)日气温循环比较

平滑温度趋势

通过设置启用平滑 smooth = TRUE,它添加了广义加性模型 (GAM) 线来显示温度趋势。

# 2019-2020年各站点每日气温变化趋势
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station", 
       time.freq = "hour",
       year = 2019:2020,
       plot_type = "basic_line", 
       smooth = TRUE)
Temperature trends with GAM smoothing for 2019-2020

2019-2020 年各站 GAM 平滑的温度趋势

保存地块

要保存绘图和数据框,请设置 isave = TRUE 并指定文件类型 save_extension (例如,“png”、“jpeg”、“svg”、“pdf”)。一个文件夹 LCZ4r_output 在您的 PC 上创建。

# 将日光图和数据框保存到电脑
lcz_ts(lcz_map, 
       data_frame = lcz_data, 
       var = "airT", 
       station_id = "station", 
       time.freq = "hour",
       year = 2020, month = 1, day = 15,
       plot_type = "basic_line", 
       by = "daylight", 
       isave = TRUE)

提示:保存的文件将自动组织在 LCZ4r_output 带有时间戳的文件名的文件夹,以便于参考。

返回数据框作为结果

要将结果保存在 R 中,请设置 iplot = FALSE 并创建一个对象。

# 返回 2020 年 1 月 15 日的日照数据框
my_output <- lcz_ts(lcz_map, 
                    data_frame = lcz_data, 
                    var = "airT", 
                    station_id = "station", 
                    time.freq = "hour",
                    year = 2020, month = 1, day = 15,
                    plot_type = "basic_line", 
                    by = "daylight", 
                    iplot = FALSE)

# 查看返回的数据框的结构
str(my_output)

参数汇总

以下是主要参数的快速参考 lcz_ts():

参数 描述 选项
time.freq 时间聚合频率 “时”、“日”、“月”、“年”
plot_type 可视化类型 “basic_line”、“facet_line”、“热图”、“warming_stripes”
by 数据分割方式 “季节”、“月份”、“工作日”、“日光”、“年份季节”
smooth 添加GAM趋势线 对/错
isave 将输出保存到 PC 对/错
iplot 显示图 对/错

有反馈或建议吗?

您有改进的想法或者发现错误吗?我们很乐意听取您的意见!单击下面的按钮创建新问题 (GitHub) 并直接与我们分享您的反馈或建议。

打开 GitHub 问题