Skip to content

Commit

Permalink
add output folder selection
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshCu committed Jun 21, 2024
1 parent ae6665d commit deb8e2e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
12 changes: 6 additions & 6 deletions modules/data_processing/file_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class file_paths:
methods do.
"""

config_file = Path("~/.NGIAB_data_preprocess").expanduser()

def __init__(self, wb_id: str):
"""
Initialize the file_paths class with a water body ID.
Expand All @@ -21,17 +23,15 @@ def __init__(self, wb_id: str):

@staticmethod
def get_working_dir() -> Path:
# check for the .NGIAB_data_preprocessor file in ~ and read the working directory from it
# if it doesn't exist, return the current directory
try:
with open(file_paths.dev_file(), "r") as f:
return Path(f.readline().strip())
with open(file_paths.config_file, "r") as f:
return Path(f.readline().strip()).expanduser()
except FileNotFoundError:
return None

@staticmethod
def set_working_dir(self, working_dir: Path) -> None:
with open(file_paths.dev_file(), "w") as f:
def set_working_dir(working_dir: Path) -> None:
with open(file_paths.config_file, "w") as f:
f.write(str(working_dir))

@staticmethod
Expand Down
32 changes: 27 additions & 5 deletions modules/map_app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@
import requests
import webbrowser


def download_file(url, save_path):
response = requests.get(url, stream=True)
total_size = int(response.headers.get('content-length', 0))
total_size = int(response.headers.get("content-length", 0))
bytes_downloaded = 0
chunk_size = 1048576
with open(save_path, "wb") as f:
for data in tqdm(response.iter_content(chunk_size=chunk_size), total=total_size/chunk_size, unit='MB', unit_scale=True):
for data in tqdm(
response.iter_content(chunk_size=chunk_size),
total=total_size / chunk_size,
unit="MB",
unit_scale=True,
):
bytes_downloaded += len(data)
f.write(data)


hydrofabric_url = "https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v20.1/conus.gpkg"
model_attributes_url = "https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v20.1/model_attributes.parquet"
model_attributes_url = (
"https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v20.1/model_attributes.parquet"
)


if not file_paths.conus_hydrofabric().is_file():
Expand All @@ -44,7 +53,19 @@ def download_file(url, save_path):
else:
print("Exiting...")
exit()


if not file_paths.config_file.is_file():
# prompt the user to set the working directory
print(
"Output directory is not set. Would you like to set it now? Defaults to ~/ngiab_preprocess_output/ (y/N)"
)
response = input()
if response.lower() == "y":
response = input("Enter the path to the working directory: ")
if response == "" or response.lower() == "n":
response = "~/ngiab_preprocess_output/"
file_paths.set_working_dir(response)


with open("app.log", "w") as f:
f.write("")
Expand Down Expand Up @@ -72,12 +93,13 @@ def download_file(url, save_path):
console_handler.setFormatter(formatter)
logging.getLogger("").addHandler(console_handler)


def open_browser():
webbrowser.open("http://localhost:5000")


if __name__ == "__main__":

if file_paths.dev_file().is_file():
with open("app.log", "a") as f:
f.write("Running in debug mode\n")
Expand Down
9 changes: 9 additions & 0 deletions modules/map_app/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ button:hover {
width: fit-content;
}

#output-info {
margin: 20px;
padding: 15px;
background: #ebffaf;
border-left: 5px solid #fdf05c;
border-radius: 8px;
width: fit-content;
}

/* Form input styling */
input[type=datetime-local] {
padding: 10px;
Expand Down
3 changes: 3 additions & 0 deletions modules/map_app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ <h2>Selected Basins</h2>
<button id="subset-to-file-button">Output list of upstreams to file</button>
<img class="loading" src="{{ url_for('static', filename='resources/loading.gif') }}" alt="Loading"
id="subset-to-file-loading">
<div id="output-info">
<strong>Output folder is configured in the ~/.NGIAB_data_preprocess file</strong>
</div>
<div id="output-path"></div>
</section>

Expand Down

0 comments on commit deb8e2e

Please sign in to comment.