Eurasia Institute of Earth Sciences Istanbul Technical University NCL Introduction Deniz Bozkurt web.itu.edu.tr/bozkurtd ITU Eurasia Institute of Earth.

Slides:



Advertisements
Similar presentations
Sue Wills July Objects The JavaScript language is completely centered around objects, and because of this, it is known as an Object Oriented Programming.
Advertisements

Introduction to MATLAB The language of Technical Computing.
Combining NCL and Fortran in C-shell
Visual Basic for Applications. What it does Extends the features and built in functions of Excel – Create and run VB procedures – Some may be easy to.
NCL NCL stands for NCAR Command Language. It is similar to IDL and MATLAB. It is most convenient for reading NetCDF files and plotting maps, but there.
Lecture 7 Sept 19, 11 Goals: two-dimensional arrays (continued) matrix operations circuit analysis using Matlab image processing – simple examples Chapter.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
FORTRAN Short Course Week 4 Kate Thayer-Calder March 10, 2009.
C++ for Engineers and Scientists Third Edition
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Java Unit 9: Arrays Declaring and Processing Arrays.
The NCAR Command Language (NCL) Ethan Alpert Visualization and Enabling Technologies Section, SCD, NCAR.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
Geog Basic Skills in Scientific Programming Syllabus, Introduction, Fundamentals of IDL Syntax.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
IE 212: Computational Methods for Industrial Engineering
Introduction to Python
Lists in Python.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
NCL Introduction Dennis Shea National Center for Atmospheric Research.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Slides based on lectures from the NCL workshop Also see the NCL homepage.
The netCDF-4 data model and format Russ Rew, UCAR Unidata NetCDF Workshop 25 October 2012.
NetCDF Operators 1 netCDF Operators [NCO]
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Introduction Dennis Shea NCAR is sponsored by the National Science Foundation.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Project 4 : SciDAC All Hands Meeting, September 11-13, 2002 A. Choudhary, W. LiaoW. Gropp, R. Ross, R. Thakur Northwestern UniversityArgonne National Lab.
File IO Dennis Shea National Center for Atmospheric Research pdf Vis5D png NCAR is sponsored by the National Science Foundation Shapefiles.
Advanced Utilities Extending ncgen to support the netCDF-4 Data Model Dr. Dennis Heimbigner Unidata netCDF Workshop August 3-4, 2009.
Brief Overview: GRIB, HDF, WRF.nc
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Climate Data Formats Deniz Bozkurt
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
NCL Sample Scripts Dennis Shea Climate and Global Dynamics Division Climate Analysis Section.
The HDF Group Introduction to netCDF-4 Elena Pourmal The HDF Group 110/17/2015.
Dennis Shea National Center for Atmospheric Research
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Arrays. Review of last lecture Overview of computer languages Overview of IDL Strength of IDL: (1) Interactive/compiled modes; (2) Array-oriented; (3)
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
Arrays. Review of last lecture Overview of IDL Strength of IDL: (1) Interactive/compiled modes; (2) Array-oriented; (3) Variables easily redefined; (4)
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
NetCDF Operators 1 netCDF Operators [NCO]
Introduction Dennis Shea NCAR is sponsored by the National Science Foundation.
GHRSST Users Symposium 2009 Working with the GHRSST Data Format Experiences of the GCOS SST/SI Intercomparison Working Group Tess Brandon, NOAA National.
An Introduction to Programming in Matlab Emily Blumenthal
NcBrowse: A Graphical netCDF File Browser Donald Denbo NOAA-PMEL/UW-JISAO
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
NetCDF Data Model Details Russ Rew, UCAR Unidata NetCDF 2009 Workshop
Web Database Programming Using PHP
Fundamentals of Programming I Overview of Programming
File Input / Output Dennis Shea Input Output
Web Database Programming Using PHP
Lecture: MATLAB Chapter 1 Introduction
NetCDF 資料格式介紹 NCL 變數設定介紹
National Scientific Library at Tbilisi State University
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Use of Mathematics using Technology (Maltlab)
Web DB Programming: PHP
HDF-EOS Workshop XXI / The 2018 ESIP Summer Meeting
Tutorial 10: Programming with javascript
NCL variable based on a netCDF variable model
Presentation transcript:

Eurasia Institute of Earth Sciences Istanbul Technical University NCL Introduction Deniz Bozkurt web.itu.edu.tr/bozkurtd ITU Eurasia Institute of Earth Sciences The International Training Course on “Climate Analysis and Applications” Alanya October 2011 The International Training Course on “Climate Analysis and Applications” Alanya October 2011

Eurasia Institute of Earth Sciences Istanbul Technical University NCAR Command Language (NCL)

