0

I have created a python script with a selection of functions for image processing. Each of these functions require variables to be inserted into them by the user.

I'm trying to work out how to prompt the user to define the variables for the function to work. The variables being inputted will be strings / file paths.

Below is an example of the function and also the start of the main procedural program:

def SRTMprocessing():
    """
    The following function mosaics together SRTM tiles, then reprojects the
    mosaic from WGS84 geographic coordinate to a projected WGS84 UTM zone
    coordinate system.
    """

    # Defining inputs

    DTM_output = "/DEMs/SRTM.tif"
    SRTM_input1 = ""
    SRTM_input2 = ""
    SRTM_input3 = ""
    UTM_Zone = ""
    Overwrite = DTM_output
    Reprojected_DTM = ""

    # Unzipping and mosaicing the Digital Terrain Model

    os.system("gdal_merge.py -init 0 -o %s %s"
             %(DTM_output, tiles))

    # Reprojecting from WGS84 geographic projection to UTM zone projection

    os.system("gdalwarp -t_srs '+proj=utm +zone=%s +datum=WGS84' -overwrite %s\
             %s" %(UTM_Zone, Overwrite, Reprojected_DTM))

    os.system("rm %s" %(DTM_output))

print ("Which data type are you processing?"),

data_type = input()
elif data_type == "SRTM":

print("Processing the SRTM input.")

SRTMprocessing()

In the example above the empty variables are what I want the user to provide. How do I write this into my python script?

Many Thanks for the help!

  • You should pass that information in. This function looks like it's trying to do too much. – Carcigenicate Jan 09 '17 at 15:06
  • 2
    Please indent your code correctly. Also, please reduce it to a [mcve]. I doubt this many variables are necessary to illustrate the question. – das-g Jan 09 '17 at 15:07
  • 1
    `data = input('Some message')` works: See http://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers-in-python for lots of detail – doctorlove Jan 09 '17 at 15:08
  • Where/how do you _use_ the empty variables like `SRTM_input1`? – martineau Jan 09 '17 at 15:29
  • You could define lists of variable names for each function and then be able to know what values to get from the user depending on the function chosen. The input from the user for each these variables could then be stored in a dictionary whose keys were the variable names, and the values were the associated user input. – martineau Jan 09 '17 at 15:35
  • Thank you @doctorlove that was what I had been trying to implement! – William_Ray Jan 09 '17 at 15:54

0 Answers0