1

I have some variable in my NetCDF4. I have 2 type of variable IR ( infrared) or VIS visible all time when when I choose var to plot in list_ var in index I need to choose cmap :

Dor IR the cmap is cmap=plt.cm.gist_yarg and for VIS cmap=plt.cm.gist_gray

This part of my code :

 path=file_names
        nc = netCDF4.Dataset(file_names)

        var = nc.variables.keys()

        list_var = [nc.variables['VIS006'],nc.variables['VIS008'],nc.variables['IR_120'],nc.variables['IR_108'],nc.variables['IR_087'],
                    nc.variables['IR_134'],nc.variables['IR_039'],nc.variables['WV_073'],nc.variables['WV_062'],nc.variables['IR_097']]
        print("update4")
        data_list = ['VIS006','VIS008','IR_120','IR_108','IR_087','IR_134','IR_039','WV_073','WV_062','IR_097']

        list_var = [nc.variables[f] for f in data_list]
        print("Option chosen update")
        global index

        self.axes.imshow(list_var[index],origin='lower')

How can I use condition if in my code like this :

 #if "IR" in var :
           # plt.imshow(data1,vmin=mini,vmax=maxi, cmap=plt.cm.gist_yarg)
        #elife  "VIS" in var :
            #plt.imshow(data1,vmin=mini,vmax=maxi, cmap=plt.cm.gist_gray)
        #else:
           # plt.imshow(data1,vmin=mini,vmax=maxi)
  • 1
    Please format all code appropriately and reduce it to the bare necessities. – bugmenot123 May 28 at 8:28
  • the code is in wxpython that why is not clear – Sarah Tohami May 28 at 9:43
  • That does not matter, fix the indentation and formatting and it will be more readable. – bugmenot123 May 28 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.