WEM.utils package

Submodules

WEM.utils.GIS_tools module

WEM.utils.GIS_tools.TimeSfcLatLon(nc, varlist, times, latslons='all')
WEM.utils.GIS_tools.WRFterrain(fileselection='control', dom=1)
WEM.utils.GIS_tools.WRFterrain_P(fileselection='control', dom=1, slice=0)
WEM.utils.GIS_tools.check_vertical_coordinate(level)

Check to see what type of level is requested by user.

WEM.utils.GIS_tools.closest(arr, val)

Find index of closest value. Only working on 1D array right now.

Inputs: val : required value arr : array of values

Output:

idx : index of closest value

WEM.utils.GIS_tools.combine_wind_components(u, v)
WEM.utils.GIS_tools.convert_kt2ms(wspd)
WEM.utils.GIS_tools.convert_tuple_to_dntimes(times)

Convert tuple or tuple of tuples to datenum date format.

WEM.utils.GIS_tools.csvprocess(data, names, convert=0)
WEM.utils.GIS_tools.datetime_to_timetuple(utc)
WEM.utils.GIS_tools.decompose_wind(wspd, wdir, convert=0)
WEM.utils.GIS_tools.determine_model(fname)

Return model depending on naming convention.

If no model exists, return false.

WEM.utils.GIS_tools.dewpoint(T, RH)
WEM.utils.GIS_tools.dstack_loop(data, obj)

Tries to stack numpy array (data) into ‘stack’ object (obj). If obj doesn’t exist, then initialise it If obj does exist, stack data.

WEM.utils.GIS_tools.dstack_loop_v2(data, obj)

Need to set obj = 0 at start of loop in master script

Tries to stack numpy array (data) into ‘stack’ object (obj). If obj doesn’t exist, then initialise it If obj does exist, stack data.

WEM.utils.GIS_tools.ensure_datenum(times, fmt='int')

Make sure times are in list-of-datenums format. If not, convert them.

Possibilities: times = 123456 #1 times = (123456,) #2 times = (123456,234567) #3 times = (2011,12,1,18,0,0) #4 times = ((2011,12,1,18,0,0),(2011,12,2,6,0,0)) #5

fmt : whether to return list of integers or an integer
‘int’ or ‘list’

Output: dntimes = (123456,) or (123456,234567)

WEM.utils.GIS_tools.ensure_timetuple(times, fmt='single')

MAke sure time(s) are in six-item tuple format (YYYY,MM,DD,HH,MM,SS)

fmt : whether to return a list of tuples or single tuple.
‘list’ or ‘single’

Possibilities: times = 123456 #1 times = (123456,) #2 times = (123456,234567) #3 times = (2011,12,1,18,0,0) #4 times = ((2011,12,1,18,0,0),(2011,12,2,6,0,0)) #5

WEM.utils.GIS_tools.find_time_index(wrftime, reqtimetuple, tupleformat=1)
WEM.utils.GIS_tools.generate_colours(M, n)

M : Matplotlib instance n : number of colours you want

Returns

Usage: when cycling over n plots, the colour should be colourlist[n].

WEM.utils.GIS_tools.generate_times(idate, fdate, interval)
Parameters:
  • itime (list,tuple) – Start date/time. Format is YYYY,MM,DD,HH,MM,SS (calendar.timegm).
  • ftime (list,tuple) – End date/time. Same format as itime.
  • interval (int) – interval between output times, in seconds.
Returns:

list of times in datenum format.

WEM.utils.GIS_tools.getXY(lats, lons, ptlat, ptlon)

Output is lat, lon so y,x

WEM.utils.GIS_tools.get_cross_section(Alat, Alon, Blat, Blon)
WEM.utils.GIS_tools.get_level_naming(va, lv, **kwargs)
WEM.utils.GIS_tools.get_map(Nlim, Elim, Slim, Wlim)
WEM.utils.GIS_tools.get_netcdf_naming(model, t, dom=0)

By default: wrfout files don’t have an extension other files have .nc extension (convert first)

WEM.utils.GIS_tools.get_sequence(x, sos=0)

Returns a sequence (tuple or list) for iteration. Avoids an error for strings/integers. SoS = 1 enables the check for a sequence of sequences (list of dates)

WEM.utils.GIS_tools.gettopo()
WEM.utils.GIS_tools.haversine_baker(lon1, lat1, lon2, lat2, radians=False, earth_rad=6371.227)

Allows to calculate geographical distance using the haversine formula. :param lon1: longitude of the first set of locations :type lon1: numpy.ndarray :param lat1: latitude of the frist set of locations :type lat1: numpy.ndarray :param lon2: longitude of the second set of locations :type lon2: numpy.float64 :param lat2: latitude of the second set of locations :type lat2: numpy.float64 :keyword radians: states if locations are given in terms of radians :type radians: bool :keyword earth_rad: radius of the earth in km :type earth_rad: float :returns: geographical distance in km :rtype: numpy.ndarray

WEM.utils.GIS_tools.hgt_from_sigma(nc)
WEM.utils.GIS_tools.interp2point(data, lat_loc, lon_loc, lat, lon, lvidx=0, xyidx=False)
WEM.utils.GIS_tools.interp_latlon(data, lat, lon, lats, lons)
WEM.utils.GIS_tools.latlon_1D(nc)
WEM.utils.GIS_tools.load_data(folder, fname, format='pickle')

Load array from file.

WEM.utils.GIS_tools.lookup_time(str)
WEM.utils.GIS_tools.mkloop(dom='d03', fpath='./')
WEM.utils.GIS_tools.netcdf_files_in(folder, dom=1, init_time=0, model='auto', return_model=False)

Hunt through given folder to find the right netcdf file for data.

Inputs: folder : Absolute path to directory dom : specify domain. None specified if zero. init_time : initialisation time. Can be tuple or datenum.

If zero, then folder must contain one unambiguous file.
model : Default: automatically detect the type of netcdf file
(RUC data, wrfout file, etc)

Returns: ncpath : Absolute path to file model : Model (RUC, WRF) of netcdf file,

if return_model is True and model is ‘auto’.
WEM.utils.GIS_tools.p_interpol(dom, var, ncfolder, datestr)
WEM.utils.GIS_tools.padded_times(timeseq)
WEM.utils.GIS_tools.return_subdomain(data, lats, lons, Nlim, Elim, Slim, Wlim, fmt='latlon')

Returns smaller domain of data and lats/lons based on specified limits.

WEM.utils.GIS_tools.save_data(data, folder, fname, format='pickle')

Save array to file.

WEM.utils.GIS_tools.string_from_time(usage, t, dom=0, strlen=0, conven=0, **kwargs)

conven : convection of MM/DD versus DD/MM

WEM.utils.GIS_tools.thinned_barbs(pres)
WEM.utils.GIS_tools.trycreate(loc)
WEM.utils.GIS_tools.vstack_loop(data, obj)

Need to set obj = 0 at start of loop in master script

Tries to stack numpy array (data) into ‘stack’ object (obj). If obj doesn’t exist, then initialise it If obj does exist, stack data.

WEM.utils.GIS_tools.wrf_nc_load(dom, var, ncfolder, datestr, thin, Nlim=0, Elim=0, Slim=0, Wlim=0)
WEM.utils.GIS_tools.wrfout_files_in(folders, dom=0, init_time='notset', descend=1, avoid=0, unambiguous=0)

Hunt through given folder(s) to find all occurrences of wrfout files.

Inputs: folders : list of absolute paths to directories dom : specify domain. None specified if zero. init_time : tuple of initialisation time descend : boolean: go into subfolders avoid : string of filenames. if a subfolder contains

the string, do not descend into this one.
unambiguous : only return a single absolute path, else throw
an Exception.

Returns: wrfouts : list of absolute paths to wrfout files

WEM.utils.GIS_tools.xs_distance(Alat, Alon, Blat, Blon)

WEM.utils.getdata module

WEM.utils.getdata.RUC_URL(utc)

Returns URL to download RUC file from nomads.

WEM.utils.getdata.RUC_fname(utc, filetype='grib')

Returns RUC filename for date.

WEM.utils.getdata.RUC_version(utc, fname=False, URL=False)

Returns the version/fname of RUC file

WEM.utils.getdata.getgefs(dates, download=1, split=1, lowres=0, custom_ens=0, control=1, coord='latlon')

This script downloads all variables for GEFS R2 reforecasts. All runs are initialised at 0000 UTC.

Inputs (all optional unless stated): dates : YYYYMMDD, list of strings (mandatory) download : whether to download the data split : whether to split up the data lowres : whether to download times after T+190 custom_ens : a custom list of perturbation ensemble members control : whether to download the control member coord : latlon/gaussian grid

WEM.utils.getdata.getgfs(dates, hours)

Downloads GFS analysis data.

Inputs: dates : List of strings, YYYYMMDD hours : List of strings, HH

WEM.utils.getdata.getnam(dates, hours, datatype, **kwargs)

Downloads NAM analysis and forecast data.

Inputs: dates : List of strings, YYYYMMDD hours : List of strings, HH datatype : analysis or forecast.

Optional arguments for forecasts via kwargs: tmax : maximum forecast time to download (inclusive) tint : internal (hr) between fetched forecasts

WEM.utils.getdata.getruc(utc, ncpath='./', convert2nc=False, duplicate=False)

WEM.utils.metconstants module

WEM.utils.unix_tools module

Utility scripts to help with directory, file, etc issues

WEM.utils.unix_tools.dir_from_naming(root, *args)

Generate file path from arguments

Inputs: root : file path base args : list of arguments to join as separate folders

WEM.utils.unix_tools.ssh_client(ky, domain, username, password)

Module contents

References these utilities in WEM.utils.