Giter Site home page Giter Site logo

nunomrm / fwi-wrfout Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 4.02 MB

Utility library that performs calculations of the Fire Weather Index (FWI) in numpy arrays to create NetCDF files from wrfout files.

License: BSD 3-Clause "New" or "Revised" License

nesC 1.09% Python 98.91%

fwi-wrfout's Introduction

fwi-wrfout

fwi-wrfout (version 1.0) is a utility library that performs calculations of the Fire Weather Index (FWI), among related operations. The main goal of this utility is to convert wrfout files (output files from the WRF atmospheric model) into output NetCDF files containing the FWI index and its sub-indices (FFMC, DMC, DC, BUI, ISI). The source code for the FWI calculation is based on the pyfwi project.

The functions to compute FWI (fwi_functions.py) use the same calculations as the original pyfwi FWI functions. However, they were adapted for calculations in numpy arrays instead of individual numbers, as it was originally designed in pyfwi. This makes a significant difference in terms of efficiency when using data-heavy (LON,LAT,XTIME) numpy arrays, which is often the case of wrfout files (in the original version several for-loops would have to be performed).

fwi-wrfout is distributed under the 3-Clause BSD License (see the LICENSE.txt file).

Prerequisites

Python 3.10 or posterior versions are recommended.

Tests were performed with these python modules:

  • numpy: 1.23.5
  • netCDF4: 1.6.3
  • matplotlib: 3.7.1
  • geopandas: 0.12.2
  • xarray: 2023.4.2
  • cartopy: 0.21.1
  • shapely: 2.0.1

Setting up

Clone the git repository:

git clone https://github.com/nunomrm/fwi-wrfout.git

Install required Python modules:

pip install -r requirements.txt

Utilities description

The functions present in utils/main_utils.py contain the core utilities of fwi-wrfout. These utilities are listed and described below:

  • fwi_idx: filters the original time array indices into indices for calculating the FWI;
  • extract_climate_vars: imports the variables necessary to calculate the FWI and performs some calculations (e.g., obtain relative humidity, obtain hourly precipitation) and extracts a dictionary data structure with the attributes t2, wind,rain_cumulative, wind, rh (for all time instants), t2_fwi, wind_fwi, rain_fwi, rh_fwi (for FWI indices);
  • compute_fwi: allows for computation of FWI by calling fwi_functions (adapted from the pyfwi project to calculate FWI with numpy arrays), and attributes initial values of FWI sub-indices dependent on previous day values (FFMC, DMC and DC);
  • calc_rh: calculates relative humidity from pressure (psfc), the ratio of saturation mixture (q2), and temperature (t2);
  • make_map: creates the figure and draws the map with cartopy;
  • plot_fwi_vars: plots FWI variables, and currently adapted for FWI and n_days of FWI (in terms of custom colormaps and labels), not yet for FWI sub-indices.

Run examples

generate_fwi_nc.py

Usage:

  1. Go to examples/
  2. Run python generate_fwi_nc.py

Input: data/wrfout_files/wrfout_test.nc

Output: output/nc_files/fwi_test.nc

Description: Computes and generates a NetCDF FWI file with the same time, lon, lat format as the wrfout. Uses an xarray dataset to open the wrfout and extract its climate/weather information. For very large wrfouts (e.g. >8GB), using xarray.open_dataset for data extraction made the runtime decrease dramatically, due to parallelization routines with dask (xarray dependency), compared to using netCDF4.Dataset. In the utilities folder (utils/) has all tools for the computation of FWI. The compute_fwi function is the allows for computation of FWI, and which calls fwi_functions (which was adapted from the pyfwi project) and makes calculation of FWI with numpy arrays. Lastly, a NetCDF file is created, storing FWI and its' sub-indices.

plots_fwi.py

Usage:

  1. Go to examples/
  2. Run python plots_fwi.py

Description: Creates three simple map plots with Matplotlib and Cartopy. Applies masking outside Portugal's Vila Real, Bragança and Guarda districts. These plots are saved in the PNG format in output/plots/. Below we see two example plots.

Map of the FWI mean without masking (fwi_mean_nomask.png):

Map of the FWI mean with masking (fwi_mean.png):

fwi-wrfout's People

Contributors

nunomrm avatar

Watchers

 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.