GithubHelp home page GithubHelp logo

georgemilosh / climate-learning Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 5.0 220.53 MB

How to predict extreme events in climate using rare event algorithms and modern tools of machine learning

Home Page: https://georgemilosh.github.io/Climate-Learning/

Python 0.59% Shell 0.01% Jupyter Notebook 99.40%
climate extreme heatwave machine-learning rare-event-algorithm

climate-learning's People

Contributors

alessandrolovo avatar clemlpr avatar dariolucente avatar georgemilosh avatar omahs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

climate-learning's Issues

Sign of tau

Changing tau to -tau in the Learn2_new.py code is super easy, barely an inconvenience... but how many things would it break?

transfer learning on `u`

I think there is no reason to have transfer learning work on u, which seems to be the case provided that load_from='last' which is default. I guess I could turn of transfer learning completely by using load_from=None. Maybe that should be defaault behavior. Or maybe default behavior should be that transfer learning occurs only with tau. Otherwise we can easily fall into a trap when not performing analysis of hyperparameter optimization carefully. I am a bit about worried about this transfer learning.

Better logging

It is better to move away from print and use instead logging.log. This allows for much easier dealing with logging to different devices and different levels of verbosity

  • Replace print with logging.log with proper logging levels, e.g. print(f'{X.shape = }') -> logging.info(f'{X.shape = }') or logging.level(20, f'{X.shape = }')
  • Log to file and terminal
  • Log important information to telegram (Alessandro knows how)

mrso masking bug

When plotting the masked mrso it seems weird: not a square grid. Understand what's going on and fix it

Xarrays

Use Xarrays instead of pure netCDF4 files.
This should make it easier to use data with other format, e.g. grid resolution

Reduce memory usage!

There are not so many machines that can handle all the data in memory. We need to find a way to deal with this issue. There are many materials online which show how it can be achieved in tensorflow (pipelines etc). The problem is that I still get out of memory issue (the process simply gets killed).

Better masked average

The current masked_average function is very slow and RAM intensive: design a better one

Early stopping

Add the possibility to have early stopping during training

Multiclass classification

Make the code able to deal with multiclass (>2) classification for different intensity of heatwaves.
Things to adapt:

  • label assignment
  • metrics
  • undersampling and its unbiasing
  • ordered classes

Merge the subm2 and main

On the first glance there seem to be no inconsistencies between the branches, thus they can be merged together. Below we list the files which many other ones depend on:

  • The most difficult file to merge is Learn2_new.py
  • Merging ERA_Fields_New.py is relatively easy to merge
  • Merging TF_Fields.py is very easy

Fix errors with resampling.py

  • Fix the location of checkpoints which seem to be outside of eons.
  • Fix problems with collective: It seems when calling python resampling.py num_eons=1 we get an error
  • Add more logging outputs, so that we can for example how much data actually gets inside the neural network. Also how much undersampling etc happens
  • Store the selection of years (also possibly days) inside of the training folder so that we can easily check what data was used.

`field_infos` should be a json file

It would be better for fields_infos to be loaded from a json file, like we do with config.json. This is because I would like to keep the labels of the fields, while working with both CESM and Plasim. The idea would be to simply modify field_infos.json when working with CESM as opposed to Plasim

The error messages return wrong lines for `Learn2_new.py`

I was running
python hyperparameter_optimization.py n_trials=100
I got an error message:

File "/ClimateDynamics/MediumSpace/ClimateLearningFR/gmiloshe/CESM/models/hypop/t2-bn-dr-l2/Learn2_new.py", line 1441, in create_model
    raise ValueError(f'Invalid length for argument {arg}')
ValueError: Invalid length for argument ['relu', None]

The problem is the line that is reported does not correspond to where the error happens precisely in the code. I've noticed this before and it is quite annoying when debugging.

Flexible latitude in `committor_projection_NN.py`

Right now the latitude used for regularization is hardcoded. This is bad for generalization. We need to get it from the fields passing through all the functions up to where it needs to go.

A possibility is to add a tunnel argument that is simply passed through all the functions in the main Learn2_new code that helps for inheritance

runs.json

Keep track of the runs in a json file instead of txt one. This way we can save metadata about the run like when it started, when (if) it ended, etc.

Use submodules

Put general purpose routines inside a git submodule so it can be accessed from other repos easily.

This may break backward compatibility

Support for padding that respects the topology of the sphere

In the context of 1000 year long dataset it seemed that global zg500 mattered less, therefore decision was taken to ignore this more advanced treatment. In 8000 year long dataset (possibly also due to weaker soil atmosphere interactions) global zg500 is more prominent, also possibly for shorter heat waves this could also be the case. In Besombes at al 2021 we see this setup for their generative model. VAE trained on Plasim shows that it is harder to generate continuous outputs with standard padding (convolution), although deeper network seems to perform better in this regard.

  • Take into account the connectivity
  • Take into account that grid points are not equally spaced

Restrict labels to heat wave onsets

