MISR Toolkit  1.5.1
MtkResampleRegressionCoeff.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkResampleRegressionCoeff =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2008, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrRegression.h"
18 #include "MisrReProject.h"
19 #include "MisrUtil.h"
20 #include <stdlib.h>
21 #include <math.h>
22 
39  const MTKt_RegressionCoeff *Regression_coeff,
40  const MTKt_MapInfo *Regression_coeff_map_info,
41  const MTKt_MapInfo *Target_map_info,
42  MTKt_RegressionCoeff *Regression_coeff_out
43 )
44 {
45  MTKt_status status_code; /* Return status of this function */
46  MTKt_status status; /* Return status of called routines. */
47  MTKt_RegressionCoeff regression_coeff_out_tmp = MTKT_REGRESSION_COEFF_INIT;
48  MTKt_DataBuffer latitude; /* Array if latitude values for the target grid. */
49  MTKt_DataBuffer longitude; /* Array if longitude values for the target grid. */
51  /* Array of line coordinates in input regression
52  coefficients grid. */
54  /* Array of sample coordinates in input regression
55  coefficients grid. */
56  MTKt_DataBuffer valid_mask_not_used = MTKT_DATABUFFER_INIT;
57  /* Unused valid mask. */
58 
59  /* ------------------------------------------------------------------ */
60  /* Argument check: Regression_coeff == NULL */
61  /* ------------------------------------------------------------------ */
62 
63  if (Regression_coeff == NULL) {
64  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Regression_coeff == NULL");
65  }
66 
67  /* ------------------------------------------------------------------ */
68  /* Argument check: Regression_coeff_out == NULL */
69  /* ------------------------------------------------------------------ */
70 
71  if (Regression_coeff_out == NULL) {
72  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Regression_coeff_out == NULL");
73  }
74 
75  /* ------------------------------------------------------------------ */
76  /* Calculate latitude/longitude for each pixel in the target grid. */
77  /* ------------------------------------------------------------------ */
78 
79  status = MtkCreateLatLon(*Target_map_info, &latitude, &longitude);
80  MTK_ERR_COND_JUMP(status);
81 
82  /* ------------------------------------------------------------------ */
83  /* Calculate line/sample coordinates in the regression coefficient */
84  /* grid. */
85  /* ------------------------------------------------------------------ */
86 
87  status = MtkTransformCoordinates(*Regression_coeff_map_info,
88  latitude, longitude, &line, &sample);
89  MTK_ERR_COND_JUMP(status);
90 
91  /* ------------------------------------------------------------------ */
92  /* Free memory. */
93  /* ------------------------------------------------------------------ */
94 
95  MtkDataBufferFree(&latitude);
96  MtkDataBufferFree(&longitude);
97 
98  /* ------------------------------------------------------------------ */
99  /* Resample regression coefficients to target grid. */
100  /* ------------------------------------------------------------------ */
101 
102  status = MtkResampleCubicConvolution(&(Regression_coeff->slope),
103  &(Regression_coeff->valid_mask),
104  &line,
105  &sample,
106  -0.5,
107  &(regression_coeff_out_tmp.slope),
108  &(regression_coeff_out_tmp.valid_mask));
109  MTK_ERR_COND_JUMP(status);
110 
111  status = MtkResampleCubicConvolution(&(Regression_coeff->intercept),
112  &(Regression_coeff->valid_mask),
113  &line,
114  &sample,
115  -0.5,
116  &(regression_coeff_out_tmp.intercept),
117  &(valid_mask_not_used));
118  MTK_ERR_COND_JUMP(status);
119 
120  MtkDataBufferFree(&valid_mask_not_used);
121 
122  status = MtkResampleCubicConvolution(&(Regression_coeff->correlation),
123  &(Regression_coeff->valid_mask),
124  &line,
125  &sample,
126  -0.5,
127  &(regression_coeff_out_tmp.correlation),
128  &(valid_mask_not_used));
129  MTK_ERR_COND_JUMP(status);
130 
131  MtkDataBufferFree(&valid_mask_not_used);
132 
133  /* ------------------------------------------------------------------ */
134  /* Free memory. */
135  /* ------------------------------------------------------------------ */
136 
137  MtkDataBufferFree(&line);
138  MtkDataBufferFree(&sample);
139 
140  /* ------------------------------------------------------------------ */
141  /* Return. */
142  /* ------------------------------------------------------------------ */
143 
144  *Regression_coeff_out = regression_coeff_out_tmp;
145  return MTK_SUCCESS;
146 
147 ERROR_HANDLE:
148  MtkDataBufferFree(&latitude);
149  MtkDataBufferFree(&longitude);
150  MtkDataBufferFree(&line);
151  MtkDataBufferFree(&sample);
152  MtkDataBufferFree(&valid_mask_not_used);
153  return status_code;
154 }
MTKt_status MtkTransformCoordinates(MTKt_MapInfo mapinfo, MTKt_DataBuffer latbuf, MTKt_DataBuffer lonbuf, MTKt_DataBuffer *linebuf, MTKt_DataBuffer *samplebuf)
Transforms latitude/longitude coordinates into line/sample coordinates for a given mapinfo...
MTKt_DataBuffer valid_mask
Map Information.
Definition: MisrMapQuery.h:65
2-dimensional Data Buffer
Definition: MisrUtil.h:98
MTKt_DataBuffer slope
#define MTKT_DATABUFFER_INIT
Definition: MisrUtil.h:109
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
MTKt_status MtkResampleCubicConvolution(const MTKt_DataBuffer *Source, const MTKt_DataBuffer *Source_mask, const MTKt_DataBuffer *Line, const MTKt_DataBuffer *Sample, float A, MTKt_DataBuffer *Resampled, MTKt_DataBuffer *Resampled_mask)
Resample source data at the given coordinates using interpolation by cubic convolution.
MTKt_DataBuffer intercept
#define MTK_ERR_CODE_MSG_JUMP(code, msg)
Definition: MisrError.h:181
MTKt_status MtkResampleRegressionCoeff(const MTKt_RegressionCoeff *Regression_coeff, const MTKt_MapInfo *Regression_coeff_map_info, const MTKt_MapInfo *Target_map_info, MTKt_RegressionCoeff *Regression_coeff_out)
Resample regression coefficients at each pixel in the target map. Resampling is by cubic convolution...
#define MTKT_REGRESSION_COEFF_INIT
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
MTKt_status MtkCreateLatLon(MTKt_MapInfo mapinfo, MTKt_DataBuffer *latbuf, MTKt_DataBuffer *lonbuf)
Creates a 2-D latitude buffer and a 2-D longitude buffer in decimal degrees corresponding to the data...
MTKt_DataBuffer correlation

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51