gnome.utilities

__init__.py for the utilities package

a few small things here, ‘cause why not?

Subpackages

Submodules

Package Contents

Functions

convert_longitude(lon[, coord_system])

Convert longitude values to a given coordinate system.

_round_sf_float(x, sigfigs)

round a float to significant figures -- no error checking

round_sf_scalar(x, sigfigs)

round_sf_array(x, sigfigs)

round to a certain number of significant figures

convert_mass_to_mass_or_volume(in_unit, out_unit, ...)

convert a mass unit to either a mass or volume unit

Attributes

div

GetCurrentProcess

gnome.utilities.div
gnome.utilities.convert_longitude(lon, coord_system='-180--180')

Convert longitude values to a given coordinate system.

Options are:

“-180–180”: Negative 180 degrees to 180 degrees

“0–360”: Zero to 360 degrees

Parameters:
  • lon – numpy array-like of longitude values of float type

  • coord_system='-180--180' – options are: {“-180–180”, “0–360”}

NOTE: this function also normalizes so that:

360 converts to 0 -180 converts to 180

It should be safe to call this on any coords – if they are already in the expected format, they will not be changes, except for the normalization above.

gnome.utilities.GetCurrentProcess
gnome.utilities._round_sf_float(x, sigfigs)

round a float to significant figures – no error checking

This uses the “g” format specifier – maybe slow, but robust for the purpose of getting the display what we want.

gnome.utilities.round_sf_scalar(x, sigfigs)
gnome.utilities.round_sf_array(x, sigfigs)

round to a certain number of significant figures

should work on floats and numpy arrays

NOTE: This should be vectorizable, but np.round takes only a scalar value

for number of decimals – you could vectorize the rest of the computation, and then loop for the round, but would that buy anything? (or use np.vectorize)

gnome.utilities.convert_mass_to_mass_or_volume(in_unit, out_unit, density, value)

convert a mass unit to either a mass or volume unit

Parameters:
  • in_unit – units of input, should be a valid mass unit.

  • out_unit – units you want the result in – can be a volume or mass unit

  • density – density to use to convert from mass to volume. has to be kg/m^3

  • value – value (in in_units) you want converted.

ex:

convert_mass_to_mass_or_volume(‘kg’, ‘bbl’, 950, 2000)

convert_mass_to_mass_or_volume(‘lbs’, ‘kg’, 950, 4000)