Prototype application for GCM bias-correction and downscaling

Overview

dodola

Prototype application for GCM bias-correction and downscaling

This is an unstable prototype. This is under heavy development.

Features

  • Nothing! The unit tests might work if you're lucky.

Example

After installing, use from the commandline with:

dodola biascorrect  
   
    
    

    
   
  
 

See more help with:

dodola --help

Installation

You shouldn't! This will likely run within a Docker container in a production environment on cloud infrastructure. But, to install with pip:

pip install git+https://github.com/ClimateImpactLab/dodola
Comments
  • 360 days calendar support

    360 days calendar support

    This PR adds support for 360-day calendar GCM input data. The changes are :

    1. I added the function xclim_convert_360day_calendar_interpolate to dodola.core. This function takes a 360-day calendar time indexed dataset and converts its calendar to a chosen target calendar type, offering the option to interpolate the inserted missing values.

    2. This functionality is now used by default with linear interpolation in standardize_gcm to handle the GCM data we currently use that has a 360-day calendar.

    3. I also added a test for this in dodola.tests.test_core, which required to add a calendar option in the _timeseriesfactory function.

    This PR solves this downscaleCMIP6 issue.

    enhancement 
    opened by emileten 12
  • update precip units in cmip6 cleanup to be pint-compatible

    update precip units in cmip6 cleanup to be pint-compatible

    As of now we convert precip units to mm day -1 and this is not pint-compatible. We need to update the units to mm/day for precip for both CMIP6 cleaning and ERA-5. This is because xclim now checks units using pint.

    bug 
    opened by dgergel 9
  • Add QDM workflow components

    Add QDM workflow components

    This PR ports some hairy quantile delta mapping (QDM) bias correction stuff. The additions are "hairy" because the these steps of the workflow have some eccentricities in Azure and currently scale in production with Argo Workflows (and not dask).

    More specifically this PR:

    Adds dodola train-qdm

    which is run like

    dodola train-qdm -h "az://historical.zarr" -r "az://reference.zarr" -v "tasmax" \
        -o "az://qdm.zarr" --kind "additive"
    

    This trains a xclim.sdba.adjustment.QuantileDeltaMapping to our spec and dumps it to a Zarr Store.

    Adds dodola apply-qdm

    which can be run like

    dodola apply-qdm \
        --simulation "az://future-simulation.zarr" \
        --qdm "az://qdm.zarr" \
        --year 2026 \
        --variable "tasmax" \
        -o "/mnt/outadjusted-simulation.nc"
    

    Note, this applies QDM to a simulation for a single year of adjusted values output to a NetCDF4 file on the local disk.

    Close #66

    enhancement 
    opened by brews 9
  • bump max polar DTR to 110 & compute stats in error msgs

    bump max polar DTR to 110 & compute stats in error msgs

    In this PR:

    • NorESM2-MM failing due to 107 DTR at (75.5, 102.5) and (76.5, 105.5), both of which are in faaaaar northern Russia along the arctic sea. This bumps the check tolerance to 110C.
    • Also computes data checks and converts to floats prior to data tests so they display cleanly in assertion errors and so they aren't computed twice when assertions fail.
    • Finally, drops (if X is not None) tests, which never evaluate to False.
    opened by delgadom 8
  • precip units temporary replacement

    precip units temporary replacement

    This solves #125, (precip units incompatible with the xclim pint registry)

    1. added an units_replacement parameter to each services.apply-* and services.train-* function, to (optionally) temporarily swap the variable units attribute for a chosen string, during bias correction and downscaling.

    2. this option is used in each upstream cli function if variable=='pr' to temporarily swap units with "mm/day".

    @brews (1) is general (variable agnostic) in case we want to make use of that in other cases, but (2) doesn't give an option and uses it for precip -- so that we don't need to change workflow templates now. I didn't write a unit test, it sounded like a lot of code to me for what it is. I am not fully aware of our test coverage ambitions though. Let me know.

    bug 
    opened by emileten 8
  • "regrid" drops dataset attributes

    Anytime we call dodola.core.xesmf_regrid, the output data is missing attributes from the input data. It would be great if we could keep — or merge — attrs from input data.

    bug 
    opened by brews 8
  • first attempt at adding basic bias correction code and fixing tests

    first attempt at adding basic bias correction code and fixing tests

    This PR adds in some super basic bias correction code as well as a dependency on a forked version of scikit-downscale with an interim fix for a current bug in PointwiseDownscaler.

    enhancement 
    opened by dgergel 8
  • Add analog downscaling prototype

    Add analog downscaling prototype

    This PR adds the analog-inspired, quantile-preserving downscaling method as a new service. It is split up into two services, train_aiqpd and adjust_aiqpd and is based on the implementation of QDM. This is intended to supersede spatial disaggregation as the main mode of downscaling in dodola for the time being.

    Basic CLI interface is:

    dodola train_aiqpd /path/to/coarse_reference.zarr \
    /path/to/fine_reference.zarr 
    --out /path/to/trained_afs.zarr \
    --v "tasmax", 
    --k "+"
    
    dodola apply_aiqpd /path/to/biascorrected.zarr \
    /path/to/trainedafs/zarr \
    -- year 2026
     --v "tasmax" 
    --out /path/to/trained_afs.zarr \
    

    closes #73

    enhancement 
    opened by dgergel 6
  • Remove conda package pins

    Remove conda package pins

    • [ ] closes #xxxx
    • [x] tests added / passed
    • [x] docs reflect changes
    • [x] entry in CHANGELOG.md

    Upate container conda environment package pins. We are pretty behind and they're in need of an update.

    enhancement 
    opened by brews 5
  • Update package setup, README, HISTORY/CHANGELOG to new system

    Update package setup, README, HISTORY/CHANGELOG to new system

    Migrate dodola package setup, build, configuration from setup.py to pyproject.toml and setup.cfg. This follows updated best practices in python packaging.

    • Migrates README from RST to Markdown.
    • Migrate HISTORY.rst to CHANGELOG.md, following https://keepachangelog.com.
    documentation enhancement 
    opened by brews 5
  • Hack fix to validate OOM errors

    Hack fix to validate OOM errors

    • [x] closes #126
    • [x] tests added / passed
    • [x] docs reflect changes
    • [x] entry in CHANGELOG.md

    Fixes dodola validate-dataset failing with out-of-memory errors on small workers without external dask cluster. This was especially a problem on quality-control checks to 0.25 degree grid input data.

    This solution is somewhat hackish in that we're reading and subsetting the input data to year available year in dodola.services — essentially refactoring the larger validation flow from dodola.core to dodola.services so that we can keep all the storage I/O implementation details out of dodola.core. This is an adaptation of the solution to used in this temporary fix.

    bug 
    opened by brews 4
  • Unit tests are very very slow

    Unit tests are very very slow

    Unit tests run in CI have become very very slow. The can take about 15 minutes to complete.

    I suspect dodola.services.validate() using dask.delayed is the culprit. Dask was used here as a hack to work around memory problems (see #126). The drawback to this hack has been that simple unit tests on Datasets covering a long time range take much more time to run.

    If this is the case I see two options:

    1. Re-write validation to work around the original memory problems in #126 while also making unit tests complete faster. i.e. replace the hack solution with a "real" solution.
    2. Find and refactor the one or two long-running unit tests so that they test the same behavior, but run faster.
    bug help wanted 
    opened by brews 0
  • Port Diana Gergel's QPLAD from CIL xclim fork

    Port Diana Gergel's QPLAD from CIL xclim fork

    This adds a port of @dgergel's QuantilePreservingAnalogDownscaling for QPLAD downscaling.

    This is ported from a ClimateImpactLab fork of xclim.

    Porting this code lets us run QPLAD in dodola without depending on pip-installing an old fork of xclim, instead, installing xclim from conda-forge. A xclim=0.30.1 dependency from conda-forge was added to environment.yaml because I think this is the last version the xclim fork synced from https://github.com/Ouranosinc/xclim. v0.30.1 of xclim was released Oct 1st, 2021. Currently, the latest version of xclim is v0.36.0.

    • [ ] closes #xxxx
    • [x] tests added / passed
    • [x] docs reflect changes
    • [ ] entry in CHANGELOG.md
    enhancement 
    opened by brews 1
  • Add label for code source to container images

    Add label for code source to container images

    We should put a label in the Dockerfile to add a URL to the code repository.

    Basically add this

    LABEL org.opencontainers.image.source="https://github.com/ClimateImpactLab/dodola"
    

    to Dockerfile.

    documentation enhancement help wanted 
    opened by brews 0
  • Validation checks should throw new ValidationFailed-like, not AssertionError

    Validation checks should throw new ValidationFailed-like, not AssertionError

    At the moment all checks to validate output data are done using assert. It would be great if we could get these to throw a custom error (like ValidationError or some subclass of this) instead.

    People often run python can be run with assertions disabled, and this would disable a key behavior in these functions. Worse still is that validation code would still quietly run and "pass" data with no indication that checks are not being performed.

    This addition could also make it easier for people to catch and handle certain types of validation problems, with more helpful error messages.

    bug help wanted 
    opened by brews 1
  • Test that `dodola.services.validate` actually fails bad data

    Test that `dodola.services.validate` actually fails bad data

    We test dodola.services.validate in dodola.tests.test_services.test_validation() for the "happy path" (well-behaved data), but it would be great if we could test to ensure validation correctly catches each of the conditions that it's supposed to catch.

    I think I've mentioned this in a few previous PRs, but I'm putting it here so we dont' forget.

    enhancement help wanted 
    opened by brews 0
  • dodola.services.get_attrs() is missing logging.

    dodola.services.get_attrs() is missing logging.

    Logging for dodola.services.get_attrs() is extremely quiet. All of the major services in dodola.services get decorated with @log_service so that it logs service entrance and exit. It looks like dodola.services.get_attrs() is missing the decorator and thus doesn't log properly.

    https://github.com/ClimateImpactLab/dodola/blob/696938abe7e7e2bc6221b36a885f41a4544677a7/dodola/services.py#L509

    bug help wanted 
    opened by brews 0
Releases(v0.19.0)
  • v0.19.0(Mar 25, 2022)

    Added

    • Add badge for current release DOI to README. (@brews)

    Changed

    • Significant update to container/package environment pins. (PR #183, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.18.0(Mar 3, 2022)

    Added

    • Add basic CI/CD test and build status badges to README. (PR #182, @brews)

    Fixed

    • Fix dodola validate-dataset OOM on small workers without dask-distributed. (PR #181, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.17.0(Feb 17, 2022)

    Changed

    • Increase max allowed tasmin, tasmax in services.validate to 377 K for UKESM1-0-LL. (PR #180, @brews)

    Fixed

    • Move in-memory data loading where it is needed for 360-days calendar conversion in clean-cmip6 (PR #179, @emileten)
    Source code(tar.gz)
    Source code(zip)
  • v0.16.2(Feb 15, 2022)

  • v0.16.1(Jan 27, 2022)

    Fixed

    • Fix the wetday frequency correction so that different replacement values are used, rather than a single one (PR #174, PR #176, @emileten, @delgadom).
    Source code(tar.gz)
    Source code(zip)
  • v0.16.0(Jan 18, 2022)

    Added

    • Improve README.md. (PR #169, @brews)

    Changed

    • Remove duplicated service-level logging info lines of code introduced by PR #148 (PR #168, @emileten)
    • Decrease validation temperature range min to 130 (PR #170, @emileten)
    Source code(tar.gz)
    Source code(zip)
  • v0.15.1(Dec 29, 2021)

  • v0.15.0(Dec 28, 2021)

    Added

    • Add maximum precipitation adjustment service that applies a "ceiling" or "cap" to precipitation values above a user-defined threshold. (PR #164, @dgergel)

    Changed

    • Increase max precipitation allowed by validation to 3000 mm. (PR #164, @dgergel)
    • Update wet day frequency correction to incorporate method additions from Hempel et al 2013. (PRs #162 and #159, @dgergel)
    • Floor and ceiling for DTR. (PR #163 @emileten)
    Source code(tar.gz)
    Source code(zip)
  • v0.14.0(Dec 21, 2021)

    Changed

    • Update wet day frequency correction to include small negative values in correction and to limit the correction range to the threshold * 10 ^ -2. (PR #158, @dgergel)
    • Update package setup, README, HISTORY/CHANGELOG to new system. (PR #154, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.13.0(Dec 18, 2021)

    • Update diurnal temperature range (DTR) validation to differentiate min DTR accepted value for CMIP6 vs bias corrected and downscaled data inputs (PR #155, @dgergel)
    • Update diurnal temperature range (DTR) validation to differentiate polar and non-polar regions (PR #153, @dgergel)
    • Fix rechunk error when converting 360 days calendars. (#149, PR #151, @brews)
    • Remove cruft code. Removes dodola commands biascorrect, downscale, buildweights along with corresponding functions in dodola.services and dodola.core. (PR #152, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.12.0(Dec 9, 2021)

    • Add 360 days calendar support (PR #144, @emileten)
    • Add an option to temporarily replace the target variable units in dodola services and use in CLI dodola for precip (PR #143, @emileten)
    • Add diurnal temperature range (DTR) correction for small DTR values below 1 (converts them to 1) (PR #145, @dgergel)
    Source code(tar.gz)
    Source code(zip)
  • v0.11.1(Dec 3, 2021)

    • Decrease allowed timesteps for bias corrected/downscaled files in validation to allow models that only go through 2099 (PR #146, @dgergel)
    Source code(tar.gz)
    Source code(zip)
  • v0.11.0(Dec 1, 2021)

    • Increase validation temperature range max to 360 (PR #142, @dgergel)
    • Distinguish missing from excess timesteps in timesteps validation (PR #140, @emileten)
    • Add post wet day correction option in CLI dodola (PR #141 @emileten)
    Source code(tar.gz)
    Source code(zip)
  • v0.10.0(Nov 22, 2021)

    • Add additional tests for dodola.core.*_analogdownscaling functions. (PR #136, @dgergel, @brews)
    • Update dtr range check max to allow up to 70 C. (PR #138, @brews, @dgergel)
    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Nov 15, 2021)

    • Fix attrs missing from services.apply_qplad output Datasets. (#135, @brews)
    • Add --root-attrs-json-file to prime-qplad-output-zarrstore, apply-qplad, prime-qdm-output-zarrstore, apply-qdm. (PR #134, @brews)
    • Add dodola get-attrs command. (PR #133, @brews)
    • Upgrade Docker base image to continuumio/miniconda3:4.10.3. (PR #132, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.8.0(Nov 11, 2021)

    • AIQPD has been renamed "Quantile-Preserving, Localized Analogs Downscaling" (QPLAD). AIQPD-named commands have been switch to QPLAD. This is backward compatibility breaking. (PR #131, @brews)
    • Add AIQPD output Zarr priming (prime-aipqd-output-zarrstore), input slicing, region writing, attrs merging, and multi-year processing. This breaks backwards compatibility for apply-aiqpd and its services and core functions. See the pull request for additional details. (PR #130, @brews)
    • Similarly, add QDM output Zarr priming (prime-qdm-output-zarrstore), region writing, attrs merging, and multi-year processing. This breaks backwards compatibility for apply-qdm and its services and core functions. See the pull request for additional details. (PR #129, @brews)
    • Make logging slightly more chatty by default. (PR #129, @brews)
    • Add pre-training slicing options to train-qdm and train-aiqpd. (PR #123, PR #128, @brews)
    • Quick fix validation reading entire zarr store for check. (PR #124, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.7.0(Nov 2, 2021)

    • Update xclim version to 0.30.1, this updates the Train/Adjust API for QDM and AIQPD and requires units attributes for all QDM and AIQPD inputs. (PR #119, @dgergel)
    • Add global validation, includes new service validate for validating cleaned CMIP6, bias corrected and downscaled data for historical and future time periods. (PR #118, @dgergel)
    • Regrid copies input Dataset attrs metadata to output (#116). (PR #121, @brews)
    • Upgrade dask to 2021.10.0 to cover https://nvd.nist.gov/vuln/detail/CVE-2021-42343. (PR #122, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Sep 8, 2021)

    • Add AIQPD downscaling method to options. Also updates xclim dependency to use the CIL-fork and "@add_analog_downscaling" branch, with 0.28.1 of xclim merged in. This supersedes the BCSD downscaling service. (PR #98, PR #115, @dgergel)
    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Aug 5, 2021)

    • Bump environment xarray to v0.19.0. Note this change has breaking changes in Zarr Store I/O. (PR #109, @brews)
    • Add --cyclic option to regrid cli and services. (PR #108, @brews)
    • Add papermill, intake-esm to Docker environment. (PR #106, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.4.1(Jul 13, 2021)

  • v0.4.0(Jul 9, 2021)

    • Add include-quantiles flag to apply_qdm to allow for including quantile information in bias corrected output. (PR #95, @dgergel)
    • Add precipitation unit conversion to standardize_gcm. (PR #94, @dgergel)
    • Add astype argument to regrid. (PR #92, @brews)
    • Make dodola container's default CMD. (PR #90, @brews)
    • Improve subprocess and death handling in Docker container. (PR #90, @brews)
    • Fix bug in train_quantiledeltamapping accounting for endpoints. (#87, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Jun 17, 2021)

    • Significant updates to container environment: Python 3.9, xarray, adlfs, xesmf, dask, and fsspec. (PR #74, PR #75, PR #76, PR #77, PR #84 @brews)
    • Update buildweights service to add support for regridding to domain file. Not backwards compatible. (PR #67, @dgergel)
    • Add downscaling service. Currently support BCSD spatial disaggregation as implemented in scikit-downscale. (PR #65, @dgergel)
    • Remove stdout buffering from container runs, add IO debug logging. (PR #72, @brews)
    • Add bias-correction quantile delta mapping (QDM) components to support Argo Workflows. New commands added: dodola train-qdm and dodola apply-qdm. (PR #70, @brews)
    • Fix CMIP6 clean to better handle coords vs dims. (PR #81, @brews)
    • Add wet day frequency correction service. Wet day frequency implemented as described in Cannon et al., 2015. New command added: dodola correct-wetday-frequency. (PR #78, @dgergel)
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Apr 23, 2021)

    • Fix TypeError from dodola rechunk. (PR #63, @brews)
    • Switch to pure fsspec-style URLs for data inputs. Added support for GCS buckets and S3 storage. Switch to fsspec backend settings to collect storage authentication. Because of this users likely will need to change the environment variables used to pass in storage credentials. dodola.services no longer require the storage argument. (PR #61, @brews)
    • Switch to simple xarray-based rechunking to workaround to instability from our use of rechunker. This change breaks the CLI for dodola rechunk, removing the -v/--variable and -m/--maxmemory options. The change also breaks the dodola.services.rechunk() signature, removing the max_mem argument and the target_chunks argument is now a mapping {coordinate_name: chunk_size}. (PR #60, @brews)
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Apr 15, 2021)

Owner
Climate Impact Lab
Code, tools, and data from the Climate Impact Lab
Climate Impact Lab
Petuhlang is a joke-like language, based on Python.

Petuhlang is a joke-like language, based on Python. It updates builtins to make a new syntax based on operators rewrite.

DenyS 9 Jun 19, 2022
This repo is related to Google Coding Challenge, given to Bright Network Internship Experience 2021.

BrightNetworkUK-GCC-2021 This repo is related to Google Coding Challenge, given to Bright Network Internship Experience 2021. Language used here is py

Dareer Ahmad Mufti 28 May 23, 2022
TeamFleming is a multicultural group of 20 young bioinformatics enthusiasts participating in the 2021 HackBio Virtual Summer Internship

💻 Welcome to Team Fleming's Repo! #TeamFleming is a multicultural group of 20 young bioinformatics enthusiasts participating in the 2021 HackBio Virt

3 Aug 08, 2021
PyLaboratory 0 Feb 07, 2022
Online-update est un programme python permettant de mettre a jour des dossier et de fichier depuis une adresse web.

Démarrage rapide Online-update est un programme python permettant de mettre a jour des dossier et de fichier depuis une adresse web. Mode préconfiguré

pf4 2 Nov 26, 2021
Simple python script for AD enumeration

AutoAD - Simple python script for AD enumeration This tool was created on my spare time to help fellow penetration testers in automating the basic enu

Mohammad Arman 28 Jun 21, 2022
200 LeetCode problems

LeetCode I classify 200 leetcode problems into some categories and upload my code to who concern WEEK 1 # Title Difficulty Array 15 3Sum Medium 1324 P

Hoang Cao Bao 108 Dec 08, 2022
A simple, fantasy and fast note taking program.

notes A simple, fantasy and fast note taking program Installation This program supposed to run in linux and may have some bugs on windows or any other

Ali Hosseinverdi 1 Apr 06, 2022
Make your Discord Account Online 24/7!

Online-Forever Make your Discord Account Online 24/7! A Code written in Python that helps you to keep your account 24/7. The main.py is the main file.

SealedSaucer 0 Mar 16, 2022
Reso is a low-level circuit design language and simulator, inspired by things like Redstone, Conway's Game of Life, and Wireworld.

Reso Reso is a low-level circuit design language and simulator, inspired by things like Redstone, Conway's Game of Life, and Wireworld. What is Reso?

Lynn 287 Nov 26, 2022
In this repo, I will put all the code related to data science using python libraries like Numpy, Pandas, Matplotlib, Seaborn and many more.

Python-for-DS In this repo, I will put all the code related to data science using python libraries like Numpy, Pandas, Matplotlib, Seaborn and many mo

1 Jan 10, 2022
CalHacks 8 Repo: Megha Jain, Gaurav Bhatnagar, Howard Meng, Vibha Tantry

CalHacks8 CalHacks 8 Repo: Megha Jain, Gaurav Bhatnagar, Howard Meng, Vibha Tantry Setup FE Install React Native via Expo, run App.js. Backend Create

0 Aug 20, 2022
Tutorials for on-ramping to StarkNet

Full-Stack StarkNet Repo containing the code for a short tutorial series I wrote while diving into StarkNet and learning Cairo. Aims to onramp existin

Sam Barnes 71 Dec 07, 2022
List Less Than Ten with python

List Less Than Ten with python

PyLaboratory 0 Feb 07, 2022
Simple calculator with random number button and dark gray theme created with PyQt6

Calculator Application Simple calculator with random number button and dark gray theme created with : PyQt6 Python 3.9.7 you can download the dark gra

Flamingo 2 Mar 07, 2022
GUI for the Gammu library.

Wammu GUI for the Gammu library. Homepage https://wammu.eu/ License GNU GPL version 3 or later. First start On first start you will be asked for set

Gammu 60 Dec 14, 2022
适用于HoshinoBot下的雀魂插件。可进行近期对局查询、查询个人数据等功能,更多功能正在扩展

Majsoul_bot This is a Majsoul plugin for HoshinoBot 这是一个HoshinoBot的雀魂相关插件 本项目目前正在扩展,后续会扩展更多功能,敬请期待 前言 项目地址:https://github.com/DaiShengSheng/Majsoul_bo

黛笙笙 33 Dec 14, 2022
How to build an Fahrenheit to Celsius Converter in Python

Generally to measure the temperature we make use of one of these two popular units i.e. Fahrenheit & Celsius.

PyLaboratory 0 Feb 07, 2022
Python Programmma DarkMap.py

DarkMap Python Programmma DarkMap.py O'rganish va rasmlarni ko'riosh https://drive.google.com/drive/folders/1l1zybs_0Zy9z_trZYz5R72WrwsE6mFOh?usp=shar

Og'abek 0 May 06, 2022
Курс про техническое совершенство для нетехнарей

Technical Excellence 101 Курс про техническое совершенство для нетехнарей. Этот курс представлят из себя серию воркшопов, при помощи которых можно объ

Anton Bevzuk 11 Nov 13, 2022