tpemartin / 110-2-R

The class repo for 110-2 Programming for Data Science
0 stars 3 forks source link

Weather data (I) #13

Open tpemartin opened 2 years ago

tpemartin commented 2 years ago

Download weather.R (https://github.com/tpemartin/110-2-R/blob/main/support/weather.R)

Run the following commands:

source("weather.R") 
# ,if the file is in the root of your project folder. Otherwise, change it to source("path to the file's folder/weather.R")

weather = Weather()
weather$dowload_data()
weather$rawData

From weather$rawData locate the weather condition that fits the 1st A1 accident date time, using the weather report from 竹子湖 station.


To download weather.R, there are two approaches:

  1. click copy raw content, then paste it in a newly created R script file in you RStudio

    image
  2. Click raw, then from your browser menu bar, select File > Save Page As... (as a R script file).

    image
image
tpemartin commented 2 years ago
source("weather.R") # if the file is in the root of your project folder
weather = Weather()
weather$dowload_data()
weather$source |> browseURL()
# weather data from all weather stations

weather$rawData

# weather station location data
weather$weatherStation$data[[1]] -> weatherStation
Chious commented 2 years ago
library(dplyr)

StationName=weather[["weatherStation"]][["data"]][[1]][["站名"]]
StationID=weather[["weatherStation"]][["data"]][[1]][["站號"]]
Precipitation=weather[["rawData"]][["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["stationObsTimes"]][["stationObsTime"]][[1]][["weatherElements"]][["precipitation"]]

Sunny<-c() # Sunny=1 means it's Sunny Day, Vice versa.

range <- 1:8784
for (i in range){
  if (Precipitation[[i]]=='T'){
    Sunny <-c(Sunny, 0)
  }
  else{
    Sunny <-c(Sunny, 1)
  }
}

#Weather_df=data.frame(StationName=StationName, StationID=StationID, Precipitation=Precipitation, Sunnu=Sunny)
#氣象資料裡面好像沒有氣象站ID,不確定要怎麼處理
#Weather_df[Weather_df$StationName == '竹子湖',]

#雨天:相對溼度=100且空氣中有足夠的凝結核(是在預測機率中通常會紀錄為T)
#晴天:與上述相反(不是T)
#Source: https://en.wikipedia.org/wiki/Trace_(precipitation)
#氣象資料裡面好像沒有氣象站ID,不確定要怎麼處理
JWLee7 commented 2 years ago
 weather$rawData[["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["station"]][["stationName"]][[5]]
[1] "竹子湖"
 weather$rawData[["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["station"]][["stationID"]][[5]]
[1] "466930"
#確定竹子湖是第五個元素,以及它的ID是466930

weather$rawData[["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["stationObsTimes"]][["stationObsTime"]][[5]]->stationObsTime466930

#第6090筆資料
#時間:2021-12-31T18:00:00+08:00
#大氣壓力:954.3
#溫度:10.2
#相對溼度:91
#風速:5.1
#風向:東北,NE
#降雨:0.0
#日照時數:0.0

weather$rawData[["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["stationObsStatistics"]][["temperature"]][["daily"]][[5]] ->temperature466930

#第254筆資料
#日期2021-12-31
#當日最高溫:12.2
#當日最低溫:10.0
#當日平均氣溫:10.7
Christychenn commented 2 years ago
weather[["rawData"]][["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["station"]][5,1:3]
#從中發現竹子湖是第五筆資料 觀察其他氣象資料皆有對稱性 
weather[["rawData"]][["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["stationObsTimes"]][["stationObsTime"]][[5]][6090,1]->climatedata1$date
weather[["rawData"]][["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["stationObsTimes"]][["stationObsTime"]][[5]][6090,2]->climatedata1$stationPressure
weather[["rawData"]][["cwbdata"]][["resources"]][["resource"]][["data"]][["surfaceObs"]][["location"]][["stationObsStatistics"]][["temperature"]][["daily"]][[5]][254,2:4]->climatedata1$temperature
截圖 2022-05-10 下午9 11 37