IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 21, 2005, 3:59:10 PM (21 years ago)
Author:
eugene
Message:

updates for cycle 5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r3069 r3070  
    1 %%% $Id: psLibSDRS.tex,v 1.168 2005-01-20 08:25:55 price Exp $
     1%%% $Id: psLibSDRS.tex,v 1.169 2005-01-22 01:57:42 eugene Exp $
    22\documentclass[panstarrs,spec]{panstarrs}
    33
     
    1111\project{Pan-STARRS Image Processing Pipeline}
    1212\organization{Institute for Astronomy}
    13 \version{10}
     13\version{11}
    1414\docnumber{PSDC-430-007}
    1515
     
    414109 & 2004 Nov 15 & final for cycle 4 \\ \hline
    424210 & 2004 Nov 30 & update for cycle 4 \\
     4311 & 2005 Jan 21 & draft for cycle 5 \\
    4344\RevisionsEnd
    4445
     
    9798search path, PSLib may be used within a program by including the line
    9899\code{#include <pslib.h>} into the C code and linking with
    99 \code{-lpslib}.
     100\code{-lpslib.}
    100101
    101102This document describes the data structures and details the functions
     
    109110principle relevance and VerbPhase describes the operation applied to
    110111that data type.  For example, the function which copies an image (of
    111 type \code{psImage}) is called \code{psImageCopy()}.
     112type \code{psImage}) is called \code{psImageCopy().}
    112113
    113114%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    41934194typedef xmlDocPtr psXMLDoc;
    41944195void psXMLDocFree(psXMLDoc *doc);
    4195 \end{verbatim}.
     4196\end{verbatim}
    41964197
    41974198The next pair of functions convert a \code{psMetadata} data structure
     
    42004201psXMLDoc *psMetadataToXMLDoc(const psMetadata *metadata);
    42014202psMetadata *psXMLDocToMetadata(const psXMLDoc *doc);
    4202 \end{verbatim}.
     4203\end{verbatim}
    42034204
    42044205The next pair of functions loads the data in a named file into a
     
    42084209psXMLDoc *psXMLParseFile(const char *filename);
    42094210int psXMLDocToFile(const psXMLDoc *doc, const char *filename);
    4210 \end{verbatim}.
     4211\end{verbatim}
    42114212
    42124213The next pair of functions accepts a block of memory and parses it
     
    42154216psXMLDoc *psXMLParseMemory(const char *buffer, const int size);
    42164217int psXMLDocToMemory(const psXMLDoc *doc, char *buffer);
    4217 \end{verbatim}.
     4218\end{verbatim}
    42184219
    42194220The next pair of functions read from and write to a file descriptor.
     
    42244225psXMLDoc *psXMLParseFD(int fd);
    42254226int psXMLDocToFD(const psXMLDoc *doc, int fd);
    4226 \end{verbatim}.
     4227\end{verbatim}
     4228
     4229\subsection{Database Functions}
     4230
     4231Many of the applications that PSLib will be used for will require
     4232access to a simple relational database.  PSLib includes generic
     4233database-independent interface mechanisms as part of its API set.  The
     4234most important aspect of PSLib's database support is to abstract as
     4235much database specific complexity as is feasible.  As almost all RDBMS
     4236provide at least a simple transactional model, commit and rollback
     4237support should be provided.
     4238
     4239Currently, only support for MySQL 4.1.x is required but other backends
     4240may be added as options in the future.  As a particular example which
     4241has implications for the database interaction model, support for
     4242SQLite may be required in the future.  Currently, the choice of
     4243backend database interface may be made as a compile option.  Details
     4244of the specified APIs in the discussion below refer to the relevant
     4245MySQL functions.
     4246
     4247Database errors must be trapped and placed onto the psError stack.
     4248The complete error message should be retrieved with the database's
     4249error function.
     4250
     4251\subsubsection{Managing the Database Connection}
     4252
     4253We specify a database handle which carries the information about the
     4254database connection:
     4255
     4256\begin{verbatim}
     4257    typedef struct {
     4258        MYSQL mysql;
     4259    } psDB;
     4260\end{verbatim}
     4261
     4262The following collection of functions provides basic database functionality:
     4263
     4264\begin{verbatim}
     4265    // wraps mysql_init() & mysql_real_connect()
     4266    psDB *psDBInit(const char *host, const char *user, const char *passwd, const char *dbname);
     4267
     4268    // wraps mysql_close()
     4269    void psDBCleanup(psDB *dbh);
     4270
     4271    // wraps mysql_create_db()
     4272    bool psDBCreate(psDB *dbh, const char *dbname);
     4273
     4274    // wraps mysql_select_db()
     4275    bool psDBChange(psDB *dbh, const char *dbname);
     4276
     4277    // wraps mysql_drop_db()
     4278    bool psDBDrop(psDB *dbh, const char *dbname);
     4279\end{verbatim}
     4280
     4281For MySQL support, \code{psDBInit()} wraps \code{mysql_init()} and
     4282\code{mysql_real_connect()} in order to initialize a psDB structure and
     4283establish a database connection.  A null pointer should be returned on
     4284failure.
     4285
     4286When implementing support for SQLite, or other DB which is purely
     4287file-based, the \code{host}, \code{user}, and \code{passwd} arguments
     4288would be ignored while \code{dbname} would specify the path to the
     4289SQLite db file.
     4290
     4291\subsubsection{Interacting with Database Tables}
     4292
     4293The functions in this section perform high level interactions with the
     4294database tables.  All of them should behave ``atomically'' with
     4295respect to the state of the database.  Specifically, all interactions
     4296with the database should be done as a part of a transaction that is
     4297rolled-back on failure and committed only after all queries used by
     4298the API have been run.  In general, this API set attempts to treat a
     4299database table as a 2D matrix where columns can be represented by a
     4300\code{psVector} and rows as a \code{psMetadata} type.  A
     4301\code{psMetadata} collection is also used to define the columns of a
     4302table and as part of the query restrictions.
     4303
     4304\begin{verbatim}
     4305    bool psDBCreateTable(psDB *dbh, const char *tableName, psMetadata *md);
     4306\end{verbatim}
     4307
     4308This function generates and executes the SQL needed to create a table
     4309named \code{tableName}, with the column names and datatypes as
     4310described in \code{md}.  Each data item in the \code{psMetadata}
     4311collection represents a single table field.  The name of the field is
     4312given by the name of the \code{psMetadataItem} and the data type is
     4313give by the \code{psMetadataItem.type} and \code{psMetadataItem.ptype}
     4314entries.  A lookup table should be used to convert from PSLib types
     4315into MySQL compatible SQL data types.  For example, a
     4316\code{PS_META_STR} would map to an SQL99 varchar.  If value of
     4317\code{type} is \code{PS_META_STR} then the \code{psMetadataItem.data}
     4318element is set to a string with the length for the field written as a
     4319text string.  The value of the \code{psMetadataItem.data} element is
     4320unused for the \code{PS_META_PRIMITIVE} types.  Other metadata types
     4321beyond \code{PS_META_STR} and \code{PS_META_PRIMITIVE} are not allowed
     4322in a table definition metadata collection.
     4323
     4324Database indexes can be specified setting the \code{comment} field to
     4325``\code{Primary Key}'' or ``\code{Key}''.  Comment are otherwise
     4326ignored.
     4327
     4328\begin{verbatim}
     4329    bool psDBDropTable(psDB *dbh, const char *tableName);
     4330\end{verbatim}
     4331
     4332This function deletes the specified table.
     4333
     4334\begin{verbatim}
     4335    psArray *psDBSelectColumn(psDB *dbh, const char *tableName, const char *col, const psU64 limit);
     4336    psVector *psDBSelectColumnNum(psDB *dbh, const char *tableName, const char *col, const psU64 limit);
     4337\end{verbatim}
     4338
     4339These functions generates and executes the SQL needed to select an
     4340entire column from a table or up to \code{limit} rows from it.  If
     4341\code{limit} is 0, the entire range is returned.  The database
     4342response is processed and a \code{psArray} of elements of the native
     4343type is returned.  The Num version of the function returns the data in
     4344a \code{psVector}.  It returns an error (NULL) if the requested field
     4345is not a numerical type.
     4346
     4347\begin{verbatim}
     4348    psArray *psDBSelectRows(psDB *dbh, const char *tableName, psMetadata *where);
     4349\end{verbatim}
     4350
     4351This function returns rows from the specified table which match
     4352the restrictions given by \code{where}.  The restrictions are
     4353specified as field / value pairs.  The \code{psMetadata} collection
     4354where must consist of valid database fields, though the database query
     4355checking functions may be used to validate the fields as part of the
     4356query.  If \code{where} is \code{NULL}, then there are no restrictions
     4357on the rows selected.  The selected rows are returned as a
     4358\code{psArray} of \code{psMetadata} values, one per row.
     4359
     4360\begin{verbatim}
     4361    bool psDBInsertRow(psDB *dbh, const char *tableName, psMetadata *row);
     4362\end{verbatim}
     4363
     4364Insert the data from \code{row} into \code{tableName}.  It should be noted in
     4365the API reference that if fields are specified in \code{row} that do not exist
     4366in \code{tablename}, the insert will fail.
     4367
     4368\begin{verbatim}
     4369    psArray *psDBDumpRows(psDB *dbh, const char *tableName);
     4370\end{verbatim}
     4371
     4372Fetch all rows as an psArray of psMetadata.
     4373
     4374\begin{verbatim}
     4375    psArray *psDBDumpCols(psDB *dbh, const char *tableName);
     4376\end{verbatim}
     4377
     4378Fetch all columns as an psArray of psVector
     4379
     4380\begin{verbatim}
     4381    psU64 psDBUpdateRow(psDB *dbh, const char *tableName, psMetadata *where, psMetadata *values);
     4382\end{verbatim}
     4383
     4384Update the columns contained in \code{values} in the row(s) that have a field
     4385with the value indicated by \code{where} (note that this is only allows very
     4386limited use of SQL99's ``where'' semantics).  The number of rows modified is
     4387returned.  If there are multiple psMetadataItems in \code{where} then each item
     4388should be considered as an additional constraint.  e.g.  ``where foo = x and
     4389where bar = y''
     4390
     4391\begin{verbatim}
     4392    psU64 psDBDeleteRow(psDB *dbh, const char *tableName, psMetadata *where);
     4393\end{verbatim}
     4394
     4395Delete the rows that are matched by \code{where} using the same semantics for
     4396\code{where} as in psDBUpdateRow().
    42274397
    42284398\subsection{FITS I/O Functions}
     
    45984768
    45994769\begin{verbatim}
    4600 psPlaneTransform *psPlaneTransformInvert(psPlaneTransform *out, const psPlaneTransform *in, float xMin,
    4601                                          float xMax, float yMin, float yMax, int nSamples);
    4602 psPlaneTransform *psPlaneTransformCombine(psPlaneTransform *out, const psPlaneTransform *trans1,
    4603                                           const psPlaneTransform *trans2);
    4604 bool psPlaneTranformFit(psPlaneTransform *trans, const psArray *source, const psArray *dest, int nRejIter,
    4605                         float sigmaClip);
     4770psPlaneTransform *psPlaneTransformInvert(psPlaneTransform *out, const psPlaneTransform *in, psRegion *region, int nSamples);
     4771psPlaneTransform *psPlaneTransformCombine(psPlaneTransform *out, const psPlaneTransform *trans1, const psPlaneTransform *trans2);
     4772bool psPlaneTranformFit(psPlaneTransform *trans, const psArray *source, const psArray *dest, int nRejIter, float sigmaClip);
    46064773\end{verbatim}
    46074774
     
    46124779the forward transformation.  In the event that the input
    46134780transformation is linear, an exact solution may be calculated;
    4614 otherwise \code{nSamples} samples in each axis, ranging from
    4615 \code{xMin} to \code{xMax} and \code{yMin} to \code{yMax} shall be
    4616 used as a grid to fit the best inverse transformation.  The function
    4617 shall return \code{NULL} if it was unable to generate the inverse
    4618 transformation; otherwise it shall return the inverse transformation.
    4619 In the event that \code{out} is \code{NULL}, a new
    4620 \code{psPlaneTransform} shall be allocated and returned.
    4621 
    4622 \code{psPlaneTransformSubsume} takes two transformations
     4781otherwise \code{nSamples} samples in each axis, covering the region
     4782specified by \code{region} shall be used as a grid to fit the best
     4783inverse transformation.  The function shall return \code{NULL} if it
     4784was unable to generate the inverse transformation; otherwise it shall
     4785return the inverse transformation.  In the event that \code{out} is
     4786\code{NULL}, a new \code{psPlaneTransform} shall be allocated and
     4787returned.
     4788
     4789\code{psPlaneTransformCombine} takes two transformations
    46234790(\code{trans1} and \code{trans2}) and returns a single transformation
    46244791that has the effect of performing \code{trans1} followed by
    46254792\code{trans2}.  The function shall return \code{NULL} if it was unable
    46264793to generate the transformation; otherwise it shall return the
    4627 transformation.  \tbd{Not sure on the algorithm yet --- it may be the
    4628 same as for \code{psPlaneTransformInvert}, in which case we will need
    4629 the ranges and number of samples as well.}
    4630 
    4631 \code{psPlaneTransform} takes two arrays containing matched
    4632 coordinates (i.e., coordinates the \code{source} correspond to the
    4633 appropriate coordinates in the \code{dest}) and returns the
     4794transformation.
     4795
     4796\code{psPlaneTransformFit} takes two arrays containing matched
     4797coordinates (i.e., coordinates in the \code{source} array correspond
     4798to the coordinates in the \code{dest} array) and returns the
    46344799best-fitting transformation.  The \code{source} and \code{dest} will
    46354800contain \code{psCoord}s.  In the event that the number of coordinates
Note: See TracChangeset for help on using the changeset viewer.