Skip to content

Commit 2b2c65b

Browse files
last
1 parent 954789a commit 2b2c65b

21 files changed

+418
-56
lines changed

analysis/create_sql.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sql = []
2+
with open("data/fires_after.csv", 'r') as f:
3+
for i in f.readlines():
4+
sql.append(f"""INSERT INTO FIRE_After SELECT 100, ST_AsText(ST_Transform(ST_Translate(ST_Transform(ST_SetSRID(ST_MakePoint('-124','54'), 4326), 32654), -(630+{i.split(',')[1]})*30, -(530+{i.split(',')[0]})*40), 4326));""")
5+
6+
with open("data.txt", "w+") as f:
7+
f.writelines(sql)

include/Cell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class cell
3636
/// @brief possible state becomes present, often is called during iteration
3737
void setNewState();
3838

39+
/// @brief set altitude to the cell
40+
/// @param altitude
3941
void setAltitude(int altitude);
4042
int getAltitude() const;
4143
~cell();

include/CellStorage.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ class CellStorage
2323
int16_t x_size_;
2424
int16_t y_size_;
2525
std::vector<std::vector<std::shared_ptr<cell>>> terrain_;
26-
Math* formula_;
26+
IMath* formula_;
2727

2828
//cell terrain_[getXArea()][getYArea()];
2929

3030
void iterateSquare(int xMin, int yMin, int xMax, int yMax);
3131

3232
public:
3333

34-
CellStorage(Math* formula);
35-
CellStorage(Math* formula, int16_t x_size, int16_t y_size);
34+
CellStorage(IMath* formula);
35+
CellStorage(IMath* formula, int16_t x_size, int16_t y_size);
3636
~CellStorage();
3737

3838
/// @brief set state of a particular cell with no checking bound invariant
@@ -84,6 +84,7 @@ class CellStorage
8484

8585
void saveFiresToJson();
8686

87+
/// @brief load the states from the file "previous.txt"
8788
void uploadFromTxt();
8889

8990
CellStorage* CopySquare(int xMin, int yMin, int xMax, int yMax) const;

include/Math.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ struct std::hash<WindMetaData>
5050
}
5151
};
5252

53-
class Math
53+
class IMath
5454
{
5555
private:
5656
public:
57-
Math();
57+
IMath();
5858
// virtual double calculateKoef(float windSpeed, double slopeAngleRad) const = 0;
5959
// virtual double calculateWindKoef(const cell* c, directions InvestigatedDirection) const = 0;
6060
virtual bool willSpread(const cell *c, directions InvestigatedDirection, int altitudeDifference) const = 0;
6161
virtual bool willSpreadThroughOne(const cell *c, directions InvestigatedDirection, int altitudeDifference) const = 0;
62-
~Math();
62+
~IMath();
6363
};
6464

6565
constexpr int ignitionPercentage()
@@ -76,7 +76,7 @@ constexpr int throughPercentage()
7676
/// "Aildland fire spread modelling using cellular
7777
/// automata: evolution in large-scale spatially heterogeneous environments
7878
/// under fire suppression tactics"
79-
class Math1 final : public Math
79+
class Math final : public IMath
8080
{
8181
private:
8282
mutable std::unordered_map<SlopeMetaData, int> slope_counter_;
@@ -104,6 +104,6 @@ class Math1 final : public Math
104104
public:
105105
bool willSpread(const cell *c, directions InvestigatedDirection, int altitudeDifference) const override;
106106
bool willSpreadThroughOne(const cell *c, directions InvestigatedDirection, int altitudeDifference) const override;
107-
Math1();
108-
~Math1();
107+
Math();
108+
~Math();
109109
};

include/ProfilingDecorator.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ struct std::hash<metaData>
3232
}
3333
};
3434

