defdownload_file(url): """Create an urllib2 request and return the request plus some useful info""" name = filename_from_url(url) r = urllib2.urlopen(urllib2.Request(url)) info = r.info() if'Content-Disposition'in info: # If the response has Content-Disposition, we take filename from it name = info['Content-Disposition'].split('filename=')[1] if name[0] == '"'or name[0] == "'": name = name[1:-1] elif r.geturl() != url: # if we were redirected, take the filename from the final url name = filename_from_url(r.geturl()) content_type = None if'Content-Type'in info: content_type = info['Content-Type'].split(';')[0] # Try to guess missing info ifnot name andnot content_type: name = 'unknown' elifnot name: name = 'unknown' + mimetypes.guess_extension(content_type) or'' elifnot content_type: content_type = mimetypes.guess_type(name)[0] return r, name, content_type import shutil defdownload_file_locally(url, dest): req, filename, content_type = download_file(url) if dest.endswith('/'): dest = os.path.join(dest, filename) withopen(dest, 'wb') as f: shutil.copyfileobj(req, f) req.close()
time = "201609"## 此处以2016年09月为例 filename = 'MCD14ML.'+time+'.006.01.txt.gz' download_file_locally('ftp://fire:burnt@fuoco.geog.umd.edu/modis/C6/mcd14ml/',filename)
import fiona from shapely.geometry import shape,Polygon, Point # read the shapefile sc_area = fiona.open("/Users/HYF/Documents/NanChong/GIS/sichuan.shp") pol = sc_area.next() from shapely.geometry import shape geom = shape(pol['geometry']) poly_data = pol["geometry"]["coordinates"][0] poly = Polygon(poly_data)
### zip the x coordidate and y coordidate of each hotspot points = zip(*np.array([df.lon.values, df.lat.values])) ### to identify whether the hotspot is inside the boundary or not mask = np.array([poly.contains(Point(x, y)) for x, y in points])
Kommentare