Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare scripts for uploading tiles to GEE Assets #7

Open
ShiruiH opened this issue Aug 7, 2024 · 5 comments
Open

Prepare scripts for uploading tiles to GEE Assets #7

ShiruiH opened this issue Aug 7, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@ShiruiH
Copy link
Owner

ShiruiH commented Aug 7, 2024

Upload S2 and Landsat tiles to GEE Assets

  • Prepare two scripts:

    1. Upload from local to GCS Buckets
    2. Upload from GCS Buckets to GEE Assets
  • Prepare one json file template to specify the tileset arguments

@ShiruiH ShiruiH self-assigned this Aug 7, 2024
@ShiruiH ShiruiH added the enhancement New feature or request label Aug 7, 2024
@kvos
Copy link
Collaborator

kvos commented Aug 7, 2024

good idea!
For reading from cloud bucket data, I skipped that part in my PR and in the notebook it's reading local CSV files but here is the way we connect read the files (it's based on a snippet that you sent me a while back).

First, connect to the GCP project (this requires gcloud installed and users to run gcloud auth application-default login to create an Application Default Credentials (ADC).

# library to load cloud bucket
import gcsfs

# create token (based on https://stackoverflow.com/questions/53472429/how-to-get-a-gcp-bearer-token-programmatically-with-python)
import google.auth
import google.auth.transport.requests
creds, project = google.auth.default()
# creds.valid is False, and creds.token is None
# Need to refresh credentials to populate those
auth_req = google.auth.transport.requests.Request()
creds.refresh(auth_req)

Once that is done, reading from the cloud buckets into dataframes :

# mount cloud bucket
fs = gcsfs.GCSFileSystem(project='nsw-dpe-gee-tst',token=creds.token)
location = 'ofs-live-test/test2'
bucket_name = '%s/historical'%location
list_files = fs.ls(bucket_name)
list_files = [_ for _ in list_files if '.csv' in _]
for i,file in enumerate(list_files):
    with fs.open(file,'r') as f:
        df = pd.read_csv(f, parse_dates=['system_time_utc'])

@ShiruiH
Copy link
Owner Author

ShiruiH commented Aug 8, 2024

@kvos Thanks for the snippet. I will integrate them into the scripts.

For uploading from local (or maybe VM) to GCS Buckets. We can use gsutil.

@ShiruiH
Copy link
Owner Author

ShiruiH commented Aug 22, 2024

Scripts added:

  1. Download_original_tiles_Landsat.js: download Landsat tiles
  2. Download_original_tiles_S2.js: download Sentinel2 tiles
  3. 02_Upload_polygon_mask_to_bucket.ipynb: upload processed tiles from 01_Create_polygon_mask.ipynb to GCS bucket. This script also contains an optional cell to delete all images in the bucket folder for re-upload
  4. 03_Upload_bucket_to_EE_asset.ipynb: upload polygon masks from bucket to GEE Assets with their specified properties
  5. (optional) 04_Reset_EE_asset_collection.ipynb: delete the asset for re-upload

Hi @kvos

I've tested the abovementioned scripts on my local machine. Please go ahead and test them on your side and let me if any amendment needed. Cheers!

@kvos
Copy link
Collaborator

kvos commented Aug 25, 2024

@ShiruiH , I tested the Landsat and Sentinel-2 images generated from GEE with notebook 01 and it's all working.
I compared the rasters against the vector geometries and the masks from USGS EArth explorer and they are the same.
image
image

@ShiruiH
Copy link
Owner Author

ShiruiH commented Aug 26, 2024

Thanks @kvos! I will close this issue then.

@ShiruiH ShiruiH closed this as completed Aug 26, 2024
@kvos kvos reopened this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants