Skip to content

Commit

Permalink
Merge branch 'main' into classifier_model
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Dec 13, 2024
2 parents ff6a208 + a71a042 commit 996680c
Show file tree
Hide file tree
Showing 51 changed files with 2,862 additions and 2,740 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Publish_package_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# It will create a create a new pip package to release it to pypi with the version specificed by the git tag.
# 🚨 GTHUB SECRETS REQUIRED: secrets.PYPI_TOKEN
# - Used to publish the package to the pypi
name: Publish to Package to PyPi
name: Publish Package to PyPi
on:
push:
# only release a new pip package if the commit it tagged ex.v1.0.3 or v1.2.0dev1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
# This should be the path to the paper within your repo.
paper-path: paper/paper.md
- name: Upload
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: paper
# This is the output path where Pandoc will write the compiled
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/pip_install_e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,36 @@ on:
pull_request:
branches: [main]

name: Test CoastSeg pip install -e .
name: Test CoastSeg Pip Installation
jobs:
Test:
name: ${{ matrix.os }}, ${{ matrix.env }}
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
# tensorflow supports up to python 3.10
os: [ubuntu-latest, windows-latest, macos-latest]
env: [ci/envs/310-coastseg.yaml]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
environment-file: ${{ matrix.env }}
miniconda-version: "latest"
python-version: "3.10"
channels: conda-forge,defaults
- run: |
conda info
conda list
- name: Install coastseg with pip install -e .
run: |
pip install -e . --user
- name: Install dependencies
run: |
conda install -c conda-forge gdal -y
pip install tensorflow
- name: Pip install pytest
run: |
pip install pytest
Expand Down
115 changes: 115 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"title": "CoastSeg: An Accessible and Extendable Hub for Satellite-Derived Shoreline (SDS) Detection and Mapping",
"description": "CoastSeg is an interactive browser-based program that aims to broaden the adoption of satellite-derived shoreline (SDS) detection workflows among coastal scientists and coastal resource management practitioners. SDS is a sub-field of coastal sciences that aims to detect and post-process a time-series of shoreline locations from publicly available satellite imagery.",
"creators": [
{
"name": "Fitzpatrick, Sharon",
"orcid": "0000-0001-6513-9132",
"affiliation": "Contracted to U.S. Geological Survey Pacific Coastal and Marine Science Center, Santa Cruz, California, United States"
},
{
"name": "Buscombe, Daniel",
"orcid": "0000-0001-6217-5584",
"affiliation": "Contracted to U.S. Geological Survey Pacific Coastal and Marine Science Center, Santa Cruz, California, United States"
},
{
"name": "Warrick, Jonathan A.",
"orcid": "0000-0002-0205-3814",
"affiliation": "U.S. Geological Survey Pacific Coastal and Marine Science Center, Santa Cruz, California, United States"
},
{
"name": "Lundine, Mark A.",
"orcid": "0000-0002-2878-1713",
"affiliation": "U.S. Geological Survey Pacific Coastal and Marine Science Center, Santa Cruz, California, United States"
},
{
"name": "Vos, Kilian",
"orcid": "0000-0002-9518-1582",
"affiliation": "New South Wales Department of Planning and Environment, Sydney, Australia"
}
],
"contributors": [
{
"name": "Doran, K.S.",
"orcid": "0000-0001-8050-5727",
"affiliation": "U.S. Geological Survey St. Petersburg Coastal and Marine Science Center, St. Petersburg, FL 33701, United States"
},
{
"name": "Janda, Catherine",
"orcid": "0009-0004-5153-3680",
"affiliation": "U.S. Geological Survey Pacific Coastal and Marine Science Center, Santa Cruz, California, United States"
},
{
"name": "Gibbs, Ann",
"orcid": "0000-0002-0883-3774",
"affiliation": "U.S. Geological Survey Pacific Coastal and Marine Science Center, Santa Cruz, California, United States"
},
{
"name": "Weber, Kathryn M.",
"orcid": "0000-0002-5498-7117",
"affiliation": "U.S. Geological Survey Woods Hole Coastal and Marine Science Center, Woods Hole, MA 02543, United States"
},
{
"name": "O'Neill, Andrea",
"orcid": "0000-0003-1656-4372",
"affiliation": "U.S. Geological Survey Pacific Coastal and Marine Science Center, Santa Cruz, California, United States"
},
{
"name": "Heslin, Julia L.",
"orcid": "0000-0002-6895-800X",
"affiliation": "U.S. Geological Survey Woods Hole Coastal and Marine Science Center, Woods Hole, MA 02543, United States"
},
{
"name": "Burgess, Joseph",
"affiliation": "U.S. Geological Survey St. Petersburg Coastal and Marine Science Center, St. Petersburg, FL 33701, United States"
},
{
"name": "Floris R. Calkoen",
"orcid": "0000-0002-7155-6247",
"affiliation": "Deltares | Delft, Netherlands"
},
{
"name": "Himmelstoss, Emily A.",
"orcid": "0000-0002-1760-5474",
"affiliation": "U.S. Geological Survey Woods Hole Coastal and Marine Science Center, Woods Hole, MA 02543, United States"
},
{
"name": "Bishop-Taylor, Robbi",
"orcid": "0000-0002-1533-2599",
"affiliation": "Geoscience Australia"
},
{
"name": "Lazarus, Eli D.",
"orcid": "0000-0003-2404-9661",
"affiliation": "University of Southampton"
},
{
"name": "Ku, Venus",
"orcid": "0000-0002-7454-8277"
},
{
"name": "Goldstein, Evan B.",
"orcid": "0000-0001-9358-1016",
"affiliation": "Sediment-Science"
}
],
"license": {
"id": "GPL-3.0-only"
},
"keywords": [
"CoastSeg",
"Satellite-Derived Shoreline",
"SDS",
"Coastal Mapping",
"Remote Sensing"
],
"access_right": "open",
"communities": [
{
"identifier": "coastal-science"
}
],
"upload_type": "software",
"language": "eng"
}

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
13 changes: 7 additions & 6 deletions 3_zoo_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@

