Skip to content

Commit

Permalink
merge with code documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tberezowski committed Feb 28, 2024
2 parents 1e31d88 + 9261db4 commit 7f414a6
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/BoundingBox.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

/*
* Class representing analyzed bound box
*/

class BoundingBox
{
public:
Expand Down
4 changes: 4 additions & 0 deletions src/HydroDataReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "csv.hpp"
#include "types.hpp"

/*
Class for paring discharge data.
*/

class HydroDataReader
{
public:
Expand Down
15 changes: 13 additions & 2 deletions src/RasterInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

namespace fs = std::filesystem;

/*
*
* Utility class for extracting infromation about satellite imagery
*
*/

class RasterInfo
{
public:
Expand All @@ -22,13 +28,18 @@ class RasterInfo
Polarization pol;
Date date;
};

/*
*
* This class contains methods to retrevie acquistiion date and polarization for input satellite imagery filebuf*
*
*/
class RasterInfoExtractor
{
public:
virtual RasterInfo extractFromPath(std::string filepath) = 0;
};

//Extractor for file preprocessed using Hyp3
class AsfExtractor : public RasterInfoExtractor
{
public:
Expand All @@ -52,7 +63,7 @@ class AsfExtractor : public RasterInfoExtractor
return RasterInfo(filepath, resultPol, resultDate);
}
};

//Extractor for locally processed imagery files (date + polarization)
class StdExtractor : public RasterInfoExtractor
{
public:
Expand Down
6 changes: 6 additions & 0 deletions src/XYPair.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#pragma once

/*
*
* Utility script for representing coordinates in the algorothm
*
*/

class XYPair
{
public:
Expand Down
6 changes: 6 additions & 0 deletions src/analyze_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#include <sys/wait.h>
#include <thread>

/*
* Utility function that contains main() . This script can is used additionaly to analyze and prepare input data for the floodsar
* algorithm.
*/

namespace fs = std::filesystem;

void
Expand Down Expand Up @@ -75,6 +80,7 @@ main(int argc, char** argv)

std::ifstream proj4file(proj4Path);

//get polarization and date info from imagery filenames
RasterInfo extractedInfo = extractor->extractFromPath(filepath.string());

std::getline(proj4file, extractedInfo.proj4);
Expand Down
31 changes: 29 additions & 2 deletions src/clustering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@
#include <random>
#include <fstream>

/*
* The 2D algorithm that performs clustering on two SAR polarizations at the same time.
@param vectorVH is a cross polarization
@param vectorVV is a co-polarization
@param numClasses is a number of flooded classes
@param maxiter is a maximum number of iteration to find clusters
@param frac is a fraction of pixels that algorithms analyzes in order to find cluster centroids.
*/
const std::string kmeansInputFilename = "KMEANS_INPUT";
const int kmeansMinimumPoints = 100;

/*
*
* Function performs k-means clustering for floodSar
*
*/
void
performClustering(std::vector<double>& vectorVH,
std::vector<double>& vectorVV,
Expand Down Expand Up @@ -159,7 +173,14 @@ performClustering(std::vector<double>& vectorVH,
ofsPoints << clusterAssignments[i] << "\n";
}
}

/*
Function that returns a vector with classes list
*
* @params clusersFilePath is a prefix for filenemame that stores flood mapping results
* @params classesNum is a number of flood classes
* @params is a strategy how to pick flood classes. Only applicable to 2D algorithm. Possible values: vh, vv, sum.
*
*/
std::vector<unsigned int>
createFloodClassesList(std::string clustersFilePath,
unsigned int classesNum,
Expand Down Expand Up @@ -202,6 +223,12 @@ createFloodClassesList(std::string clustersFilePath,


void
/*
Function to calculate flooder Areas
@params floodedAreas is a vector that is filled in during function invocation.
@params numberofClasses iz total number of classes analyzed by k-means
@params floodClassesNum is a number of flood classes to calculate area
*/
calculateFloodedAreasFromKMeansOutput(
std::vector<unsigned int>& floodedAreas, // vector to fill
unsigned int numberOfClasses,
Expand Down
4 changes: 4 additions & 0 deletions src/csv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <string>
#include <vector>

/*
* Class for reading a CSV file with discharge data. See exammple -> discharge.csv file
*/

class CSVRow
{
public:
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "utils.hpp"
#include "clustering.hpp"

/*
* Main function file
*/

namespace fs = std::filesystem;


Expand Down
11 changes: 9 additions & 2 deletions src/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

namespace fs = std::filesystem;

/*
*
* This is a postprocessing script for transforming floodSar results to rasters.
*
*/
int
main(int argc, char** argv)
{
Expand All @@ -34,6 +39,7 @@ main(int argc, char** argv)
"a,auto",
"automatically use best k-means results");

//default values for 1D algorithm
int numAllClassess = 2;
int numFloodClasses = 1;
int aa;
Expand Down Expand Up @@ -67,12 +73,12 @@ main(int argc, char** argv)
// base algoritm mapping.
floodClasses.push_back(1);
std::string pol = userInput["base"].as<std::string>();
// bedzie VV albo VH
// either VV or VH

pointsFile = "./.floodsar-cache/1d_output/" + pol;
mapDirectory = "./mapped/base_algo_pol_" + pol + "/";
} else {
// improved algo mapping.
// 2D algroithm
if (userInput.count("auto"))
{
std::ifstream bestClassStream(".floodsar-cache/kmeans_outputs/best.txt");
Expand Down Expand Up @@ -167,6 +173,7 @@ main(int argc, char** argv)
std::cout << "Its time to stop. \n";
break;
}
//mapPath contains reults raster for particular date
mapPath = mapDirectory + dates[dateIndex] + ".tif";
std::filesystem::copy_file(rasterToClassify, mapPath);

Expand Down
7 changes: 7 additions & 0 deletions src/polarization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

#include <iostream>

/*
*
* Utility scripts for converting strings to polarization and vice versa.
*
*/


enum class Polarization
{
VH,
Expand Down
30 changes: 27 additions & 3 deletions src/rasters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#include <thread>
#include <fstream>


/*
* Gets the bounding box of Sentintel Imagery raster
* @param raster is retreived from GDAL
*
*/

BoundingBox
getRasterBoundingBox(GDALDataset* raster)
{
Expand Down Expand Up @@ -41,6 +48,13 @@ getRasterBoundingBox(GDALDataset* raster)
return boundingBox;
}

/*
* The functions crops satellite imagery in smaller region of interes
* @param zoneBbox defines area of interest
* @param info is a georeference info GDAL
* @param epsgCode is projection code applied in satelltie imagery*
*/

void
cropToZone(BoundingBox zoneBBox, RasterInfo info, std::string epsgCode)
{
Expand Down Expand Up @@ -68,6 +82,13 @@ cropToZone(BoundingBox zoneBBox, RasterInfo info, std::string epsgCode)
std::system(command.c_str());
}

/* The function reduces geographcially raster to the area of interest in order to save memory.
*
* @param rasterPaths is a vector of raster information (RasterInfo) of analyzed satellite imageries
* @param aoiDataset is a pointer to imagery data
* @param epsgCode is a cartographic projection code used in imagery (assumed equal to every imagery)
*
*/
void
cropRastersToAreaOfInterest(std::vector<RasterInfo>& rasterPaths,
GDALDataset* aoiDataset,
Expand Down Expand Up @@ -97,6 +118,7 @@ cropRastersToAreaOfInterest(std::vector<RasterInfo>& rasterPaths,
}
}

//get imagery projection info
void
getProjectionInfo(std::string rasterPath, std::string proj4filePath)
{
Expand All @@ -120,8 +142,7 @@ printProjCrs(RasterInfo info)
std::system(command.c_str());
}

// returns absolute paths to all images that will take part in calculating the
// result
// returns absolute paths to all images that will take part in calculating the result...
std::vector<RasterInfo>
readRasterDirectory(std::string dirname,
std::string fileExtension,
Expand Down Expand Up @@ -183,6 +204,7 @@ mosaicRasters(const std::string targetPath,
std::system(command.c_str());
}

//if two rasters with the same are present then mosaicing is performed...
void
performMosaicking(std::vector<RasterInfo>& rasterInfos,
std::vector<RasterInfo>& outputVector)
Expand Down Expand Up @@ -226,6 +248,7 @@ performMosaicking(std::vector<RasterInfo>& rasterInfos,
}
}

//prefrom reprojection using GDAL (gdalwarp)
std::string
performReprojection(RasterInfo& info, std::string epsgCode)
{
Expand All @@ -248,7 +271,7 @@ performReprojection(RasterInfo& info, std::string epsgCode)

return filename;
}

//in case of different projection of a raster file..
void
reprojectIfNeeded(std::vector<RasterInfo>& rasters, std::string epsgCode)
{
Expand Down Expand Up @@ -301,6 +324,7 @@ getPixelValuesFromRaster(GDALDataset* raster,
CPLFree(buffer);
}

// Method to calculae flooder area basing on threshold in 1D algorithm
unsigned int
calcFloodedArea(GDALDataset* raster, double threshold)
{
Expand Down
5 changes: 4 additions & 1 deletion src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct ClassifiedCentroid
double vv;
unsigned int cl;
};

//simple utilites to compare value of centroids by polariztion (vh,vv or sum).
struct compareByVH
{
inline bool operator()(const ClassifiedCentroid& c1,
Expand Down Expand Up @@ -105,6 +105,7 @@ calcCorrelationCoeff(std::vector<unsigned int>& floodedAreaVals,
return corr;
}

//Converts hydrological date format to standard date format yyyymmdd
Date
hydrologicalToNormalDate(std::string_view year,
std::string_view month,
Expand Down Expand Up @@ -156,6 +157,7 @@ hydrologicalToNormalDate(std::string_view year,
return out;
}

//utility function that prints obsElevationMaps to console
void
printMap(const std::map<std::string, double>& m)
{
Expand All @@ -165,6 +167,7 @@ printMap(const std::map<std::string, double>& m)
std::cout << '\n';
}

//creates neccasary local files
void
createCacheDirectoryIfNotExists()
{
Expand Down

0 comments on commit 7f414a6

Please sign in to comment.