Choose labels which correspond to the first few days of the onset of heat waves and see what happens. Currently we mix the labels of heat waves which correspond to already started heat waves (that take 14 days) and heat waves that have been on-going for a long time (and are still above 5 %). This potentially destroys dynamical information and prevents us from extracting it from the DNN

  • Determine what are the characteristics of the events we want to keep as class heat wave onset and the amount of positive labels we thus keep
  • Possibly introduce a class for "on-going heat wave"

xarray masks

Redesign the region-wise masks to work with xarray

Better exploitation of xarray features

Cleanup old features?

  • Is rolling still necessary now that we have wrap around longitude?
  • Is it worth saving longitude and latitude in prepare_XY

Further optimization

  • Save data with already monotonized years, so we don't need to do it run-time

early stopping for eons

Implement early stopping for eons in resampling.py: meaning that if the score doesn't improve over the eons we stop training

utilities

Move all general purpose functions/classes to a utilities.py module

Accelerate the VAE routines

  • kwargs support
  • modularity
  • json file configs
  • k_fold_cross_val implemented
  • trainer class
  • reconstruction.py should not load all the years
  • classification.py with a possible choice of classifiers and hyperparameters

:sparkles: **Modular support for PLASIM/Learn2.py** :sparkles:

This will allow us to selectively load different subroutines of Learn2.py. Sometimes when analysing the predictions of the model we don't need to load all the data. This leads to unnecessary delays, in particular when working with multiple tau (lag times)

  • Create modular support for PLASIM/Learn2.py similar to the one in VAE/vae_learn1.py
  • The idea is to also be able to load specific permutation of years from the *.nc file without loading the who *.nc file
  • add tau as argument of PLASIM/Learn2.py
  • config file?
  • Include Brier score in the metric evaluation (subclass tensorflow)
  • Write an analogue for PLASIM/Recalc_Tau_Metrics.py routine that would benefit from these changes

Working with CESM

The point is to be able to load the fields from the CESM model using the same classes we have written

Use Learn2_new.py for vae_learn2.py

George has to fix the error which curiously occurs when passing from vae_learn1.py to vae_learn2.py

"Traceback (most recent call last):
File "/ClimateDynamics/MediumSpace/ClimateLearningFR/gmiloshe/VAE/vae_learn2.py", line 274, in
X, LON, LAT, vae, Z_DIM, N_EPOCHS, INITIAL_EPOCH, BATCH_SIZE, LEARNING_RATE, checkpoint_path, checkpoint_name, myinput, history = PrepareDataAndVAE()
File "/ClimateDynamics/MediumSpace/ClimateLearningFR/gmiloshe/VAE/vae_learn2.py", line 259, in PrepareDataAndVAE
vae, history, N_EPOCHS, INITIAL_EPOCH, checkpoint, checkpoint_path = ConstructVAE(INPUT_DIM, Z_DIM, checkpoint_name, N_EPOCHS, myinput, K1, K2, from_logits=False, mask_weights=filter_mask)
File "/ClimateDynamics/MediumSpace/ClimateLearningFR/gmiloshe/VAE/vae_learn2.py", line 169, in ConstructVAE
decoder_input, decoder_output, decoder = tff.build_decoder_skip(input_dim = 64,
File "/ClimateDynamics/MediumSpace/ClimateLearningFR/gmiloshe/ERA/TF_Fields.py", line 287, in build_decoder_skip
decoder_outputs = ConstMul(mask,(~mask)*0.5)(x[-1]) # This will multiply the input by mask consisting of 0's (False) and 1's (True). Because the decoder is expected to reconstruct sigmoid function we add 0.5 where there were 0's
File "/home/gmiloshe/miniconda3/envs/myenvnew/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py", line 951, in call
return self._functional_construction_call(inputs, args, kwargs,
File "/home/gmiloshe/miniconda3/envs/myenvnew/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1090, in _functional_construction_call
outputs = self._keras_tensor_symbolic_call(
File "/home/gmiloshe/miniconda3/envs/myenvnew/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py", line 822, in _keras_tensor_symbolic_call
return self._infer_output_signature(inputs, args, kwargs, input_masks)
File "/home/gmiloshe/miniconda3/envs/myenvnew/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py", line 863, in _infer_output_signature
outputs = call_fn(inputs, *args, **kwargs)
File "/home/gmiloshe/miniconda3/envs/myenvnew/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 670, in wrapper
raise e.ag_error_metadata.to_exception(e)
NotImplementedError: in user code:

/ClimateDynamics/MediumSpace/ClimateLearningFR/gmiloshe/ERA/TF_Fields.py:49 call  *
    return inputs * self.const_a + self.const_b
/home/gmiloshe/miniconda3/envs/myenvnew/lib/python3.9/site-packages/tensorflow/python/ops/math_ops.py:1175 binary_op_wrapper
    out = r_op(x)
/home/gmiloshe/miniconda3/envs/myenvnew/lib/python3.9/site-packages/tensorflow/python/framework/ops.py:852 __array__
    raise NotImplementedError(

NotImplementedError: Cannot convert a symbolic Tensor (Placeholder:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

"

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.