Skip to content

Commit

Permalink
Fix in time variable index. Added shift_hours_units_start description…
Browse files Browse the repository at this point in the history
… in README
  • Loading branch information
doc78 committed Nov 27, 2024
1 parent ea6fe55 commit ed4f18b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/lisfloodutilities/water-demand-historic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The global sectoral water demand maps at 3 arcmin (or 0.05 degrees) resolution,

The utility consists of five scripts which require several following datasets and files. The full list of datasets is provided below. For each dataset, this documentation provides the link and the instructions relative to available version at the time of creation of the scripts. The correct functioning of the scripts is guaranteed for those datasets. Clearly, updated versions are regularly published: one relevant example is [Global Human Settlement - Datasets - European Commission (europa.eu)](https://ghsl.jrc.ec.europa.eu/datasets.php) (see Global Human Settlement Layer (GHSL)). Albeit the functioning of the utility is expected to be maintained, the users are invited to report problems or suggestions via GitHub issues.
1. [FAO AQUASTAT](http://fao.org/aquastat/statistics/query/index.html?lang=en) sectoral water withdrawal estimates. Select "All Countries". Then Select the variable groups "Geography and population" and "Water use" (if needed select the subgroubps "Economy, development and food security" and "Water withdrawal by sector"). From these variable groups, select the following seven fields: "Gross Domestic Product (GDP)", "Industry, value added to GDP", "Agricultural water withdrawal", "Industrial water withdrawal", "Municipal water withdrawal", "Total water withdrawal", and "Irrigation water withdrawal". Select All Years, or manually select the years from 1976 to 2021. Select "Design your own" to add "Area","m49","Variable","Value","Year" fields if not present, then click on the "Show Data" button. Finally click on the "Download" button on the top right corner to download the csv file containing all data (or copy and paste the Table in CSV format shown in the web page to a csv file). Save the csv file as `aquastat_clean.csv` in `aquastat_folder` specified in the configuration file.
1. [Global Human Settlement Layer (GHSL)](https://human-settlement.emergency.copernicus.eu/ghs_pop2023.php) POP R2023A residential population estimates for target years from 1975 to 2020. You will find data as an archive [here](https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/GHS_POP_GLOBE_R2023A/). For each year, download the 3 arcsec (folders ending by "_3ss"), e.g. "GHS_POP_E2015_GLOBE_R2023A_4326_3ss") maps in WGS84 projection and resample them to 0.01° using `gdalwarp -t_srs EPSG:4326 -tr 0.01 0.01 -r average -of GTiff GHS_POP_E<year>_GLOBE_R2023A_4326_3ss_V1_0.tif GHS_POP_E<year>_GLOBE_R2023A_4326_3ss_V1_0_reprojected.tif`, where `<year>` is 1975 to 2020. We resample the maps using `average` instead of `sum` as the latter is broken. Put resampled files in `ghsl_folder`. You will need to specify also the 'ghsl_folder_factor = 144' to account for resampling from 0.000833 (3 arcsec) to 0.01 degrees.
1. [Global Human Settlement Layer (GHSL)](https://human-settlement.emergency.copernicus.eu/ghs_pop2023.php) POP R2023A residential population estimates for target years from 1975 to 2020. You will find data as an archive [here](https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/GHS_POP_GLOBE_R2023A/). For each year, download the 3 arcsec (folders ending by "_3ss"), e.g. "GHS_POP_E2015_GLOBE_R2023A_4326_3ss") maps in WGS84 projection and resample them to 0.01° using `gdalwarp -t_srs EPSG:4326 -tr 0.01 0.01 -r average -of GTiff GHS_POP_E<year>_GLOBE_R2023A_4326_3ss_V1_0.tif GHS_POP_E<year>_GLOBE_R2023A_4326_3ss_V1_0_reprojected.tif`, where `<year>` is 1975 to 2020. We resample the maps using `average` instead of `sum` as the latter is broken. Put resampled files in `ghsl_folder`. You will need to specify also the `ghsl_folder_factor = 144` to account for resampling from 0.000833 (3 arcsec) to 0.01 degrees.
1. [Global Change Analysis Model (GCAM)](https://github.com/JGCRI/gcam-core/releases) regional water withdrawal and electricity consumption estimates. Download the Windows release package version 7.1, execute `run-gcam.bat`, wait for the model to finish. Execute `run-model-interface.bat`, click "File" > "Open" > "DB Open", select `output/database_basexdb`, and select all scenarios and all regions. Select `water demand`, select `water withdrawals by sector`, and click "Run query". Select `energy transformation`, select `electricity`, select `elec consumption by demand sector`, and click "Run query". For each tab, select all data with ctrl-a and click "Edit" > "Copy". Open a blank [Google Sheets](http://sheets.google.com/) spreadsheet, press ctrl-v, manually add the headers, click "File" > "Download" > "Comma-separated values", save as `water_demand.csv` and `elec_consumption.csv`, respectively, and put both files in `gcam_folder`.
1. [Gridded Livestock of the World (GLW 3)](https://doi.org/10.1038/sdata.2018.227) species distribution dataset. Download the eight zip files (each representing a different species) and extract them to `glw_folder`.
1. [Huang et al. (2018)](https://doi.org/10.5281/zenodo.1209296) global gridded water withdrawal estimates. These estimates are not incorporated in our dataset, but are only used for the sake of comparison. Download all 7z files and extract them to `huang_folder`.
Expand All @@ -32,6 +32,7 @@ Rasterize to 0.01° using `gdal_rasterize -l CNTR_RG_01M_2024_4326 -a country-co
-->

The locations of the datasets and files are specified in the configuration file (see the `config.cfg` example). The script also requires a template map which defines the output resolution and area. The template map should be in netCDF-4 format and contain `lat` and `lon` variables and a data variable (any name). The location of the template map is specified using `templatemap_path` in the configuration file. The data are produced for the period spanning `year_start` to `year_end` and saved in netCDF-4 format to `output_folder` (all specified in the configuration file).
The option `shift_hours_units_start = 24` indicates the number of hours to shift the time reference unit when producing the maps to be used in Lisflood EFAS (12 hours) and GloFAS (24 hours). It will affect the reference units field (e.g. "days since 1979-01-01 12:00:00") in the NetCDF output file.

# Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def main():
for month in np.arange(1,13):

index = (year-config['year_start'])*12+month-1
ncfile.variables['time'][index] = (pd.to_datetime(datetime(year,month,1))-pd.to_datetime(datetime(config['year_start'], 1, 1))).total_seconds()/86400
ncfile.variables['time'][index] = (pd.to_datetime(datetime(year,month,1))-pd.to_datetime(datetime(int(config['year_start']), 1, 1))).total_seconds()/86400
ncfile.variables[varname][index,:,:] = data

print("Time elapsed is "+str(time.time()-t0)+" sec")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def main():

index = (year-config['year_start'])*12+month-1

ncfile.variables['time'][index] = (pd.to_datetime(datetime(year,month,1))-pd.to_datetime(datetime(config['year_start'], 1, 1))).total_seconds()/86400
ncfile.variables['time'][index] = (pd.to_datetime(datetime(year,month,1))-pd.to_datetime(datetime(int(config['year_start']), 1, 1))).total_seconds()/86400
ncfile.variables[varname][index,:,:] = data

print("Time elapsed is "+str(time.time()-t0)+" sec")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def main():
data = np.round(data,decimals=2)
data = data[row_upper:row_upper+len(template_lat),col_left:col_left+len(template_lon)] # Subset to template map area
index = (year-config['year_start'])*12+month-1
ncfile.variables['time'][index] = (pd.to_datetime(datetime(year,month,1))-pd.to_datetime(datetime(config['year_start'], 1, 1))).total_seconds()/86400
ncfile.variables['time'][index] = (pd.to_datetime(datetime(year,month,1))-pd.to_datetime(datetime(int(config['year_start']), 1, 1))).total_seconds()/86400
ncfile.variables[varname][index,:,:] = data

print("Time elapsed is "+str(time.time()-t1)+" sec")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def main():
data = np.round(data,decimals=2)
data = data[row_upper:row_upper+len(template_lat),col_left:col_left+len(template_lon)] # Subset to template map area
index = (year-config['year_start'])*12+month-1
ncfile.variables['time'][index] = (pd.to_datetime(datetime(year,month,1))-pd.to_datetime(datetime(config['year_start'], 1, 1))).total_seconds()/86400
ncfile.variables['time'][index] = (pd.to_datetime(datetime(year,month,1))-pd.to_datetime(datetime(int(config['year_start']), 1, 1))).total_seconds()/86400
ncfile.variables[varname][index,:,:] = data

print("Time elapsed is "+str(time.time()-t1)+" sec")
Expand Down

0 comments on commit ed4f18b

Please sign in to comment.