r - How to convert my spatiotemporal NetCDF data to spatial data? -


i beginner in r. , totally struck problem. can download netcdf file link below take look.

https://drive.google.com/file/d/0byy3oaw62eshbkf6vwnfukrymmm/view?usp=sharing

^this netcdf atmospheric data file 8 variable , 8 dimension. here,my variables of interest are:

timsid number of site (its include urban site, rural site etc.)
urban :: number of urban sites [urban 3 row 250 column matrix. row1 number of urban sites , row2 latidude, row 3 longitude.]
time :: data collected 1 march 2012 may 2012 [encoding 'time' yyyymmddhh]
pm10 :: hourly particulate matter concentration measured @ every station of every site

i need work these 4 variables large data set.

i have separate data of pm10 values @ urban sites "1 march 2012". (actually need find in timsid variable sites urban sites , match corresponding pm10 value urban sites 01 march 2012.)

for example, in timsid, different type of sites exist urban, rural etc named 111121,111122,111123,111124 urban site number 111121,111123..etc have consider urban site timsid data , want match corresponding pm10 value, time, latitude, longitude. , wanna make new dataset.

the final table/dataset should ~ column1-time(only 1 march 2012),column2-urban sites number, column (3,4)-latitude , longitude of corresponding urban sites, column 5- hourly pm10 value in each urban sites

i have used these following command read data netcdf file. can't understand should further...

install.packages("ncdf",dependencies=true) library(ncdf)  nc<-open.ncdf("2012_03_05_pm10_surface.nc") print(nc)  tmsid<-get.var.ncdf(nc,"tmsid") timsid  urban<-get.var.ncdf(nc,"urban") urban time<-get.var.ncdf(nc,"time")  pm10<-get.var.ncdf(nc,"pm10") 

as beginner in r know basic commands. can't figure out, specific package should learn solve problem. please me out? in advance valuable time. if need further information please ask me anytime.

library(ncdf) nc <- open.ncdf("2012_03_05_pm10_surface.nc") tmsid <- get.var.ncdf(nc,"tmsid") urban <- get.var.ncdf(nc,"urban") time <- get.var.ncdf(nc,"time") pm10 <- get.var.ncdf(nc,"pm10") 

first let's have @ nc:

[1] "file ~/downloads/2012_03_05_pm10_surface.nc has 8 dimensions:" [1] "data_num   size: 683016" [1] "ncl1   size: 683016" [1] "obsnum_urban   size: 250" [1] "id_lat_lon   size: 3" [1] "obsnum_road   size: 33" [1] "obsnum_background   size: 5" [1] "obsnum_rural   size: 16" [1] "ncl7   size: 683016" [1] "------------------------" [1] "file ~/downloads/2012_03_05_pm10_surface.nc has 8 variables:" [1] "int tmsid[data_num]  longname:tmsid missval:na" [1] "int time[ncl1]  longname:time missval:na" [1] "float pm10[data_num]  longname:pm10 missval:1e+30" [1] "float urban[id_lat_lon,obsnum_urban]  longname:urban missval:1e+30" [1] "float road[id_lat_lon,obsnum_road]  longname:road missval:1e+30" [1] "float background[id_lat_lon,obsnum_background]  longname:background missval:1e+30" [1] "float rural[id_lat_lon,obsnum_rural]  longname:rural missval:1e+30" [1] "int tms_julian[ncl7]  longname:tms_julian missval:na" 

what tells urban's rows id, latitude , longitude. have tmsid giving vector of ids of same size vector of time: 1 per data_num, i. e. 1 couple id-time per datapoint in pm10, meaning able subset pm10 ids (which given first row of urban) , timestamp (from 2012030101 2012030124).

# first need make dataframe out of urban, convenience. urban <- as.data.frame(t(urban)) colnames(urban) <- c("id", "lat", "lon") # subsetting using lapply, can batch-subset: res <- lapply(urban$id,                function(x)data.frame(id=x,                                     pm=pm10[tmsid%in%x & time%in%2012030101:2012030124],                                      time=2012030101:2012030124)) # gives list of sub-dataframes want compress single dataframe: res <- do.call(rbind,res) # merge original urban dataframe # each entry has own lat , lon: res <- merge(res, urban, by="id") res #         id   pm       time      lat      lon #1    111121   42 2012030101 37.56464 126.9760 #2    111121   36 2012030102 37.56464 126.9760 #3    111121   46 2012030103 37.56464 126.9760 #4    111121   40 2012030104 37.56464 126.9760 #5    111121   36 2012030105 37.56464 126.9760 #... #5995 831154   81 2012030119 37.52662 126.8064 #5996 831154   72 2012030120 37.52662 126.8064 #5997 831154   81 2012030121 37.52662 126.8064 #5998 831154   70 2012030122 37.52662 126.8064 #5999 831154   74 2012030123 37.52662 126.8064 #6000 831154   74 2012030124 37.52662 126.8064 

250 urban sites x 24 hours = 6 000 datapoints, indeed here.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -