Code Monkey home page Code Monkey logo

netcdf-cog-stac's Introduction

netcdf-cog-stac

This repository contains example code to convert NetCDF files from an FTP site to COG and STAC files. Specifically, it was designed to convert NetCDF files from CMIP3 and CMIP5 Climate and Hydrology Projections. The resulting COG and STAC files can be written to a local directory or to AWS S3. Also included is a Google Earth Engine dashboard that you can use to view and compare composite images, along with code to make it work with COGs.

Setup

Install Anaconda/Miniconda on your machine if you haven't already.

Open a terminal and cd into the folder where you've checked out this git repoository. In the following instructions, text in a fixed-width font is a command to be entered into the terminal.

Create a new conda environment:

conda env create -n netcdf-cog-stac -f conda-environment.yml

You'll need to rerun this after creating the environment and in any new terminal window:

conda activate netcdf-cog-stac

Once the environment is activated, you can install the required python dependencies. You'll need to rerun this if requirements.txt has changed.

pip install -r requirements.txt

If you'd like the conversion tool to write to S3, configure access keys in either environment variables or an AWS configuration file

File conversion

The following command will convert a NetCDF file or folder from FTP at ftp://HOST/FOLDER/FILE (replace with the actual location) into COG and STAC files on BUCKET in S3. Inside the bucket, files will be placed inside a folder named based on the original NetCDF filename, so a source FILE of foo-bar.nc would create files under s3://BUCKET/foo-bar/.

python -m netcdf_cog_stac -v ftp://HOST/FOLDER/FILE s3://BUCKET/

For example:

python -m netcdf_cog_stac -v ftp://gdo-dcp.ucllnl.org/pub/dcp/archive/1950-2099/sresb1/sresb1.bccr_bcm2_0.1.monthly.Prcp.1950-2099.nc s3://your-output-bucket

You can get more information about other options for the conversion command by running

python -m netcdf_cog_stac --help

Google Earth Engine Dashboard

Screenshot of Google Earth Engine dashboard

To use the example dashboard, run the following commands:

python -m netcdf_cog_stac -v ftp://gdo-dcp.ucllnl.org/pub/dcp/archive/1950-2099/sresa1b/sresa1b.bccr_bcm2_0.1.monthly.Prcp.1950-2099.nc output
python -m netcdf_cog_stac -v ftp://gdo-dcp.ucllnl.org/pub/dcp/archive/1950-2099/sresa1b/sresa1b.bccr_bcm2_0.1.monthly.Tavg.1950-2099.nc output

Upload the contents of the output folder into a Google Cloud Storage (GCS) bucket.

To create ImageCollections out of the files in GCS, open the included Jupyter notebook into a notebook runner like Google Colab. Change the variables that have "# CHANGE" comments. Click the Runtime menu, then Run all. You'll be prompted twice to authorize access - once for Google Earth Engine, and once for Google Cloud Platform. You'll run it twice - once with the location of the Prcp data, and once for the Tavg data.

Paste the contents of dashboard.js into the Earth Engine Code Editor, editing the variables at the top of the code as needed to point to the Earth Engine project that contains the ImageCollections you created. Click Run. You should now be able to interact with your map, following the instructions provided.

Contact

New Light Technologies, Inc.

[email protected]

netcdf-cog-stac's People

Contributors

aripollak avatar pfpulse avatar

Stargazers

Ryan Shields avatar frankfanslc avatar Selim Horri avatar Jan Žák avatar

Watchers

Adam Thomann avatar Carl Anderson avatar Jorge Hassan avatar Ryan Cunningham avatar  avatar  avatar Gee Araya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.