From 456b74866fa5f755c724f69a0103abac2357f6cb Mon Sep 17 00:00:00 2001 From: Lars Hoffmann Date: Mon, 23 Dec 2024 10:41:52 +0100 Subject: [PATCH] Moved Python venv to working directories. --- .gitignore | 2 ++ projects/meteo/get_era5.sh | 5 +++++ projects/python/README.md | 20 +++++--------------- projects/python/plot.sh | 6 ++++-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 72e3c0c50..24b80c137 100644 --- a/.gitignore +++ b/.gitignore @@ -20,10 +20,12 @@ projects/meteo/era5/ projects/meteo/gfs/ projects/meteo/merra2/ projects/meteo/ncep/ +projects/meteo/venv/ !projects/paraview/ projects/paraview/data/ !projects/python/ projects/python/plots/ +projects/python/venv/ src/*.o src/*.mod src/atm2grid diff --git a/projects/meteo/get_era5.sh b/projects/meteo/get_era5.sh index 21b7e8b2d..b9ef7429b 100755 --- a/projects/meteo/get_era5.sh +++ b/projects/meteo/get_era5.sh @@ -34,6 +34,11 @@ dir=$4/${year}/${mon} res=$5 dt=$6 +# Create Python environment... +python3 -m venv venv +source ./venv/bin/activate +pip install "cdsapi>=0.7.2" + # Set time string... tstr=$(seq 0 "$dt" 23 | awk '{printf("%02d:00:00/", $1)}' | awk '{print substr($1,1,length($1)-1)}') diff --git a/projects/python/README.md b/projects/python/README.md index 61a08cf66..61c55d434 100644 --- a/projects/python/README.md +++ b/projects/python/README.md @@ -4,19 +4,9 @@ Here we provide some example Python scripts that can be used to plot MPTRAC outp ## Preparations -Create a virtual environment for python in your home directory: +The script `plot.sh` creates and activates a Python virtual environment (`venv`) in your working directory. -``` - python3 -m venv ~/venv -``` - -Activate the environment: - -``` - source ~/venv/bin/activate -``` - -Install the python modules required for ingesting and plotting the data: +Additionally, it installs the necessary Python modules for data ingestion and plotting: ``` pip install basemap basemap-data cartopy matplotlib numpy pandas scipy xarray @@ -26,7 +16,7 @@ Install the python modules required for ingesting and plotting the data: Three programs are provided for plotting air parcel and grid output, `plot_atm.py`, `plot_atm_3d.py` and `plot_grid.py`. -Call the python plot scripts with parameter `datadir` (the directory of the data files) and `plotdir` (the directory where the plots will be written to), e.g., for `plot_atm.py` it would be: +Call the Python plot scripts with parameter `datadir` (the directory of the data files) and `plotdir` (the directory where the plots will be written to), e.g., for `plot_atm.py` it would be: ``` python ./plot_atm.py ../example/data pythonplots @@ -34,7 +24,7 @@ Call the python plot scripts with parameter `datadir` (the directory of the data ## Plotting of trajectories and meteo map output of MPTRAC -To plot the trajectory data files created with `atm_select`, call the python script `atm_traj.py`: +To plot the trajectory data files created with `atm_select`, call the Python script `atm_traj.py`: ``` python3 plot_traj.py @@ -42,7 +32,7 @@ To plot the trajectory data files created with `atm_select`, call the python scr Here, a single trajectory on a map is plotted from the data file `traj_5450.tab` provided in the directory `data`. -To plot meteo data files created with `met_map` call the python script `plot_met_map.py`: +To plot meteo data files created with `met_map` call the Python script `plot_met_map.py`: ``` python3 plot_met_map.py diff --git a/projects/python/plot.sh b/projects/python/plot.sh index 4fbd53d5d..7e8a22032 100755 --- a/projects/python/plot.sh +++ b/projects/python/plot.sh @@ -1,7 +1,9 @@ #! /bin/bash -# Activate venv... -source ~/venv/bin/activate +# Create Python environment... +python3 -m venv venv +source ./venv/bin/activate +pip install basemap basemap-data cartopy matplotlib numpy pandas scipy xarray # Setup... datadir="../example/data.ref"