Re: [python-users] Reliable Siphon Source for Metar Data and Graceful Failure for NCSS empty queries

  • To: "Capehart, William J" <William.Capehart@xxxxxxxxx>
  • Subject: Re: [python-users] Reliable Siphon Source for Metar Data and Graceful Failure for NCSS empty queries
  • From: Ryan May <rmay@xxxxxxxx>
  • Date: Tue, 28 Sep 2021 14:51:14 -0600
Greetings!

Regarding METAR data, my current best workflow is to download from our
*testing* THREDDS server using Siphon and parsing using MetPy's
`metpy.io.parse_metar_file` function:


https://thredds-test.unidata.ucar.edu/thredds/catalog/noaaport/text/metar/catalog.html

https://unidata.github.io/MetPy/latest/api/generated/metpy.io.parse_metar_file.html

Relying on the test server isn't optimal, but I haven't had the cycles to
set up the METARs as a proper dataset on our main demonstration server. As
far as handling errors from Siphon is concerned, you have two options.
Given the following script:

    from datetime import datetime
    from requests import HTTPError
    from siphon.catalog import TDSCatalog

    cat = TDSCatalog('
https://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p5deg/catalog.xml
')
    ds = cat.datasets['Best GFS Half Degree Forecast Time Series']
    ncss = ds.subset()
    query = ncss.query()

    query.time(datetime(2022, 3, 4, 12))
    query.lonlat_box(east=-60, west=-70, north=30, south=25)
    query.variables('Temperature_isobaric')

You can catch the error and fail gracefully:

    try:
        nc = ncss.get_data(query)
    except HTTPError:
        # Handle error
        pass

Or you can look at the metadata the NCSS endpoint provides (accessible in
the code above as `ncss.metadata`) and use that to decide if your query
will succeed. You're probably most interested in ncss.metadata.time_span,
ncss.metadata.variables, and ncss.metadata.lat_lon_box. For more
information, see:

  https://unidata.github.io/siphon/latest/api/ncss.html
  https://unidata.github.io/siphon/latest/api/ncssdataset.html

Hope this helps!

Ryan

On Mon, Sep 27, 2021 at 8:58 AM Capehart, William J <
William.Capehart@xxxxxxxxx> wrote:

> Hi All.
>
>
>
> I’m adopting siphon and climbing its learning curve as a substitute for
> some of our LDM functionality and we’re running into a problem with finding
> a reliable source for a metars in real time.  My querries into unidata’s
> ncss via thredds is not always getting a steady stream.
>
>
>
> Also along these lines, I’m also having some problems in getting siphon
> returning something other than a 404 crash on a ncss.get_data(query) when
> the search turns up no results for a time/location so I can jump to the
> next step in some of my automated scripting.
>
>
>
> Is there an option here I’m missing on both issues (steady metars and a
> workable test on how many results my query will deliver)?
>
>
>
> Cheers and Thanks
>
> Bill
>
> –––––––––––––––––––––––––––––––––––––––––––
> *Dr. Bill Capehart*, Director, Atmospheric and Environmental Sciences
> *Civil & Environmental Engineering*
> South Dakota Mines
> 501 E. Saint Joseph St., Rapid City, SD 57701
> 605.484.5692 (Cell) | William.Capehart@xxxxxxxxx
>
> [image: South Dakota Mines] <https://www.sdsmt.edu/>
>
> [image: South Dakota Mines on Facebook]
> <https://www.facebook.com/SouthDakotaMines/>[image: South Dakota Mines on
> Instagram] <https://www.instagram.com/southdakotamines/>[image: South
> Dakota Mines on Twitter] <https://twitter.com/sdsmt>[image: South Dakota
> Mines on Snapchat] <https://www.snapchat.com/add/sdsmt>
>
>
>
>
>
>
> _______________________________________________
> NOTE: All exchanges posted to Unidata maintained email lists are
> recorded in the Unidata inquiry tracking system and made publicly
> available through the web.  Users who post to any of the lists we
> maintain are reminded to remove any personal information that they
> do not want to be made public.
>
>
> python-users mailing list
> python-users@xxxxxxxxxxxxxxxx
> For list information, to unsubscribe, or change your membership options,
> visit: https://www.unidata.ucar.edu/mailing_lists/
>


-- 
Ryan May, Ph.D.
Software Engineer
UCAR/Unidata
Boulder, CO

PNG image

PNG image

PNG image

PNG image

PNG image

  • 2021 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the python-users archives: