rex.utilities.utilities

Collection of helpful functions

Functions

check_eval_str(s)

Check an eval() string for questionable code.

check_res_file(res_file)

Check resource to see if the given path - It belongs to a multi-file handler - Is on local disk - Is a hsds path

check_tz(time_index)

Check datetime index for timezone, if None set to UTC

dict_str_load(dict_str)

Load jsonified string entries into dictionaries using JSON

filename_timestamp(file_name[, time_format])

extract timestamp from file name

get_chunk_ranges(ds_dim, chunk_size)

Create list of chunk slices [(s_i, e_i), ...]

get_class_properties(cls)

Get all class properties Used to check against config keys

get_dtype(col)

Get column dtype for converstion to records array

get_lat_lon_cols(df)

Get columns that contain (latitude, longitude) coordinates

jsonify_dict(di)

Jsonify a dictionary into a string with handling for int/float keys.

mean_irrad(arr)

Calc the annual irradiance at a site given an irradiance timeseries.

parse_date_int(s)

Parse data parameters from an integer or string of format YYYYMMDD

parse_table(table)

Load pandas DataFrame from .csv or .json file or dictionary

parse_timestamp(path[, time_format])

extract timestamp with given format from given path

parse_year(inp[, option])

Attempt to parse a year out of a string.

res_dist_threshold(lat_lons[, tree, margin])

Distance threshold for nearest neighbor searches performed on resource points.

roll_timeseries(arr, timezones)

Roll timeseries from UTC to local time.

row_col_indices(sc_point_gids, row_length)

Convert supply curve point gids to row and col indices given row length

safe_json_load(fpath)

Perform a json file load with better exception handling.

slice_sites(shape, chunks[, sites, ...])

Slice sites into given number of sub-sets with given number of chunks per sub-set

split_sites_list(sites, slice_size)

Split sites into sub-lists of ~ size slice_size

split_sites_slice(sites_slice, n_sites, ...)

Break up sites_slice into slices of size slice_size

str_to_date(s)

Convert a date string of format YYYYMMDD to date object.

str_to_datetime(s)

Convert a date string of format YYYYMMDD to datetime object.

timestamp_format_to_redex(time_format)

convert time stamp format to redex

to_records_array(df)

Convert pandas DataFrame to numpy Records Array

unstupify_path(path)

Utility to create sensical os agnostic paths from relative or local path such as: - ~/file - file - /.

write_json(path, data)

Write data to given json file

Classes

Retry([tries, n_sec])

Retry Decorator to run a function multiple times