Project

General

Profile

« Previous | Next » 

Revision d7dc526e

Added by Adam Wilson almost 11 years ago

Updating visualization and validation of MOD09 cloud product

View differences:

climate/procedures/ee.MOD09.py
15 15
#logging.basicConfig()
16 16

  
17 17
## set working directory (where files will be downloaded)
18
os.chdir('/home/adamw/acrobates/adamw/projects/cloud/data/mod09')
18
os.chdir('/mnt/data2/projects/cloud/mod09')
19 19

  
20 20
MY_SERVICE_ACCOUNT = '511722844190@developer.gserviceaccount.com'  # replace with your service account
21 21
MY_PRIVATE_KEY_FILE = '/home/adamw/EarthEngine-privatekey.p12'       # replace with you private key file path
......
45 45
## set a year-month if you don't want to run the loop (for testing)
46 46
#year=2001
47 47
#month=2
48

  
48
#r=1
49 49

  
50 50
## define the regions to be processed
51 51
regions=['[[-180, -60], [-180, 0], [0, 0], [0, -60]]',  # SW
......
64 64

  
65 65
      # output filename
66 66
      filename='mod09_'+rnames[r]+"_"+str(year)+"_"+str(month)
67
      unzippedfilename='mod09_'+rnames[r]+"_"+str(year)+"_"+str(month)+".MOD09_"+str(year)+"_"+str(month)+".tif"
67 68

  
68 69
      # Check if file already exists and continue if so...
69
      if(os.path.exists(filename+".zip")):
70
      if(os.path.exists(unzippedfilename)):
70 71
        print("File exists:"+filename)
71 72
        continue
72 73

  
73 74
      # MOD09 internal cloud flag for this year-month
74 75
      # to filter by a date range:  filterDate(datetime.datetime(yearstart,monthstart,1),datetime.datetime(yearstop,monthstop,31))
75 76
      mod09 = ee.ImageCollection("MOD09GA").filter(ee.Filter.calendarRange(year,year,"year")).filter(ee.Filter.calendarRange(month,month,"month")).map(getmod09);
77
#      myd09 = ee.ImageCollection("MYD09GA").filter(ee.Filter.calendarRange(year,year,"year")).filter(ee.Filter.calendarRange(month,month,"month")).map(getmod09);
76 78
      # calculate mean cloudiness (%), rename band, multiply by 100, and convert to integer
77 79
      mod09a=mod09.mean().select([0], ['MOD09_'+str(year)+'_'+str(month)]).multiply(ee.Image(100)).byte();
80
#      myd09a=myd09.mean().select([0], ['MYD09_'+str(year)+'_'+str(month)]).multiply(ee.Image(100)).byte();
78 81
      
79
      # Next few lines for testing only
80
      # print info to confirm there is data
81
      # mod09a.getInfo()
82
      # add to plot to confirm it's working
83
      # ee.mapclient.addToMap(mod09a, {'range': '0,100'}, 'MOD09')
82
```
83
# Next few lines for testing only
84
# print info to confirm there is data
85
mod09a.getInfo()
86
myd09a.getInfo()
87

  
88
# add to plot to confirm it's working
89
ee.mapclient.addToMap(mod09a, {'range': '0,100'}, 'MOD09')
90
ee.mapclient.addToMap(myd09a, {'range': '0,100'}, 'MOD09')
91
```
84 92

  
85 93
      # build the URL and name the object (so that when it's unzipped we know what it is!)
86 94
      path =mod09a.getDownloadUrl({
......
101 109
        # try to unzip it
102 110
        print("Unzipping "+filename)
103 111
        zipstatus=call("unzip "+filename+".zip",shell=True)
104
        # if file doesn't exists or it didn't unzip, remove it and try again      
112
         # if file doesn't exists or it didn't unzip, remove it and try again      
105 113
        if(zipstatus==9):
106 114
          print("ERROR: "+filename+" unzip-able")
107 115
          os.remove(filename)

Also available in: Unified diff