-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selection steep #2
base: master
Are you sure you want to change the base?
Changes from all commits
b2e31bb
11f45a3
120ef5b
ce0ae58
055e59d
99e0dc9
1b24c66
b31c645
5d7a22a
871068a
e18ebc1
46cc6b7
23becb9
0f0cee7
faebb0f
508aaa4
97115ec
2e03956
338d953
27bb7f7
aeeb711
d1e3826
96eeea9
bf2f5b5
d642291
11a7af7
608d93d
2b9d5b6
8e3897b
213d456
558bda6
9007242
3a0fe71
a7a3a3e
2a1ca06
62ca537
f3e992a
86f78f8
26fad31
76a3993
17c68bf
433cbb1
7cea211
73ab0e5
debd3a4
d6090bb
3db5972
d253f36
8d859a7
6eac1ee
51ab7d3
d31da7f
c2cae48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#include "STEEP.h" | ||
|
||
void compute_H0(double net_radiation_line[], double soil_heat_flux[], int width_band, double ho_line[]) | ||
{ | ||
for (int col = 0; col < width_band; col++) | ||
ho_line[col] = net_radiation_line[col] - soil_heat_flux[col]; | ||
}; | ||
|
||
void filter_valid_values(double *target_line, double *target_values, int width_band, int *pos) | ||
{ | ||
for (int col = 0; col < width_band; col++) | ||
{ | ||
if (!isnan(target_line[col]) && !isinf(target_line[col])) | ||
{ | ||
target_values[*pos] = target_line[col]; | ||
(*pos)++; | ||
} | ||
} | ||
} | ||
|
||
void get_quartiles(TIFF *target, double *v_quartile, int height_band, int width_band, double first_interval, double last_interval) | ||
{ | ||
const int SIZE = height_band * width_band; | ||
double target_line[width_band]; | ||
double *target_values = (double *)malloc(sizeof(double) * SIZE); | ||
|
||
if (target_values == NULL) | ||
exit(15); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O exit 15 ta especificado no README? |
||
|
||
int pos = 0; | ||
for (int line = 0; line < height_band; line++) | ||
{ | ||
read_line_tiff(target, target_line, line); | ||
filter_valid_values(target_line, target_values, width_band, &pos); | ||
} | ||
|
||
sort(target_values, target_values + pos); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As imagens cabem em memória para poder carregar tudo e ordenar aqui? |
||
|
||
v_quartile[0] = target_values[int(floor(first_interval * pos))]; | ||
v_quartile[1] = target_values[int(floor(last_interval * pos))]; | ||
|
||
free(target_values); | ||
} | ||
|
||
Candidate getHotPixelSTEPP(TIFF** ndvi, TIFF** surface_temperature, TIFF** albedo, TIFF** net_radiation, TIFF** soil_heat, int height_band, int width_band) | ||
{ | ||
std::vector<double> ndvi_line(width_band); | ||
std::vector<double> surface_temperature_line(width_band); | ||
std::vector<double> net_radiation_line(width_band); | ||
std::vector<double> soil_heat_line(width_band); | ||
std::vector<double> albedo_line(width_band); | ||
std::vector<double> ho_line(width_band); | ||
std::vector<Candidate> candidatesGroup; | ||
|
||
std::vector<double> ndviQuartile(2); | ||
std::vector<double> tsQuartile(2); | ||
std::vector<double> albedoQuartile(2); | ||
|
||
get_quartiles(*ndvi, ndviQuartile.data(), height_band, width_band, 0.15, 0.85); | ||
get_quartiles(*albedo, albedoQuartile.data(), height_band, width_band, 0.50, 0.75); | ||
get_quartiles(*surface_temperature, tsQuartile.data(), height_band, width_band, 0.85, 0.97); | ||
|
||
for (int line = 0; line < height_band; line++) | ||
{ | ||
read_line_tiff(*net_radiation, net_radiation_line.data(), line); | ||
read_line_tiff(*soil_heat, soil_heat_line.data(), line); | ||
|
||
compute_H0(net_radiation_line.data(), soil_heat_line.data(), width_band, ho_line.data()); | ||
|
||
read_line_tiff(*ndvi, ndvi_line.data(), line); | ||
read_line_tiff(*surface_temperature, surface_temperature_line.data(), line); | ||
read_line_tiff(*albedo, albedo_line.data(), line); | ||
|
||
for (int col = 0; col < width_band; col++) | ||
{ | ||
bool ndviValid = !std::isnan(ndvi_line[col]) && ndvi_line[col] > 0.10 && ndvi_line[col] < ndviQuartile[0]; | ||
bool albedoValid = !std::isnan(albedo_line[col]) && albedo_line[col] > albedoQuartile[0] && albedo_line[col] < albedoQuartile[1]; | ||
bool tsValid = !std::isnan(surface_temperature_line[col]) && surface_temperature_line[col] > tsQuartile[0] && surface_temperature_line[col] < tsQuartile[1]; | ||
|
||
if (albedoValid && ndviValid && tsValid) | ||
{ | ||
candidatesGroup.emplace_back(ndvi_line[col], surface_temperature_line[col], net_radiation_line[col], | ||
soil_heat_line[col], ho_line[col], line, col); | ||
} | ||
} | ||
} | ||
|
||
if (candidatesGroup.empty()) | ||
{ | ||
cerr << "Pixel problem! - There are no final candidates"; | ||
exit(15); | ||
} | ||
|
||
std::sort(candidatesGroup.begin(), candidatesGroup.end(), compare_candidate_temperature); | ||
unsigned int pos = static_cast<unsigned int>(std::floor(candidatesGroup.size() * 0.5)); | ||
|
||
return candidatesGroup[pos]; | ||
} | ||
|
||
Candidate getColdPixelSTEPP(TIFF** ndvi, TIFF** surface_temperature, TIFF** albedo, TIFF** net_radiation, TIFF** soil_heat, int height_band, int width_band) | ||
{ | ||
std::vector<double> ndvi_line(width_band); | ||
std::vector<double> surface_temperature_line(width_band); | ||
std::vector<double> net_radiation_line(width_band); | ||
std::vector<double> soil_heat_line(width_band); | ||
std::vector<double> albedo_line(width_band); | ||
std::vector<double> ho_line(width_band); | ||
std::vector<Candidate> candidatesGroup; | ||
|
||
std::vector<double> ndviQuartile(2); | ||
std::vector<double> tsQuartile(2); | ||
std::vector<double> albedoQuartile(2); | ||
|
||
get_quartiles(*ndvi, ndviQuartile.data(), height_band, width_band, 0.15, 0.97); | ||
get_quartiles(*albedo, albedoQuartile.data(), height_band, width_band, 0.25, 0.50); | ||
get_quartiles(*surface_temperature, tsQuartile.data(), height_band, width_band, 0.20, 0.85); | ||
|
||
for (int line = 0; line < height_band; line++) | ||
{ | ||
read_line_tiff(*net_radiation, net_radiation_line.data(), line); | ||
read_line_tiff(*soil_heat, soil_heat_line.data(), line); | ||
|
||
compute_H0(net_radiation_line.data(), soil_heat_line.data(), width_band, ho_line.data()); | ||
|
||
read_line_tiff(*ndvi, ndvi_line.data(), line); | ||
read_line_tiff(*surface_temperature, surface_temperature_line.data(), line); | ||
read_line_tiff(*albedo, albedo_line.data(), line); | ||
|
||
for (int col = 0; col < width_band; col++) | ||
{ | ||
bool ndviValid = !std::isnan(ndvi_line[col]) && ndvi_line[col] > ndviQuartile[1]; | ||
bool albedoValid = !std::isnan(albedo_line[col]) && albedo_line[col] > albedoQuartile[0] && albedo_line[col] < albedoQuartile[1]; | ||
bool tsValid = !std::isnan(surface_temperature_line[col]) && surface_temperature_line[col] < tsQuartile[0]; | ||
|
||
if (albedoValid && ndviValid && tsValid) | ||
{ | ||
candidatesGroup.emplace_back(ndvi_line[col], surface_temperature_line[col], net_radiation_line[col], | ||
soil_heat_line[col], ho_line[col], line, col); | ||
} | ||
} | ||
} | ||
|
||
if (candidatesGroup.empty()) | ||
{ | ||
cerr << "Pixel problem! - There are no final candidates"; | ||
exit(15); | ||
} | ||
|
||
std::sort(candidatesGroup.begin(), candidatesGroup.end(), compare_candidate_temperature); | ||
unsigned int pos = static_cast<unsigned int>(std::floor(candidatesGroup.size() * 0.5)); | ||
|
||
return candidatesGroup[pos]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "types.h" | ||
#include "utils.h" | ||
#include "parameters.h" | ||
#include "pixel_reader.h" | ||
#include "candidate.h" | ||
|
||
void compute_H0(double net_radiation_line[], double soil_heat_flux[], int width_band, double ho_line[]); | ||
|
||
void filter_valid_values(double *target_line, double *target_values, int width_band, int *pos); | ||
|
||
void get_quartiles(TIFF *target, double *v_quartile, int height_band, int width_band, double first_interval, double last_interval); | ||
|
||
Candidate getHotPixelSTEPP(TIFF** ndvi, TIFF** surface_temperature, TIFF** albedo, TIFF** net_radiation, TIFF** soil_heat, int height_band, int width_band); | ||
|
||
Candidate getColdPixelSTEPP(TIFF** ndvi, TIFF** surface_temperature, TIFF** albedo, TIFF** net_radiation, TIFF** soil_heat, int height_band, int width_band); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,20 +117,30 @@ Candidate getHotPixel(TIFF** ndvi, TIFF** surface_temperature, TIFF** albedo, TI | |
} | ||
|
||
} | ||
|
||
if(candidatesGroupI.size() <= 0) { | ||
cerr << "Pixel problem! - There are no precandidates"; | ||
exit(15); | ||
} | ||
|
||
//Creating second pixel group, all values lower than the 3rd quartile are excluded | ||
sort(candidatesGroupI.begin(), candidatesGroupI.end(), compare_candidate_temperature); | ||
unsigned int pos = int(floor(candidatesGroupI.size() * 0.75)); | ||
vector<Candidate> candidatesGroupII(candidatesGroupI.begin() + pos, candidatesGroupI.end()); | ||
|
||
if(candidatesGroupII.size() <= 0) { | ||
cerr << "Pixel problem! - There are no final candidates"; | ||
exit(15); | ||
} | ||
|
||
pos = int(floor(candidatesGroupII.size() * 0.5)); | ||
Candidate hotPixel = candidatesGroupII[pos]; | ||
|
||
free(ndviQuartile); | ||
free(tsQuartile); | ||
free(albedoQuartile); | ||
|
||
hotPixel.toString(); | ||
//hotPixel.toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remover comentário |
||
|
||
return hotPixel; | ||
} | ||
|
@@ -193,19 +203,31 @@ Candidate getColdPixel(TIFF** ndvi, TIFF** surface_temperature, TIFF** albedo, T | |
|
||
} | ||
|
||
if(candidatesGroupI.size() <= 0) { | ||
cerr << "Pixel problem! - There are no precandidates"; | ||
exit(15); | ||
} | ||
|
||
//Creating second pixel group, all pixels with values higher than the 1 st quartile are excluded | ||
sort(candidatesGroupI.begin(), candidatesGroupI.end(), compare_candidate_temperature); | ||
unsigned int pos = int(floor(candidatesGroupI.size() * 0.25)); | ||
vector<Candidate> candidatesGroupII(candidatesGroupI.begin(), candidatesGroupI.begin() + pos); | ||
|
||
|
||
if(candidatesGroupII.size() <= 0) { | ||
cerr << "Pixel problem! - There are no final candidates"; | ||
exit(15); | ||
} | ||
|
||
pos = int(floor(candidatesGroupII.size() * 0.5)); | ||
|
||
Candidate coldPixel = candidatesGroupII[pos]; | ||
|
||
free(ndviQuartile); | ||
free(tsQuartile); | ||
free(albedoQuartile); | ||
|
||
coldPixel.toString(); | ||
// coldPixel.toString(); | ||
|
||
return coldPixel; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,8 +79,11 @@ void Landsat::process_partial_products(TIFF* read_bands[], MTL mtl, Station stat | |
double eo_emissivity_line[width_band], ea_emissivity_line[width_band], enb_emissivity_line[width_band]; | ||
double large_wave_radiation_atmosphere_line[width_band], large_wave_radiation_surface_line[width_band]; | ||
double short_wave_radiation_line[width_band]; | ||
|
||
//Calculating the partial products for each line | ||
|
||
//DEBUG - OLHAR ESSES CARAS AQUI!! | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remover comentário |
||
for(int line = 0; line < height_band; line ++){ | ||
radiance_function(read_bands, mtl, sensor, width_band, line, radiance_line, this->noData); | ||
reflectance_function(read_bands, mtl, sensor, radiance_line, width_band, line, reflectance_line, this->noData); | ||
|
@@ -141,16 +144,15 @@ void Landsat::process_final_products(Station station, MTL mtl){ | |
|
||
Candidate hot_pixel, cold_pixel; | ||
|
||
if (this->method == 0) { //Our SEBAL | ||
hot_pixel = select_hot_pixel(&ndvi, &surface_temperature, &net_radiation, &soil_heat, height_band, width_band); | ||
cold_pixel = select_cold_pixel(&ndvi, &surface_temperature, &net_radiation, &soil_heat, height_band, width_band); | ||
if (this->method == 0) { //STEEP | ||
hot_pixel = getHotPixelSTEPP(&ndvi, &surface_temperature, &albedo, &net_radiation, &soil_heat, height_band, width_band); | ||
cold_pixel = getColdPixelSTEPP(&ndvi, &surface_temperature, &albedo, &net_radiation, &soil_heat, height_band, width_band); | ||
} else if (this->method == 1) { //ASEBAL | ||
hot_pixel = getHotPixel(&ndvi, &surface_temperature, &albedo, &net_radiation, &soil_heat, height_band, width_band); | ||
cold_pixel = getColdPixel(&ndvi, &surface_temperature, &albedo, &net_radiation, &soil_heat, height_band, width_band); | ||
} else if (this->method == 2) { //ESA SEBAL | ||
TIFF* land_cover = TIFFOpen(this->land_cover_path.c_str(), "r"); | ||
pair<Candidate, Candidate> pixels = esaPixelSelect(&ndvi, &surface_temperature, &albedo, &net_radiation, &soil_heat, &land_cover, height_band, width_band, this->output_path); | ||
|
||
hot_pixel = pixels.first, cold_pixel = pixels.second; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]){ | |
if(noData_flag.substr(0,5) == "-nan=") | ||
noData = atof(noData_flag.substr(5, noData_flag.size()).c_str()); | ||
} | ||
|
||
string tal_path = argv[9]; | ||
|
||
TIFF *bands_resampled[8]; | ||
|
@@ -70,11 +70,11 @@ int main(int argc, char *argv[]){ | |
|
||
Landsat landsat = Landsat(tal_path, output_path, method, noData, landCoverPath); | ||
|
||
begin = chrono::steady_clock::now(); | ||
landsat.process_partial_products(bands_resampled, mtl, station, sensor); | ||
end = chrono::steady_clock::now(); | ||
time_span_us = chrono::duration_cast< chrono::duration<double, micro> >(end - begin); | ||
printf("PHASE 1 - DURATION, %.5f\n", time_span_us); | ||
// begin = chrono::steady_clock::now(); | ||
// landsat.process_partial_products(bands_resampled, mtl, station, sensor); | ||
// end = chrono::steady_clock::now(); | ||
// time_span_us = chrono::duration_cast< chrono::duration<double, micro> >(end - begin); | ||
// printf("PHASE 1 - DURATION, %.5f\n", time_span_us); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remover comentários acima |
||
|
||
begin = chrono::steady_clock::now(); | ||
|
||
|
@@ -84,4 +84,4 @@ int main(int argc, char *argv[]){ | |
time_span_us = chrono::duration_cast< chrono::duration<double, micro> >(end - begin); | ||
printf("PHASE 2 - DURATION, %.5f\n", time_span_us); | ||
return 0; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por que removeu o make?