Difference between revisions of "UCVM API"

From SCECpedia
Jump to navigationJump to search
 
(38 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
= Overview =
 
= Overview =
  
The Unified California Velocity Model API (UCVM API) is a programming interface that allows the user to directly
+
The Unified California Velocity Model API (UCVM API) is a programming interface that allows the user to directly query multiple velocity models in a program.  
query multiple velocity models in a program. The API currently support these models:
 
  
* CVM-S
+
This document has been superseded by the [[UCVM User Guide]].
* CVM-H
 
* USGS Central California
 
* Hadley-Kanamori 1D
 
  
 +
This page now remains as a collection point for outstanding science issues. Significant science issues remain to be resolved. Please see the Science Issues section below.
  
= API =
 
  
 +
= Source Code =
  
== Data Types and Definitions ==
+
The UCVM source and cvm2mesh mesh generator may be checked out from SVN with these commands:
  
<pre>
+
UCVM: svn co https://source.usc.edu/svn/ucvm/trunk
/* Maximum number of supported models */
 
#define UCVM_MAX_MODELS 10
 
  
/* Maximum projection description length */
+
cvm2mesh: svn co https://source.usc.edu/svn/cvm2mesh/trunk
#define UCVM_MAX_PROJ_LEN 256
 
  
/* Maximum model label length */
 
#define UCVM_MAX_LABEL_LEN 64
 
 
/* Maximum model version length */
 
#define UCVM_MAX_VERSION_LEN 64
 
 
/* Maximum path length */
 
#define UCVM_MAX_PATH_LEN 256
 
 
/* NO CVM flag */
 
#define UCVM_MODEL_NONE -1
 
 
/* Supported error codes */
 
typedef enum { UCVM_CODE_SUCCESS = 0,
 
              UCVM_CODE_ERROR,
 
              UCVM_CODE_DATAGAP,
 
              UCVM_CODE_NODATA} ucvm_code_t;
 
 
/* Supported coordinate query modes */
 
typedef enum { UCVM_COORD_GEO_DEPTH = 0,
 
              UCVM_COORD_UTM_DEPTH,
 
              UCVM_COORD_GEO_ELEV,
 
              UCVM_COORD_UTM_ELEV } ucvm_ctype_t;
 
 
/* Supported grid types */
 
typedef enum { UCVM_GRID_CELL_CENTER = 0,
 
              UCVM_GRID_CELL_VERTEX} ucvm_gtype_t;
 
 
/* 3D point */
 
typedef struct ucvm_point_t
 
{
 
  double coord[3];
 
} ucvm_point_t;
 
 
/* 3D dims */
 
typedef struct ucvm_dim_t
 
{
 
  int dim[3];
 
} ucvm_dim_t;
 
 
/* Material properties */
 
typedef struct ucvm_prop_t
 
{
 
  int model;
 
  double vp;
 
  double vs;
 
  double rho;
 
} ucvm_prop_t;
 
 
/* Region box */
 
typedef struct ucvm_region_t
 
{
 
  ucvm_ctype_t cmode;
 
  double p1[3];
 
  double p2[3];
 
} ucvm_region_t;
 
 
/* Projection */
 
typedef struct ucvm_proj_t
 
{
 
  char proj[UCVM_MAX_PROJ_LEN];
 
} ucvm_proj_t;
 
 
/* Projection transformation */
 
typedef struct ucvm_trans_t
 
{
 
  double origin[3];
 
  double rotate;
 
  double translate[3];
 
  ucvm_gtype_t gtype;
 
} ucvm_trans_t;
 
 
/* Model */
 
typedef struct ucvm_model_t
 
{
 
  char label[UCVM_MAX_LABEL_LEN];
 
  ucvm_region_t region;
 
  char config[UCVM_MAX_PATH_LEN];
 
  int (*init)(int id, ucvm_region_t *r, const char *config);
 
  int (*finalize)();
 
  const char* (*version)();
 
  int (*query)(ucvm_ctype_t cmode,
 
              int n, ucvm_point_t *pnt,
 
              ucvm_prop_t *prop);
 
} ucvm_model_t;
 
</pre>
 
 
 
== UCVM Interface ==
 
 
Provides an interface for querying Vp, Vs, and rho from any supported model.
 
 
<pre>
 
/* Initializer */
 
int ucvm_init(const char *config);
 
 
/* Finalizer */
 
int ucvm_finalize();
 
 
/* Set query mode */
 
int ucvm_query_mode(ucvm_ctype_t c);
 
 
/* Enable specific model, return new model id */
 
int ucvm_add_model(ucvm_model_t *m, int *id);
 
 
/* Get label for a model */
 
int ucvm_model_label(int m, char *label, int len);
 
 
/* Get version for a model */
 
int ucvm_model_version(int m, char *ver, int len);
 
 
/* Get model id from a label */
 
int ucvm_model_id(const char *label, int *id);
 
 
/* Query underlying models */
 
int ucvm_query(int n, ucvm_point_t *pnt, ucvm_prop_t *prop);
 
</pre>
 
 
 
Pre-defined model constructors are provided for CVM-S, CVM-H, CenCal, and 1D. To use these constructors, include the appropriate header file listed below in your code, link the UCVM libucvm_*.a library file for that model, and call the appropriate <code>ucvm_*_get_model()</code> function with an empty model structure. The filled-in ucvm_model_t structure may then be passed into <code>ucvm_add_model()</code> to enable that model.
 
 
<pre>
 
  /include/ucvm_cvms.h:
 
 
  /* Fill model m struct with CVM-S configuration */
 
  ucvm_cvms_get_model(ucvm_model_t *m);
 
 
  /include/ucvm_cvmh.h:
 
 
  /* Fill model m struct with CVM-H configuration */
 
  ucvm_cvmh_get_model(ucvm_model_t *m);
 
 
  /include/ucvm_cencal.h:
 
 
  /* Fill model m struct with CenCal configuration */
 
  ucvm_cencal_get_model(ucvm_model_t *m);
 
 
  /include/ucvm_1d.h:
 
 
  /* Fill model m struct with 1D configuration */
 
  ucvm_1d_get_model(ucvm_model_t *m);
 
</pre>
 
 
The programmer may easily define their own constructors by creating a C source wrapper that defines init(), finalize(), version(), and query() functions for their model, and a ucvm_*_get_model() function for populating a new ucvm_model_t structure with the model information.
 
 
 
== UCVM Grid Interface ==
 
 
Provides an interface for generating 2D regular grids in any USGS map projection.
 
 
<pre>
 
/* Generate grid from projection and dimensions */
 
int ucvm_grid_gen(ucvm_proj_t *iproj, ucvm_trans_t *trans,
 
                  ucvm_proj_t *oproj,
 
                  ucvm_dim_t *dims, double spacing,
 
                  ucvm_point_t *pnts);
 
 
/* Generate grid from projection and dimensions */
 
int ucvm_grid_gen_file(ucvm_proj_t *iproj, ucvm_trans_t *trans,
 
                      ucvm_proj_t *oproj,
 
                      ucvm_dim_t *dims, double spacing,
 
                      const char *filename);
 
 
/* Convert point list from one projection to another */
 
int ucvm_grid_convert(ucvm_proj_t *iproj,
 
                      ucvm_proj_t *oproj,
 
                      size_t n, ucvm_point_t *pnts);
 
 
/* Convert point list from one projection to another */
 
int ucvm_grid_convert_file(ucvm_proj_t *iproj,
 
                          ucvm_proj_t *oproj,
 
                          size_t n, const char *filename);
 
 
</pre>
 
 
 
= Example Usage of API =
 
 
The following code snippet illustrates how the API is used:
 
 
<pre>
 
  int i;
 
  int nn = NUM_POINTS;
 
  ucvm_point_t *pnt1;
 
  ucvm_prop_t *prop1;
 
 
 
  int num_models;
 
  ucvm_model_t models[UCVM_MAX_MODELS];
 
  int model_ids[UCVM_MAX_MODELS];
 
 
  printf("Init\n");
 
  if (ucvm_init("./ucvm.conf") != UCVM_CODE_SUCCESS) {
 
    fprintf(stderr, "Init failed\n");
 
    return(1);
 
  }
 
 
 
  printf("Query Mode\n");
 
  if (ucvm_query_mode(UCVM_COORD_GEO_DEPTH) != UCVM_CODE_SUCCESS) {
 
    fprintf(stderr, "Set query mode failed\n");
 
    return(1);
 
  }
 
 
 
  printf("Get Model\n");
 
  if (ucvm_cvms_get_model(&(models[0])) != UCVM_CODE_SUCCESS) {
 
    fprintf(stderr, "Retrieval of CVM-S failed\n");
 
    return(1);
 
  }
 
 
  if (ucvm_add_model(&(models[0]), &(model_ids[0])) != UCVM_CODE_SUCCESS) {
 
    fprintf(stderr, "Enable CVM-S failed\n");
 
    return(1);
 
  }
 
 
  printf("Create points\n");
 
  for (i = 0; i < NUM_POINTS; i++) {
 
    pnt1[i].coord[0] = -119.0;
 
    pnt1[i].coord[1] = 31.0;
 
    pnt1[i].coord[2] = 2000.0;
 
  }
 
 
  printf("Query Models\n");
 
  if (ucvm_query(nn, pnt1, prop1) != UCVM_CODE_SUCCESS) {
 
    fprintf(stderr, "Query CVM failed\n");
 
    return(1);
 
  }
 
 
  printf("Results\n");
 
  for (i = 0; i < NUM_POINTS; i++) {
 
    printf("%d: model=%d, vp=%lf, vs=%lf, rho=%lf\n", i,
 
          prop1[i].model, prop1[i].vp, prop1[i].vs, prop1[i].rho);
 
  }
 
</pre>
 
 
  
 
= Implementation Details =
 
= Implementation Details =
  
 
* Models are queried in the order they are enabled in the interface. The material properties for a particular (lon,lat) point are from the first model in the ordered list to return valid values.
 
* Models are queried in the order they are enabled in the interface. The material properties for a particular (lon,lat) point are from the first model in the ordered list to return valid values.
* Only lon,lat,dep coordinates are currently supported
+
* Only lon,lat,dep and lon,lat,elev coordinates are currently supported
* No smoothing between models is performed. They are simply tiled.
+
* No smoothing between crustal models is performed. They are simply tiled.
 
* Projections are performed with the Proj.4 package
 
* Projections are performed with the Proj.4 package
 +
* Depth is defined as the offset from the free surface (ground/air interface, ground/water interface) in meters, positive down. Negative depths are not supported. Elevation is defined as meters offset from MSL, positive up.
  
  
 
= Future Improvements =
 
= Future Improvements =
  
* Addition of a high resolution state-wide DEM to allow query by elevation
 
 
* Addition of other regional models
 
* Addition of other regional models
* Addition of one or more GTLs
+
* Addition of other GTLs
 +
* Addition of other DEMs, VS30 maps
 +
* Bindings for Fortran, C++
 +
 
  
 
 
= Science Issues =
 
= Science Issues =
  
Line 298: Line 61:
  
 
All models that support query by elevation should use a standard DEM derived from the same source.
 
All models that support query by elevation should use a standard DEM derived from the same source.
 +
 +
 +
== Standardized Handling of Depth ==
 +
 +
Depth can be defined in a number of ways, with a reference point that is the ground/water interface or water/air interface or MSL, and positive down versus positive up. In fact, different regional models do define it differently. CVM-S/CVM-H defines depth as distance from ground/air interface, positive down, negative depths not supported. The USGS Bay Are model (cencalvm) defines depth as disance from the ground/air and water/air interface, positive up. The LinThurber model defines depth as offset from MSL, positive up. UCVM currently defines depth in the CVM-S convention and enforces this definition on the models by modifying how they are queried if necessary.
  
  

Latest revision as of 19:47, 19 August 2011

Overview

The Unified California Velocity Model API (UCVM API) is a programming interface that allows the user to directly query multiple velocity models in a program.

This document has been superseded by the UCVM User Guide.

This page now remains as a collection point for outstanding science issues. Significant science issues remain to be resolved. Please see the Science Issues section below.


Source Code

The UCVM source and cvm2mesh mesh generator may be checked out from SVN with these commands:

UCVM: svn co https://source.usc.edu/svn/ucvm/trunk
cvm2mesh: svn co https://source.usc.edu/svn/cvm2mesh/trunk


Implementation Details

  • Models are queried in the order they are enabled in the interface. The material properties for a particular (lon,lat) point are from the first model in the ordered list to return valid values.
  • Only lon,lat,dep and lon,lat,elev coordinates are currently supported
  • No smoothing between crustal models is performed. They are simply tiled.
  • Projections are performed with the Proj.4 package
  • Depth is defined as the offset from the free surface (ground/air interface, ground/water interface) in meters, positive down. Negative depths are not supported. Elevation is defined as meters offset from MSL, positive up.


Future Improvements

  • Addition of other regional models
  • Addition of other GTLs
  • Addition of other DEMs, VS30 maps
  • Bindings for Fortran, C++


Science Issues

Overlapping Models

Imagine the scenario outlined below, where the user wishes to combine two models, a SoCal model and a NoCal model:

State-wide-Overlapping-Models.png

The models may overlap in ways which makes merging them difficult.

  • For a point that falls within the Kern County region, simply interpolating between the two models may not work if NoCal reports water properties (vp, rho, no vs) and the SoCal model reports soil/rock. No interpolation is possible in this case. To deal with this situation, there are several options:
    • Coordinate edits to each model to bring their material properties into better agreement within the overlap region.
    • Crop one or both models to remove the overlap, and smooth them into the California background model.
    • Create a new “Transition Model” that covers Kern County and surrounding area that interpolates/averages the the two other models in a scientifically acceptable way. Register this new model in the API, and give it priority over the other two models. In effect, tile the Transition Model, the NoCal Model, and the SoCal Model.
    • Allow the models to overlap with discontinuities. This is currently how the UCVM API handles overlap.


Projection Distortion

Several issues with map projections come into play:

  • Distortion in projections on large scales. Any state-wide model that supports querying by UTM or other projection coordinates must account for and minimize distortion.
  • Inconsistent handling of projections within models. Each model generally has its own internal projection. For example, CVM-H uses a UTM projection. The projection codes used across all models should be standardized on the Proj.4 projection package to avoid small differences in the handling of coordinates. This may require resampling of the data inside the models.


Standardized Handling of Elevation

All models that support query by elevation should use a standard DEM derived from the same source.


Standardized Handling of Depth

Depth can be defined in a number of ways, with a reference point that is the ground/water interface or water/air interface or MSL, and positive down versus positive up. In fact, different regional models do define it differently. CVM-S/CVM-H defines depth as distance from ground/air interface, positive down, negative depths not supported. The USGS Bay Are model (cencalvm) defines depth as disance from the ground/air and water/air interface, positive up. The LinThurber model defines depth as offset from MSL, positive up. UCVM currently defines depth in the CVM-S convention and enforces this definition on the models by modifying how they are queried if necessary.


GTL

If a state-wide GTL is developed, the GTL within each underlying model must be stripped away.