getgfs package

Submodules

getgfs.decode module

Decodes the downloaded files to extract the variables and their coordinates

class getgfs.decode.Coordinate(name, values)

Bases: object

Holds the information and values describing a coordinate

class getgfs.decode.File(text)

Bases: object

Holds the variables and information from a text file returned by the forecast site

class getgfs.decode.Variable(name, coords, data)

Bases: object

Holds the information and data for an extracted variable

getgfs.decode.replace_val(arr, val, position)

Inserts a value into a 1 to 4 dimensional numpy array

Note

I am sure there are better ways todo this but I couldn’t find any after quite a search

Args:

arr (numpy array): Array to insert into val (float/int): Value to insert position (tuple): Coordinate position in array

Raises:

TypeError: Position invalid ValueError: Dimensionality of array too high

Returns:

[type]: [description]

getgfs.getgfs module

getgfs - a library for extracting weather forecast variables from the NOAA GFS forecast in a pure python, no obscure dependencies way

class getgfs.getgfs.Forecast(resolution='0p25', timestep='')

Bases: object

Object that can be manipulated to get forecast information

check_avail(forecast_date, forecast_time)
datetime_to_forecast(date_time)

Works out which forecast date/run/time is required for the latest values for a chosen time

Parameters

date_time (string) – The date and time of the desired forecast, parser is used so any format is valid e.g. 20210205 11pm

Raises

ValueError – The date time requested is not available from the NOAA at this time

Returns

forecast date string: forecast run string: forecast query time (the appropriate timestep within the forecast)

Return type

string

get(variables, date_time, lat, lon)

Returns the latest forecast available for the requested date and time

Note

  • “raw” since you have to put indexes in rather than coordinates and it returns a file object rather than a processed file

  • If a variable has level dependance, you get all the levels - it seems extremely hard to impliment otherwise

Args:

variables (list): list of required variables by short name date_time (string): datetime requested (parser used so any format fine) lat (string or number): latitude in the format “[min:max]” or a single value lon (string or number): longitude in the format “[min:max]” or a single value

Raises:

ValueError: Invalid variable choice ValueError: Level dependance needs to be specified for chosen variable Exception: Unknown failure to download the file

Returns:

File Object: File object with the downloaded variable data (see File documentation)

get_windprofile(date_time, lat, lon)

Finds the verticle wind profile for a location. I wrote this since it is what I require in another program. The U/V compoents of wind with sigma do not go down to the surface so the surface components are also included as well as a pressure altitude change of x- variable.

Parameters
  • date_time (string) – datetime requested (parser used so any format fine)

  • lat (string or number) – Latitude for data

  • lon (string or number) – Longitude for data

Returns

U component of wind interpolater by altitude interpolation object: V component of wind interpolater by altitude

Return type

interpolation object

search(variable, sensetivity=80)

The short names of the forecast variables are nonsence so this can be used to find the short name (used for the rest of the forecast) that you are looking for

Note

Will not work if fuzzywuzzy is not installed

Args:

variable (string): Search terms for the variable (e.g. U-Component wind) sensetivity (int, optional): The search sensitivity, for common words a higher sensitivity may be required. Defaults to 80.

Raises:

RuntimeError: Fuzzywuzzy not installed

Returns:

list: List of possible matches sorted by ratio, short name (what you need) and long name also given

value_input_to_index(coord, inpt)

Turns a chosen value of a coordinate/coordinate range to the index in the forecast array

Parameters
  • coord (string) – The short name of the coordinate to convert

  • inpt (float/str) – The value or range requested, for a range a string in the format [min_val:max_val] is required

Raises

ValueError – Incorrect inpt format

Returns

Index of coordinate value(s) as the forecast requires it (i.e. within [])

Return type

str

value_to_index(coord, value)

Turns a coordinate value into the index in the forecast array

Parameters
  • coord (string) – The short name of the coordinate to convert

  • inpt (float/str) – The value requested

Returns

Index in array

Return type

int

getgfs.getgfs.extract_line(possibles, line)

Works out what is being refered to by a line in the das and dds pages for the forecast

Parameters
  • possibles (list) – Possible titles

  • line (string) – Line to search

Returns

Index of the attribute

Return type

int

getgfs.getgfs.get_attributes(res, step)

Finds the available variables and coordinates for a given forecast

Parameters
  • res (str, optional) – The forecast resulution, choices are 1p00, 0p50 and 0p25. Defaults to “0p25”.

  • step (str, optional) – The timestep of the forecast to use, most do not have a choice but 0p25 can be 3hr (default) or 1hr. Defaults to “”.

Raises
  • Exception – Failed to download the requested resolution and forecast

  • RuntimeError – Failed to download the other attributes

Returns

Time attributes (the number of timesteps and the size of the timesteps) dict: Coordinates for the forecast with their short name, number of steps, min, max, resolution dict: Variables with all the information about them

Return type

dict

getgfs.getgfs.hour_round(t)

Rounds to the nearest hour for a datetime object

Parameters

t (datetime) – Datetime to round

Returns

Rounded datetime

Return type

datetime

getgfs.test module

class getgfs.test.Decode(methodName='runTest')

Bases: TestCase

test_data()
test_variables()
class getgfs.test.TestBasics(methodName='runTest')

Bases: TestCase

test_attribute()
test_folders()

Module contents