Hi Bob.
About the issue with dateline. The HYDRA in 1.8 has that problem, but the HYDRA in 1.9beta1 does not have that problem. Perhaps that would help you.
Referring to this post,
viewtopic.php?p=7149#p7149. I would like make a suggestion. Perhaps make a custom function that tracks what changes in the UI? For example, Step 1, turn the tracking function on. Step 2, make a change somewhere in the UI. Step 3, turn off the tracking function. Step 4, display what has changes, what functions were called between Step 1 and Step 3. I have no idea if this can be easily implemented or not. So it's just a suggestion. To me, it would be friendlier to user, as it helps user to easily identify what changes in the UI functionality and how to replicate it..
Below is the script I wrote. I would like to have your feedback on it. Technically this is my first Python script, so I think I might not be writing it properly. Basically I have several MOD021km files, and I want to plot the imagery, and the corresponding msl and 10m wind from ERA5 reanalysis (rounded to earlier hour). The data was downloaded earlier based on spatial search on NASA EarthData Search. I took into account of 1 or more imagery in the area, therefore, the script currently checks if there's any granules that are next to each other, and plots both granules, then msl and 10m winds from ERA5.
I have plan to include the possibility of third imagery in the area of interest, but that would be later. That is why there is an empty else. I thought, based on description of 'pass', it would work as place holder, but somehow it doesn't work.
Code: Select all
from datetime import datetime
from ucar.unidata.util import Range
#Grab the current active Display
panel=activeDisplay()
#Open a bundle that has been modified.
openBundle("G:/My Drive/Terra Nova Bay Work in Progress/McIDAS-V/TNB-Ross-Sea.mcv")
#ERA5 file containing mslp, u10, v10, and t2m. The file is hourly.
ERA5Case13='G:/My Drive/Terra Nova Bay Work in Progress/Terra Nova Bay Strong Wind Event/Case13_ERA5_hourly_u10_v10_msl_t2m_20160516-20160529.nc'
#The directory containing the MOD images.
Data_Dir = 'G:/My Drive/Terra Nova Bay Work in Progress/Raw-Data/MODIS-MOD021KM/Terra/20160521'
#Make a list of MODIS imagery in a folder
File_List=sorted(os.listdir(Data_Dir))
#Make a local ADDE entry, not permanent.
Terra20160521 = makeLocalADDEEntry(dataset='TEST1', imageType='MOD021KM', mask=Data_Dir, format='MODS', save=False)
#Identifier for skipping files. 0 means don't skip. 1 means skips.
skip1=0
#Clear any layers being displayed.
removeAllLayers( )
#for file in range(len(File_List)):
for file in range(len(File_List)):
if skip1==1:
#If skip was set to 1, do skip, and reset the skip indicator
print 'Skipping file ',file,' ',File_List[file]
skip1=0
continue
else:
#pass doesn't work
print 'Because pass doesn\'t work'
print "Working on file ",file," ", File_List[file]
#Grab the time details from the MODIS file name.
file_Time_1 = File_List[file][10:22]
file_Time_formatted_1 = datetime.strptime(file_Time_1, "%Y%j.%H%M")
#Check if it's the last file.
if file+1==len(File_List):
file_Time_2=None
file_Time_formatted_2=None
continue
else:
file_Time_2 = File_List[file+1][10:22]
file_Time_formatted_2 = datetime.strptime(file_Time_2, "%Y%j.%H%M")
skip1=1
#Need to add another in case there are 3 imagery for one area.
#Try to use dictionary next time.
Image1=loadADDEImage(server='localhost',localEntry=Terra20160521,\
time=file_Time_formatted_1.strftime("%X"),day=file_Time_formatted_1.strftime("%Y%j"),\
band=31,size='ALL',unit='TEMP')
#To see a summary of the Image1.
#print(describe(Image1))
#Mask the image from extremem values.
maskedImage1 = maskWithinRange(Image1, 1, 350, 1) * Image1
#Get the new min and max value from masked image.
#Range1=getMinMax(maskedImage1)
#To see a summary of masked Image1.
#print(describe(maskedImage1))
MOD1=panel.createLayer('Image Display', maskedImage1)
#MOD2.setEnhancement('FROSTWW')
MOD1.setEnhancement('Inverse Gray shade')
#Apparently you don't need the line below.
#MOD1.getGridDisplay().setRangeForColor(Range(Range1))
#If the next file in File_List is the next granule, load it and display it.
if abs(file_Time_formatted_1.minute-file_Time_formatted_2.minute)==5:
Image2=loadADDEImage(server='localhost',localEntry=Terra20160521,\
time=file_Time_formatted_2.strftime("%X"),day=file_Time_formatted_2.strftime("%Y%j"),\
band=31,size='ALL',unit='TEMP')
maskedImage2 = maskWithinRange(Image2, 1, 350, 1) * Image2
MOD2=panel.createLayer('Image Display', maskedImage2)
#MOD2.setEnhancement('FROSTWW')
MOD2.setEnhancement('Inverse Gray shade')
#Need indicator double/triple plotting is needed.
else:
#pass doesn't work.
print 'Because pass doesn\'t work'
#Load ERA5 mslp.
ERA5MSLP=loadGrid(filename=ERA5Case13,
field='msl',latLonBounds=(-55,120,-85,240),time=file_Time_formatted_1.strftime("%Y-%m-%d %H:00:00 UTC"),xStride=1,yStride=1)
layer1=panel.createLayer('Contour Plan View', ERA5MSLP)
#Change the display unit into hPa
layer1.setDisplayUnit('hPa')
#Setting contour display to be standardised.
a=layer1.getContourInfo()
a.interval=4
a.base=930
a.max=1030
layer1.setContourInfo(a)
#Change the whole shading into red
layer1.setEnhancement("Red")
#Loading 10m wind vector.
ERA5u10=loadGrid(filename=ERA5Case13,
field='u10',latLonBounds=(-55,120,-85,240),time=file_Time_formatted_1.strftime("%Y-%m-%d %H:00:00 UTC"),xStride=8,yStride=2)
ERA5v10=loadGrid(filename=ERA5Case13,
field='v10',latLonBounds=(-55,120,-85,240),time=file_Time_formatted_1.strftime("%Y-%m-%d %H:00:00 UTC"),xStride=8,yStride=2)
#Creat display for 10m winds.
ERA5MSLP10mwind=makeVector(ERA5u10,ERA5v10)
layer2=panel.createLayer('Vector Plan View', ERA5MSLP10mwind)
#Change the vecto color to black
aaa=layer2.getColor()
layer2.setColor(aaa.BLACK)
#Standardise the vector range.
layer2.setFlowRange(Range(-25,25))
#Save the image.
panel.captureImage('G:/My Drive/Terra Nova Bay Work in Progress/McIDAS-V/MOD021KM_and_MYD021KM_Imagery/'+file_Time_formatted_1.strftime("%Y%m%d-%H%M")+'.png')
#Remove all displays for the next iteration.
removeAllLayers( )
print 'Finish'
Yunus.