ydoherty / CoastSat.PlanetScope

Batch shoreline extraction toolkit for PlanetScope Dove satellite imagery
GNU General Public License v3.0
48 stars 13 forks source link

Syntax error #12

Closed jimpaulobautista closed 1 year ago

jimpaulobautista commented 1 year ago

Hi @ydoherty !

I have tried CoastSat before and produced promising results. I am now exploring your work, CoastSat.PlanetScope due to the availability of Planet Scope images in our country.

I am trying to run it on Windows OS. However, I keep on getting syntax error from the 'downloads_folder' up to the rest of the settings/parameters like what is shown below: image

I explicitly used the code you established and followed the instructions on installation but I keep on getting this error. `settings = {

General Settings

# Site name (for output folder and files)
'site_name': 'Calauag_Quezon_ROI1',
# Maximum image AOI cover percentage threshold
'cloud_threshold': 10, # Default 10
# Minimum image AOI cover threshold
'extent_thresh': 80, # Default 80
# Desired output shoreline epsg
'output_epsg': '32651',

### Reference files (in "...Coastsat.PlanetScope/user_inputs/") ###
# Area of interest file (save as .kml file from geojson.io website)
'aoi_kml' : 'Calauag_Quezon_ROI1.kml',
# Transects in geojson file (ensure same epsg as output_epsg)
'transects' : 'NARRA_transects.geojson',  False
    # If False boolean given, popup window will allow for manual drawing of transects
# Tide csv file in MSL and UTC 
'tide_data': 'NARRA_tides.csv',
# Local folder planet imagery downloads location (provide full folder path)
'downloads_folder': os.path.join(os.getcwd(),'Calauag_Quezon_Planet_images','files'),

### Processing settings ###
# Machine learning classifier filename (in "...CoastSat.PlanetScope/classifier/models")
    # A new classifier may be re-trained after step 1.3. Refer "...CoastSat.PlanetScope/classifier/train_new_classifier.py" for instructions. 
'classifier': 'NN_4classes_PS_NARRA.pkl',
# Image co-registration choice ['Coreg Off', 'Local Coreg', 'Global Coreg']
'im_coreg': 'Coreg Off', # refer https://pypi.org/project/arosics/ for details on Local vs Global coreg. Local recommended but slower. 

### Advanced settings ###
# Buffer size around masked cloud pixels [in metres]
'cloud_buffer': 9, # Default 9 (3 pixels)  
# Max distance from reference shoreline for valid shoreline [in metres]
'max_dist_ref': 75, # Default 75
# Minimum area (m^2) for an object to be labelled as a beach
'min_beach_area': 150*150, # Default 22500
# Minimum length for identified contour line to be saved as a shoreline [in metres]
'min_length_sl': 500, # Default 500 
# GDAL location setting (Update path to match GDAL path. Update 'coastsat_ps' to chosen environment name. Example provided is for mac)

'GDAL_location': r'C:\ProgramData\Anaconda3\envs\coastsat_ps\Library\bin',

# for Windows
'GDAL_location': r'C:\Users\Jim\anaconda3\envs\coastsat.ps\Library\bin',

#### Additional advanced Settings can be found in "...CoastSat.PlanetScope/coastsat_ps/data_import.py"

}

Import data and updade settings based on user input

outputs = initialise_settings(settings)` Thanks for you help.

Best,

Jim

ydoherty commented 1 year ago

Hi Jim,

If it’s a syntax error it’s likely you may have accidentally put the inputs in incorrectly, rather than it being an issue with the toolbox.

Looking through the snippet you sent, it appears you may have accidentally left out a # or a comma in the following line.

You had: ‘transects' : 'NARRA_transects.geojson', False

It should be: 'transects' : 'NARRA_transects.geojson', #False Or: 'transects' : False,

The inputs dictionary is the same syntax as any other python dict so be careful not to accidentally delete commas or have two variables for each dict key.

Let me know if that fixed the problem. If not then send the issue and your run python scrip rather than a copy/paste text and I can look in a text editor when I have time.

Cheers, Yarran

On Thu, 13 Jul 2023 at 11:46, Jim Paulo Bautista @.***> wrote:

Hi @ydoherty https://github.com/ydoherty !

I have tried CoastSat before and produced promising results. I am now exploring your work, CoastSat.PlanetScope due to the availability of Planet Scope images in our country.

I am trying to run it on Windows OS. However, I keep on getting syntax error from the 'downloads_folder' up to the rest of the settings/parameters like what is shown below: [image: image] https://user-images.githubusercontent.com/108282093/253136722-29780077-5777-40ab-a558-64cc66d2d73c.png

