Setting up CDA writes and cwms-python on T7s
Important
This is a living document and are subject to change. Last updated:
Install local CDA instance
https://github.com/USACE/cwms-data-api/wiki/Installing-into-Tomcat
Setup Writing Data to CDA
Generate API KEY
- Goto the following URL for you local instance of CDA where xxx is your district code.
- https://wm.XXX.ds.usace.army.mil:8243/CWMSLogin/login
- If you get a “HTTP Status 404” error when trying to access that page then you need to Submit a General Request ticket to the G6 "Unix Web Server Support" Team in the body of the ticket write.
- “Forward to Web Team. web Team please coordinate with HEC to install CWMS Tomcat CAC auth components and CWMSLogin.war on coe-XXXuwa04XXX.XXX.usace.army.mil
- A agreement will appear. Click accept. An output will show up with your user and the CWMS user roles assigned to your account. In order to write data the CWMS Users role is needed.
- in server admin make sure you web user has the following permissions
- Goto you CDA swagger page
- Goto the Authorization endpoint and open the POST function
- Click “Try it out”
- In the example values dictionary enter your UPASSID. Or the UPASSID for the ID you want to create a key for.
- Enter a key-name. This is a descriptor and can be anything that you can remember
- For api-key you can leave this as ‘string’. The function will create an api key for you
- Expires enter a date in the future. You will need to update your api key before the expires date
- After those values have been entered click Execute.
- Under the 201 Created response a API key should be displayed. Save this apikey to be used to write data using CDA.
- You can use your api key in cwms-python or using CDA. When using the apikey it needs to be prefix with the word ‘apikey ’ (without the single quotes and it does need a space between the word apikey and your actual apikey).
- NOTE: If you are storing your API in a file to use in a script we recommend storing it without the apikey prefix and then adding the prefix in your script itself. For steps on how to do this please follow the steps listed under "5" in the portion "Using CDA and cwms-python Server side" below.
Using CDA and cwms-python Server side.
- use new install python 3.9.18 version /wm/wmsoft/python/v3.9.18-Solaris11.4.65.157
- connection for both cwbi-test and your local copy of CDA in python require access to DOD root certificates.
- Those certificates have been copied to the /wm/wmsoft/certs folder.
- To allow python/request package to access them In your .bashrc file enter the following
- export REQUESTS_CA_BUNDLE=/wm/wmsoft/certs/cacert.pem
- to store and use your apikey to write data in a python script do the following
- create a folder .cwms in the /wm/xxx/xxcwpaxx folder that has 700 permissions.
- In the folder create a file cda_api_key that has 700 permissions
- In the file add your API_KEY to a single line.
- Can either access the api key by grabbing and storing in a environment variable in your .bashrc file
- Or you can use the following code in your python script
- with open(os.environ["CWMS_HOME"] + "/.cwms/cda_api_key", "r") as f:
- APIKEY = 'apikey ' + f.readline().strip()
- I would also suggest adding the following to you .bashrc file
- export CDA_API_ROOT=https://wm.XXX.ds.usace.army.mil:8243/XXX-data/
- then in your python scripts you can access it using
- APIROOT = os.environ['CDA_API_ROOT']
- Install cwms-python
- Run ./wm/wmsoft/python/v3.9.18-Solaris11.4.65.157/bin/pip install cwms-python
- update symlink
- update your symlink in /wm/localsoft/ to python3 to reference the new version of python.
- to update to a new version of cwms-python
- Run ./wm/wmsoft/python/v3.9.18-Solaris11.4.65.157/bin/pip install -U cwms-python
Using cwms-python on workstation
Setup Using Anacaonda (no longer supported by USACE)
- for use of cwms-python on your workstation follow the following steps in the cwms-python_workstation_setup.docx located in the following teams folder 2024 Data Workshop.
Setup using a portable python package
- Follow the following steps to setup a portably python environment. Install Portable Python with cwms.docx with files located in the following folder. python install. Start of step B to just use the already created portable python environment. If you want to create your own start with step A.
- Tutorials for cwms-python can be found in the github repo through the following link. https://github.com/HydrologicEngineeringCenter/cwms-python/tree/main/examples