Oyster Harvest Area Closure Analysis 0.1
Prediction and analysis of NSW oyster harvest area closures.
Loading...
Searching...
No Matches
transform.h File Reference
#include <libpq-fe.h>
#include <stdio.h>
#include <stdlib.h>
#include <log.h>
#include "BOM/stations.h"
#include "FoodAuthority/harvest_area.h"
#include "WillyWeather/location.h"
#include "utils.h"
Include dependency graph for transform.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  T_LocationLookup_TypeDef
 Structure of a location (i.e. program location) More...
 
struct  T_LocationsLookup_TypeDef
 Locations lookup table structure. More...
 
struct  T_Outlook_Typedef
 Harvest area outlook / prediction information. More...
 
struct  T_OutlookData_TypeDef
 
struct  T_OutlookDataset_TypeDef
 

Macros

#define T_MAX_N_LOCATIONS   50
 Maximum number of locations. More...
 
#define T_TIMESTAMP_SIZE   50
 Maximum size of timestamp (num chars) More...
 
#define T_OUTLOOK_BUF_SIZE   200
 Outlook buffer size. More...
 
#define T_EST_CLOSURE_BUF_SIZE   20
 Outlook closue time code. More...
 
#define T_DATA_TYPE_SIZE   30
 Data type size. More...
 
#define T_DATA_QUERY_LENGTH   15
 
#define T_DATA_WINDOW_SIZE   7
 

Functions

void T_BuildWeatherDB (T_LocationsLookup_TypeDef *locations, PGconn *psql_conn)
 Build weather table in PostgreSQL database. More...
 
void T_FloodPrediction (PGconn *psql_conn)
 Transforms data from all harvest programs into flood prediction. More...
 
void T_WindowDataset (PGconn *psql_conn, int program_id)
 Window transform Z-Score values into a probability of flooding event. More...
 
void T_NormaliseWindowedPrecipitation (PGconn *psql_conn, int program_id)
 Normalise summed moving window precipitation between 0 and 1. More...
 

Macro Definition Documentation

◆ T_DATA_QUERY_LENGTH

#define T_DATA_QUERY_LENGTH   15

◆ T_DATA_TYPE_SIZE

#define T_DATA_TYPE_SIZE   30

Data type size.

◆ T_DATA_WINDOW_SIZE

#define T_DATA_WINDOW_SIZE   7

◆ T_EST_CLOSURE_BUF_SIZE

#define T_EST_CLOSURE_BUF_SIZE   20

Outlook closue time code.

◆ T_MAX_N_LOCATIONS

#define T_MAX_N_LOCATIONS   50

Maximum number of locations.

◆ T_OUTLOOK_BUF_SIZE

#define T_OUTLOOK_BUF_SIZE   200

Outlook buffer size.

◆ T_TIMESTAMP_SIZE

#define T_TIMESTAMP_SIZE   50

Maximum size of timestamp (num chars)

Function Documentation

◆ T_BuildWeatherDB()

void T_BuildWeatherDB ( T_LocationsLookup_TypeDef locations,
PGconn *  psql_conn 
)

Build weather table in PostgreSQL database.

Main weather table for each location.

This table contains both forecasted and historical weather information for each harvest location. One column contains precipitation data where forecasted weather is added first, then overwritten using observed values. Both forecasted and observed data are stored in seperate columns.

Note
This function requires weather_ibm_eis and weather_bom tables to be populated.
Parameters
locationsUnique locations information.
psql_connPostgreSQL connection handler.

◆ T_FloodPrediction()

void T_FloodPrediction ( PGconn *  psql_conn)

Transforms data from all harvest programs into flood prediction.

@breif Main entry point for calculating the risk of a harvest area closure.

Gets a list of the harvest areas. Loops through each of these locations to calcualte a windowed moving average of precipitation and then normalises this window to provide a value between 0 and 1.

Parameters
psql_connPostgreSQL connection.

◆ T_NormaliseWindowedPrecipitation()

void T_NormaliseWindowedPrecipitation ( PGconn *  psql_conn,
const int  program_id 
)

Normalise summed moving window precipitation between 0 and 1.

@breif Normalise precipiation data between 0 and 1.

After a summed window average has been completed by T_WindowDataset the data can then be normalised. This normalisation is program specific i.e. each normalisations max and min are based on that program only and not the max and min of all programs in NSW.

Parameters
psql_connPostgreSQL connection.

◆ T_WindowDataset()

void T_WindowDataset ( PGconn *  psql_conn,
const int  program_id 
)

Window transform Z-Score values into a probability of flooding event.

Window transform Z-Score values into a probability of flooding event.

For each program_id calcualte the sum of the next 8-days precipitation and the previous 5-days preciptiation. This acts as a moving window across all available data.

Note
The outlook and hindlook can be adjusted by altering the w_start and w_end variables in this function.
Parameters
psql_connPostgreSQL connection.
program_idFood authority program ID.