Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 4a270e1
Merge: 64bd0b0 d14fce4
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Thu Jun 6 07:04:33 2024 -0700

    Merge branch 'pr-255' into new_release/1.2.6

commit 64bd0b0
Merge: 2f84fa2 e7d8e89
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Thu Jun 6 07:01:40 2024 -0700

    Merge branch 'issue/259/get_kmeans_cluster' into new_release/1.2.6

commit 2f84fa2
Merge: c0b2d01 606488f
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Thu Jun 6 07:01:25 2024 -0700

    Merge branch 'temp/issue/patch/251' into new_release/1.2.6

commit e7d8e89
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Tue Jun 4 15:38:46 2024 -0700

commit 7ffdf9d
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Tue Jun 4 13:11:09 2024 -0700

commit d14fce4
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Tue Jun 4 12:37:53 2024 -0700

commit 111d8ae
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Tue Jun 4 12:14:09 2024 -0700

    Fix the issue where ROI IDs were not converted to strings if passed as ints

commit 5e5da50
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Tue Jun 4 12:13:28 2024 -0700

commit 606488f
Merge: a366bb0 7a397c9
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Wed May 29 19:41:10 2024 -0700

    Merge branch 'fix/roi/id_issue' into temp/issue/patch/251

commit 7a397c9
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Tue May 21 13:57:55 2024 -0700

    fix preview available imagery to accept ids

commit 0b68d41
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Tue May 21 13:57:27 2024 -0700

    force roi to turn all incoming ids into type string

commit fdcc737
Author: Floris Calkoen <44444001+FlorisCalkoen@users.noreply.github.com>
Date:   Tue May 21 22:26:53 2024 +0200

     helper function to infer data dir

commit 441a06a
Author: floriscalkoen <floris_calkoen@hotmail.com>
Date:   Tue May 21 22:15:46 2024 +0200

    helper function to infer data dir

commit a366bb0
Author: Sharon Fitzpatrick <SF2309@Gmail.Com>
Date:   Tue May 21 13:15:21 2024 -0700

    add some docstrings, improve error messages and organize loading from config
  • Loading branch information
2320sharon committed Jun 6, 2024
1 parent 24d6ba6 commit a631569
Show file tree
Hide file tree
Showing 18 changed files with 377 additions and 143 deletions.
29 changes: 14 additions & 15 deletions 1_download_imagery.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import os
from coastseg import coastseg_logs
from coastseg.common import initialize_gee
from coastseg import coastseg_map
import os
from coastseg import core_utilities

base_dir = core_utilities.get_base_dir()
print(f"The base directory is {base_dir}")
# path to Coastseg/data
data_folder = base_dir / "data"
print(f"The data directory is {data_folder}")

# if you get an error here, enter your project id
initialize_gee(auth_mode = "localhost",project='')

# initialize the CoastSeg map
coastsegmap=coastseg_map.CoastSeg_Map(create_map=False)

# Get the directory of the current script
script_dir = os.path.dirname(os.path.abspath(__file__))
print(f"The script directory is {script_dir}")
# Construct the path to rois.geojson
rois_path = os.path.join(script_dir, 'examples',"rois.geojson")
rois_path = os.path.join(os.path.abspath(base_dir), 'examples',"rois.geojson")
print(f"Loading ROIs from {rois_path}")

# path to Coastseg/data
data_folder = os.path.join(script_dir, 'data')
print(f"The data folder is {data_folder}")

# sample ROI (Region of Interest) file
roi = coastsegmap.load_feature_from_file('roi',rois_path)
print(roi)
Expand All @@ -35,10 +34,11 @@
"apply_cloud_mask": True, # apply cloud mask to the imagery. If False, the cloud mask will not be applied.
}

# download the imagery for that ROI to the /data folder
# # download the imagery for that ROI to the /data folder
coastsegmap.download_imagery(rois=roi.gdf,selected_ids=roi_ids,settings=settings,file_path=data_folder)