Eurasia Institute of Earth Sciences Istanbul Technical University Parts of netCDF file ncdump –h foo.nc (or ncl_filedump foo.nc) DIMENSION SIZES & NAMES dimensions: lat = 64 lon = 128 time = 12 VARIABLES: Names, Types, Attributes, Coordinate Variables variables: float lat(lat) lat:long_name = "latitude" lat:units = "degrees_north" float lon(lon) lon:long_name = "longitude" lon:units = "degrees_east" int time(time) time:long_name = "time" time:units = "Month of Year" double T(time, lat, lon) T:long_name = “Temperature” T:units = “degC" T:missing_value = 1.e+20f T:_FillValue = 1.e+20f FILE ATTRIBUTES global attributes: title = “Temp: 1999” source = “NCAR” Conventions = ”CF-1.0” exercise: ncl_filedump FOO.nc | less time=UNLIMITED (12 currently)

Eurasia Institute of Earth Sciences Istanbul Technical University netCDF/NCL variable long_name: “Temperature” units: “degC” named dimensions: x(time,lat) lat: (/ -60, -30,0, 30, 60 /) time: (/2000, 2001, 2002, 2003, 2004, 2005, 2006 /) x name: x type: float [real] shape: 2-dimensions size: 6 (rows) x 5 (columns) values: x(2,3) = 8.46 [row major, 0-based indexing] Meta data

Eurasia Institute of Earth Sciences Istanbul Technical University Detailed look netCDF variable (NCL) ncl ; interactive mode ncl 0 > f = addfile ("UV300.nc", "r") ; open file (nc, grb, hdf, hdfeos) ncl 1 > u = f->U ; import STRUCTURE ncl 2 > printVarSummary (u) ; overview of variable Variable: u Type: float Total Size: bytes values Number of Dimensions: 3 Dimensions and Sizes: [time|2] x [lat | 64] x [lon | 128] Coordinates: time: [ ] lat: [ ] lon: [ ] Number of Attributes: 5 _FillValue : 1e36 [CF ] units : m/s [COARDS, CF] long_name : Zonal Wind [COARDS, CF] short_name : U missing_value : 1e36 [COARDS ] Classic netCDF Variable Model NCL syntax/funcs query use modify add any aspect of data object

Eurasia Institute of Earth Sciences Istanbul Technical University netCDF [NCL] Variable model f = addfile(“foo.nc”,”r”) ; grb/hdf x = f - >X X Scalar or Array attributes long_name _FillValue units add_offset scale_factor etc. values Scalar or Array attributes long_name _FillValue units add_offset scale_factor etc. accessed accessed via & time lev lat lon etc. coordinates time lev lat lon etc. coord var NCL reads the scalar/array, attributes, and coordinate variables as an object (structure) X

Eurasia Institute of Earth Sciences Istanbul Technical University netCDF [NCL] Variable model load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" f = addfile("erai_ mon.msl_psl.nc","r") ; open file [hdf,grib] p = f->SLP ; (time,lat,lon) ; ( 252,121,240) printVarSummary(p) ; netCDF variable model wks = gsn_open_wks("ps","parvis_1") ; open a PS file plot = gsn_csm_contour_map(wks,p(0,:,:),False) ; default plot ; uses attributes, coordinates NetCDF [NCL] Variable model p = f->SLP NCL reads data values attributes coordinate arrays as a single data object. scalar or array valuesattributescoords p accessed via & _FillValue long_name missing_value units etc. time latitude longitude etc

Eurasia Institute of Earth Sciences Istanbul Technical University netCDF [NCL] Variable model load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" f = addfile("erai_ mon.msl_psl.nc","r") ; open file [hdf,grib] p = f->SLP ; (time,lat,lon) ; ( 252,121,240) printVarSummary(p) ; netCDF variable model wks = gsn_open_wks("ps","parvis_1") ; open a PS file plot = gsn_csm_contour_map(wks,p(0,:,:),False) ; default B&W plot

Eurasia Institute of Earth Sciences Istanbul Technical University pdf, png Vis5D NCL Overview portable: linux/unix, windows (cygwin), MacOS general purpose: unique capabilities excellent graphics (2D, limited 3D) freeware: supported, public domain Integrated processing environment

Eurasia Institute of Earth Sciences Istanbul Technical University NCAR Command Language Complete Programming Language – data types – variables – operators – expressions – conditional statements – loops – functions/procedures/graphics Features – query / manipulate meta data – import data in a variety of formats – array syntax / operations – can use user fortran/C codes and commercial libraries – most functions/procedures ignore missing data

Eurasia Institute of Earth Sciences Istanbul Technical University Running NCL Interactive Mode (Command line) – ncl [options][command-line-arguments] ncl> enter commands ncl> quit – can save interactive commands ncl> record “file_name” ncl> stop record Batch Mode [.ncl suffix is optional] – ncl [options][arguments] script.ncl – ncl < script.ncl [also acceptable] – ncl [options][arguments] script.ncl >&! out – ncl [options][arguments] script.ncl >&! out &  appending "&" means put in background  note: the >&! & are csh and tcsh syntax

Eurasia Institute of Earth Sciences Istanbul Technical University Language Basics

