Coder Social home page Coder Social logo

Reading MERRA-2 data about pydap HOT 6 CLOSED

pydap avatar pydap commented on June 1, 2024
Reading MERRA-2 data

from pydap.

Comments (6)

laliberte avatar laliberte commented on June 1, 2024 2

@jenfly
Simply replace the line

session = setup_session(username, password)

by

session = setup_session(username, password, check_url=url2)

This is explained in the updated documentation but unfortunately the readthedocs version was not updated after the last commit so there was no way for you to find out. @jameshiebert any chance the online documentation could be updated?

The reason is that the NASA URS authentication only gives you the right cookies when you actually query some data..

from pydap.

jenfly avatar jenfly commented on June 1, 2024

Perfect! Thanks so much, @laliberte.

from pydap.

jameshiebert avatar jameshiebert commented on June 1, 2024

Re: readthedocs: readthedocs automatically builds the docs from GitHub every time we tag a release (not on every commit, I think), so one should be able to read the updated docs now that a release has been tagged.

from pydap.

laliberte avatar laliberte commented on June 1, 2024

Yes, it is working! Good to know that a release has to be tagged :)

from pydap.

empeeu avatar empeeu commented on June 1, 2024

I'm also trying to access this data. Using

from pydap.client import open_url                                               
from pydap.cas.urs import setup_session                                         

url2 = ('https://goldsmr4.gesdisc.eosdis.nasa.gov/opendap/MERRA2/'              
           'M2I1NXASM.5.12.4/2015/08/MERRA2_400.inst1_2d_asm_Nx.20150802.nc4')                                                                       
url3 = ('https://goldsmr5.gesdisc.eosdis.nasa.gov/opendap/hyrax/MERRA2/'                                                                          
            'M2I3NVASM.5.12.4/2015/08/MERRA2_400.inst3_3d_asm_Nv.20150802.nc4')                                                                        
                                 
session = setup_session(username, password, check_url=url2)                     
ds2 = open_url(url2, session=session)                                           
ds3 = open_url(url3, session=session)                                           
                                 
print(ds2['TS'].shape)                                                          
print(ds2['TS'][0, 0, 0])                                                       
print(ds3['T'].shape)                                                           
print(ds3['T'][0, 0, 0, 0])     

I get :

(24, 361, 576)
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-37-a6a3022d846a> in <module>()
     12 
     13 print(ds2['TS'].shape)
---> 14 print(ds2['TS'][0, 0, 0])
     15 print(ds3['T'].shape)
     16 print(ds3['T'][0, 0, 0, 0])

/home/mpubatman/anaconda3/lib/python3.6/site-packages/pydap/model.py in __getitem__(self, index)
    318     def __getitem__(self, index):
    319         out = copy.copy(self)
--> 320         out.data = self._get_data_index(index)
    321         return out
    322 

/home/mpubatman/anaconda3/lib/python3.6/site-packages/pydap/model.py in _get_data_index(self, index)
    347             return np.vectorize(decode_np_strings)(self._data[index])
    348         else:
--> 349             return self._data[index]
    350 
    351     def _get_data(self):

/home/mpubatman/anaconda3/lib/python3.6/site-packages/pydap/handlers/dap.py in __getitem__(self, index)
    140         logger.info("Fetching URL: %s" % url)
    141         r = GET(url, self.application, self.session, timeout=self.timeout)
--> 142         raise_for_status(r)
    143         dds, data = r.body.split(b'\nData:\n', 1)
    144         dds = dds.decode(r.content_encoding or 'ascii')

/home/mpubatman/anaconda3/lib/python3.6/site-packages/pydap/net.py in raise_for_status(response)
     34             detail=response.status+'\n'+response.text,
     35             headers=response.headers,
---> 36             comment=response.body
     37         )
     38 

HTTPError: 302 Found
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://urs.earthdata.nasa.gov/oauth/authorize/?scope=uid&amp;app_type=401&amp;client_id=e2WVk8Pw6weeLUKZYOxvTQ&amp;response_type=code&amp;redirect_uri=https%3A%2F%2Fgoldsmr4.gesdisc.eosdis.nasa.gov%2Fdata-redirect&amp;state=aHR0cHM6Ly9nb2xkc21yNC5nZXNkaXNjLmVvc2Rpcy5uYXNhLmdvdi9vcGVuZGFwL01FUlJBMi9NMkkxTlhBU00uNS4xMi40LzIwMTUvMDgvTUVSUkEyXzQwMC5pbnN0MV8yZF9hc21fTnguMjAxNTA4MDIubmM0LmRvZHM%2FVFNbMDoxOjBdWzA6MTowXVswOjE6MF0">here</a>.</p>
</body></html>

Help much appreciated.

Incidentally, I get the same thing if I enter a random username and password. I'm quite sure I got those right. I'm not sure how to debug this one... Thanks!

from pydap.

empeeu avatar empeeu commented on June 1, 2024

Wow, nevermind. I followed the link and just followed the instructions. Turns out I had to authorize the NASA GESDISC DATA ARCHIVE applications as part of my Earthdata account.

from pydap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.