Bekerja dengan Netcdf dan Matlab

Ada banyak sekali cara dan tools yang dapat digunakan untuk membaca dan atau memodifikasi file netcdf. Tulisan ini mencoba sedikit menerangkan cara memulai bekerja dengan file netcdf menggunakan tools matlab. Tool membaca file netcdf menggunakan matlab juga banyak sekali. Saya mencoba menggunakan nctoolbox yang dapat di unduh di http://code.google.com/p/nctoolbox/ . ada beberapa pertimbangan mengapa saya menggunakan toolbox ini yaitu 1. Kemudahan penginstalan (*setidaknya buat saya =)) ), 2. Konsep datasetnya sangat memudahkan bagi saya, 3. Filenya kecil. 1. Install nctoolbox a. Download nctoolbox di alamat http://code.google.com/p/nctoolbox/downloads/list b. Kemudian extract zip file tersebut ke tempat/folder yang anda inginkan. c. Arahkan directori matlab ke folder tadi d. Ketik di command prompt >>setup_nctoolbox e. Jika tidak terjadi apa-apa maka nctoolbox sudah terinstall dengan baik. 2. Help toolbox Ketik di command prompt >> help ncdataset
NCDATASET Provide access to datasets accessable by the NetCDF 4 API Use as: ds = ncdataset(dataref) Arguments: dataref = A reference to a ncdataset that can be accessed by the NetCDF 4 API. This includes local netcdf files, netcdf files on web servers and OpenDAP URLs Return: An instance of a ncdataset class Properties: netcdf = For power users. This is an instance of a ucar.nc2.ncdataset.NetcdfDataset (NetCDF-Java 4.0) and is used for the underlying data access. This object can be tweaked as needed. (For example, to enable/disable data caching.) See http://www.unidata.ucar.edu/software/netcdf-java/v4.0/javadoc/index.html variables = A cell array of all variables in the ncdataset. These names are used as arguments into other ncdataset methods Methods:

ncdataset.axes - access coordinate variable names for a given variable ncdataset.attributes - access global or variable attributes ncdataset.data - retrieve data (or a subset of data) for a variable ncdataset.size - returns the size of a variable in the data store ncdataset.time - Attempt to convert a variable to matlabs native time format (see datenum) For more information on the methods use help. For example: >> help ncdataset.data Example: ds = ncdataset('http://dods.mbari.org/cgi-bin/nphnc/data/ssdsdata/deployments/m1/200810/m1_metsys_20081008_original.nc') ga = ds.attributes; % Global Attributes sv = 'SonicVelocity'; % A variable that we're interested in. d = ds.data(sv); % Data for the SonicVelocity variable svAx = ds.axes(sv); % Coordinate Variable names for the SonicVelocity variable svAt = ds.attributes(sv); % Attributes for SonicVelocity

Membuka dataset
>> ds=ncdataset('tes.nc') ds = ncdataset handle Properties: netcdf: [1x1 ucar.nc2.dataset.NetcdfDataset] variables: {10x1 cell} Methods, Events, Superclasses

Membuka property netcdf
>> ds.netcdf ans = netcdf tes.nc { dimensions: time = 132247; variables: float plannedMeterDepth; :units = "metres"; float sampleRate; :units = "minutes"; double time_raw(time=132247); :units = "hours since 01-jan-2003 00:00:00"; :_FillValue = -99999.0; // double

:missing = -1.0E34; // double float temperature(time=132247); :units = "degrees Celsius ITS-90"; :_FillValue = -99999.0f; // float :missing = -1.0E34; // double float temperature_raw(time=132247); :units = "degrees Celsius ITS-90"; :_FillValue = -99999.0f; // float :missing = -1.0E34; // double float pressure_raw(time=132247); :units = " "; :_FillValue = -99999.0f; // float :missing = -1.0E34; // double float latitude; :units = "degrees where south is negative"; :_CoordinateAxisType = "Lat"; float longitude; :units = "degrees 0 -360"; :_CoordinateAxisType = "Lon"; double time(time=132247); :units = "hours since 01-jan-2003 00:00:00"; :_FillValue = -99999.0; // double :missing = -1.0E34; // double :_CoordinateAxisType = "Time"; float pressure(time=132247); :units = "dbar"; :missing = -1.0E34; // double :_FillValue = -99999.0f; // float :_CoordinateAxisType = "Pressure"; :Organisation = "Scripps Institute of Oceanography"; :Scientist = "Dr Janet Sprintall"; :netcdfAuthor = "Bernadette Heaney/Rebecca Cowley CSIRO Marine and Atmospheric Research, Australia"; :experimentName = "INSTANT"; :mooringName = "Ombai South"; :deploymentNumber = "1"; :latitude = "08 32.00S"; :longitude = "125 03.86E"; :waterDepth = 3225.0; // double :mooringDeploymentDate = "08-Aug-2003"; :mooringRetrievalDate = "01-Jul-2005"; :serialNo = "1331"; :meterType = "SBE-39-TP";

:manufacturer = "SeaBird Electronics Inc"; :sampleRate = 7.5; // double :startData = "06-Aug-2003 00:22:30"; :endData = "24-Jun-2005 19:07:30"; :comments = " Mooring was tangled on recovery, this instrument was recovered with the VMCM 002. Pressure was measured, so the data is OK."; :time_comment = " "; :temperature_comment = " "; :pressure_comment = " "; }

Membuka property variables
>> ds.variables ans = 'plannedMeterDepth' 'sampleRate' 'time_raw' 'temperature' 'temperature_raw' 'pressure_raw' 'latitude' 'longitude' 'time' 'pressure'

Membaca data
>> ds.variables ans = 'plannedMeterDepth' 'sampleRate' 'time_raw' 'temperature' 'temperature_raw' 'pressure_raw' 'latitude' 'longitude' 'time' 'pressure' >> coba=ds.data('pressure'); >> coba=ds.data(ds.variables(10));

Tes plot data >>plot(ds.data(‘time’),ds.data(‘pressure’));

Sign up to vote on this title
UsefulNot useful