I explicitly used the code you established and followed the instructions on installation but I keep on getting this error. `settings = {

General Settings

Site name (for output folder and files)

'site_name': 'Calauag_Quezon_ROI1',

Maximum image AOI cover percentage threshold

'cloud_threshold': 10, # Default 10

Minimum image AOI cover threshold

'extent_thresh': 80, # Default 80

Desired output shoreline epsg

'output_epsg': '32651',

Reference files (in "...Coastsat.PlanetScope/user_inputs/")

Area of interest file (save as .kml file from geojson.io website)

'aoi_kml' : 'Calauag_Quezon_ROI1.kml',

Transects in geojson file (ensure same epsg as output_epsg)

'transects' : 'NARRA_transects.geojson', False

If False boolean given, popup window will allow for manual drawing of transects

Tide csv file in MSL and UTC

'tide_data': 'NARRA_tides.csv',

Local folder planet imagery downloads location (provide full folder path)

'downloads_folder': os.path.join(os.getcwd(),'Narrabeen_images_PSScene4Band','files'),

Processing settings

Machine learning classifier filename (in "...CoastSat.PlanetScope/classifier/models")

# A new classifier may be re-trained after step 1.3. Refer "...CoastSat.PlanetScope/classifier/train_new_classifier.py" for instructions.

'classifier': 'NN_4classes_PS_NARRA.pkl',

Image co-registration choice ['Coreg Off', 'Local Coreg', 'Global Coreg']

'im_coreg': 'Coreg Off', # refer https://pypi.org/project/arosics/ for details on Local vs Global coreg. Local recommended but slower.

Advanced settings

Buffer size around masked cloud pixels [in metres]

'cloud_buffer': 9, # Default 9 (3 pixels)

Max distance from reference shoreline for valid shoreline [in metres]

'max_dist_ref': 75, # Default 75

Minimum area (m^2) for an object to be labelled as a beach

'min_beach_area': 150*150, # Default 22500

Minimum length for identified contour line to be saved as a shoreline [in metres]

'min_length_sl': 500, # Default 500

GDAL location setting (Update path to match GDAL path. Update 'coastsat_ps' to chosen environment name. Example provided is for mac)

'GDAL_location': r'C:\ProgramData\Anaconda3\envs\coastsat_ps\Library\bin',

for Windows

'GDAL_location': r'C:\ProgramData\Anaconda3\envs\coastsat_ps\Library\bin',

Additional advanced Settings can be found in "...CoastSat.PlanetScope/coastsat_ps/data_import.py"

}

Import data and updade settings based on user input

outputs = initialise_settings(settings)` Thanks for you help.

Best,

Jim

— Reply to this email directly, view it on GitHub https://github.com/ydoherty/CoastSat.PlanetScope/issues/12, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOKZTRT4A3ERCVZESWIGDNTXP5HNXANCNFSM6AAAAAA2IHZJZA . You are receiving this because you were mentioned.Message ID: @.***>

jimpaulobautista commented 1 year ago

Hi @ydoherty !

This solves my problem, thank you.

However, when I executed the 1.3. Image co-registration and scene merging step in your example, I keep on getting this file not found error:

image

I have used around 17 cloudless Planet images but the co-registration step keeps on failing. Is there a way to skip the co-registration and proceed with shoreline extraction? I am also getting this error even if I inputted "Coreg off".

Thank you.

Cheers,

Jim

ydoherty commented 1 year ago

Hi Jim,

I’ll need a screenshot of the whole error message to be able to help, and a copy of the CoastSat_PS.py file to see what’s going on fully. Double check you have the spelling exactly the same however. Noting that it’s also case sensitive. It should be “Coreg Off”.

Regards, Yarran

On Mon, 17 Jul 2023 at 12:15, Jim Paulo Bautista @.***> wrote:

Hi @ydoherty https://github.com/ydoherty !

This solves my problem, thank you.

However, when I executed the 1.3. Image co-registration and scene merging step in your example, I keep on getting this file not found error:

[image: image] https://user-images.githubusercontent.com/108282093/253841110-a397e0c1-a9e9-4822-a995-a0263ee6bc62.png

I have used around 17 cloudless Planet images but the co-registration step keeps on failing. Is there a way to skip the co-registration and proceed with shoreline extraction? I am also getting this error even if I inputted "Coreg off".

Thank you.

Cheers,

Jim

— Reply to this email directly, view it on GitHub https://github.com/ydoherty/CoastSat.PlanetScope/issues/12#issuecomment-1637288837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOKZTRUX2VELRNQ7IXOJPPLXQSN3HANCNFSM6AAAAAA2IHZJZA . You are receiving this because you were mentioned.Message ID: @.***>

jimpaulobautista commented 1 year ago

Here is the screenshot of the error: image image

Note that I'm using jupyter notebook in running the code. For some reason I cannot attach the .py file here in Github.

jimpaulobautista commented 1 year ago

Here is the copy of the code I used.

On Mon, Jul 17, 2023 at 2:30 PM ydoherty @.***> wrote:

Hi Jim,

I’ll need a screenshot of the whole error message to be able to help, and a copy of the CoastSat_PS.py file to see what’s going on fully. Double check you have the spelling exactly the same however. Noting that it’s also case sensitive. It should be “Coreg Off”.

Regards, Yarran

On Mon, 17 Jul 2023 at 12:15, Jim Paulo Bautista @.***> wrote:

Hi @ydoherty https://github.com/ydoherty !

