정보
-
업무명 : 육지 및 해양에 대한 마스킹 (Masking) 처리 및 가시화
-
작성자 : 이상호
-
작성일 : 2020-03-08
-
설 명 :
-
수정이력 :
내용
[개요]
-
안녕하세요? 기상 연구 및 웹 개발을 담당하고 있는 해솔입니다.
-
일반적으로 기상 자료 (수치 예측 모델, 위성 자료)를 이용할 경우 전체 영역 (기온)에 대해서 필요하나 일부 산출물은 육지 (예. 지표면 온도) 또는 해양 (예. 해수면 온도) 영역에 필요합니다.
-
따라서 오늘 포스팅은 육지 및 해양에 대한 마스킹 처리 및 가시화를 소개해 드리고합니다.
[특징]
-
육지 또는 해양 영역에 대한 자료 처리하기 위해서 마스킹 기술이 요구되며 이 프로그램은 이러한 목적을 달성하기 위한 소프트웨어
[기능]
-
Rwalc 패키지에서 gshhsMask 함수를 통해 육/해양 마스킹
-
metR 패키지에서 MaskLand 함수를 통해 육/해양 마스킹
-
spData 패키지에서 geom_sf 함수를 통해 육지 마스킹
[활용 자료]
-
없음
[자료 처리 방안 및 활용 분석 기법]
-
없음
[사용법]
-
소스 코드 참조
[사용 OS]
-
Windows 10
[사용 언어]
-
R v3.6.3
-
R Studio v1.2.5033
소스 코드
[명세]
-
전역 설정
-
최대 10 자리 설정
-
메모리 해제
-
영어 인코딩 설정
-
폰트 설정
-
# Set Option
memory.limit(size = 9999999999999)
options(digits = 10)
Sys.setlocale("LC_TIME", "english")
font = "Palatino Linotype"
-
라이브러리 읽기
# Library Load
library(extrafont)
library(tidyverse)
library(lubridate)
library(spData)
library(RWalc)
library(noncompliance)
library(metR)
-
데이터 프레임 설정
-
변수 설정
-
기준 위도 : -90에서 90까지 0.5 간격
-
기준 경도 : 0에서 360까지 0.5 간격
-
-
데이터 프레임 설정
-
즉 기준 위도 (-90)를 기준으로 기준 경도 (0-360, 0.5 간격) 설정
-
-
# Set Variable
nRefLat = seq(-90, 90, 0.5)
nRefLon = seq(0, 360, 0.5)
# Set Data Frame
dfData = noncompliance::expand.grid.DT(
nRefLat
, nRefLon
, col.names = c("nLat", "nLon")
)
dplyr::tbl_df(dfData)

Land Sea Mask (1) : gshhsMask
-
gshhsMask
-
Rwalc 패키지에서 gshhsMask 함수를 이용하여 마스킹 분류
-
그 결과 육지의 경우 TRUE이고 해양에서는 FALSE로 반환
-
mask = RWalc::gshhsMask(res = c("0.1", "0.05"), land = TRUE, latmin = -90, latmax = 90)
dfGshhsMaskData = dfData %>%
dplyr::mutate(
isLand = mask(0, nLon, nLat)
)
dplyr::tbl_df(dfGshhsMaskData)

ggplot(data = dfGshhsMaskData, aes(x = nLon, y = nLat, fill = isLand)) +
theme_bw() +
geom_tile() +
labs(
title = "Gshhs Mask : Land (TRUE) and Sea (FALSE)"
, x = ""
, y = ""
) +
metR:::theme_field() +
theme(text = element_text(family = font)) +
ggsave(filename = paste0("FIG2/Gshhs_Mask.png"), width = 10, height = 6, dpi = 600)

Land Sea Mask (2) : MaskLand
-
MaskLand
-
metR 패키지에서 MaskLand 함수를 이용하여 마스킹 분류
-
그 결과 육지의 경우 TRUE이고 해양에서는 FALSE로 반환
-
dfMaskLandData = dfData %>%
dplyr::mutate(
isLand = metR::MaskLand(nLon, nLat, mask = "world")
)
dplyr::tbl_df(dfMaskLandData)

ggplot(data = dfGshhsMaskData, aes(x = nLon, y = nLat, fill = isLand)) +
theme_bw() +
geom_tile() +
labs(
title = "Gshhs Mask : Land (TRUE) and Sea (FALSE)"
, x = ""
, y = ""
) +
metR:::theme_field() +
theme(text = element_text(family = font)) +
ggsave(filename = paste0("FIG2/Gshhs_Mask.png"), width = 10, height = 6, dpi = 600)

