RAVE
rave_data2d.h File Reference

Represents a 2-dimensional data array. More...

#include "rave_object.h"
#include "rave_types.h"

Go to the source code of this file.

Typedefs

typedef struct _RaveData2D_t RaveData2D_t
 Defines a Rave 2-dimensional data array.
 

Functions

void RaveData2D_useNodata (RaveData2D_t *self, int use)
 Sets if the operations should take into account nodata value or not.
 
int RaveData2D_usingNodata (RaveData2D_t *self)
 Returns if the calculations are taking into account the nodata value.
 
void RaveData2D_setNodata (RaveData2D_t *self, double nodata)
 
double RaveData2D_getNodata (RaveData2D_t *self)
 
long RaveData2D_getXsize (RaveData2D_t *self)
 Returns the xsize.
 
long RaveData2D_getYsize (RaveData2D_t *self)
 Returns the ysize.
 
RaveDataType RaveData2D_getType (RaveData2D_t *self)
 Returns the data type.
 
void * RaveData2D_getData (RaveData2D_t *self)
 Returns a pointer to the internal data storage.
 
int RaveData2D_setData (RaveData2D_t *self, long xsize, long ysize, void *data, RaveDataType type)
 Sets the data.
 
int RaveData2D_createData (RaveData2D_t *self, long xsize, long ysize, RaveDataType type, double value)
 Creates a data field with the specified size and type.
 
int RaveData2D_fill (RaveData2D_t *self, double v)
 Fills the field with the specified value.
 
int RaveData2D_setValue (RaveData2D_t *self, long x, long y, double v)
 Sets the value at the specified coordinates.
 
int RaveData2D_setValueUnchecked (RaveData2D_t *self, long x, long y, double v)
 Same as RaveData2D_setValue but there is no boundary checking performed.
 
int RaveData2D_getValue (RaveData2D_t *self, long x, long y, double *v)
 Returns the value at the specified x and y position.
 
int RaveData2D_getValueUnchecked (RaveData2D_t *self, long x, long y, double *v)
 Same as RaveData2D_getValue but there is no boundary checking performed.
 
int RaveData2D_hasData (RaveData2D_t *self)
 Returns if this object contains data and a xsize and ysize > 0.
 
double RaveData2D_min (RaveData2D_t *self)
 Returns min in self.
 
double RaveData2D_max (RaveData2D_t *self)
 Returns max in self.
 
RaveData2D_tRaveData2D_concatX (RaveData2D_t *field, RaveData2D_t *other)
 Concatenates field with other horizontally and returns the new field.
 
RaveData2D_tRaveData2D_concatY (RaveData2D_t *field, RaveData2D_t *other)
 Concatenates field with other vertically and returns the new field.
 
RaveData2D_tRaveData2D_circshift (RaveData2D_t *field, int nx, int ny)
 Circular shift of the field in x & y dimension.
 
int RaveData2D_circshiftData (RaveData2D_t *field, int nx, int ny)
 Circular shift of the internal field in x & y dimension.
 
RaveData2D_tRaveData2D_addNumber (RaveData2D_t *field, double v)
 Adds the specified value to field and returns a new field.
 
RaveData2D_tRaveData2D_add (RaveData2D_t *field, RaveData2D_t *other)
 Adds the array value to field and returns a new field.
 
RaveData2D_tRaveData2D_subNumber (RaveData2D_t *field, double v)
 Substracts the specified value from field and returns a new field.
 
RaveData2D_tRaveData2D_sub (RaveData2D_t *field, RaveData2D_t *other)
 Substracts the array value from field and returns a new field.
 
RaveData2D_tRaveData2D_mulNumber (RaveData2D_t *field, double v)
 Multiplicates all values in field with v and returns a new field.
 
RaveData2D_tRaveData2D_emul (RaveData2D_t *field, RaveData2D_t *other)
 Element wise multiplication.
 
RaveData2D_tRaveData2D_powNumber (RaveData2D_t *field, double v)
 Element wise pow on a matrix.
 