35-
class ProfilingDecorator final : public Math
35+
/// @brief class that store metrics and call Math primary class atttributes
36+
class ProfilingDecorator final : public IMath
3637
{
3738
private:
38-
Math *primary_class_;
39+
IMath *primary_class_;
3940
mutable int positive_counter_;
4041
mutable int counter_;
4142
mutable clock_t overall_timer_;
4243
mutable std::unordered_map<metaData, int> results_;
4344
mutable std::unordered_map<directions, int> results_directions_;
4445

4546
public:
46-
ProfilingDecorator(Math *formula);
47+
ProfilingDecorator(IMath *formula);
4748
bool willSpread(const cell *c, directions InvestigatedDirection, int altitudeDifference) const override;
4849
bool willSpreadThroughOne(const cell *c, directions InvestigatedDirection, int altitudeDifference) const override;
4950
~ProfilingDecorator();

include/Wind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Wind
1414
float getWindSpeed() const;
1515
int getMoistureCoeff() const;
1616

17-
/// @deprecated now calculates over math module
17+
/// @deprecated now calculates in math module
1818
/// @brief calculate the wind coeff based on mathematical model
1919
/// @param InvestigatedDirection direction in which koeff is investigated
2020
/// @return calculated coefficient

parsing/CMRParser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from utils import IBoundingBox, IDataset
2+
import requests
3+
4+
class CMSParser:
5+
def __init__(self, box: IBoundingBox, dataset: IDataset) -> None:
6+
self.box = box
7+
self.dataset = dataset
8+
9+
def parse_file_names(self) -> list[str]:
10+
req = requests.get(f'https://cmr.earthdata.nasa.gov/search/granules.json?{self.dataset.identifier}&page_size=2000&pageNum=1&bounding_box={self.box.W},{self.box.S},{self.box.E},{self.box.N}').json()['feed']['entry']
11+
files = [g['links'][0]['href'] for g in req]
12+
return self.dataset.process_file_names(files)

parsing/FileDownloader.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
3+
def read_token():
4+
return "eyJ0eXAiOiJKV1QiLCJvcmlnaW4iOiJFYXJ0aGRhdGEgTG9naW4iLCJzaWciOiJlZGxqd3RwdWJrZXlfb3BzIiwiYWxnIjoiUlMyNTYifQ.eyJ0eXBlIjoiVXNlciIsInVpZCI6ImVhcnRoZGF0YWZvcnN0dWR5IiwiZXhwIjoxNzM0OTgzMDQ0LCJpYXQiOjE3Mjk3OTkwNDQsImlzcyI6Imh0dHBzOi8vdXJzLmVhcnRoZGF0YS5uYXNhLmdvdiJ9.jrRFN_ViJAFd2aKs2lgAjcOSwo4Yf7sfUCap5eDFHz700VupWPlCJyOyFUH6VjvjB8Ystoo3Gx3ReKgn8JIspB4bdxVocPzoOKqr1xV_cHYmloK5U9wyqTWV9yQlSieAKPgbXpaGZqMP5XqZMpgVGHEZKsObUWqEJCKf8ZFFAn66uNMKA3EPsyUOGF5inVhzbWt4yC79pfIRAoNaBefqcjYFjuMAvgkRg7YmCV4l19fihYl9ubNAvSJAGrsQxRrK5RSOs2UDO5P2nksuiuiDat1Soi95h7iuGAiWZBeqeFq2_KROXf78VmNVxbyZCHQ0RfSuqmNgkjNoEtaYkLFXbA"
5+
6+
class FileDownloader:
7+
def __init__(self, folder_to_save: str = "./data/") -> None:
8+
self.folder_to_save = folder_to_save
9+
self.__token = read_token()
10+
11+
def download(self, files: list[str]):
12+
sess = requests.Session()
13+
sess.headers = {'Authorization': 'Bearer {0}'.format(self.__token)}
14+
for i in files:
15+
response = sess.get(i, allow_redirects=True)
16+
print(response.status_code)
17+
if response.status_code == 200:
18+
filename = i.split('/')[-1]
19+
with open(f'{self.folder_to_save}{filename}', 'wb') as f:
20+
f.write(response.content)
21+
22+
23+
24+

parsing/docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3.1'
2+
services:
3+
4+
database:
5+
image: postgis/postgis:17-3.5-alpine
6+
container_name: database
7+
ports:
8+
- '5431:5432'
9+
environment:
10+
POSTGRES_PASSWORD: postgis
11+
PGUSER: postgis
12+
POSTGRES_USER: postgis
13+
POSTGRES_DATABSE: postgis
14+
volumes:
15+
- ./enableExt.sql:/docker-entrypoint-initdb.d/enableExt.sql:ro
16+
- ./data/:/home/database/
17+
- ./to_database.bash:/home/database/to_database.bash
18+
19+
# raster2pgsql -F -I -C -t 10000x10000 /home/database/file1.tif /home/database/file2.tif public.dem > /home/database/out.sql
20+
21+
# raster2pgsql -F -I -C -t 10000x10000 /home/database/1/*.tif public.dem > /home/database/out.sql
22+
23+
# psql -d postgis -f /home/database/out.sql
24+
25+
# raster2pgsql -F -I -C -t 10000x10000 /home/database/2/*.tif public.biomass > /home/database/out.sql
26+
27+
# psql -d postgis -f /home/database/out.sql
28+
29+
# raster2pgsql -F -I -C -t 10000x10000 /home/database/3/*.nc public.weather > /home/database/out.sql
30+
31+
# psql -d postgis -f /home/database/out.sql

parsing/enableExt.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE EXTENSION postgis_raster;
2+
3+
CREATE TABLE IF NOT EXISTS FIRE
4+
(
5+
brightness NUMERIC(3),
6+
geom geometry(Point, 4326)
7+
)

0 commit comments

Comments
 (0)