# name the session where you want to save the extracted shorelines
# session_name = 'sample_session1'
session_name = 'sample_session1'
coastsegmap.set_session_name(session_name)

Expand All @@ -47,15 +47,14 @@
# - a minimum beach area of 500 m^2
# - a minimum length of 20 m
# - a maximum distance from the reference shoreline of 300 m
coastsegmap.set_settings(min_beach_area=500,min_length_sl=20,max_dist_ref=300)
coastsegmap.set_settings(min_beach_area=100,min_length_sl=20,max_dist_ref=300)

# load a shoreline file from the examples folder
script_dir = os.path.dirname(os.path.abspath(__file__))
shoreline_path = os.path.join(script_dir, 'examples', "shoreline.geojson")
shoreline_path = os.path.join(base_dir, 'examples', "shoreline.geojson")
shoreline = coastsegmap.load_feature_from_file('shoreline',shoreline_path)

# load transects from the examples folder
transect_path = os.path.join(script_dir,'examples', "transects.geojson")
transect_path = os.path.join(base_dir,'examples', "transects.geojson")
transects = coastsegmap.load_feature_from_file('transects', transect_path)

# extract the shorelines for the selected ROI and save them to the /sessions/session_name folder
Expand Down
7 changes: 5 additions & 2 deletions 2_extract_shorelines.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
from coastseg import coastseg_logs
from coastseg import coastseg_map
import os
from coastseg import core_utilities

base_dir = core_utilities.get_base_dir()

# Run this script only after running 1_download_imagery.py

Expand All @@ -10,7 +13,7 @@
# Enter the name of the session you want to load here
session_name = 'sample_session1'
# session_name = 'paper_dfg2_extract_shorelines_buffer_62'
session_path = os.path.join(os.getcwd(),'sessions', session_name)
session_path = os.path.join(os.path.abspath(base_dir),'sessions', session_name)
print(f"Loading session from {session_path}")
# r"C:\development\doodleverse\coastseg\CoastSeg\sessions\paper_dfg2_extract_shorelines_buffer_62"
coastsegmap.load_fresh_session(session_path)
Expand Down
10 changes: 5 additions & 5 deletions src/coastseg/coastseg_logs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from datetime import datetime
import logging

from coastseg import core_utilities
# DESCRIPTION: Sets up a logging system that writes logs to a file named with the current timestamp in a "logs" directory.


def prepare_logging():
"""create a directory named 'logs' in the current working directory if a 'logs' directory does not exist"""
if not os.path.exists(os.path.abspath(os.path.join(os.getcwd(), "logs"))):
os.mkdir(os.path.abspath(os.path.join(os.getcwd(), "logs")))
if not os.path.exists(os.path.abspath(os.path.join(core_utilities.get_base_dir(), "logs"))):
os.mkdir(os.path.abspath(os.path.join(core_utilities.get_base_dir(), "logs")))


def clear_default_handlers() -> None:
Expand All @@ -22,10 +22,10 @@ def create_root_logger():
log_<year>-<month>-<day>-<hour>-<minute>. This log file will be written to by all the other loggers
"""
log_filename = "log_" + datetime.now().strftime("%m-%d-%y-%I_%M_%S") + ".txt"
log_file = os.path.abspath(os.path.join(os.getcwd(), "logs", log_filename))
log_file = os.path.abspath(os.path.join(core_utilities.get_base_dir(), "logs", log_filename))
# configure the logger
log_format = "%(asctime)s - %(filename)s at line %(lineno)s in %(funcName)s() - %(levelname)s : %(message)s"
os.path.abspath(os.path.join(os.getcwd(), "logs"))
os.path.abspath(os.path.join(core_utilities.get_base_dir(), "logs"))
# Use FileHandler() to log to a file
file_handler = logging.FileHandler(log_file, mode="a")
formatter = logging.Formatter(log_format)
Expand Down
Loading

0 comments on commit a631569

Please sign in to comment.