Skip to contents

Parse NOAA ISD/ISH data files - line by line

Usage

isd_parse_line(x, additional = TRUE, as_data_frame = TRUE)

Arguments

x

(character) a single ISD line

additional

(logical) include additional and remarks data sections in output. Default: TRUE

as_data_frame

(logical) output a tibble. Default: FALSE

Value

A tibble (data.frame)

References

ftp://ftp.ncdc.noaa.gov/pub/data/noaa

See also

Examples

path <- system.file('extdata/024130-99999-2016.gz', package = "isdparser")
lns <- readLines(path, encoding = "latin1")
isd_parse_line(lns[1])
#> # A tibble: 1 × 38
#>   total_chars usaf_station wban_station date  time  date_flag latitude longitude
#>   <chr>       <chr>        <chr>        <chr> <chr> <chr>     <chr>    <chr>    
#> 1 0054        024130       99999        2016… 0000  4         +60750   +012767  
#> # … with 30 more variables: type_code <chr>, elevation <chr>,
#> #   call_letter <chr>, quality <chr>, wind_direction <chr>,
#> #   wind_direction_quality <chr>, wind_code <chr>, wind_speed <chr>,
#> #   wind_speed_quality <chr>, ceiling_height <chr>,
#> #   ceiling_height_quality <chr>, ceiling_height_determination <chr>,
#> #   ceiling_height_cavok <chr>, visibility_distance <chr>,
#> #   visibility_distance_quality <chr>, visibility_code <chr>, …
isd_parse_line(lns[1], FALSE)
#> # A tibble: 1 × 31
#>   total_chars usaf_station wban_station date  time  date_flag latitude longitude
#>   <chr>       <chr>        <chr>        <chr> <chr> <chr>     <chr>    <chr>    
#> 1 0054        024130       99999        2016… 0000  4         +60750   +012767  
#> # … with 23 more variables: type_code <chr>, elevation <chr>,
#> #   call_letter <chr>, quality <chr>, wind_direction <chr>,
#> #   wind_direction_quality <chr>, wind_code <chr>, wind_speed <chr>,
#> #   wind_speed_quality <chr>, ceiling_height <chr>,
#> #   ceiling_height_quality <chr>, ceiling_height_determination <chr>,
#> #   ceiling_height_cavok <chr>, visibility_distance <chr>,
#> #   visibility_distance_quality <chr>, visibility_code <chr>, …

res <- lapply(lns[1:1000], isd_parse_line)
library("data.table")
library("tibble")
as_tibble(
 rbindlist(res, use.names = TRUE, fill = TRUE)
)
#> # A tibble: 1,000 × 38
#>    total_chars usaf_station wban_station date     time  date_flag latitude
#>    <chr>       <chr>        <chr>        <chr>    <chr> <chr>     <chr>   
#>  1 0054        024130       99999        20160101 0000  4         +60750  
#>  2 0054        024130       99999        20160101 0100  4         +60750  
#>  3 0054        024130       99999        20160101 0200  4         +60750  
#>  4 0054        024130       99999        20160101 0300  4         +60750  
#>  5 0054        024130       99999        20160101 0400  4         +60750  
#>  6 0039        024130       99999        20160101 0500  4         +60750  
#>  7 0054        024130       99999        20160101 0600  4         +60750  
#>  8 0039        024130       99999        20160101 0700  4         +60750  
#>  9 0054        024130       99999        20160101 0800  4         +60750  
#> 10 0054        024130       99999        20160101 0900  4         +60750  
#> # … with 990 more rows, and 31 more variables: longitude <chr>,
#> #   type_code <chr>, elevation <chr>, call_letter <chr>, quality <chr>,
#> #   wind_direction <chr>, wind_direction_quality <chr>, wind_code <chr>,
#> #   wind_speed <chr>, wind_speed_quality <chr>, ceiling_height <chr>,
#> #   ceiling_height_quality <chr>, ceiling_height_determination <chr>,
#> #   ceiling_height_cavok <chr>, visibility_distance <chr>,
#> #   visibility_distance_quality <chr>, visibility_code <chr>, …

# only control + mandatory sections
isd_parse_line(lns[10], additional = FALSE)
#> # A tibble: 1 × 31
#>   total_chars usaf_station wban_station date  time  date_flag latitude longitude
#>   <chr>       <chr>        <chr>        <chr> <chr> <chr>     <chr>    <chr>    
#> 1 0054        024130       99999        2016… 0900  4         +60750   +012767  
#> # … with 23 more variables: type_code <chr>, elevation <chr>,
#> #   call_letter <chr>, quality <chr>, wind_direction <chr>,
#> #   wind_direction_quality <chr>, wind_code <chr>, wind_speed <chr>,
#> #   wind_speed_quality <chr>, ceiling_height <chr>,
#> #   ceiling_height_quality <chr>, ceiling_height_determination <chr>,
#> #   ceiling_height_cavok <chr>, visibility_distance <chr>,
#> #   visibility_distance_quality <chr>, visibility_code <chr>, …
isd_parse_line(lns[10], additional = TRUE)
#> # A tibble: 1 × 38
#>   total_chars usaf_station wban_station date  time  date_flag latitude longitude
#>   <chr>       <chr>        <chr>        <chr> <chr> <chr>     <chr>    <chr>    
#> 1 0054        024130       99999        2016… 0900  4         +60750   +012767  
#> # … with 30 more variables: type_code <chr>, elevation <chr>,
#> #   call_letter <chr>, quality <chr>, wind_direction <chr>,
#> #   wind_direction_quality <chr>, wind_code <chr>, wind_speed <chr>,
#> #   wind_speed_quality <chr>, ceiling_height <chr>,
#> #   ceiling_height_quality <chr>, ceiling_height_determination <chr>,
#> #   ceiling_height_cavok <chr>, visibility_distance <chr>,
#> #   visibility_distance_quality <chr>, visibility_code <chr>, …