21.1 NetCDF Importing
In Origin, we support NetCDF Connector to import and partial import
NetCDF file can only be imported into workbook/matrixbook. So make sure workbook window or matrix window is active.
- 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.
- 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.
- Data Connector Brower dialog opens with all variables listed on the left panel with basic info.
- Origin only supports importing one variable at a time.
- 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.
Import 1 Dimensional Variable
lat, lon and time, level, etc. are 1 dimensional data. They can only be imported into workbook.
- Double click on a variable or click the down arrow to select the variable to import.
- It will be put to bottom panel.
- Click OK to import.
- Click the data connector icon and click Select... to change to import another 1 dimensional data. It will replace the previously imported data.
- 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.
- 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.
- 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.
- It will be put to bottom panel.
- Click OK to import.
- Click the data connector icon and click Select... to change to import another 2 dimensional data. It will replace the previously imported data.
- 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.
- sst in above image is a 3 dimensional variable (e.g. time * lat * lon)
- Double click or click the Down arrow button to add it to the bottom panel.
- If a workbook is active and the file can be imported to either matrix or workbook, a dialog will popup for you to choose
- 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.
- Choose Use a new Matrixbook and click OK.
- Data will be listed at the bottom panel.
- 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.
- 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.
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...
Import 4 Dimensional Variable
- If the variable's Dimensionality is 4, (e.g. time * level * lat * lon) 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.
- Click the the Connector icon and choose Select.. to view the connection string (e.g. NetCDF/t[z][y][x]. indicating that level 10 was imported).
- You can modify it to be NetCDF/t[z][y][x]; to import the level 1 instead.
- 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
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*lat*lon and you want to import the value at 2nd latitude and 5th longitude of all time frames into a column.
- With workbook window active, open netCDF data connector and choose the .nc file.
- In Data Connector Browser dialog, double click variable tas
- In the prompt that shows, choose the 3rd option Worksheet Columns (can be slow).
- Then in bottom panel, add [x] and click OK.
- 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*level*lat*lon, e.g. need to add [x] 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 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.
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.
In the Import Option dialog, expand the Averaging section to set it.
- 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.
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)
Sample 2： Import the average value of 4 years (from 1900 to 1903) in April, May and June three months
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.
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.
If the longitude is in approximately (0, 360) range, check this checkbox. Longitude will be shifted to (-180, 180).
By default, the imported data is from south to north. Select this checkbox to change latitude to from north to south.
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.
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.
While the connection string syntax can be complex, it follows the basic form of ...
... 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.