Land Sea Mask (3) : geom_sf
-
geom_sf
-
spData 패키지에서 geom_sf 함수를 이용하여 육지 마스킹
-
그 결과 육지의 경우 grey80 색으로 덮어쓰기
-
# Set Map Data
mapData = spData::world
ggplot() +
theme_bw() +
geom_sf(data = mapData, fill = "grey80", color = "black") +
labs(
title = "Land Mask"
, x = ""
, y = ""
) +
metR:::theme_field() +
theme(text = element_text(family = font)) +
ggsave(filename = paste0("FIG2/Sf_Land_Mask.png"), width = 10, height = 6, dpi = 600)

[전체]
#============================================================================ | |
# Routine : Main R program | |
# | |
# Purpose : Visualization and Masking for Land and Sea | |
# | |
# Author : MS. Sang-Ho Lee | |
# | |
# Revisions: V1.0 March 08, 2019 First release (MS. Sang-Ho Lee) | |
#============================================================================ | |
# Set Option | |
memory.limit(size = 9999999999999) | |
options(digits = 10) | |
Sys.setlocale("LC_TIME", "english") | |
font = "Palatino Linotype" | |
# Library Load | |
library(extrafont) | |
library(tidyverse) | |
library(lubridate) | |
library(spData) | |
library(RWalc) | |
library(noncompliance) | |
library(metR) | |
# Set Variable | |
nRefLat = seq(-90, 90, 0.5) | |
nRefLon = seq(0, 360, 0.5) | |
# Set Data Frame | |
dfData = noncompliance::expand.grid.DT( | |
nRefLat | |
, nRefLon | |
, col.names = c("nLat", "nLon") | |
) | |
dplyr::tbl_df(dfData) | |
#=============================================== | |
# gshhsMask | |
#=============================================== | |
mask = RWalc::gshhsMask(res = c("0.1", "0.05"), land = TRUE, latmin = -90, latmax = 90) | |
dfGshhsMaskData = dfData %>% | |
dplyr::mutate( | |
isLand = mask(0, nLon, nLat) | |
) | |
dplyr::tbl_df(dfGshhsMaskData) | |
ggplot(data = dfGshhsMaskData, aes(x = nLon, y = nLat, fill = isLand)) + | |
theme_bw() + | |
geom_tile() + | |
labs( | |
title = "Gshhs Mask : Land (TRUE) and Sea (FALSE)" | |
, x = "" | |
, y = "" | |
) + | |
metR:::theme_field() + | |
theme(text = element_text(family = font)) + | |
ggsave(filename = paste0("FIG2/Gshhs_Mask.png"), width = 10, height = 6, dpi = 600) | |
#=============================================== | |
# MaskLand | |
#=============================================== | |
dfMaskLandData = dfData %>% | |
dplyr::mutate( | |
isLand = metR::MaskLand(nLon, nLat, mask = "world") | |
) | |
dplyr::tbl_df(dfMaskLandData) | |
ggplot(data = dfMaskLandData, aes(x = nLon, y = nLat, fill = isLand)) + | |
theme_bw() + | |
geom_tile() + | |
labs( | |
title = "Mask Land : Land (TRUE) and Sea (FALSE)" | |
, x = "" | |
, y = "" | |
) + | |
metR:::theme_field() + | |
theme(text = element_text(family = font)) + | |
ggsave(filename = paste0("FIG2/Land_Mask.png"), width = 10, height = 6, dpi = 600) | |
#=============================================== | |
# geom_sf | |
#=============================================== | |
# Set Map Data | |
mapData = spData::world | |
ggplot() + | |
theme_bw() + | |
geom_sf(data = mapData, fill = "grey80", color = "black") + | |
labs( | |
title = "Land Mask" | |
, x = "" | |
, y = "" | |
) + | |
metR:::theme_field() + | |
theme(text = element_text(family = font)) + | |
ggsave(filename = paste0("FIG2/Sf_Land_Mask.png"), width = 10, height = 6, dpi = 600) |
참고 문헌
[논문]
- 없음
[보고서]
- 없음
[URL]
- 없음
문의사항
[기상학/프로그래밍 언어]
- sangho.lee.1990@gmail.com
[해양학/천문학/빅데이터]
- saimang0804@gmail.com