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
Url-check-migration-python - A python script using Apica API's to migrate URL checks between environments

url-check-migration-python A python script using Apica API's to migrate URL chec

Angelo Aquino 1 Feb 16, 2022
📽 Streamlit application powered by a PyScaffold project setup

streamlit-demo Streamlit application powered by a PyScaffold project setup. Work in progress: The idea of this repo is to demonstrate how to package a

PyScaffold 2 Oct 10, 2022
a really simple bot that send you memes from reddit to whatsapp

a really simple bot that send you memes from reddit to whatsapp want to use use it? install the dependencies with pip3 install -r requirements.txt the

pai 10 Nov 28, 2021
A general-purpose wallet generator, for supported coins only

2gen A general-purpose generator for keys. Designed for all cryptocurrencies supporting the Bitcoin format of keys and addresses. Functions To enable

Vlad Usatii 1 Jan 12, 2022
Python Projects is an Open Source to enhance your python skills

Welcome! 👋🏽 Python Project is Open Source to enhance your python skills. You're free to contribute. 🤓 You just need to give us your scripts written

Tristán 6 Nov 28, 2022
YourCity is a platform to match people to their prefect city.

YourCity YourCity is a city matching App that matches users to their ideal city. It is a fullstack React App made with a Redux state manager and a bac

Nico G Pierson 6 Sep 25, 2021
A OBS service to package a published repository into a tar.gz file

OBS Source Service obs-service-publish_tar obs-service-publish_tar will create a archive.tar[.tar compression] archive containing the published repo

Erico Mendonca 1 Feb 16, 2022
This program tries to book a tennis court slot in either Southwark Park or Tanner Street Park in Southwark, London.

Book tennis courts in London This program tries to book a tennis court slot in either Southwark Park or Tanner Street Park in Southwark, London. Note:

Daniele 1 Jul 25, 2022
Convert Photoshop curves (acv) to xmp presets for Lightroom

acv2xmp Convert Photoshop curves (acv) to Lightroom preset (xmp) acv2xmp.py Basic command prompt that relies on standard library only and can be used

5 Feb 06, 2022
Emulate and Dissect MSF and *other* attacks

Need help in analyzing Windows shellcode or attack coming from Metasploit Framework or Cobalt Strike (or may be also other malicious or obfuscated code)? Do you need to automate tasks with simple scr

123 Dec 16, 2022
Bible-App : Simple Tool To Show Bible Books

Bible App Simple Tool To Show Bible Books Socials: Language:

ميخائيل 5 Jan 18, 2022
TrackGen - The simplest tropical cyclone track map generator

TrackGen - The simplest tropical cyclone track map generator Usage Each line is a point to be plotted on the map Each field gives information about th

TrackGen 6 Jul 20, 2022
The earliest beta version of pytgcalls on Linux x86_64 and ARM64! Use in production at your own risk!

Public beta test. Use in production at your own risk! tgcalls - a python binding for tgcalls (c++ lib by Telegram); pytgcalls - library connecting pyt

Il'ya 21 Jan 13, 2022
ripgrep recursively searches directories for a regex pattern while respecting your gitignore

ripgrep (rg) ripgrep is a line-oriented search tool that recursively searches the current directory for a regex pattern. By default, ripgrep will resp

Andrew Gallant 35k Dec 31, 2022
《赛马娘》(ウマ娘: Pretty Derby)辅助 🐎🖥 基于 auto-derby 可视化操作/设置 启动器 一键包

ok-derby 《赛马娘》(ウマ娘: Pretty Derby)辅助 🐎 🖥 基于 auto-derby 可视化操作/设置 启动器 一键包 便捷,好用的 auto_derby 管理器! 功能 支持客户端 DMM (前台) 实验性 安卓 ADB 连接(后台)开发基于 1080x1920 分辨率

秋葉あんず 90 Jan 01, 2023
Interfaces between napari and pymeshlab library to allow import, export and construction of surfaces.

napari-pymeshlab Interfaces between napari and the pymeshlab library to allow import, export and construction of surfaces. This is a WIP and feature r

Zach Marin 4 Oct 12, 2022
Tool to audit and fix Python project requirements.

Requirement Auditor Utility to revise and updated python requirement files.

Luis Carlos Berrocal 1 Nov 07, 2021
Minitel 5 somewhat reverse-engineered

Minitel 5 The Minitel was a french dumb terminal with an embedded modem which had its Golden Age before the rise of Internet. Typically cubic, with an

cLx 10 Dec 28, 2022
The fastest way to copy to (not from) high speed flash storage.

FastestCopy The fastest way to copy to (not from) high speed flash storage. This is about 3-6x faster than file copy on explorer.exe to usb flash driv

Derek Frombach 0 Nov 03, 2021
Replay Felica Exchange For Python

FelicaReplay Replay Felica Exchange Description Standalone Replay Module Usage Save FelicaRelay (=2.0) output to file, then python replay.py [FILE].

3 Jul 14, 2022