From 23ca9aea77a5f2bf26652508cdf8ebe0e441a60a Mon Sep 17 00:00:00 2001 From: SeyyedMohammadAmin Mousavi Date: Sun, 26 Jun 2022 17:45:34 +0430 Subject: [PATCH 1/3] Update getgfs.py --- getgfs/getgfs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getgfs/getgfs.py b/getgfs/getgfs.py index a3b61da..6aef47c 100644 --- a/getgfs/getgfs.py +++ b/getgfs/getgfs.py @@ -256,8 +256,8 @@ def value_input_to_index(self, coord, inpt): """ if isinstance(inpt, str): if inpt[0] == "[" and inpt[-1] == "]" and ":" in inpt: - val_1 = float(re.findall(r"\[(.*?):", inpt)) - val_2 = float(re.findall(r"\:(.*?)]", inpt)) + val_1 = float(re.findall(r"\[(.*?):", inpt)[0]) + val_2 = float(re.findall(r"\:(.*?)]", inpt)[0]) val_min = self.value_to_index(coord, min(val_1, val_2)) val_max = self.value_to_index(coord, max(val_1, val_2)) ind = "[%s:%s]" % (val_min, val_max) From ac87d8e62a24d6af8d498f710baef46e0f5222a8 Mon Sep 17 00:00:00 2001 From: Jago Date: Mon, 4 Jul 2022 16:21:08 +0100 Subject: [PATCH 2/3] messy solution to issue #3 --- getgfs/getgfs.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/getgfs/getgfs.py b/getgfs/getgfs.py index 6aef47c..7901a31 100644 --- a/getgfs/getgfs.py +++ b/getgfs/getgfs.py @@ -258,6 +258,9 @@ def value_input_to_index(self, coord, inpt): if inpt[0] == "[" and inpt[-1] == "]" and ":" in inpt: val_1 = float(re.findall(r"\[(.*?):", inpt)[0]) val_2 = float(re.findall(r"\:(.*?)]", inpt)[0]) + if coord == "lon": + val_1 = val_1 % 360 + val_2 = val_2 % 360 val_min = self.value_to_index(coord, min(val_1, val_2)) val_max = self.value_to_index(coord, max(val_1, val_2)) ind = "[%s:%s]" % (val_min, val_max) @@ -269,8 +272,12 @@ def value_input_to_index(self, coord, inpt): "The format of the %s variable was incorrect, it must either be a single number or a range in the format [min:max]. You entered '%s'" % (coord, inpt) ) + if coord == "lon": + inpt = inpt % 360 ind = "[%s]" % self.value_to_index(coord, inpt) else: + if coord == "lon": + inpt = inpt % 360 ind = "[%s]" % self.value_to_index(coord, inpt) return ind From a81f3136c48f743b375067f746fa10440c2f0570 Mon Sep 17 00:00:00 2001 From: Jago Date: Mon, 4 Jul 2022 16:42:27 +0100 Subject: [PATCH 3/3] added check that forecast has been released, solves issue #1 --- getgfs/getgfs.py | 20 ++++++++++++++++++++ setup.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/getgfs/getgfs.py b/getgfs/getgfs.py index 7901a31..6f13ca0 100644 --- a/getgfs/getgfs.py +++ b/getgfs/getgfs.py @@ -185,6 +185,21 @@ def get(self, variables, date_time, lat, lon): else: return File(r.text) + def check_avail(self, forecast_date, forecast_time): + r = requests.get( + url.format( + res=self.resolution, + step=self.timestep, + date=forecast_date, + hour=int(forecast_time), + info="ascii?gustsfc[0][540][1260]", + ) + ) + if r.text[:6] == "": + return False + else: + return True + def datetime_to_forecast(self, date_time): """Works out which forecast date/run/time is required for the latest values for a chosen time @@ -223,6 +238,11 @@ def datetime_to_forecast(self, date_time): forecast_date = query_forecast.strftime("%Y%m%d") forecast_time = query_forecast.strftime("%H") + while not self.check_avail(forecast_date, forecast_time): + query_forecast -= timedelta(hours=6) + forecast_date = query_forecast.strftime("%Y%m%d") + forecast_time = query_forecast.strftime("%H") + query_time = "[{t_ind}]".format( t_ind=round( (desired_date - query_forecast).seconds diff --git a/setup.py b/setup.py index cf0af63..9566378 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ url="https://getgfs.readthedocs.io/", # license="LICENSE.txt", - description="getgfs extracts weather forecast variables from the NOAA GFS forecast with no obscure depdndencies (looking at you ecCodes)", + description="getgfs extracts weather forecast variables from the NOAA GFS forecast", # Dependent packages (distributions) install_requires=[ "scipy",