Yogesh Tiwari
2007-Feb-19 12:23 UTC
[R] need help in reading TOMS observed ASCII data file
Hello R Users, I am new to R. I have two data sets i) TOMS aerosol optical depth(AOD) and ii) TOMS ozone(O3).> > AOD data is on 1x1 grid and O3 data is on 5x5 grid. > > First I want to read AOD and O3 as it is and then I want to regrid AOD on > 5x5 grid as O3. > > Reading is first problem. > > FIRST PROBLEM READING AOD: > > AOD data is in following format: > > ######### > Latitute: 89.5 > 167 0 0 0 0 0 182 0 0 0 0 0 0 0 0 0 0 0 0 200 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 155 0 0 0 0 0 156 0 0 0 0 0 0 > ............ > ........... > > Latitude: 88.5 > ......... > ........ > > Lat......... > ......... > ....... > ...... > Latitude: -88.5 > 180 0 0 0 0 0 182 0 0 0 0 0 0 0 0 0 0 0 0 500 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 655 0 0 0 0 0 156 0 0 0 0 0 0 > ...... > ..... > ###### > > After each latitude header there is 360 AOD values (1x1 grid). This is > monthly mean data. I have many years of data file. > > So the first problem is how to read the data by omiting latitude header, > also data is written along row not along column ? > > > > SECOND PROBLEM READING O3: > > O3 data is in following format: > > ozone(72,12,324) > > 72: Longitude -177.5,-172.5,...,177.5' > > 12: Latitude -27.5,-22.5,...,27.5' > > 324: Month Jan79,Feb79,....,Dec05' > > ################### > > Month index: 0 > 20.8 22.1 20.0 19.0 16.3 20.0 24.4 23.5 27.9 23.7 0.0 32.4 > 21.6 23.8 20.4 17.9 16.0 22.2 25.3 25.1 31.1 27.4 0.0 30.3 > 23.2 23.9 20.7 17.3 16.5 23.1 25.9 25.4 30.4 29.3 0.0 29.9 > 26.1 24.7 21.3 15.9 16.8 22.8 25.3 25.8 29.8 30.1 0.0 31.6 > > -------------------------- > > ---------------- > > > > Month index: 323 > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > > --------------------------------- > > ------------------------- > > ################# > > 12 columns and 72 rows (latitudexlongitude) > > > > > > THIRD PROBLEM regriding AOD: > How to regrid 1x1 AOD data on 5x5 grid as O3. > > > Many thanks for yours help. > > Regards, > Yogesh > > -- > Dr. Yogesh K. Tiwari, > Scientist, > Indian Institute of Tropical Meteorology, > Homi Bhabha Road, > Pashan, > Pune-411008 > INDIA > > Phone: 0091-99 2273 9513 (Cell) > : 0091-20-258 93 600 (O) ( Ext.250) > Fax : 0091-20-258 93 825 >-- Dr. Yogesh K. Tiwari, Scientist 'B', Indian Institute of Tropical Meteorology, Homi Bhabha Road, Pashan, Pune-411008 INDIA Phone: 0091-99 2273 9513 (Cell) : 0091-20-258 93 600 (O) (Ext.250) Fax : 0091-20-258 93 825 [[alternative HTML version deleted]]
Here is a script that will read in you O3 data. It assumes that the data is perfect. You will have to either prescan the data for errors, or add code to catch them.> # setup to read your file > # this procedure works if the data is 'perfect'; it does not catch errors > # 'result' is a list of matrices of the data > f.1 <- file("/jph/r-help/TOMS_O3.txt", "r") > result <- list() > while(length(month <- readLines(f.1, n=1))){+ # read in 12*72 real numbers from the file after reading the 'month' header + data.in <- matrix(scan(f.1, what=0, n=12*72), ncol=12, byrow=TRUE) + # extract just the number and use it as the index into the list to save the matrix + result[[gsub(".*(\\d <file://d/>+)", "\\1 <file://0.0.0.1/>", month, perl=TRUE)]] <- data.in + } Read 864 items Read 864 items Read 864 items Read 864 items> str(result)List of 4 $ 0: num [1:72, 1:12] 20.8 21.6 23.2 26.1 26.2 29 22.2 18.5 19 20.5 ... $ 1: num [1:72, 1:12] 22.7 22.4 20.4 19.7 16.9 20.8 24 25.1 24.7 24.7 ... $ 2: num [1:72, 1:12] 25.4 24.6 27 28 29.9 33.3 32.4 28.2 24.5 21.6 ... $ 3: num [1:72, 1:12] 31 31 31 30 30.1 27.4 20.5 19 18.8 19.2 ...> >On 2/19/07, Yogesh Tiwari <yogesh.mpi@googlemail.com> wrote:> > Hello R Users, > > I am new to R. > > I have two data sets i) TOMS aerosol optical depth(AOD) and ii) TOMS > ozone(O3). > > > > > AOD data is on 1x1 grid and O3 data is on 5x5 grid. > > > > First I want to read AOD and O3 as it is and then I want to regrid AOD > on > > 5x5 grid as O3. > > > > Reading is first problem. > > > > FIRST PROBLEM READING AOD: > > > > AOD data is in following format: > > > > ######### > > Latitute: 89.5 > > 167 0 0 0 0 0 182 0 0 0 0 0 0 0 0 0 0 0 0 200 0 0 0 0 0 0 > > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 155 0 0 0 0 0 156 0 0 0 0 0 0 > > ............ > > ........... > > > > Latitude: 88.5 > > ......... > > ........ > > > > Lat......... > > ......... > > ....... > > ...... > > Latitude: -88.5 > > 180 0 0 0 0 0 182 0 0 0 0 0 0 0 0 0 0 0 0 500 0 0 0 0 0 0 > > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 655 0 0 0 0 0 156 0 0 0 0 0 0 > > ...... > > ..... > > ###### > > > > After each latitude header there is 360 AOD values (1x1 grid). This is > > monthly mean data. I have many years of data file. > > > > So the first problem is how to read the data by omiting latitude header, > > also data is written along row not along column ? > > > > > > > > SECOND PROBLEM READING O3: > > > > O3 data is in following format: > > > > ozone(72,12,324) > > > > 72: Longitude -177.5,-172.5,...,177.5' > > > > 12: Latitude -27.5,-22.5,...,27.5' > > > > 324: Month Jan79,Feb79,....,Dec05' > > > > ################### > > > > Month index: 0 > > 20.8 22.1 20.0 19.0 16.3 20.0 24.4 23.5 27.9 23.7 0.0 32.4 > > 21.6 23.8 20.4 17.9 16.0 22.2 25.3 25.1 31.1 27.4 0.0 30.3 > > 23.2 23.9 20.7 17.3 16.5 23.1 25.9 25.4 30.4 29.3 0.0 > 29.9 > > 26.1 24.7 21.3 15.9 16.8 22.8 25.3 25.8 29.8 30.1 0.0 31.6 > > > > -------------------------- > > > > ---------------- > > > > > > > > Month index: 323 > > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > 0.0 > > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > > 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 > > > > --------------------------------- > > > > ------------------------- > > > > ################# > > > > 12 columns and 72 rows (latitudexlongitude) > > > > > > > > > > > > THIRD PROBLEM regriding AOD: > > How to regrid 1x1 AOD data on 5x5 grid as O3. > > > > > > Many thanks for yours help. > > > > Regards, > > Yogesh > > > > -- > > Dr. Yogesh K. Tiwari, > > Scientist, > > Indian Institute of Tropical Meteorology, > > Homi Bhabha Road, > > Pashan, > > Pune-411008 > > INDIA > > > > Phone: 0091-99 2273 9513 (Cell) > > : 0091-20-258 93 600 (O) ( Ext.250) > > Fax : 0091-20-258 93 825 > > > > > > -- > Dr. Yogesh K. Tiwari, > Scientist 'B', > Indian Institute of Tropical Meteorology, > Homi Bhabha Road, > Pashan, > Pune-411008 > INDIA > > Phone: 0091-99 2273 9513 (Cell) > : 0091-20-258 93 600 (O) (Ext.250) > Fax : 0091-20-258 93 825 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]]