Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Instruction for running HEG on Command line mode (batch job) for a bunch of similar files

If you have lots of similar hdf files that need to be processed by HEG, you can use a script similar to the one given below (for example the one provided in HEG's bin directory) or just simply use HEG GUI. If you want to run a batch using HEG GUI please read section 8 of the GUI "Help".

Please follow the instructions below for Unix/Linux or Windows depending on your system.

Unix/Linux:

...

  1. Create a directory and put all of your similar hdf files (for the same product) in that directory

...

  1. Run HEG GUI so that you create a template parameter file

...

  1. Select File -> Open and choose one of the file in the directory created in step a; click open

...

  1. Select Field, and then click on "down" arrow.

...

  1. Select output file type, projection, etc and click "Accept"

...

  1. Click "Save". Choose your parameter file name in the popped up window and then click "Save" on it. Please note that HEG will append "_sawth " to the end of the name that you chose for your parameter file to indicate that the products that you intended to convert are SWATH type. It will append "_grid" for grid products.

...

  1. Close HEG GUI. Now edit your created parameter file and make the following changes:

      ...

        1. Change input file name to "input"

      ...

        1. change the bounding box (corner lats/lons) to:

      ...

        1.      SPATIAL_SUBSET_UL_CORNER = ( 90.0 -180.0 )

      ...

        1.      SPATIAL_SUBSET_LR_CORNER = ( -90.0 180.0)

      ...

        1. change your output file name to "input_out" with appropriate extension ".tif" or ".hdf"

      ...

        1. save and close this file and rename it to heg_template_unix.prm
              Following is an example of such a template file created for a MODIS product:

              NUM_RUNS = 1
              BEGIN
              INPUT_FILENAME = /home/abe/GIS_Proj/HEG_MODIS/2007/elt_season/input
              OBJECT_NAME = MOD_Grid_Snow_500m
              FIELD_NAME = Fractional_Snow_Cover
              BAND_NUMBER = 1
              SPATIAL_SUBSET_UL_CORNER = ( 90.0 -180.0 )
              SPATIAL_SUBSET_LR_CORNER = ( -90.0 180.0)
              RESAMPLING_TYPE = NN
              OUTPUT_PROJECTION_TYPE = UTM
              ELLIPSOID_CODE = WGS84
              UTM_ZONE = 0
              OUTPUT_PROJECTION_PARAMETERS = ( 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 )
              OUTPUT_PIXEL_SIZE = 500.0
              OUTPUT_FILENAME =      /home/abe/GIS_Proj/HEG_MODIS/2007/out/melt_season/input_out.tif

      ...

              OUTPUT_TYPE = GEO
              END

      h8. Create a Shell Script file using following lines and make it executable type (e.g use "chmod 0755 myScript.sh"):      

              #! /bin/sh

              # in this script it is assumed that HEG executables are in
              # "/home/user/heg2.9/HEG/bin" directory, and that we are
              # processing a file that contains GRIDS. For processing files

      ...

              # that contain SWATH use "swtif" instead of "resample"

      ...



              for i

      ...

      in  `find .` ; do

      ...


                hdffile=`file $i | awk '

      ...

      {print $2

      ...

      }'`

      ...


                if

      ...

      [ "$hdffile" = "Hierarchical" 

      ...

      ] ; then

      ...


                  sed 's/input/'$i'/' heg_template_unix.prm > $i.prm

      ...


             

      ...

          

      ...

      /home/username/heg2.9/HEG/bin/resample -p $i.prm

      ...


               

      ...

      fi

      ...


              done

      ...


      9. Before running the script set 3 environment variables (assuming that HEG is installed in /home/username/heg2.9/HEG/

      ...

      ):

      ...

          setenv MRTDATADIR /home/username/heg2.9/HEG/data

      ...


          setenv PGSHOME /home/username/heg2.9/HEG/TOOLKIT_MTD

      ...


          setenv HEGUSER ME

      ...


      10. Now run the shell script for a HEG batch job!


      Windows:

      1.   Create a directory and put all of your similar hdf files in that directory
      2. Run HEG GUI to create a template parameter file
      3. Select File -> Open and choose one of the file in the directory created in step a; click open
      4. Select Field, and then click on "down" arrow.
      5. Select output file type, projection, etc and click "Accept"
      6. Click "Save". Choose you parameter file name in the popped up window and then click "Save" on it. Please note that HEG will append "_sawth " to the end of the name that you chose for your parameter file to indicate that the products that you intended to convert are SWATH type. It will append "_grid" for grid products.
      7. Close HEG GUI. Now edit your created parameter file and make the following changes:
        1. Change input file name to "input"
        2. change the bounding box (corner lats/lons) to:
               SPATIAL_SUBSET_UL_CORNER = ( 90.0 -180.0 )
               SPATIAL_SUBSET_LR_CORNER = ( -90.0 180.0)
        3. change your output file name to "input_out" with appropriate extension ".tif" or ".hdf"
        4. save and close this file and rename it to heg_template_unix.prm
              Following is an example of such a template file created for a MODIS product:

      ...



              NUM_RUNS = 1

      ...


              BEGIN

      ...


              INPUT_FILENAME

      ...

       = /home/abe/GIS_Proj/HEG_MODIS

      ...

      /2007

      ...

      /elt_season

      ...

      /input

      ...


              OBJECT_NAME = MOD_Grid_Snow_500m

      ...


              FIELD_NAME = Fractional_Snow_Cover

      ...


              BAND_NUMBER = 1

      ...


              SPATIAL_SUBSET_UL_CORNER = ( 90.0 -180.0 )

      ...


              SPATIAL_SUBSET_LR_CORNER = ( -90.0 180.0)

      ...


              RESAMPLING_TYPE = NN

      ...


              OUTPUT_PROJECTION_TYPE = UTM

      ...


              ELLIPSOID_CODE = WGS84

      ...


              UTM_ZONE = 0

      ...


              OUTPUT_PROJECTION_PARAMETERS = ( 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 )

      ...


              OUTPUT_PIXEL_SIZE = 500.0

      ...


              OUTPUT_FILENAME =

      ...

            /home/abe/GIS_Proj/HEG_MODIS

      ...

      /2007

      ...

      /out/melt_season

      ...

      /input_out.tif

      ...


             

      ...

      OUTPUT_TYPE = GEO

      ...


              END

      ...

      Warning:

      ...

      Please

      ...

      be

      ...

      aware

      ...

      that

      ...

      in

      ...

      windows

      ...

      if

      ...

      you

      ...

      edit

      ...

      your

      ...

      file

      ...

      with

      ...

      some

      ...

      editors

      ...

      such

      ...

      as

      ...

      wordpad

      ...

      the

      ...

      editor

      ...

      puts

      ...

      carriage

      ...

      return

      ...

      "^M"

      ...

      at

      ...

      the

      ...

      end

      ...

      of

      ...

      each

      ...

      line.

      ...

      This

      ...

      will

      ...

      prevent

      ...

      HEG

      ...

      from

      ...

      running

      ...

      and

      ...

      will

      ...

      cause

      ...

      error.

      ...

      Make

      ...

      sure

      ...

      that

      ...

      your

      ...

      editor

      ...

      will

      ...

      work

      ...

      like

      ...

      UNIX

      ...

      editors.

      ...

      If

      ...

      you

      ...

      have

      ...

      linux

      ...

      or

      ...

      cygwin,

      ...

      do

      ...

      editing

      ...

      there.

      ...

      Also

      ...

      the

      ...

      linux

      ...

      application

      ...

      "dos2unix"

      ...

      cleans

      ...

       up

      ...

      "^M"

      ...

      from

      ...

      a

      ...

      file.

      ...


      1. The script MyHEG_batchScript.bat

      ...

      1. in

      ...

      1. BatchRunning.zip

      ...

      1. uses

      ...

      1. MS

      ...

      1. DOS

      ...

      1. script

      ...

      1. commands

      ...

      1. to

      ...

      1. run

      ...

      1. a

      ...

      1. batch

      ...

      1. job

      ...

      1. for

      ...

      1. HEG

      ...

      1. in

      ...

      1. windows.

      ...

      1. First

      ...

      1. it

      ...

      1. edits

      ...

      1. a

      ...

      1. template

      ...

      1. parameter

      ...

      1. file

      ...

      1. (created

      ...

      1. using

      ...

      1. HEG

      ...

      1. GUI

      ...

      1. or

      ...

      1. by

      ...

      1. other

      ...

      1. means

      ...

      1. as

      ...

      1. instructed

      ...

      1. above)

      ...

      1. to

      ...

      1. the

      ...

      1. desired

      ...

      1. format.

      ...

      1. The

      ...

      1. edited

      ...

      1. file

      ...

      1. that

      ...

      1. the

      ...

      1. script

      ...

      1. creates,

      ...

      1. using

      ...

      1. the

      ...

      1. .bat

      ...

      1. file

      ...

      1. for

      ...

      1. filename

      ...

      1. substitution,

      ...

      1. will

      ...

      1. contain

      ...

      1. the

      ...

      1. LineFeed

      ...

      1. characters

      ...

      1. at

      ...

      1. the

      ...

      1. end

      ...

      1. of

      ...

      1. each

      ...

      1. line.

      ...

      1. Since

      ...

      1. HEG

      ...

      1. does

      ...

      1. not

      ...

      1. recognize

      ...

      1. this

      ...

      1. character

      ...

      1. (causing

      ...

      1. error)

      ...

      1. they

      ...

      1. should

      ...

      1. be

      ...

      1. removed.

      ...

      1. In

      ...

      1. future

      ...

      1. this

      ...

      1. will

      ...

      1. be

      ...

      1. worked

      ...

      1. out

      ...

      1. to

      ...

      1. be

      ...

      1. done

      ...

      1. with

      ...

      1. MS

      ...

      1. DOS

      ...

      1. commands

      ...

      1. if

      ...

      1. possible.

      ...

      1. Currently

      ...

      1. script

      ...

      1. uses

      ...

      1. CYGWIN's

      ...

      1. dos2unix.exe

      ...

      1. tool

      ...

      1. that

      ...

      1. does

      ...

      1. cleaning

      ...

      1. for

      ...

      1. us.

      ...

      1. To

      ...

      1. use

      ...

      1. this

      ...

      1. executable

      ...

      1. we

      ...

      1. require

      ...

      1. to

      ...

      1. have

      ...

      1. a

      ...

      1. few

      ...

      1. other

      ...

      1. cygwin's

      ...

      1. dll

      ...

      1. files

      ...

      1. in

      ...

      1. the

      ...

      1. same

      ...

      1. directory

      ...

      1. that

      ...

      1. dos2unix.exe

      ...

      1. exist.

      ...

         Please

      ...

      also

      ...

      note

      ...

      that

      ...

      if

      ...

      you

      ...

      use

      ...

      MS

      ...

      wordpad

      ...

      for

      ...

      creating

      ...

      parameter

      ...

      file,

      ...

      you

      ...

      can

      ...

      use

      ...

      this

      ...

      executable

      ...

      on

      ...

      command

      ...

      line

      ...

      to

      ...

      get

      ...

      rid

      ...

      of

      ...

      LineFeed

      ...

      characters

      ...

      in

      ...

      your

      ...

      .prm

      ...

      file.

      ...


      Here

      ...

      are

      ...

      the

      ...

      steps

      ...

      for

      ...

      using

      ...

      our

      ...

      Windows

      ...

      batch

      ...

      script:

      1. Download BatchRunning. zip
      2. The sample template parameter file is created for an ASTER product. You need to create your own template parameter file possibly by using HEG GUI, and editing it to put in the desired form as the sample (i.e. having "infile" “infile” for the input filename, and in output filename, and modifying the subset lat/lon as instruvted in step b above.)
      3. Extract the files from BatchRunning.zip. In the main directory you will have all executables (except for the resample.exe, swtif.exe, etc. needed for HEG executable), scripts and dll files
      4. In this directory we have indir and outdir. You should put all your input files in indir. The outdir will contain your template parameter file. After executing the MyHEG_batchScript.bat file your output files will go to outdir directory.
      5. Outputs will have swath or grid area in the original file although in the template parameter file you may use a global subset area.
      6. The Modified parameter files will exist in the main directory for later reference

      ...