RaveData2D_tRaveData2D_epow (RaveData2D_t *field, RaveData2D_t *other)
 Element wise pow on a matrix This means that others x&y size must either be 1 or the same as selfs xsize/ysize.
 
RaveData2D_tRaveData2D_medfilt2 (RaveData2D_t *field, long winXsize, long winYsize)
 Executes a median filtering in 2D.
 
RaveData2D_tRaveData2D_cumsum (RaveData2D_t *field, int dir)
 Runs a cummulative sum of either columns or rows.
 
RaveData2D_tRaveData2D_movingstd (RaveData2D_t *field, long nx, long ny)
 Computes the standard deviation over a given number of pixels (nx * ny).
 
long * RaveData2D_hist (RaveData2D_t *field, int bins, long *nnodata)
 Creates a histogram of field with bins number of bins.
 
int RaveData2D_entropy (RaveData2D_t *field, int bins, double *entropy)
 Calculate the entropy value for the field.
 
void RaveData2D_disp (RaveData2D_t *field)
 Helper function to print field to stdout.
 
const char * RaveData2D_str (RaveData2D_t *field)
 Helper function that returns the matrix as a string.
 
void RaveData2D_replace (RaveData2D_t *field, double v, double v2)
 Replaces all occurances of v with v2 in the provided data field.
 
RaveData2D_tRaveData2D_zeros (long xsize, long ysize, RaveDataType type)
 Utility function for creating a new rave data 2d object filled with zeros.
 
RaveData2D_tRaveData2D_ones (long xsize, long ysize, RaveDataType type)
 Utility function for creating a new rave data 2d object filled with ones.
 
RaveData2D_tRaveData2D_createObject (long xsize, long ysize, RaveDataType type)
 Utility function for creating a new rave data 2d object.
 

Variables

RaveCoreObjectType RaveData2D_TYPE
 Type definition to use when creating a rave object.
 

Detailed Description

Represents a 2-dimensional data array.

This object supports RAVE_OBJECT_CLONE.

Author
Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
Date
2009-12-17

Typedef Documentation

◆ RaveData2D_t

typedef struct _RaveData2D_t RaveData2D_t

Defines a Rave 2-dimensional data array.

Function Documentation

◆ RaveData2D_add()

RaveData2D_t * RaveData2D_add ( RaveData2D_t * field,
RaveData2D_t * other )

Adds the array value to field and returns a new field.

Other's x&y size must either be 1 or the same as selfs xsize/ysize.

Parameters
[in]field- self
[in]other- the other array to add
Returns
the new field or NULL on error

◆ RaveData2D_addNumber()

RaveData2D_t * RaveData2D_addNumber ( RaveData2D_t * field,
double v )

Adds the specified value to field and returns a new field.

Parameters
[in]field- self
[in]v- the value to add
Returns
the new field or NULL on error

◆ RaveData2D_circshift()

RaveData2D_t * RaveData2D_circshift ( RaveData2D_t * field,
int nx,
int ny )

Circular shift of the field in x & y dimension.

Parameters
[in]field- the field to be shifted
[in]nx- the number of steps to be shifted in x-direction. Can be both positive and negative
[in]ny- the number of steps to be shifted in y-direction. Can be both positive and negative
Returns
the shifted field

◆ RaveData2D_circshiftData()

int RaveData2D_circshiftData ( RaveData2D_t * field,
int nx,
int ny )

Circular shift of the internal field in x & y dimension.

Parameters
[in]field- the field to be shifted
[in]nx- the number of steps to be shifted in x-direction. Can be both positive and negative
[in]ny- the number of steps to be shifted in y-direction. Can be both positive and negative
Returns
1 if shift was successful otherwise 0

◆ RaveData2D_concatX()

RaveData2D_t * RaveData2D_concatX ( RaveData2D_t * field,
RaveData2D_t * other )

Concatenates field with other horizontally and returns the new field.

The field's and other's y-dimensions must be the same as well as the data type.

Parameters
[in]field- self
[in]other- the field to contatenate
Returns
the concatenated field on success otherwise NULL

