fgout_tools module for working with fgout grids

Documentation auto-generated from the module docstrings

fgout_tools module: $CLAW/geoclaw/src/python/geoclaw/fgout_tools.py

Tools to specify and work with fgout grids, used to output GeoClaw solutions on a fixed grid at a sequence of times, regardless of the AMR structure.

Includes:

  • class FGoutFrame: used to hold a single frame of fgout output data

  • class FGoutGrid: used to specify and store info about an fgout grid, with

    methods to read and write info to fgout_grids.data

  • function make_fgout_fcn_xy: Takes an FGoutFrame object and produces an

    interpolating function that can be evaluated for any (x,y).

  • function make_fgout_fcn_xyt: Takes 2 FGoutFrame objects and produces an

    interpolating function that can be evaluated for any (x,y,t) at intermediate times.

  • function write_netcdf: Write a specified set of qoi’s from a list of

    fgout frames, as a single netCDF file

  • function read_netcdf: Read a netCDF file and return a list of fgout frames,

    assuming the file contains all the qoi’s needed to reconstruct q.

  • function read_netcdf_arrays: Read a netCDF file and extract the

    requested quantities of interest as numpy arrays.

  • print_netcdf_info: Print info about the contents of a netCDF file containing

    some fgout frames.

class clawpack.geoclaw.fgout_tools.FGoutFrame(fgout_grid, frameno=None)

Class to hold a single frame of fgout data at one output time. Several attributes are defined as properties that can be evaluated and stored only when needed by the user.

property B

topography

property eta

surface eta = h+B

property h

depth

property hss

momentum flux h*s**2

property hu

momentum h*u

property hv

momentum h*v

property s

speed s = sqrt(u**2 + v**2)

property u

speed u, computed as hu/h or set to 0 if h<self.drytol

property v

speed v, computed as hv/h or set to 0 if h<self.drytol

class clawpack.geoclaw.fgout_tools.FGoutGrid(fgno=None, outdir=None, output_format=None)

New class introduced in 5.9.0 to keep store information both about the fgout input data and the output generated by a GeoClaw run.

property X

2D array X of longitudes (cell centers)

property Y

2D array Y of latitudes (cell centers)

property extent_centers

Extent of cell centers [xmin,xmax,ymin,ymax]

property extent_edges

Extent of cell edges [xmin,xmax,ymin,ymax]

read_fgout_grids_data(fgno=None, data_file='fgout_grids.data')

Read input info for fgout grid number fgno from the data file fgout_grids.data, which should have been created by setrun.py. This file now contains info about all fgout grids.

read_frame(frameno)

Read a single frame of fgout data.

set_plotdata()

Create a plotdata, assuming attributes fgno, outdir, output_format have all been set.

write_to_fgout_data(fid)

Convert fgout data specified in setrun.py to file fgout_grids.data read in by GeoClaw fortran code.

property x

1D array x of longitudes (cell centers)

property y

1D array y of latitudes (cell centers)

clawpack.geoclaw.fgout_tools.get_as_array(var, rootgrp, verbose=True)

Utility function to retrieve variable from netCDF file and convert to numpy array.

clawpack.geoclaw.fgout_tools.make_fgout_fcn_xy(fgout, qoi, method='nearest', bounds_error=False, fill_value=nan)

Create a function that can be called at (x,y) and return the qoi interpolated in space from the fgout array.

qoi should be a string (e.g. ‘h’, ‘u’ or ‘v’) corresponding to an attribute of fgout.

The function returned takes arguments x,y that can be floats or (equal length) 1D arrays of values that lie within the spatial extent of fgout.

bounds_error and fill_value determine the behavior if (x,y) is not in the bounds of the data, as in scipy.interpolate.RegularGridInterpolator.

clawpack.geoclaw.fgout_tools.make_fgout_fcn_xyt(fgout1, fgout2, qoi, method_xy='nearest', method_t='linear', bounds_error=False, fill_value=nan)

Create a function that can be called at (x,y,t) and return the qoi interpolated in space and time between the two frames fgout1 and fgout2.

qoi should be a string (e.g. ‘h’, ‘u’ or ‘v’) corresponding to an attribute of fgout.

method_xy is the method used in creating the spatial interpolator, and is passed to make_fgout_fcn_xy.

method_t is the method used for interpolation in time, currently only ‘linear’ is supported, which linearly interpolates.

bounds_error and fill_value determine the behavior if (x,y,t) is not in the bounds of the data.

The function returned takes arguments x,y (floats or equal-length 1D arrays) of values that lie within the spatial extent of fgout1, fgout2 (which are assumed to cover the same uniform grid at different times) and t should be a float that lies between fgout1.t and fgout2.t.

clawpack.geoclaw.fgout_tools.print_netcdf_info(fname_nc)

Print out info about the contents of a netCDF file contining fgout frames, written using write_netcdf.

clawpack.geoclaw.fgout_tools.read_netcdf(fname_nc, fgout_grid=None, verbose=True)

Read a netCDF file and return a list of FGoutFrame instances. This will only be possible if the netCDF file contains at least the qoi’s ‘h’,’hu’,’hv’,’eta’ required to reconstruct the q array as output by GeoClaw.

clawpack.geoclaw.fgout_tools.read_netcdf_arrays(fname_nc, qois, verbose=True)

Read a netCDF file and extract the quantities of interest denoted by strings in the list qois, which can include:

‘h’, ‘eta’, ‘hu’, ‘hv’, ‘u’, ‘v’, ‘s’, ‘hss’, ‘B’.

qois can also include the time-independent ‘B0’ and/or ‘Bfinal’

Returns

x, y, t, qoi_arrays

where x,y define the longitude, latitudes, t is the times of the frames, and qoi_arrays is a dictionary indexed by the strings from qois.

Each dict element is an array with shape (len(t), len(x), len(y)) for time-dependent qoi’s, or (len(x), len(y)) for B0 or Bfinal, or None if that qoi was not found in the netCDF file.

clawpack.geoclaw.fgout_tools.write_netcdf(fgout_frames, fname_nc='fgout_frames.nc', qois=['h', 'hu', 'hv', 'eta'], datatype='f4', include_B0=False, include_Bfinal=False, description='', verbose=True)

Write a list of fgout frames (at different times on the same rectangular grid) to a single netCDF file, with some metadata and the topography, if desired.

fgout_frames should be a list of FGoutFrame objects, all of the same size and at increasing times.

fname_nc is the name of the file to write.

qois is a list of strings, the quantities of interest to include in file.

This could include any of:

‘h’, ‘eta’, ‘hu’, ‘hv’, ‘u’, ‘v’, ‘s’, ‘hss’, ‘B’.

All other quantities can be computed from h, hu, hv, eta, the original fgout variables from GeoClaw, but for some applications you might only want to save ‘h’ and ‘s’, for example.

datatype should be ‘f4’ [default] or ‘f8’, specifying bytes per qoi value.

‘f8’ has full precision of the original data, but the file will be twice as large and may not be needed for downstream applications.

Note that the topography B = eta - h, so it is not necessary to store all three of these. Also, B is often the same for all frames, so rather than storing B at each frame as a qoi, two other options are also provided (and then storing eta or h for all frames allows calculating the other):

include_Bfinal: If True, include the topography B array from the final frame as the Bfinal array.

include_B0: If True, include the topography B array from the first frame as the B0 array. This is only useful if, e.g., the first frame is initial topography before co-seismic deformation, and at later times the topography is always equal to Bfinal.

description is a string that will be added as metadata. A metadata field history will also be added, which includes the time the file was created and the path to the directory where it was made.