# Extract Shoreline Settings
settings ={
'min_length_sl': 500, # minimum length (m) of shoreline perimeter to be valid
'max_dist_ref':300, # maximum distance (m) from reference shoreline to search for valid shorelines. This detrmines the width of the buffer around the reference shoreline
'min_length_sl': 100, # minimum length (m) of shoreline perimeter to be valid
'max_dist_ref':500, # maximum distance (m) from reference shoreline to search for valid shorelines. This detrmines the width of the buffer around the reference shoreline
'cloud_thresh': 0.5, # threshold on maximum cloud cover (0-1). If the cloud cover is above this threshold, no shorelines will be extracted from that image
'dist_clouds': 300, # distance(m) around clouds where shoreline will not be mapped
'min_beach_area': 500, # minimum area (m^2) for an object to be labelled as a beach
'dist_clouds': 100, # distance(m) around clouds where shoreline will not be mapped
'min_beach_area': 50, # minimum area (m^2) for an object to be labelled as a beach
'sand_color': 'default', # 'default', 'latest', 'dark' (for grey/black sand beaches) or 'bright' (for white sand beaches)
"apply_cloud_mask": True, # apply cloud mask to the imagery. If False, the cloud mask will not be applied.
}


# The model can be run using the following settings:
model_setting = {
"sample_direc": None, # directory of jpgs ex. C:/Users/username/CoastSeg/data/ID_lla12_datetime11-07-23__08_14_11/jpg_files/preprocessed/RGB/",
"use_GPU": "0", # 0 or 1 0 means no GPU
"implementation": "BEST", # BEST or ENSEMBLE
"model_type": "segformer_RGB_4class_8190958", # model name ex. segformer_RGB_4class_8190958
"model_type": "global_segformer_RGB_4class_14036903", # model name from the zoo
"otsu": False, # Otsu Thresholding
"tta": False, # Test Time Augmentation
}
# Available models can run input "RGB" # or "MNDWI" or "NDWI"
img_type = "RGB"
img_type = "RGB" # make sure the model name is compatible with the image type
# percentage of no data allowed in the image eg. 0.75 means 75% of the image can be no data
percent_no_data = 0.75

Expand Down
91 changes: 91 additions & 0 deletions 5_zoo_workflow_local_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import os
from coastseg import coastseg_logs
from coastseg import zoo_model
from coastseg.tide_correction import compute_tidal_corrections
from coastseg import file_utilities

# The Zoo Model is a machine learning model that can be used to extract shorelines from satellite imagery.
# This script will only run a single ROI at a time. If you want to run multiple ROIs, you will need to run this script multiple times.

