Coder Social home page Coder Social logo

camels_netcdf's Introduction

CAMELS dataset in NetCDF/Feather formats

Motivation

The CAMELS datasets are now provided in an ideal format and takes a bit of data processing to convert them to useful and convenient dataframes. So, I decided to use the beloved netcdf and feather formats to make the dataset more accessible!

Usage

First make sure that h5netcdf, geopandas, xarray, and requests Python packages are installed, then load the files directly like so:

import io

import geopandas as gpd
import requests
import xarray as xr

r = requests.get("https://media.githubusercontent.com/media/cheginit/camels_netcdf/main/camels_attributes_v2.0.feather")
attrs = gpd.read_feather(io.BytesIO(r.content))

r = requests.get("https://media.githubusercontent.com/media/cheginit/camels_netcdf/main/camels_attrs_v2_streamflow_v1p2.nc")
qobs = xr.open_dataset(io.BytesIO(r.content), engine="h5netcdf")

Methodology

This repo contains the code that I used to generate the datasets. Two data sources are available from the CAMELS dataset:

  • Streamflow observations for all 671 stations in the CAMELS dataset.
  • All the watershed attributes (camels_attributes_v2.0).

The camel_netcdf.py generate two files:

  • camels_attributes_v2.0.feather: Includes basin geometries and 60 basin-level attributes that are available in CAMELS.
  • camels_attrs_v2_streamflow_v1p2.nc: A xarray.Dataset that includes streamflow observations for all 671 stations, as well as the 60 basin-level attributes.

Additionally, the script takes care of some small annoyances in the dataset:

  • Station names didn't have a consistent format and there were some missing commas and extra periods! Now, the names have a consistent format (title) and there is comma before the states.
  • Station IDs and HUC 02 are strings with leading zero if needed.

Although, the generated netcdf and feather files are available in this repo, you can recreate them locally using mambaforge (or conda) like so:

mamba env create -f environment.yml
conda activate camels
chmod +x ./camels_netcdf.py
./camels_netcdf.py

Example Plots

Snow fraction using camels_attributes_v2.0.feather: camels_snow_fraction

The dataset camels_attrs_v2_streamflow_v1p2.nc: dataset

Streamflow observations for USGS-01013500: qobs_01013500

Contributions

Contributions are welcome! Please feel free to open an issue/PR if you have any suggestions that can improve the database.

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.