2016-10-17 9 views
2
내가 시도

요청 pydap, URLLIB 및 netcdf4을 사용하고 보관 중 오류 또는 권한 오류를 리디렉션지고 항공 우주국 (NASA) 위성 OPeNDAP 데이터를 다운로드하는 방법 :다음 NASA의 데이터를 다운로드 할 때 파이썬에게

GLDAS_NOAH025SUBP_3H : GLDAS 노아의 땅 표면 모델 L4 3 시간마다 0.25 x 0.25도 서브 세트 V001 (http://disc.sci.gsfc.nasa.gov/uui/datasets/GLDAS_NOAH025SUBP_3H_V001/summary?keywords=Hydrology)

Google 크롬 브라우저에 붙여 넣을 때 작동하는 약 50k 개의 파일을 다운로드하려고합니다 (사용자 이름과 비밀번호가 올바른 경우).) :

http://hydro1.gesdisc.eosdis.nasa.gov/daac-bin/OTF/HTTP_services.cgi?FILENAME=%2Fdata%2FGLDAS_V1%2FGLDAS_NOAH025SUBP_3H%2F2016%2F244%2FGLDAS_NOAH025SUBP_3H.A2016244.2100.001.2016256190725.grb&FORMAT=TmV0Q0RGLw&BBOX=-11.95%2C28.86%2C-0.62%2C40.81&LABEL=GLDAS_NOAH025SUBP_3H.A2016244.2100.001.2016286201048.pss.nc&SHORTNAME=GLDAS_NOAH025SUBP_3H&SERVICE=SUBSET_GRIB&VERSION=1.02&LAYERS=AAAB&DATASET_VERSION=001

누구나 파이썬을 사용하여 웹에서 OPeNDAP NASA 데이터를 얻은 경험이 있습니까? 원하는 경우 더 많은 정보를 제공해 드리겠습니다.

import requests 

def httpdownload(): 
    '''loop through each line in the text file and open url''' 
    httpfile = open(pathlist[0]+"NASAdownloadSample.txt", "r") 
    for line in httpfile: 
     print line 
     outname = line[-134:-122]+".hdf" 
     print outname 
     username = "" 
     password = "*" 
     r = requests.get(line, auth=("username", "password"), stream=True) 
     print r.text 
     print r.status_code 
     with open(pathlist[0]+outname, 'wb') as out: 
      out.write(r.content) 
     print outname, "finished" # keep track of progress 

그리고 여기에 리디렉션 오류주는 pydap 예는 다음과 같습니다 : 나는 파이썬을 사용하여 해결책을 찾을 수 없습니다

import install_cas_client 
from pydap.client import open_url 

def httpdownload(): 
    '''loop through each line in the text file and open url''' 
    username = "" 
    password = "" 
    httpfile = open(pathlist[0]+"NASAdownloadSample.txt", "r") 
    fileone = httpfile.readline() 
    filetot = fileone[:7]+username+":"+password+"@"+fileone[7:] 
    print filetot 
    dataset = open_url(filetot) 

답변

4

하지만, 주어진 여기

401 오류를 제공 요청의 시도이다 내가 가지고있는 정보는 이제 가능해야합니다. ( https://disc.gsfc.nasa.gov/information/howto?title=How%20to%20Download%20Data%20Files%20from%20HTTP%20Service%20with%20wget)를 다음과 같이 나는 도시에 .netrc 파일과 쿠키 파일을 wget을 사용 :
#!/bin/bash 

cd # path to output files 
touch .netrc 
echo "machine urs.earthdata.nasa.gov login <username> password <password>" >> .netrc 
chmod 0600 .netrc 
touch .urs_cookies 
wget --content-disposition --trust-server-names --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --auth-no-challenge=on --keep-session-cookies 
-i <path to text file of url list> 

은이 서버에서 NASA의 데이터로 작업 다른 사람을 도움이되기를 바랍니다.