Scripting McIDAS-X in a Python environment Kevin Hallock SSEC Datacenter Programmer September 10, 2013 2013 McIDAS Users Group Meeting.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Chapter 2.2 – More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld senior.
Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
Chapter Modules CSC1310 Fall Modules Modules Modules are the highest level program organization unit, usually correspond to source files and.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 1.
Visual Web Information Extraction With Lixto Robert Baumgartner Sergio Flesca Georg Gottlob.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
SQL Reporting Services Overview SSRS includes all the development and management pieces necessary to publish end user reports in  HTML  PDF 
C++ fundamentals.
By. What advantages has it? The Reasons for Choosing Python  Python is free  It is object-oriented  It is interpreted  It is operating-system independent.
InSTALL InVEST Rich Sharp. InVEST Installation process InVEST: The Application Get InVEST Install the core InVEST application – InVEST statistics while.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
What is R By: Wase Siddiqui. Introduction R is a programming language which is used for statistical computing and graphics. “R is a language and environment.
Arc: Programming Options Dr Andy Evans. Programming ArcGIS ArcGIS: Most popular commercial GIS. Out of the box functionality good, but occasionally: You.
Advanced File Processing
Introduction to InVEST ArcGIS Tool Nasser Olwero GMP, Bangkok April
Selecting and Combining Tools F. Duveau 02/03/12 F. Duveau 02/03/12 Chapter 14.
Introduction to Shell Script Programming
SB ScriptBasic Introduction to ScriptBasic There are more people writing programs in BASIC than the number of people capable programming.
BIT 1003 – Presentation 7. Contents GENERATIONS OF LANGUAGES COMPILERS AND INTERPRETERS VIRTUAL MACHINES OBJECT-ORIENTED PROGRAMMING SCRIPTING LANGUAGES.
An Introduction to Unix Shell Scripting
By: Joshua O’Donoghue. Operating System Interface In order to interact with the operating system in python you will want to become familiar with the OS.
Final Year Project Interim Presentation Software Visualisation and Comparison Tool Presented By : Shane Lillis, , 4th Year Computer Engineering.
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
Introduction of Geoprocessing Topic 7a 4/10/2007.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
CIT 590 Intro to Programming Lecture 4. Agenda Doubts from HW1 and HW2 Main function Break, quit, exit Function argument names, scope What is modularity!
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Linux+ Guide to Linux Certification, Third Edition
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
Integrating Open Source Statistical Packages with ArcGIS Mark V. Janikas Liang-Huan (Leo) Chin.
Agenda Getting Started: Using Unix Unix Structure / Features Elements of the Unix Philosophy Unix Command Structure Command Line Editing Online Unix Command.
Configuring Disk Devices. Module 4 – Configuring Disk Devices ♦ Overview This module deals with making partitions using fdisk, implementing RAID and Logical.
By James Braunsberg. What are Modules? Modules are files containing Python definitions and statements (ex. name.py) A module’s definitions can be imported.
Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and.
Univ. of TehranDistributed Operating Systems1 Advanced Operating Systems University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani.
_______________________________________________________________CMAQ Libraries and Utilities ___________________________________________________Community.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
Introduction of Geoprocessing Lecture 9. Geoprocessing  Geoprocessing is any GIS operation used to manipulate data. A typical geoprocessing operation.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 5.
Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?
Introduction of Geoprocessing Lecture 9 3/24/2008.
LECTURE 2 Python Basics. MODULES So, we just put together our first real Python program. Let’s say we store this program in a file called fib.py. We have.
Linux Administration Working with the BASH Shell.
Bash Jerome Lewis Kelly Benson Andrew Kimble. Overview  Shell Language (UNIX based)  Paradigms – Command, Scripting  Has ability to read straight from.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
Introduction to InVEST ArcGIS Tool
MET4750 Techniques for Earth System Modeling
The Road to Using Python with McIDAS-X
IPYTHON AND MATPLOTLIB Python for computational science
The Linux Operating System
Tom Rink Tom Whittaker Paolo Antonelli Kevin Baggett.
Henning Schulzrinne Advanced Programming
Learning to Program in Python
Guide To UNIX Using Linux Third Edition
Brief Intro to Python for Statistics
Python’s Standard library part I
Python 19 Mr. Husch.
Option One Install Python via installing Anaconda:
Python 19 Mr. Husch.
Installations for Course
SHELLSHOCK ATTACK.
Installations for Course
Presentation transcript:

Scripting McIDAS-X in a Python environment Kevin Hallock SSEC Datacenter Programmer September 10, McIDAS Users Group Meeting

What problems are we trying to solve? Running a mcenv instance within a bash script requires redirection of stdin (i.e. "<< 'EOF'") Parsing text in bash can be clumsy, requires piping commands together to extract useful information. Manipulating dates in bash is messy, code can often depend on having a particular version of GNU date installed, for example.