This solves my problem, thank you.

However, when I executed the 1.3. Image co-registration and scene merging step in your example, I keep on getting this file not found error:

[image: image] < https://user-images.githubusercontent.com/108282093/253841110-a397e0c1-a9e9-4822-a995-a0263ee6bc62.png>

I have used around 17 cloudless Planet images but the co-registration step keeps on failing. Is there a way to skip the co-registration and proceed with shoreline extraction? I am also getting this error even if I inputted "Coreg off".

Thank you.

Cheers,

Jim

— Reply to this email directly, view it on GitHub < https://github.com/ydoherty/CoastSat.PlanetScope/issues/12#issuecomment-1637288837>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/AOKZTRUX2VELRNQ7IXOJPPLXQSN3HANCNFSM6AAAAAA2IHZJZA>

. You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/ydoherty/CoastSat.PlanetScope/issues/12#issuecomment-1637453399, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZ2EB3KF2XMWDCMC5UN3NW3XQTLZTANCNFSM6AAAAAA2IHZJZA . You are receiving this because you authored the thread.Message ID: @.***>

load coastsat modules

import os from coastsat_ps.data_import import initialise_settings from coastsat_ps.extract_shoreline import extract_shorelines, compute_intersection from coastsat_ps.interactive import filter_shorelines
from coastsat_ps.preprocess import (data_extract, pre_process, select_ref_image, add_ref_features) from coastsat_ps.postprocess import tidal_correction, ts_plot_single

settings = {

### General Settings ###
# Site name (for output folder and files) 
'site_name': 'NARRA',
# Maximum image cloud cover percentage threshold
'cloud_threshold': 30, # Default 10
# Minimum image AOI cover percentage threshold
'extent_thresh': 80, # Default 80
# Desired output shoreline epsg
'output_epsg': '32651',

### Reference files (in "...CoastSat.PlanetScope/user_inputs/") ###
# Area of interest file (save as .kml file from geojson.io website)
'aoi_kml': 'Calauag_Quezon_ROI1.kml',
# Transects in geojson file (ensure same epsg as output_epsg)
'transects': False,
    # If False boolean given, popup window will allow for manual drawing of transects
# Tide csv file in MSL and UTC 
'tide_data': 'NARRA_tides.csv',
# Local folder planet imagery downloads location (provide full folder path)
'downloads_folder': os.path.join(os.getcwd(),'Narrabeen_images_PSScene4Band','files'),

### Processing settings ###
# Machine learning classifier filename (in "...CoastSat.PlanetScope/classifier/models")
    # A new classifier may be re-trained after step 1.3. Refer "...CoastSat.PlanetScope/classifier/train_new_classifier.py" for instructions. 
'classifier': 'NN_4classes_PS_NARRA.pkl',
# Image co-registration choice ['Coreg Off', 'Local Coreg', 'Global Coreg']
'im_coreg': 'Local Coreg', # refer https://pypi.org/project/arosics/ for details on Local vs Global coreg. Local recommended but slower. 

### Advanced settings ###
# Buffer size around masked cloud pixels [in metres]
'cloud_buffer': 100, # Default 9 (3 pixels)  
# Max distance from reference shoreline for valid shoreline [in metres]
'max_dist_ref': 75, # Default 75
# Minimum area (m^2) for an object to be labelled as a beach
'min_beach_area': 150*150, # Default 22500
# Minimum length for identified contour line to be saved as a shoreline [in metres]
'min_length_sl': 500, # Default 500 
# GDAL location setting (Update path to match GDAL path. Update 'coastsat_ps' to chosen environment name. Example provided is for mac)
'GDAL_location': r'C:\Users\Jim\anaconda3\envs\coastsat_ps\Library\share',
# for Windows
# 'GDAL_location': r'C:\ProgramData\Anaconda3\envs\coastsat_ps\Library\bin',

#### Additional advanced Settings can be found in "...CoastSat.PlanetScope/coastsat_ps/data_import.py"

}

Import data and update settings based on user input

outputs = initialise_settings(settings)

%% 1.1) Pre-processing - TOA conversion and mask extraction

data_extract(settings, outputs)

%% 1.2) Pre-processing - Select reference image for co-registration

select_ref_image(settings)

%% 1.3) Pre-Processing - image coregistration and scene merging

del_files_int = True will delete intermediate coregistration files to save space

pre_process(settings, outputs, del_files_int = False)

%% 2.2) Extract shoreline data

%matplotlib qt add_ref_features(settings) %matplotlib inline

shoreline_data = extract_shorelines(outputs, settings,

del_index = True will delete water index .tif files once used to save space

    del_index = False, 
    # reclassify = True will reclassify images if they have been classified previously
        # useful when running again with a new classifier
        # use False to save time on re-runs with the same classifier to save processing time
    reclassify = False)
jimpaulobautista commented 1 year ago

Hello @ydoherty .

I managed to proceed with the process by manipulating the directory. However, I keep on getting KeyError when I'm running the shoreline extraction step.

Can you help me figure out this problem?

Thanks.

image