将字节从urllib转换为栅格对象

时间:2019-07-17 15:09:30

标签: python urllib2 raster urlrequest

我正在尝试检索SMAP图像的单个观测值,以用于模型计算。该模型运行良好,我只需要弄清楚如何将urllib中的响应(以字节为单位)转换为栅格对象即可。

我不熟悉如何在Python中使用字节,因此不确定要采取的后续步骤,甚至不确定是否可以实现

from http.cookiejar import CookieJar
import urllib.parse
import urllib.request

#User Inputs
username = "username"
password = "password"
day = "2019.07.12" #Must be input in YYYY.MM.DD Format

通过输入,我正在查询Earthdata

url = "https://n5eil01u.ecs.nsidc.org/DP6/SMAP/SPL4SMAU.004/" + day + "/SMAP_L4_SM_aup_20190712T120000_Vv4030_001.h5"
password_manager = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, "https://urs.earthdata.nasa.gov", username, password)
cookie_jar = CookieJar()
opener = urllib.request.build_opener(
    urllib.request.HTTPBasicAuthHandler(password_manager),
    urllib.request.HTTPHandler(debuglevel=1),    # Uncomment these two lines to see
    urllib.request.HTTPSHandler(debuglevel=1),   # details of the requests/responses
    urllib.request.HTTPCookieProcessor(cookie_jar))
urllib.request.install_opener(opener)

request = urllib.request.Request(url)
response = urllib.request.urlopen(request)

这部分代码可以正常工作,响应是一个http.client.HTTPResponse对象。然后我在下面阅读它:

SMAP = response.read()

使用.read(),它将成为字节对象。

我需要弄清楚如何处理作为栅格对象提取的图像,以及从这里可以得到的任何想法?

非常感谢您的帮助!

0 个答案:

没有答案
相关问题