What is Python? Python is a general-purpose interpreted programming language that supports multiple programming paradigms, including both object- oriented and procedural programming. Python is very flexible and can be used to write anything from simple scripts to an entire application with a fully graphical interface. Because of the flexibility it provides, Python has been one of the most popular programming languages over the past 10 years.

What makes Python a good alternative? PopularitY-of-Programming-Language nt/paperinfo/tpci/index.html Where is bash?

What makes Python a good alternative? Existing Python modules such as NumPy and SciPy offer advanced mathematical/scientific analytical tools comparable to MATLAB or R. As implied by the name, Python modules are modular, allowing a user to import whichever modules they deem necessary for their project. Because of the nature of Python modules, code implementing the McIDAS-X module can easily be added to an existing project; similarly, any McIDAS-X Python script can be extended to use other modules.

What makes Python a good alternative? Python is multi-platform

How our solution works The Python 'subprocess' module is used to spawn an instance of the mcenv shell in the backround mcenv shell commands are passed to the mcenv session using pseudo-native python functions, as in the following examples: – bash: imglist.k DATA/SET FORM=ALL – python: mcenv.imglist("DATA/SET FORM=ALL") In this case, the imglist method is not explicitly defined, but rather is interpreted such that the example bash command is run in the mcenv sub-shell.

bash example #!/bin/bash PATH=/home/mcidas/bin:$PATH MCPATH=$HOME/mcidas/data:/home/mcidas/data export PATH MCPATH mcenv << 'EOF' logon.k ABC 1234 dataloc.k ADD GROUP SERVER.DOMAIN imglist.k GROUP/DESCRIPTOR TIME=12:00 EOF

Python example #!/usr/bin/env python import mcidasx import os os.environ['PATH'] = "%s:%s" % ('/home/mcidas/bin', os.environ['PATH']) os.environ['MCPATH'] = '%s/mcidas/data:~mcidas/data' % os.environ['HOME'] m = mcidasx.mcidas.mcenv() m.logon('ABC 1234') m.dataloc('ADD GROUP SERVER.DOMAIN') m.imglist('GROUP/DESCRIPTOR TIME=12:00') Setting environment variables could be further abstracted into the module import step in order to simplify code.

GOES East Full Disk over a range of days #!/usr/bin/env python import mcidasx import os Import sys from datetime import datetime from mcidasx.utilities import date_range mcidas_home = '/home/mcidas' os.environ['PATH'] = "%s:%s" % (mcidas_home + '/bin', os.environ['PATH']) os.environ['MCPATH'] = '%s/mcidas/data:%s/data' % (os.environ['HOME'], mcidas_home) def main(start_date, end_date): mcenv = mcidasx.mcidas.mcenv(frame_size='900x1200') mcenv.logon("ABC 1234") mcenv.dataloc("ADD AGOES13 GEOARC.SSEC.WISC.EDU") for day in date_range(start_date, end_date): d = day.strftime('%Y%j') mcenv.imgdisp("AGOES13/FD MAG= BAND=1 DAY=%s TIME=17:45" % d) mcenv.frmsave("1 test-%s.jpg" % d) if __name__ == "__main__": start_date = datetime.strptime(sys.argv[1], '%Y-%m-%d') end_date = datetime.strptime(sys.argv[2], '%Y-%m-%d') main(start_date, end_date)

Relevant python modules NumPy SciPy netCDF4 GDAL matplotlib PyTables pandas

How can users install the McIDAS-X python module? Care was taken to ensure that the McIDAS-X python module could be installed and imported just like any other python module. ftp://ftp.ssec.wisc.edu/pub/mug/mug_meeting/2013/ python/mcidasx-python.tar.gz ftp://ftp.ssec.wisc.edu/pub/mug/mug_meeting/2013/ python/mcidasx-python.tar.gz Decompress the archive, and run 'python setup.py install --user' in the new directory (or use a Python tool such as pip or easy_install to install the.tar.gz directly). Now, within python, add the command 'import mcidasx', and all of the functionality of this module should be available.

Future work Additional modules which offer more direct access to underlying McIDAS-X commands – For example, the imglist command could return a Python object with callable methods and accessible attributes, rather than returning a multi-line string (which needs to be manually parsed to be useful). Additional specialized/specific utility functions – Perhaps functions that generate commonly used McIDAS time/date formats Although we are giving this "McIDAS-X/Python" presentation at the MUG meeting, this project is not currently funded by MUG. – Funded by another project at SSEC where the use of Python was necessary Disclaimer – This project was initially designed as a proof-of- concept, and as such has not been thoroughly tested for every McIDAS-X command.

Questions?