Skip to content

Commit 8d0771a

Browse files
authored
Merge pull request #58 from via-cs/wip/cleanup
Wip/cleanup
2 parents cd35a45 + 92e03db commit 8d0771a

File tree

5 files changed

+32
-41
lines changed

5 files changed

+32
-41
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
# Usage
22

33
## To start the Flask Backend:
4-
- ```cd``` into ```/birdmig/backend/app```
4+
- Ensure all requirements are installed
5+
- This can be done by running `pip install -r requirements.txt` in `/backend`
56
- Run the backend
6-
- To run the backend for showcase and documentation purposes, enter ```fastapi dev base.py``` in your terminal.
7+
- ```cd``` into ```/backend/app```
8+
- Run the command ```fastapi dev base.py``` in your terminal in order to start the backend.
79
- Access docs by navigating to ```localhost:8000/docs``` on your web browser
810
- To run the backend for debugging purposes, run ```uvicorn base:app --reload``` in your terminal.
911
- Note that this only runs the backend. It can not be navigated to on the web browser, nor will documentation be available.
1012

1113
## To start the React Frontend:
1214

1315
- ```cd``` into ```/birdmig```
14-
- If the front end was never run before, run the following commands:
15-
```
16-
npm install &&
17-
npm install d3 &&
18-
npm install react-cookie &&
19-
npm install leaflet react-leaflet leaflet-arrowheads leaflet-polylinedecorator &&
20-
npm install --save-dev @testing-library/react @testing-library/jest-dom jest-fetch-mock &&
21-
npm install --save-dev @testing-library/jest-dom
22-
```
23-
- enter ```npm start``` in your terminal
16+
- Run the command ```npm install``` to install required packages
17+
- Run ```npm start``` in your terminal to start the front end
2418

2519
# To run Docker with all applications
2620
- Ensure that the Docker daemon is running

model/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,4 @@ The general code structure is notated in `birdmid-sdm.ipynb`. The actual scripts
7474
used for SDM training and predicting are `model_train.py` and
7575
`model_predict.py` respectively.
7676
77-
### Using `model_train.py`
78-
79-
### Using `model_predict.py`
77+
In order to run the SDM model, see the technical document located at `/techdoc/tech-doc.pdf`

src/App.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
grid-template-columns: repeat(2, 1fr);
1111
gap: 20px;
1212
padding: 20px 20px;
13-
margin-top: 60px;
13+
margin-top: 100px;
1414
background-color: #ecf0f1;
1515
overflow-y: auto;
1616
}
@@ -19,7 +19,7 @@
1919
background-color: #2c3e50;
2020
color: white;
2121
width: 100%;
22-
height: 15%;
22+
height: 100px;
2323
top: 0;
2424
left: 0;
2525
position: fixed;
@@ -50,7 +50,7 @@
5050
width: 100%;
5151
width: 200px;
5252
margin-top: 100px;
53-
padding-top: 15%;
53+
padding-top: 10px;
5454
background-color: #2c3e50;
5555
color: white;
5656
display: flex;

techdoc/tech-doc.pdf

19.1 KB
Binary file not shown.

