21.1 NetCDF Importing

In Origin, we support NetCDF Connector to import and partial import

Import NetCDF

NetCDF file can only be imported into workbook/matrixbook. So make sure workbook window or matrix window is active.

  1. To import a .nc file on local PC or network,
    • Drag .nc file from Windows Explorer into Origin workspace, workbook or matrixbook.
    • Choose Data: Connect to File: NetCDF... menu to pick the .nc file and click OK.
  2. To import a .nc data on web, choose Data: Connect to Web, set File Type to NetCDF (optional) and enter URL link (e.g. https://psl.noaa.gov/thredds/fileServer/Datasets/cpc_us_precip/precip.V1.0.1948.nc), or click Recent URLs if you have down import in the past. Then click OK.
  3. Data Connector Brower dialog opens with all variables listed on the left panel with basic info.
  4. Origin only supports importing one variable at a time.
  5. Click variable on the left to view extra info. on the right panel. E.g. sst in the following image is a 3 dimensional data.
NetCDF Importing 01.png

Import 1 Dimensional Variable

lat, lon and time, level, etc. are 1 dimensional data. They can only be imported into workbook.

  1. Double click on a variable or click the down arrow to select the variable to import.
  2. It will be put to bottom panel.
  3. Click OK to import.
  4. Click the data connector icon and click Select... to change to import another 1 dimensional data. It will replace the previously imported data.
  5. All variables are listed on left panel of the workbook. Click on any other 1 dimensional data, right click and choose Add to active sheet to add it to current sheet.
  6. Or choose Add and connect sheets to import the selected variable to a new sheet in same book.

Import 2 Dimensional Variable

lat*lon, etc. are 2 dimensional data. They can only be imported into workbook or matrix.

  1. With matrix window ative, open the netCDF Data Connector and pick a .nc file. Pick a double click on a 2 dimensional variable or click the down arrow to select the variable to import.
  2. It will be put to bottom panel.
  3. Click OK to import.
  4. Click the data connector icon and click Select... to change to import another 2 dimensional data. It will replace the previously imported data.
  5. All variables are listed on left panel of the workbook. Click on any other 2 dimensional data, right click and choose Add and connect sheets to import the selected variable to a new sheet in same book.

Import 3 Dimensional Variable

3 and 4 dimensional data can be imported into either workbook or matrix book.

  1. sst in above image is a 3 dimensional variable (e.g. time * lat * lon)
  2. Double click or click the Down arrow button to add it to the bottom panel.
  3. If a workbook is active and the file can be imported to either matrix or workbook, a dialog will popup for you to choose
    NetCDF rmatrix.png
    • Use a new Matrixbook - this is the most straightforward way.
    • Use an embedded Matrixbook - this will import data into matrix but the matrix is embedded as a sheet in workbook.
    • Worksheet Columns (can be slow) -- this will import each time frame of matrix into multiple columns so it can create a worksheet with many many columns and cause slowness if data is big.
  4. Choose Use a new Matrixbook and click OK.
  5. Data will be listed at the bottom panel.
  6. Click the Import Options button (the "pencil" icon) and choose your options. Here, you can specify a partial import, convert longitude or flip your matrix vertically, or transform data using a formula.
    OH netcdf import options.png
  7. Click OK to close Import Options and click OK again to close the Browser and import your data. Large files may take some time to import. When the file is imported a Browser panel is added to the left side of the matrix. Note the slider at the top of the matrix window for viewing individual matrix objects.
OH matrix slider after import.png

Once a file is imported, you can change import options by clicking the Connector icon and choosing Options...; or choose another variable by choosing Select...

Help connect netCDF import ch 3.png

Import 4 Dimensional Variable

  1. If the variable's Dimensionality is 4, (e.g. time[248] * level[18] * lat[180] * lon[360]) and choose Use a new MatrixBook to import it, Origin will only pick one level to import (e.g. the middle level). A matrix book with one matrix sheet will be created for that level, each time frame will show on one matrix object. You can drag the slider on top of matrix sheet to view all imported time frames.
  2. Click the the Connector icon and choose Select.. to view the connection string (e.g. NetCDF/t[z][10][y][x]. indicating that level 10 was imported).
  3. You can modify it to be NetCDF/t[z][1][y][x]; to import the level 1 instead.
  4. Use the following LabTalk script to import all 18 levels of data into one matrix book, each level on one matrix sheet.
newbook mat:=1 sheet:=18; //create a matrix book with 20 sheets.
string fname$="c:\tmp\mynetCDF\aa.nc"; //specify filename
wbook.dc.add("netCDF"); //add netCDF connector to the matrix book
loop(i, 1, 18) 
{
   page.active=i; //activate ith sheet
   wks.dc.source$=fname$; //specify source file of the connector to the active sheet
   wks.dc.sel$="NetCDF/t[z][$(i)][y][x]"; //specify which level to import
   wks.dc.import(); //import
}

Import a Pixel Value in 3D/4D variable into Worksheet Column

Origin supports importing a single pixel value e.g. on certain latitude and longitude of all time frames into a worksheet column. For example if youu have a 3D variable tas of time[300]*lat[145]*lon[192] and you want to import the value at 2nd latitude and 5th longitude of all time frames into a column.

  1. With workbook window active, open netCDF data connector and choose the .nc file.
  2. In Data Connector Browser dialog, double click variable tas
  3. In the prompt that shows, choose the 3rd option Worksheet Columns (can be slow).
    NetCDF sheetormatrix.png
  4. Then in bottom panel, add [x][2][5] and click OK.
    NetCDF 3D to column.png
  5. Then in the left panel of workbook, click time variable. Right click it and choose Add to active Sheet to add time column in same sheet. Set time column as X and tas as Y so you can do further analysis an plotting.

Note: For 4D variable time[300]*level[20]*lat[145]*lon[192], e.g. need to add [x][1][2][5] to import pixel values at 2nd latitude, 5th longitude of level1 in all time frames to a column.

Partial import NetCDF

Specify the time range for importing data

In the Data Connector Brower, after select the importing dataset, you can click on the Import Option - Slicing, Averaging, Formular button NetCDF Import Option.png to open the Import Option dialog.

  • From & To: data-time range to import.
  • Time Axis Skipping: Read m records and skip n records and repeat.
For example, if data is monthly, Read = 1 and Skip = 11 would repeat the pattern of read one month and skip 11 for the entire date-time range.
NetCDF Importing 02.png

Calculate annual/monthly average during import

In the importing process, you can import the annual/monthly average directly. Averaging option perform an average based on an Interval and either Sampling by Across Years or Consecutive.

NetCDF Importing 03.png

In the Import Option dialog, expand the Averaging section to set it.

Sampling
  • Consecutive: Calculate an average for consecutives time. For example, There is a dataset with 5 years. Set Interval = y, which means continuous 12 months. So that it is get 5 matrixes with annual average value.
  • Across Years: Calculate an average for the same month across the year. For example, There is a dataset with 5 years. Set Interval = m, then it get 12 matrixes and each matrix is the average value of the five years in the current month.
Interval

Enter numeric to indicate consecutive months.

Enter letter: d=daily, m=monthly, y=yearly, q=quarterly


Here, we use two samples to show how use Time Axis Skipping and Averaging options to import the average of yearly data in specified months.

Sample 1: Import the average value of 3 months (April, May and June) of each year (from 1900 to 1903)

NetCDF Import Average Consecutive.gif


Sample 2: Import the average value of 4 years (from 1900 to 1903) in April, May and June three months

NetCDF Import Average Across Years.gif

Subregion to Import

In the Import Option dialog, expand the Subregion section to specify the importing region part with longitude and latitude, corresponding index of latitude and longitude will be found and used in connection string.

NetCDF subregion.png

For large data, user can also do subregion + skip every N rows or columns. E.g. NetCDF/analysed_sst[z][2100:4800|1-40#][300:6600|1-50], means for for latitude from index 2100 to 4800, import 1, skip 40, # means latitude flipped, for longitude from index 300 to 6600, import 1 and skip 50.

NetCDF subregion skip.png

Longitude Shift

If the longitude is in approximately (0, 360) range, check this checkbox. Longitude will be shifted to (-180, 180).

Latitude Flip

By default, the imported data is from south to north. Select this checkbox to change latitude to from north to south.

Formula

In the importing process, you can calculate new value in the matrix by formula.

For example, if you want to convert imported temperature data from Celsius to Fahrenheit, you can enter this formula in this edited box. v represent the original imported matrix cell value.

(v*9/5)+32

Connection String

Once you've set import options and closed the dialog, the connection string at the bottom of the left side will be updated to show the syntax we used to customize the import. You can directly double click on the string to edit/modify it.

OH partial import connection string 1.png

While the connection string syntax can be complex, it follows the basic form of ...

NetCDF/variable[z][y][x]

... where "variable" is the variable that you are importing, and [z],[y] and [x] specify handling, including partial import, of z, y and x dimension data.

We recommend using Import Options dialog to customize import to build the Connection string.
When import 4D variable, first click the pencil button to customize how to import one level. Then get the string and modify the part between [z] & [y] for level. E.g. modify the loop part in Import 4 Dimensional Variables section. E.g. loop i from 1 to 9, and use wks.dc.sel$="NetCDF/t[1:0|ave-d][$(i*2)][y][x]" to import every other level 2, 4, 6, ..., 18, and instead of importing all frames, import daily average.