◆ RaveData2D_concatY()

RaveData2D_t * RaveData2D_concatY ( RaveData2D_t * field,
RaveData2D_t * other )

Concatenates field with other vertically and returns the new field.

The field's and other's x-dimensions must be the same as well as the data type.

Parameters
[in]field- self
[in]other- the field to contatenate
Returns
the concatenated field on success otherwise NULL

◆ RaveData2D_createData()

int RaveData2D_createData ( RaveData2D_t * self,
long xsize,
long ysize,
RaveDataType type,
double value )

Creates a data field with the specified size and type.

Parameters
[in]self- self
[in]xsize- x-size
[in]ysize- y-size
[in]type- the data type
[in]value- initial value to set for all positions in the data field
Returns
1 on success, otherwise 0

◆ RaveData2D_createObject()

RaveData2D_t * RaveData2D_createObject ( long xsize,
long ysize,
RaveDataType type )

Utility function for creating a new rave data 2d object.

Parameters
[in]xsize- x-size
[in]ysize- y-size
[in]type- the data type
Returns
The instance on success, otherwise NULL

◆ RaveData2D_cumsum()

RaveData2D_t * RaveData2D_cumsum ( RaveData2D_t * field,
int dir )

Runs a cummulative sum of either columns or rows.

If dir == 1, then it's columnwise sum. Else if dir == 2, then it's row based cummulative sum.

Parameters
[in]field- self
[in]ifit's goind to be column (1) or row (2) based cummulation.
Returns
a new field with the cummulative sum

◆ RaveData2D_disp()

void RaveData2D_disp ( RaveData2D_t * field)

Helper function to print field to stdout.

Parameters
[in]field- field

◆ RaveData2D_emul()

RaveData2D_t * RaveData2D_emul ( RaveData2D_t * field,
RaveData2D_t * other )

Element wise multiplication.

I.e. not a real matrix multiplication but instead it atempts to perform item wise multiplication row or columnwise. This means that others x&y size must either be 1 or the same as selfs xsize/ysize.

Parameters
[in]field- self
[in]other- the other array to use for multiplication

◆ RaveData2D_entropy()

int RaveData2D_entropy ( RaveData2D_t * field,
int bins,
double * entropy )

Calculate the entropy value for the field.

Entropy is a statistical measure of randomness.

Parameters
[in]field- self
[in]bins- the number of bins
[in,out]entropy- the calculated entropy
Returns
1 on success otherwise 0

◆ RaveData2D_epow()

RaveData2D_t * RaveData2D_epow ( RaveData2D_t * field,
RaveData2D_t * other )

Element wise pow on a matrix This means that others x&y size must either be 1 or the same as selfs xsize/ysize.

Parameters
[in]field- self
[in]other- the other array to use for multiplication

◆ RaveData2D_fill()

int RaveData2D_fill ( RaveData2D_t * self,
double v )

Fills the field with the specified value.

Parameters
[in]self- self
[in]v- the value to fill with
Returns
1 on success, otherwise 0

◆ RaveData2D_getData()

void * RaveData2D_getData ( RaveData2D_t * self)

Returns a pointer to the internal data storage.

Parameters
[in]self- self
Returns
the internal data pointer (NOTE! Do not release this pointer)

◆ RaveData2D_getNodata()

double RaveData2D_getNodata ( RaveData2D_t * self)
Parameters
[in]self- self
Returns
the nodata value

◆ RaveData2D_getType()

RaveDataType RaveData2D_getType ( RaveData2D_t * self)

Returns the data type.

Parameters
[in]self- self
Returns
the data type

◆ RaveData2D_getValue()

int RaveData2D_getValue ( RaveData2D_t * self,
long x,
long y,
double * v )

Returns the value at the specified x and y position.

If coordinates is outside the boundaries, v will be left as is so initialize it before calling this function.

Parameters
[in]self- self
[in]x- the x index
[in]y- the y index
[out]v- the data at the specified index
Returns
1 if the value could be extracted and returned, otherwise 0

