Skip to content

Commit

Permalink
wps
Browse files Browse the repository at this point in the history
  • Loading branch information
jmills-ncar committed May 23, 2018
1 parent c2451a2 commit 2776a53
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
65 changes: 65 additions & 0 deletions wps/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
###################################
# Author: Joe Mills <[email protected]>
# Date: 9.27.2017
###################################
#
# This Dockerfile compiles WRF and WPS from source using the bare-bones requirements for training purposes.
# See https://ral.ucar.edu/projects/ncar-docker-wrf for more complete WRF and WPS docker builds with additional functionality

FROM wrfhydro/dev:conda

MAINTAINER [email protected]
USER root

############################
###WRF and WPS

#Set WRF and WPS version argument
ARG WRFWPS_VERSION="3.9"

#Install WRF AND WPS
WORKDIR /home/docker/WRF_WPS
#
# Download sources for version specified by WRFWPS_VERSION argument
#
RUN wget https://www2.mmm.ucar.edu/wrf/src/WRFV${WRFWPS_VERSION}.TAR.gz \
&& \
mkdir WRFV${WRFWPS_VERSION} \
&& tar -zxf WRFV${WRFWPS_VERSION}.TAR.gz \
&& rm WRFV${WRFWPS_VERSION}.TAR.gz
RUN wget https://www2.mmm.ucar.edu/wrf/src/WPSV${WRFWPS_VERSION}.TAR.gz \
&& mkdir WPSV${WRFWPS_VERSION} \
&& tar -zxf WPSV${WRFWPS_VERSION}.TAR.gz \
&& rm WPSV${WRFWPS_VERSION}.TAR.gz

# Build WRF first, required for WPS
WORKDIR /home/docker/WRF_WPS/WRFV3
RUN printf '32\n0' | ./configure \
&& ./compile em_real

# Build WPS second after WRF is built
WORKDIR /home/docker/WRF_WPS/WPS
RUN printf '1' | ./configure \
&& ./compile geogrid

RUN rm -r /home/docker/WRF_WPS/WPSV3.9 \
&& rm -r /home/docker/WRF_WPS/WRFV3.9

RUN chmod -R 777 /home/docker/WRF_WPS

############################
# Setup stuff for entrypoint

RUN mv /home/docker/WRF_WPS/WPS/namelist.wps \
/home/docker/WRF_WPS/WPS/namelist.wps_orig

COPY make_geogrid.py /home/docker/runTimeScripts/make_geogrid.py

####################################
########## DOCKER USER #############
####################################
USER docker
WORKDIR /home/docker
#ENV NETCDF=/usr/local

#ENTRYPOINT python make_geogrid.py
5 changes: 5 additions & 0 deletions wps/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

docker build "$@" -t wrfhydro/wps .

exit $?
83 changes: 83 additions & 0 deletions wps/make_geogrid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import f90nml
import subprocess
import sys
from argparse import ArgumentParser
import pathlib
import copy

def patch_namelist(orig_nml_path: str,patch_nml_path: str,new_nml_path: str):
"""This function updates a larger orginal namelist with a file containing a smaller subset of
changes and writes out a new namelist to a file.
Args:
orig_nml_path: Path to the namelist file to be updated
patch_nml_path: Path to the file containing the namelist updates
new_nml_path: Path to write the new namelist file with updates applied.
Returns:
None
"""
# Read in namelist patch
patch_nml = f90nml.read(nml_path=patch_nml_path)

# Write new namelist to file
f90nml.patch(nml_path=orig_nml_path,
nml_patch=patch_nml,
out_path=new_nml_path)

print('New namelist written to ' + new_nml_path)
return(None)


#def plot_domain(ref_lat: float,ref_lon: float,x: int,y: int):

import pyproj



def main():

parser = ArgumentParser()
parser.add_argument("--patch_nml_path",
dest="patch_nml_path",
help="Path to namelist file containing the namelist updates")
parser.add_argument("--orig_nml_path",
dest="orig_nml_path",
default='/home/docker/WRF_WPS/WPS/namelist.wps_orig',
help="Path to original wps namelist")
parser.add_argument("--new_nml_path",
dest="new_nml_path",
default='/home/docker/WRF_WPS/WPS/namelist.wps',
help="Path to write the new namelist file with updates applied."
"Note this path must be the same as the directory containing "
"geogrid.exe")
parser.add_argument("--plot",
dest="plot",
default='False',
help="Create a plot of the domain. Geogrid will not be created if "
"show_plot = True, only a plot of the domain.")
args = parser.parse_args()

orig_nml_path = args.orig_nml_path
new_nml_path = args.new_nml_path
patch_nml_path = args.patch_nml_path
plot = bool(args.plot)

if plot:
None
# Run plotting function
else:
# First patch the namelist
patch_namelist(orig_nml_path=orig_nml_path,
patch_nml_path=patch_nml_path,
new_nml_path=new_nml_path)

# Now run geogrid.exe
subprocess.run(['./geogrid.exe'],
cwd=pathlib.Path(new_nml_path).parent,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)


if __name__ == '__main__':
main()

0 comments on commit 2776a53

Please sign in to comment.