Possible issue with PlotObs .time - via MetPy Mondays #115 - Declarative Station Plots #1724
-
|
Following the Code:
Removing The only thing we can think of is perhaps something in the environment related to the Is this issue replicable on your end? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I don't get the error that you got, but I do get a blank map. I think the reason for this error is that it doesn't find the time within this catalog the files are organized from oldest to newest. The selection of ds = cat.datasets[0]grabs the oldest file (which is about a month before current). The problem is that the newest files are "in the future". Due to errors in the transcription of the data at some point, the latest files are for March 31, 2021 at 23 UTC - clearly in the future as of 4 March 2021 when I am writing this response. We can go about it via another method to get the data you desire, though not through Siphon. By using the request module, we can construct the web address from the desired date/time and download the file. The following code will do that and replaces the use of Siphon. import requests
# Set the time from the computer
now = datetime.utcnow()
# Use the time variable to set the standard filename using an f-string
file = f'metar_{now:%Y%m%d_%H00}.txt'
# Use the request module to get the file from the web location
myfile = requests.get(f'https://thredds-test.unidata.ucar.edu/thredds/fileServer/'
f'noaaport/text/metar/{file}')
# Save the data to the same filename locally
open(file, 'wb').write(myfile.content)Additionally, for surface data, it would be best to include a time_window (15 minutes is usually sufficient) since it takes just a bit of time to get the data process through the system before the data are available.
Here is a reworked example using your original code with the modifications suggested here: from siphon.catalog import TDSCatalog
import pandas as pd
from datetime import datetime, timedelta
import cartopy.crs as ccrs
from metpy.io import parse_metar_file
from metpy.plots.declarative import *
from metpy.units import units
import requests
# Set the time from the computer
now = datetime.utcnow()
# Use the time variable to set the standard filename using an f-string
file = f'metar_{now:%Y%m%d_%H00}.txt'
# Use the request module to get the file from the web location
myfile = requests.get(f'https://thredds-test.unidata.ucar.edu/thredds/fileServer/'
f'noaaport/text/metar/{file}')
# Save the data to the same filename locally
open(file, 'wb').write(myfile.content)
# Read in metar file that was downloaded locally
df = parse_metar_file(file)
df["tempf"] = (df.air_temperature.values * units.degC).to("degF")
obs = PlotObs()
obs.data = df
obs.time = datetime.utcnow()
obs.time_window = timedelta(minutes=15)
obs.level = None
obs.fields = ["tempf", "dew_point_temperature"]
obs.locations = ["NW", "SW"]
obs.colors = ["tab:red", "tab:green"]
obs.formats = [None, None]
obs.vector_field = ["eastward_wind", "northward_wind"]
panel = MapPanel()
panel.area = "co"
panel.projection = ccrs.PlateCarree()
panel.layers = ["coastline", "borders", "states"]
panel.plots = [obs]
pc = PanelContainer()
pc.size = (15, 15)
pc.panels = [panel] |
Beta Was this translation helpful? Give feedback.
I don't get the error that you got, but I do get a blank map. I think the reason for this error is that it doesn't find the time within this catalog the files are organized from oldest to newest. The selection of
grabs the oldest file (which is about a month before current). The problem is that the newest files are "in the future". Due to errors in the transcription of the data at some point, the latest files are for March 31, 2021 at 23 UTC - clearly in the future as of 4 March 2021 when I am writing this response. We can go about it via another method to get the data you desire, though not through Siphon.
By using the request module, we can construct the web address…