Eurasia Institute of Earth Sciences Istanbul Technical University NCL Language Basics special syntax characters data types Variables  netCDF/NCL variable model attributes _FillValue named dimensions coordinate variables print and printVarSummary shaping subscripting

Eurasia Institute of Earth Sciences Istanbul Technical University NCL Syntax Characters ; - comment [can appear anywhere] -> - use to (im/ex)port variables via addfile - reference/create attributes ! - reference/create named dimension & - reference/create coordinate variable {…} - coordinate subscripting $ - enclose strings when (im/ex)port variables via addfile (/../) - array construction (variable); remove meta data [/../] – list construction; [:] all elements of a list : - array syntax | - separator for named dimensions \ - continue character [statement to span multiple lines] :: - syntax for external shared objects (eg, fortran/C)

Eurasia Institute of Earth Sciences Istanbul Technical University Simple Variable Creation a_int = 1 a_float = 2.0 ; , 2e-5 a_double = 3.2d ; d, 3.2d-3 a_string = "a” a_logical = True [False] ; note capital T/F array constructor characters (/…/) – a_integer= (/1,2,3/) ; ispan(1,3,1) – a_float = (/2.0, 5, 8.0/) ; fspan(2,8,3) – a_double = (/1., 2, 3.2 /) *1d5 – a_string = (/"abcd", "e", "Hello, World”/) – a_logical = (/True, False, True/) – a_2darray= (/ (/1,2,3/), (/4,5,6/), (/7,8,9/) /)

Eurasia Institute of Earth Sciences Istanbul Technical University Variable Creation and Deletion a = 2.0 pi = 4.0*atan(1.0) s = (/ “Melbourne”, “Sydney”, “Boulder” /) r = f->precip ; (time,lat,lon) R = random_normal(20,7, (/N,M/) ) ; R(N,M) q = new ( (/ntim, klev, nlat, mlon/), “double” ) ; free memory; Generally, do not need to do this ; delete each variable individually delete(a) delete(pi) delete(s) delete(r) delete(R) ; delete variables in one line; use list syntax [/ … /] (v 6.0.0) delete( [/ a, pi, s, r, R, q /] )

Eurasia Institute of Earth Sciences Istanbul Technical University Attributes assign/access character (variable T) – = “degC” – = “Temperature” – = (/ 0.25, 0.5, 0.25 /) – = (/ (/1,2,3/), (/4,5,6/), (/7,8,9/) /) – = -999 – title = attribute functions [isatt, getfilevaratts] – if (isatt(T,"units")) then.... end if – atts = getfilevaratts (fin, "T") delete can eliminate an attribute – info about a variable or file [meta data] – attributes can be any data type except file or list – scalar, multi dimensional array (string, numeric)

Eurasia Institute of Earth Sciences Istanbul Technical University Arrays row major  left dimension varies slowest; right varies fastest  dimension numbering left to right [0,1,..] subscripts  0-based [ entire range for N values: 0,N-1 ] Comment: NCL/C/C++ are 0-based and row major fortran is 1-based and column major Matlab is 1-based and row major IDL is 0-based and column major R is 1-based and column major (like fortran) Consider T(:,:,:)  T (0,1,2) left dimension is 0 middle dimension is 1 right dimension is 2

Eurasia Institute of Earth Sciences Istanbul Technical University Variable Subscripting (1 of 3) Standard Array Subscripting (Indexing) ranges: start/end and [optional] stride Index values separated by : omitting start/end index implies default begin/end Consider T(time,lat,lon) T  entire array [ don't use T(:,:,:) ] T(0,:,::5)  1 st time index, all lat, every 5 th lon T(0, ::-1, :50)  1 st time index, reverse, 1 st 51 lon T(:1,45,10:20)  1 st 2 time indices, 46 th value of lat, indicies of lon Can use variables to index: T(tstrt:tlast, :, ln1:ln2 )  time index tstrt:tlast, all lat :, longitude index values ln1:ln2

Eurasia Institute of Earth Sciences Istanbul Technical University Variable Subscripting (2 of 3) Coordinate Variable Subscripting only applies to coordinate variables same rules apply for ranges, strides, defaults use curly brackets {…} standard and coordinate subs can be mixed [if no reorder] T(2:7,{-30:30},:)  sixl times, all lon, lat -30° to +30° (inclusive) T(0,{-20},{-180:35:3})  1 st time, lat nearest - 20°, every 3rd lon between -180° and 35° T(::12,{latS:latN},:)  all times/lon, lat latS to latN (inclusive) T(8,{latS},{lonL:lonR:3})  9 th time, lat nearest latS, every 3rd lon between latL and lonR

Eurasia Institute of Earth Sciences Istanbul Technical University Variable Subscripting (3 of 3) Named Dimensions only used for dimension reordering indicated by | dim names must be used for each subscript named/coordinate subscripting can be mixed Consider T(time,lat,lon) t = T(lat|:, lon|:, time|:)  makes t(lat,lon,time) t = T(time|:,{lon|90:120},{lat|-20:20})  all times, ° lon, ° lat