geoclaw.util module of utility functions

This describes new tools added in Clawpack 5.2.1.

Documentation auto-generated from the module docstrings

GeoClaw util Module $CLAW/geoclaw/src/python/geoclaw/util.py

Module provides provides utility functions.

Functions:
  • dms2decimal - Convert (degrees, minutes, seconds) to decimal degrees

  • dist_meters2latlong - Convert dx, dy distance in meters to degrees

  • dist_latlong2meters - Convert dx, dy distance in degrees to meters

  • haversine - Calculate the haversine based great circle distance

  • inv_haversine - Inverts the haversine distance

  • bearing - Compute the bearing from on location to another

  • gctransect - Compute a set of points on the great circle between two points

  • fetch_noaa_tide_data - Fetches water levels and tide predictions

clawpack.geoclaw.util.bearing(x0, y0, x1, y1, units='degrees', bearing_units='degrees')

Compute the bearing from (x0,y0) to (x1,y1), i.e., the angle clockwise from due North of the great circle path from point 0 to 1.

The value returned is thus between 0 and 360 if bearing_units=’degrees’, or between 0 and 2*pi if bearing_units=’radians’.

Note: If using this to initialize a radially-symmetric 2d velocity on the sphere based on a radial velocity U(r), symmetric about (x0, y0), set:

# lat-long assumed to be in degrees, r in meters r = haversine(x0,y0,x,y) beta = bearing(x0,y0,x,y,bearing_units=’radians’) u = U(r) * sin(beta) # beta measured from North! v = U(r) * cos(beta)

clawpack.geoclaw.util.dist_latlong2meters(dx, dy, latitude=0.0)

Convert distance from degrees longitude-latitude to meters.

Takes the distance described by dx and dy in degrees and converts it into distances in meters.

returns (float, float)

clawpack.geoclaw.util.dist_meters2latlong(dx, dy, latitude=0.0)

Convert distance from meters to degrees of longitude-latitude.

Takes the distance described by dx and dy in meters and converts it into distances in the longitudinal and latitudinal directions in degrees.

returns (float, float)

clawpack.geoclaw.util.dms2decimal(d, m, s, coord='N')

Convert coordinates in (degrees, minutes, seconds) to decimal form.

If coord == ‘S’ or coord == ‘W’ then value is negated too.

Example:
>>> topotools.dms2decimal(7,30,36,'W')
-7.51

(Note that you might want to add 360 to resulting W coordinate if using E coordinates everywhere in a computation spanning date line.)

Returns:

float

clawpack.geoclaw.util.fetch_noaa_tide_data(station, begin_date, end_date, time_zone='GMT', datum='STND', units='metric', cache_dir=None, verbose=True)

Fetch water levels and tide predictions at given NOAA tide station.

The data is returned in 6 minute intervals between the specified begin and end dates/times. A complete specification of the NOAA CO-OPS API for Data Retrieval used to fetch the data can be found at:

By default, retrieved data is cached in the geoclaw scratch directory located at:

$CLAW/geoclaw/scratch

Required Arguments:
  • station (string): 7 character station ID

  • begin_date (datetime): start of date/time range of retrieval

  • end_date (datetime): end of date/time range of retrieval

Optional Arguments:
  • time_zone (string): see NOAA API documentation for possible values

  • datum (string): see NOAA API documentation for possible values

  • units (string): see NOAA API documentation for possible values

  • cache_dir (string): alternative directory to use for caching data

  • verbose (bool): whether to output informational messages

Returns:
  • date_time (numpy.ndarray): times corresponding to retrieved data

  • water_level (numpy.ndarray): preliminary or verified water levels

  • prediction (numpy.ndarray): tide predictions

clawpack.geoclaw.util.gctransect(x1, y1, x2, y2, npts, coords='W', units='degrees', Rearth=6367500.0)

Given (longitude,latitude) pairs (x1,y1), (x2,y2) and npts Compute (x,y) for npts equally spaced points on the great circle connecting them.

If coords=’W’ the points will all have -2*pi < x <= 0. If coords=’E’ the points will all have -0 <= x < 2*pi. With continuity at the date line x = pm pi.

Sample usage for 50 points on great circle from Tohoku to Crescent City:

from clawpack.geoclaw import util,kmltools xtrans,ytrans = util.gctransect(142,37,-124.2,41.74,50,’W’) kmltools.transect2kml(xtrans,ytrans) # then open transect.kml to view on Google Earth

Based in part on formulas in

https://math.stackexchange.com/questions/1783746

clawpack.geoclaw.util.haversine(x0, y0, x1=None, y1=None, units='degrees')

x0,y0 is assumed to be a point (or an array with the same shapes as x1,y1) x1,y1 is a point or two arrays of points (of the same dimension) returns array with same shape as x1 and y1 containing distance of each point from (x0,y0).

For backward compatibility, also allows x0,y0 to be 2-tuples specifying two points, but this is not suggested since the notation is not consistent.

clawpack.geoclaw.util.inv_haversine(d, x1, y1, y2, Rsphere=6367500.0, units='degrees')

Invert the Haversine function to find dx given a distance and point.

Invert the haversine function to find dx given distance d and (x1,y1) and y2. The corresponding x2 can be x1+dx or x1-dx. May return NaN if no solution.