Project

General

Profile

From nc file to txt

Added by Nurul Ain almost 4 years ago

Hello. I need help.

I want to change my file type from nc file to txt.

So, i used cdo outputtab,date,value infile.nc > outfile.txt

But, the outcome data is not what i want. It display as -9999 for all data.

Can somebody help me. Thank you in advance!:)


Replies (6)

RE: From nc file to txt - Added by Brendan DeTracey almost 4 years ago

You need to learn a little about netcdf files. You should google up a tutorial. :)

$ ncdump -h chirps_8485.nc
netcdf chirps_8485 {
dimensions:
        longitude = 430 ;
        latitude = 280 ;
        time = UNLIMITED ; // (24 currently)
variables:
        float longitude(longitude) ;
                longitude:standard_name = "longitude" ;
                longitude:long_name = "longitude" ;
                longitude:units = "degrees_east" ;
                longitude:axis = "X" ;
        float latitude(latitude) ;
                latitude:standard_name = "latitude" ;
                latitude:long_name = "latitude" ;
                latitude:units = "degrees_north" ;
                latitude:axis = "Y" ;
        double time(time) ;
                time:standard_name = "time" ;
                time:units = "days since 1980-1-1 00:00:00" ;
                time:calendar = "standard" ;
                time:axis = "T" ;
        float precip(time, latitude, longitude) ;
                precip:standard_name = "convective precipitation rate" ;
                precip:long_name = "Climate Hazards group InfraRed Precipitation with Stations" ;
                precip:units = "mm/month" ;
                precip:_FillValue = -9999.f ;
                precip:missing_value = -9999.f ;
                precip:time_step = "month" ;
                precip:geostatial_lat_min = -50.f ;
                precip:geostatial_lat_max = 50.f ;
                precip:geostatial_lon_min = -180.f ;
                precip:geostatial_lon_max = 180.f ;

// global attributes:
                :CDI = "Climate Data Interface version 1.7.2 (http://mpimet.mpg.de/cdi)" ;
                :history = "Tue Jul 28 13:08:17 2020: cdo -selyear,1984/1985 chirps_v20_monthlyMI.nc chirps_8485.nc\nMon Jul 27 13:07:54 2020: cdo sellonlatbox,98.5,120,-6,8 chirps_v20_monthly.nc chirps_v20_monthlyMI.nc\ncreated by Climate Hazards Group" ;
                :institution = "Climate Hazards Group.  University of California at Santa Barbara" ;
                :Conventions = "CF-1.6" ;
                :title = "CHIRPS Version 2.0" ;
                :version = "Version 2.0" ;
                :date_created = "2020-04-21" ;
                :creator_name = "Pete Peterson" ;
                :creator_email = "pete@geog.ucsb.edu" ;
                :documentation = "http://pubs.usgs.gov/ds/832/" ;
                :reference = "Funk, C.C., Peterson, P.J., Landsfeld, M.F., Pedreros, D.H., Verdin, J.P., Rowland, J.D., Romero, B.E., Husak, G.J., Michaelsen, J.C., and Verdin, A.P., 2014, A quasi-global precipitation time series for drought monitoring: U.S. Geological Survey Data Series 832, 4 p., http://dx.doi.org/110.3133/ds832. " ;
                :comments = " time variable denotes the first day of the given month." ;
                :acknowledgements = "The Climate Hazards Group InfraRed Precipitation with Stations development process was carried out through U.S. Geological Survey (USGS) cooperative agreement #G09AC000001 \"Monitoring and Forecasting Climate, Water and Land Use for Food Production in the Developing World\" with funding from: U.S. Agency for International Development Office of Food for Peace, award #AID-FFP-P-10-00002 for \"Famine Early Warning Systems Network Support,\" the National Aeronautics and Space Administration Applied Sciences Program, Decisions award #NN10AN26I for \"A Land Data Assimilation System for Famine Early Warning,\" SERVIR award #NNH12AU22I for \"A Long Time-Series Indicator of Agricultural Drought for the Greater Horn of Africa,\" The National Oceanic and Atmospheric Administration award NA11OAR4310151 for \"A Global Standardized Precipitation Index supporting the US Drought Portal and the Famine Early Warning System Network,\" and the USGS Land Change Science Program." ;
                :ftp_url = "ftp://chg-ftpout.geog.ucsb.edu/pub/org/chg/products/CHIRPS-latest/" ;
                :website = "http://chg.geog.ucsb.edu/data/chirps/index.html" ;
                :faq = "http://chg-wiki.geog.ucsb.edu/wiki/CHIRPS_FAQ" ;
                :CDO = "Climate Data Operators version 1.7.2 (http://mpimet.mpg.de/cdo)" ;
}

The -9999.9 is the missing value/fill value for variable precip. There are non -9999. in your output if you would look further than the first 100 lines. I think what you want is:
cdo outputtab,date,lat,lon,value infile.nc > outfile.txt
although why you would want to do this is a complete mystery...

RE: From nc file to txt - Added by Nurul Ain over 3 years ago

thank you sir! ya, i am a newbie with cdo:D i need this data to calculate spi index. currently using the spei package in r.

RE: From nc file to txt - Added by Brendan DeTracey over 3 years ago

I do not use R but I do know that R has a package to read netcdf files directly. ;)

RE: From nc file to txt - Added by Nurul Ain over 3 years ago

so i can just directly download the data in nc file and calculate the spi index using r right? thank you sir! i'll try to google about it more! thanks a lot sir!:D

RE: From nc file to txt - Added by Nurul Ain over 3 years ago

thankyou very much! a lot

    (1-6/6)