# Extract Shoreline Settings
settings ={
'min_length_sl': 100, # minimum length (m) of shoreline perimeter to be valid
'max_dist_ref':500, # maximum distance (m) from reference shoreline to search for valid shorelines. This detrmines the width of the buffer around the reference shoreline
'cloud_thresh': 0.5, # threshold on maximum cloud cover (0-1). If the cloud cover is above this threshold, no shorelines will be extracted from that image
'dist_clouds': 100, # distance(m) around clouds where shoreline will not be mapped
'min_beach_area': 50, # minimum area (m^2) for an object to be labelled as a beach
'sand_color': 'default', # 'default', 'latest', 'dark' (for grey/black sand beaches) or 'bright' (for white sand beaches)
"apply_cloud_mask": True, # apply cloud mask to the imagery. If False, the cloud mask will not be applied.
}


# The model can be run using the following settings:
model_setting = {
"sample_direc": None, # directory of jpgs ex. C:/Users/username/CoastSeg/data/ID_lla12_datetime11-07-23__08_14_11/jpg_files/preprocessed/RGB/",
"use_GPU": "0", # 0 or 1 0 means no GPU
"implementation": "BEST", # BEST or ENSEMBLE
"model_type": "global_segformer_RGB_4class_14037041", # model name from the zoo
"otsu": False, # Otsu Thresholding
"tta": False, # Test Time Augmentation
"use_local_model": True, # Use local model (not one from zeneodo)
"local_model_path": r"C:\development\doodleverse\coastseg\CoastSeg\src\coastseg\downloaded_models\non_validation_model", # path to the local model
}

# Available models can run input "RGB" # or "MNDWI" or "NDWI"
img_type = "RGB" # make sure the model name is compatible with the image type
# percentage of no data allowed in the image eg. 0.75 means 75% of the image can be no data
percent_no_data = 0.75

# 1. Set the User configuration Settings
# ---------------------------
# a. ENTER THE NAME OF THE SESSION TO SAVE THE MODEL PREDICTIONS TO
model_session_name = "sample_session_demo1"
# b. ENTER THE DIRECTORY WHERE THE INPUT IMAGES ARE STORED
# - Example of the directory where the input images are stored ( this should be the /data folder in the CoastSeg directory)
sample_directory = r"C:\development\doodleverse\coastseg\CoastSeg\data\ID_wra5_datetime03-04-24__03_43_01\jpg_files\preprocessed\RGB"


# 2. Save the settings to the model instance
# -----------------
# Create an instance of the zoo model to run the model predictions
zoo_model_instance = zoo_model.Zoo_Model()
# Set the model settings to read the input images from the sample directory
model_setting["sample_direc"] = sample_directory
model_setting["img_type"] = img_type

# save settings to the zoo model instance
settings.update(model_setting)
# save the settings to the model instance
zoo_model_instance.set_settings(**settings)


# OPTIONAL: If you have a transects and shoreline file, you can extract shorelines from the zoo model outputs
transects_path = "" # path to the transects geojson file (optional, default will be loaded if not provided)
shoreline_path = "" # path to the shoreline geojson file (optional, default will be loaded if not provided)
shoreline_extraction_area_path= "" # path to the shoreline extraction area geojson file (optional)

# 3. Run the model and extract shorelines
# -------------------------------------
zoo_model_instance.run_model_and_extract_shorelines(
model_setting["sample_direc"],
session_name=model_session_name,
shoreline_path=shoreline_path,
transects_path=transects_path,
shoreline_extraction_area_path = shoreline_extraction_area_path
)

# 4. OPTIONAL: Run Tide Correction
# ------------------------------------------
# Tide Correction (optional)
# Before running this snippet, you must download the tide model to the CoastSeg/tide_model folder
# Tutorial: https://github.com/Doodleverse/CoastSeg/wiki/09.-How-to-Download-and-clip-Tide-Model
# You will need to uncomment the line below to run the tide correction

beach_slope = 0.02 # Slope of the beach (m)
reference_elevation = 0 # Elevation of the beach Mean Sea Level (M.S.L) (m)

# UNCOMMENT THESE LINES TO RUN THE TIDE CORRECTION
# roi_id = file_utilities.get_ROI_ID_from_session(session_name) # read ROI ID from the config.json file found in the extracted shoreline session directory
# compute_tidal_corrections(
# session_name, [roi_id], beach_slope, reference_elevation
# )
Loading

0 comments on commit 996680c

Please sign in to comment.