◆ RaveData2D_getValueUnchecked()

int RaveData2D_getValueUnchecked ( RaveData2D_t * self,
long x,
long y,
double * v )

Same as RaveData2D_getValue but there is no boundary checking performed.

I.e. unless you know what you are doing you might be accessing unreserved memory.

Parameters
[in]self- self
[in]x- the x index
[in]y- the y index
[out]v- the data at the specified index
Returns
1 if the value could be extracted and returned, otherwise 0

◆ RaveData2D_getXsize()

long RaveData2D_getXsize ( RaveData2D_t * self)

Returns the xsize.

Parameters
[in]self- self
Returns
the xsize

◆ RaveData2D_getYsize()

long RaveData2D_getYsize ( RaveData2D_t * self)

Returns the ysize.

Parameters
[in]self- self
Returns
the ysize

◆ RaveData2D_hasData()

int RaveData2D_hasData ( RaveData2D_t * self)

Returns if this object contains data and a xsize and ysize > 0.

Parameters
[in]self- self
Returns
1 if this object contains data, otherwise 0.

◆ RaveData2D_hist()

long * RaveData2D_hist ( RaveData2D_t * field,
int bins,
long * nnodata )

Creates a histogram of field with bins number of bins.

The histogram will be determined as Calculate bin ranges as scale = (max - min) / nbins Bin1: max >= x <= max + scale Bin2: max + scale > x <= max + 2*scale Bin3: max + 2*scale > x <= max + 3*scale and so on.....

Example: y=[-7 -5 -3 -2 -2 -1 0 1 2 3 3 4 5 5 6 7] nbins = 4

scale = (7 - (-7)) / 4 = 3.5 => b1 = -7 => -3.5 b2 = -3.49 => 0 b3 = 0.01 => 3.5 b4 = 3.51 => 7

Parameters
[in]field- self
[in]bins- number of bins
[in,out]nnodata- If using nodata, this will be number of nodata values since they won't be in the histogram counts.

Calculate bin ranges as scale = (max - min) / nbins Bin1: max >= x <= max + scale Bin2: max + scale > x <= max + 2*scale Bin3: max + 2*scale > x <= max + 3*scale and so on.....

Example: y=[-7 -5 -3 -2 -2 -1 0 1 2 3 3 4 5 5 6 7] nbins = 4

scale = (7 - (-7)) / 4 = 3.5 => b1 = -7 => -3.5 b2 = -3.49 => 0 b3 = 0.01 => 3.5 b4 = 3.51 => 7

◆ RaveData2D_max()

double RaveData2D_max ( RaveData2D_t * self)

Returns max in self.

Parameters
[in]self- self
Returns
max value

◆ RaveData2D_medfilt2()

RaveData2D_t * RaveData2D_medfilt2 ( RaveData2D_t * field,
long winXsize,
long winYsize )

Executes a median filtering in 2D.

I.e. takes surrounding pixels in winXsize, winYsize and determines the median value for each pixel in the field. I.e. box will be x +/- winXsize/2, y +/- winYsize/2

Parameters
[in]field- self
[in]winXsize- the number of pixels in x-direction
[in]winYsize- the number of pixels in y-direction
Returns
the filtered data field

◆ RaveData2D_min()

double RaveData2D_min ( RaveData2D_t * self)

Returns min in self.

Parameters
[in]self- self
Returns
min value

◆ RaveData2D_movingstd()

RaveData2D_t * RaveData2D_movingstd ( RaveData2D_t * field,
long nx,
long ny )

Computes the standard deviation over a given number of pixels (nx * ny).

If nx or ny = 0, it will be row or col wise std.

Parameters
[in]field- self
[in]nx- number of pixels in x-dim
[in]ny- number of pixels in y-dim

◆ RaveData2D_mulNumber()

RaveData2D_t * RaveData2D_mulNumber ( RaveData2D_t * field,
double v )

Multiplicates all values in field with v and returns a new field.

Parameters
[in]field- self
[in]v- the value to multply with

◆ RaveData2D_ones()

