Skip to content

Commit

Permalink
fix for leap years in mswx dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
doc78 committed Nov 21, 2024
1 parent 1951052 commit f7ab62d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lisfloodutilities/water-demand-historic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The utility consists of five scripts which require several following datasets an
1. [USGS NWIS](https://waterdata.usgs.gov/nv/nwis/wu) water withdrawal estimates for 1985--present. For each state in the "Geographic Area" drop-down menu, select "State Data", "ALL Years", "State Total", and "ALL Categories" and click "Submit". Then select "Tab-separated data" and click "Submit". Do this for each state and put files in `usgs_water_use_folder`.
1. USGS water withdrawal data files for [1985](https://water.usgs.gov/watuse/data/1985/index.html) and [1990](https://water.usgs.gov/watuse/data/1990/index.html) (to supplement the NWIS data). Download "Data file of state-level data" for each year (`us85st.txt` and `us90st.txt`) and put the files in `usgs_water_use_folder`.
1. [Vassolo and Döll (2005)](https://doi.org/10.1029/2004WR003360) industrial and thermoelectric water withdrawal maps (included in this repository with permission from Petra Döll). The industrial withdrawal shape file is rasterized using `gdal_rasterize -l "industry_paper_vassolo&doell" -a MANUF_WWD -tr 0.5 0.5 -a_nodata 0.0 -te -180.0 -90.0 180.0 90.0 -ot Float32 -of GTiff "industry_paper_vassolo&doell.shp" manuf_wwd.tif`. Thermoelectric shape file rasterized using same command but with `WWD_PS` and `wwd_ps.tif`. Put the files in `vassolo_doll_folder`.
1. [GISCO](https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units/countries) country borders shape file. Select year 2024, File format SHP, Geometry type Polygons (RG), Scale 01M, Coordinate system EPGS 4326, click Download. Open QGIS, then open the shape file and the csv file "un_country_codes.csv" in ancillary_data folder. Open Preprocessing->Toolbox and search for "Join Attributes by Field Value". Select the shape file as Input Layer with Table field "ISO3_CODE" and the csv file as Input layer 2 with Table field "alpha-3". Select "country-code" into "Layer 2 fields to copy" and run the preprocessing. Save the reulting layer as "CNTR_RG_01M_2024_4326".
1. [GISCO](https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units/countries) country borders shape file. Select year 2024, File format SHP, Geometry type Polygons (RG), Scale 01M, Coordinate system EPGS 4326, click Download. Open QGIS, then open the shape file and the csv file "un_country_codes.csv" in ancillary_data folder. Open Preprocessing->Toolbox and search for "Join Attributes by Field Value". Select the shape file as Input Layer with Table field "ISO3_CODE" and the csv file as Input layer 2 with Table field "alpha-3". Select "country-code" into "Layer 2 fields to copy" and run the preprocessing. Save the resulting layer as "CNTR_RG_01M_2024_4326".
Rasterize to 0.01° using `gdal_rasterize -l CNTR_RG_01M_2024_4326 -a country-co -tr 0.01 0.01 -a_nodata 0.0 -te -180.0 -90.0 180.0 90.0 -ot Float32 -of GTiff CNTR_RG_01M_2024_4326.shp CNTR_RG_01M_2024_4326_rasterized.tif`. Put the result in `world_borders_folder`.

1. [World Bank](https://data.worldbank.org/) manufacturing value added and gross domestic product data. Search for "Manufacturing, value added (constant 2015 US$)" and "GDP (constant 2015 US$)", download as CSV, and put in `world_bank_folder` (Remove Metadata csv files, if any).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,11 @@ def main():
mswx_month = np.zeros((1800,3600,ndays),dtype=np.single)*np.NaN
for day in np.arange(1,ndays+1):
if year<1979: #MSWX dataset starts from 1979
filepath = os.path.join(config['mswx_folder'],'Past','Temp','Daily',datetime(1979,month,day).strftime('%Y%j')+'.nc')
try:
date=datetime(1979,month,day)
except: # fix for Leap years < 1979
date=datetime(1979,month,day-1)
filepath = os.path.join(config['mswx_folder'],'Past','Temp','Daily',date.strftime('%Y%j')+'.nc')
else:
filepath = os.path.join(config['mswx_folder'],'Past','Temp','Daily',datetime(year,month,day).strftime('%Y%j')+'.nc')
if os.path.isfile(filepath):
Expand Down

0 comments on commit f7ab62d

Please sign in to comment.