techdoc/tech-doc.tex

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ \subsubsection*{Requirements}
147147
\\\\
148148
Required libraries include \texttt{os, tqdm, glob, pyimpute, pickle, rasterio, matplotlib, geopandas, sklearn, numpy,} and \texttt{pandas}. These libraries can be installed in a Python terminal using \texttt{pip}.
149149
\\\\
150-
Ensure that preprocessed data from R exists under \texttt{/model/input/}. There should be three folders: \texttt{geojson, historical,} and \texttt{future}, each containing the appropriate data. \texttt{geojson} and \texttt{historical} are required for model training, while \texttt{future} and \texttt{/data/pickle} is required for model predicting. Example pickle files can be found at the Box link \href{https://ucdavis.box.com/s/l5iky1y6z526r6ewifvtr6c4ccp5jsjz}{here}.
150+
Ensure that preprocessed data from R exists under \texttt{/model/input/}. There should be three folders: \texttt{geojson, historical,} and \texttt{future}, each containing the appropriate data. \texttt{geojson} and \texttt{historical} are required for model training, while \texttt{future} and \texttt{/data/models} is required for model predicting. Example pickle files under \texttt{/data/models} can be found at the Box link \href{https://ucdavis.box.com/s/l5iky1y6z526r6ewifvtr6c4ccp5jsjz}{here}.
151151

152152
\subsubsection{SDM Training}
153153
The model is trained by associating presence/absence data with zonal averages for temperature and precipitation. In other words, the model learns what zonal environmental factors typically correlate to a presence or absence of a species. When given a file containing possible future climate readings, the model can then predict how the distribution of a species may react to that climate.
@@ -201,14 +201,14 @@ \subsubsection{SDM Predicting}
201201

202202
\noindent There exists a future climate raster for each year (2015-2100) for each SSP (ssp126, ssp245, ssp370, ssp585). These rasters are used to predict distribution for five species, making a total of 1,720 images.
203203
\\\\
204-
\texttt{\href{run:../model/model\_prediction.py}{model\_prediciton.py}} is comprised of a triple-nested for loop (species > ssp > year) and two functions, \texttt{make\_predictions()} and \texttt{create\_pngs()}. The former function is responsible for steps 1-3 listed above, while the latter function is responsible for step 4. TIFF images are converted to PNG through the use of \texttt{matplotlib}, and are saved in high resolution.
204+
\texttt{\href{run:../model/model\_prediction.py}{model\_prediciton.py}} is comprised of a triple-nested for loop (species \verb|->| ssp \verb|->| year) and two functions, \texttt{make\_predictions()} and \texttt{create\_pngs()}. The former function is responsible for steps 1-3 listed above, while the latter function is responsible for step 4. TIFF images are converted to PNG through the use of \texttt{matplotlib}, and are saved in high resolution.
205205

206206
\section{Web Application}
207207

208208
\subsection{APIs}
209209

210210
\subsubsection{React}
211-
Reactjs was used to created the front end, and the main component is found under \texttt{/src/App.js}. In App.js, there are calls to the back end to gather data for the various components
211+
React.js was used to created the front end, and the main component is found under \texttt{/src/App.js}. In App.js, there are calls to the back end to gather data for the various components
212212
located in the \texttt{/src/components} folder. These components include:
213213
\begin{itemize}
214214
\item \texttt{BirdInfo.js}: returns the summary of the desired bird
@@ -282,16 +282,6 @@ \subsection{Usage}
282282

283283
\subsubsection{Requirements}
284284

285-
The front end of the application was implemented with ReactJS. For ReactJS to work, first Node.js must be installed. Information on how to do so can be found \href{https://nodejs.org/en/learn/getting-started/how-to-install-nodejs}{here}. Once Node.js is installed, download ReactJS and Leaflet. Running the following lines of code in the project root directory in either the Linux command line or the Windows terminal will install the dependencies to run the front end:
286-
\begin{verbatim}
287-
npm install
288-
npm install d3
289-
npm install react-cookie
290-
npm install leaflet react-leaflet leaflet-arrowheads leaflet-polylinedecorator
291-
npm install --save-dev @testing-library/react @testing-library/jest-dom jest-fetch-mock
292-
npm install --save-dev @testing-library/jest-dom
293-
\end{verbatim}
294-
295285
The backend developed primarily with Python 3.12, but also functions on Python 3.11. It relies primarily on FastAPI for functionality, while unit testing is done using the \texttt{pytest} python module. Ensure that the correct Python version (Python 3.12 or Python 3.11) is installed, and ensure the following Python modules are installed:
296286

297287
\begin{verbatim}
@@ -306,7 +296,10 @@ \subsubsection{Requirements}
306296
pytest
307297
\end{verbatim}
308298

309-
All these modules are able to be installed using the command \texttt{pip install}.
299+
\noindent These modules can be installed by running the command \texttt{pip install -r requirements.txt} in \texttt{/backend}.
300+
\\\\
301+
The front end of the application was implemented with React.js. For React.js to work, first Node.js must be installed. Information on how to do so can be found \href{https://nodejs.org/en/learn/getting-started/how-to-install-nodejs}{here}. Once Node.js is installed, download React.js and Leaflet. Alternatively, running \texttt{npm install} in terminal will install the dependencies required to run the front end.
302+
310303

311304
\subsubsection{Process/Steps}
312305
\begin{enumerate}
@@ -315,17 +308,16 @@ \subsubsection{Process/Steps}
315308
\item Start the backend first by following the following steps:
316309
\begin{enumerate}
317310
\item In the terminal dedicated to the back end, run the \texttt{cd} command until the current working directory of the terminal is \texttt{"project root"/backend/app}. for example, if the project is located in a folder called \texttt{birdmigration}, the working directory of the back end terminal should be \texttt{birdmigration/backend/app}.
318-
\item If the back end is being run for the f
319-
\item In this terminal, run the command \texttt{fastapi dev base.py}.
311+
\item In this directory, run the command \texttt{fastapi dev base.py}.
320312
\item To access documentation of the back end, use a web browser and navigate to \url{localhost:8000/docs}
321313
\item The back end should update automatically with saved modifications to the file. To terminate the back end, terminate the program with a SIGINT using \texttt{control + C}, if using either a Linux or Windows command terminal.
322314
\end{enumerate}
323315
\item Once the back end is initialized, the front end of the application may be started.
324316
\begin{enumerate}
325-
\item In the terminal dedicated to running the front end, ensure the current working directory of the terminal is the root folder for the project. This can be checked by using the command \texttt{ls}, and seeing if the folder \texttt{"project root"/src}\texttt is listed.
326-
\item If this is the first time the front end is being started, run the command \texttt{npm install} to ensure that all the necessary Reactjs components and shortcut commands are installed and functional in this directory.
327-
\item Once the shortcut commands for Reactjs are installed (refer to the prior step), run the command \texttt{npm start}.
328-
\item After a couple seconds of loading the front end application, the front end should open automatically in a new web browser window. If this window is either closed or does not open, use a web browser to navigate to \texttt{http://localhost:3000} to observe the front end User Interface.
317+
\item In the terminal dedicated to running the front end, ensure the current working directory of the terminal is the root folder for the project. This can be checked by using the command \texttt{ls}, and seeing if the folder \texttt{"project root"/src} is listed.
318+
\item Run the command \texttt{npm install} to ensure that all the necessary React.js components and shortcut commands are installed and functional in this directory.
319+
\item Once the shortcut commands for React.js are installed (refer to the prior step), run the command \texttt{npm start}.
320+
\item After a frew minutes, the front end should open automatically in a new web browser window. If this window is either closed or does not open, use a web browser to navigate to \texttt{http://localhost:3000} to observe the front end User Interface.
329321
\end{enumerate}
330322
\item Do not close either terminal unless their respective application is fully terminated. If a new terminal is started and another instance of either the front end or the back end is already running, a restart of the device may be required.
331323
\end{enumerate}
@@ -343,17 +335,24 @@ \subsection{Design}
343335

344336
\subsection{FAQ}
345337

346-
The necessary ReactJS components are installed, but the front end application is still causing an error.
338+
\noindent \textit{The necessary React.js components are installed, but the front end application is still causing an error.}
347339

348340
\begin{itemize}
349-
\item Ensure that all necessary Reactjs libraries have been installed in the project directory using the \texttt{npm install} command.
341+
\item Ensure that all necessary React.js libraries have been installed in the project directory using the \texttt{npm install} command.
350342
\item If the front end still does not start, the React cache may need to be cleared. In a Windows or Linux terminal, navigate to the root folder of the project using the \texttt{cd} command, and run the command npm cache clean --force to clear the React cache, and then execute \texttt{npm install}.
351343
\end{itemize}
352344

353-
The terminals that house the front end and/or back end have been closed without terminating the program, and now the corresponding end point of the application will not start.
345+
\noindent \textit{The terminals that house the front end and/or back end have been closed without terminating the program, and now the corresponding end point of the application will not start.}
354346

355347
\begin{itemize}
356348
\item Restart the device, and ensure that the back end and front end applications have fully terminated before closing the terminals. This can be forced by forcing a SIGINT on the program with \texttt{control + C} on either the Windows or Linux terminal.
357349
\end{itemize}
358350

351+
\noindent \textit{Running FastAPI on \texttt{base.py} fails due to missing packages}.
352+
353+
\begin{itemize}
354+
\item Ensure your terminal is in the \texttt{/backend/app} directory.
355+
\item Ensure that all required python packages are installed. This can be done by running \texttt{pip install -r requirements.txt} in \texttt{/backend}
356+
\end{itemize}
357+
359358
\end{document}

0 commit comments

Comments
 (0)