RaveData2D_t * RaveData2D_ones ( long xsize,
long ysize,
RaveDataType type )

Utility function for creating a new rave data 2d object filled with ones.

Parameters
[in]xsize- x-size
[in]ysize- y-size
[in]type- the data type
Returns
The instance on success, otherwise NULL

◆ RaveData2D_powNumber()

RaveData2D_t * RaveData2D_powNumber ( RaveData2D_t * field,
double v )

Element wise pow on a matrix.

Parameters
[in]field- self
[in]v- the pow value

◆ RaveData2D_replace()

void RaveData2D_replace ( RaveData2D_t * field,
double v,
double v2 )

Replaces all occurances of v with v2 in the provided data field.

Parameters
[in]field- self
[in]v- the value to search for
[in]v2- the value that should be used as replacement

◆ RaveData2D_setData()

int RaveData2D_setData ( RaveData2D_t * self,
long xsize,
long ysize,
void * data,
RaveDataType type )

Sets the data.

Parameters
[in]self- self
[in]xsize- x-size
[in]ysize- y-size
[in]data- the data
[in]type- the data type
Returns
1 on success, otherwise 0

◆ RaveData2D_setNodata()

void RaveData2D_setNodata ( RaveData2D_t * self,
double nodata )
Parameters
[in]self- self
[in]nodata- the nodata value to use.

◆ RaveData2D_setValue()

int RaveData2D_setValue ( RaveData2D_t * self,
long x,
long y,
double v )

Sets the value at the specified coordinates.

Parameters
[in]self- self
[in]x- the x-position
[in]y- the y-position
[in]v- the value to set
Returns
1 if the value could be set, otherwise 0

◆ RaveData2D_setValueUnchecked()

int RaveData2D_setValueUnchecked ( RaveData2D_t * self,
long x,
long y,
double v )

Same as RaveData2D_setValue but there is no boundary checking performed.

I.e. unless you know what you are doing you might be accessing unreserved memory.

Parameters
[in]self- self
[in]x- the x-position
[in]y- the y-position
[in]v- the value to set
Returns
1 if the value could be set, otherwise 0

◆ RaveData2D_str()

const char * RaveData2D_str ( RaveData2D_t * field)

Helper function that returns the matrix as a string.

Note, this is not reentrant since it's using a static buffer.

Parameters
[in]field- self
Returns
matrix as a string

◆ RaveData2D_sub()

RaveData2D_t * RaveData2D_sub ( RaveData2D_t * field,
RaveData2D_t * other )

Substracts the array value from field and returns a new field.

Other's x&y size must either be 1 or the same as selfs xsize/ysize.

Parameters
[in]field- self
[in]other- the other array to substract
Returns
the new field or NULL on error

◆ RaveData2D_subNumber()

RaveData2D_t * RaveData2D_subNumber ( RaveData2D_t * field,
double v )

Substracts the specified value from field and returns a new field.

Parameters
[in]field- self
[in]v- the value to substract
Returns
the new field or NULL on error

◆ RaveData2D_useNodata()

void RaveData2D_useNodata ( RaveData2D_t * self,
int use )

Sets if the operations should take into account nodata value or not.

Default is turned off

Parameters
[in]self- self
[in]use- 1 if nodata controls should be performed, otherwise it's turned off

◆ RaveData2D_usingNodata()

int RaveData2D_usingNodata ( RaveData2D_t * self)

Returns if the calculations are taking into account the nodata value.

Parameters
[in]self- self
Returns
if nodata value is taken into account when performing the operations

◆ RaveData2D_zeros()

RaveData2D_t * RaveData2D_zeros ( long xsize,
long ysize,
RaveDataType type )

Utility function for creating a new rave data 2d object filled with zeros.

Parameters
[in]xsize- x-size
[in]ysize- y-size
[in]type- the data type
Returns
The instance on success, otherwise NULL

Variable Documentation

◆ RaveData2D_TYPE

RaveCoreObjectType RaveData2D_TYPE
extern

Type definition to use when creating a rave object.