From 974af11bdab5ae3572abcc6af654c59c498d5004 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:39:22 +0000 Subject: [PATCH 1/4] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v4.5.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v4.5.0) - [github.com/pre-commit/mirrors-mypy: v1.4.1 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.4.1...v1.9.0) - [github.com/psf/black: 23.3.0 → 24.3.0](https://github.com/psf/black/compare/23.3.0...24.3.0) - [github.com/astral-sh/ruff-pre-commit: v0.0.276 → v0.3.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.276...v0.3.5) - [github.com/macisamuele/language-formatters-pre-commit-hooks: v2.9.0 → v2.13.0](https://github.com/macisamuele/language-formatters-pre-commit-hooks/compare/v2.9.0...v2.13.0) - [github.com/python-poetry/poetry: 1.5.0 → 1.8.0](https://github.com/python-poetry/poetry/compare/1.5.0...1.8.0) --- .pre-commit-config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b6e3462..4629c93 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: no-commit-to-branch - id: debug-statements @@ -16,7 +16,7 @@ repos: - id: check-toml - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v1.9.0 hooks: - id: mypy pass_filenames: false @@ -25,25 +25,25 @@ repos: additional_dependencies: [types-requests >= 2.28.0] - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 24.3.0 hooks: - id: black language_version: python3.10 - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.276 + rev: v0.3.5 hooks: - id: ruff args: [--fix] - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.9.0 + rev: v2.13.0 hooks: - id: pretty-format-yaml args: [--autofix, --indent, '2'] - repo: https://github.com/python-poetry/poetry - rev: 1.5.0 + rev: 1.8.0 hooks: - id: poetry-check - id: poetry-lock From fdf3380d6a47e52150831f8e80c548f698d3e60a Mon Sep 17 00:00:00 2001 From: Alankar Dutta Date: Sun, 28 Apr 2024 12:29:28 +0530 Subject: [PATCH 2/4] [DOC] Typos and other minor changes README.md --- README.md | 61 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 2035064..bc40608 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ -> A *Cloudy* database with functions to quickly interpolate physical state of astrophysical plasma without detailed Plasma modelling +> A *Cloudy* database with functions to quickly interpolate physical state of astrophysical plasma without detailed plasma modeling -Running Cloudy models on the fly, especially when there are lot of models to run with different parameters can become extremely expensive. `AstroPlasma` aims to provide a workaround by using a library of pre-computed cloudy models to generate most of the common plasma properties for a large range of parameter space by interpolation. Owing to a simple and easy to use interface, `AstroPlasma` also provides an abstraction layer enabling the user to get the plasma properties without worrying much about the details of plasma modelling. We find this extremely useful while building models and predicting observables like column densities in different kinds of astrophysical systems. +Running Cloudy models on the fly, especially when there are a lot of models to run with different parameters, can become extremely expensive. `AstroPlasma` aims to provide a workaround using a library of pre-computed cloudy models to generate most of the common plasma properties for a large range of parameter space by interpolation. Owing to a simple and easy-to-use interface, `AstroPlasma` also provides an abstraction layer enabling the user to get the plasma properties without worrying much about the details of plasma modeling. We find this extremely useful while building models and predicting observables like column densities in different kinds of astrophysical systems. [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/dutta-alankar/AstroPlasma) @@ -12,7 +12,7 @@ Running Cloudy models on the fly, especially when there are lot of models to run ![GitHub repo size](https://img.shields.io/github/repo-size/dutta-alankar/AstroPlasma) | ![GitHub repo file count](https://img.shields.io/github/directory-file-count/dutta-alankar/AstroPlasma) | -[![Lines of code](https://tokei.rs/b1/github/dutta-alankar/AstroPlasma?category=lines)](https://github.com/dutta-alankar/AstroPlasma) +![Lines of code](https://raw.githubusercontent.com/dutta-alankar/AstroPlasma/badges/lines_of_code.svg) ![GitHub last commit (branch)](https://img.shields.io/github/last-commit/dutta-alankar/AstroPlasma/main) | ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/dutta-alankar/AstroPlasma) @@ -48,7 +48,7 @@ cd AstroPlasma ``` #### Prepare Python virtual environment -The instructions here can be follwoed to setup a virtual envinronment (named `.venv` here) and install AstroPlasma and its dependencies: +The instructions here can be followed to set up a virtual environment (named `.venv` here) and install AstroPlasma and its dependencies: ``` python -m venv .venv source .venv/bin/activate @@ -76,7 +76,8 @@ source venv/bin/activate #### Alternative setup using `poetry` Alternatively, one can use `poetry` to install and setup `AstroPlasma` -> Install `poetry` following the installation instruction ![here](https://python-poetry.org/docs/#installing-with-the-official-installer). +> Install `poetry` following the installation instructions [here](https://python-poetry.org/docs/#installation). + > Do the following depending on requirements: - For user, `poetry install` - For developer, `poetry install --with dev,test` @@ -85,7 +86,7 @@ Alternatively, one can use `poetry` to install and setup `AstroPlasma` > As a one-time process, install `AstroPlasma` in this virtual environment using `python -m pip install --editable .`. ### Download the database -Once `AstroPlasma` and its dependencies are setup, the simplest way to get the entire database locally, is to run the following script in python with the virtual environment activated. Before running the following script, the environment variable `export PARALLEL_DOWNLOAD_JOBS=8` needs to be set. Here one can replace `8` with any number which sets how many files in the database will be downloaded from the web simultaneously. +Once `AstroPlasma` and its dependencies are set up, the simplest way to get the entire database locally is to run the following script in Python with the virtual environment activated. Before running the following script, the environment variable `export PARALLEL_DOWNLOAD_JOBS=8` needs to be set. Here, one can replace `8` with any number that sets how many files in the database will be downloaded from the web simultaneously. ```python from astro_plasma import download_all download_all() @@ -99,7 +100,7 @@ Alternatively, one can use a custom data location as well. Please see the releva ### Ionization modeling -This is how one would use astro_plasma for calculating ionization state of any typical astrophysical plasma. This would be useful in any modeling that depends on calculating the ionization of the plasma. Determining temperautre from density, calculating the free electron density in the plasma are few such examples where `AstroPlasma` can find application. +This is how one would use astro_plasma to calculate the ionization state of any typical astrophysical plasma. This would be useful in any modeling that depends on calculating the ionization of the plasma. Determining temperature from density and calculating the free electron density in the plasma are a few examples of applications of `AstroPlasma`. ```python # Import AstroPlasma Ionization module @@ -109,7 +110,7 @@ from astro_plasma.core.utils import AtmElement # for element naming using symbol #### Let us calculate ionization fraction of $\bf{OVI\ (O^{5+}})$ -In `AstroPlasma` elements are labelled by their atomic number. +In `AstroPlasma` elements are labeled by their atomic number. - Atomic number of the desired element is passed to the `element` argument in several functions of `AstroPlasma`. For example, Oxygen corresponds to `element=8`. - For the ionization state, `AstroPlasma` labels them according to the value passed to the `ion` argument. For example, ionization state III, corresponds to `ion=3`. - Summarizing, to know the ionization state of $\bf{OVI}$, one needs to pass `element=8` and `ion=6`. @@ -119,7 +120,7 @@ In `AstroPlasma` elements are labelled by their atomic number. fIon = Ionization.interpolate_ion_frac ``` -Now we are going to define typical physical values that characterizes an astrophysical plasma. +Now, we are going to define typical physical values that characterize an astrophysical plasma. ```python @@ -136,7 +137,7 @@ For *photo-ionization equilibrium*, the photo-ionizing backgrounds that are used ```python -# Lets get the ionization of OVI +# Let's get the ionization of OVI element = AtmElement.Oxygen ion = 6 fOVI = fIon(nH = nH, @@ -152,14 +153,14 @@ print(f"f_OVI = {fOVI:.3e}") ``` **Note**: -- Ionization fraction returned by `AstroPlasma` is in **log10** scale. -- As of now, we **do not** support vectorization of these functions and indivdual values must be passed and **not** arrays. This can lead to errors or un-defined behavior. -- You can provide element and ions in 4 ways +- The ionization fraction returned by `AstroPlasma` is on the **log10** scale. +- Currently, we **do not** support vectorization of these functions and indivdual values must be passed and **not** arrays. This can lead to errors or un-defined behavior. +- You can provide `element` and `ion` in 4 ways ```python # Using atomic number and ion count (int version of roman) fIon(element=8, ion=6) # OVI - # Using symbol of the element + # Using the symbol of the element fIon(element='O', ion=6) # OVI # Using AtmElement for element @@ -235,7 +236,7 @@ print(f"Total neutral particle density = {nn:.3e} cm^-3") print(f"Total HI particle density = {nHI:.3e} cm^-3") ``` -Although it is straightforward to obtain mean particle mass, we provide functions to so for the convenience of the user. We use the following relation for calculating these quantities. +Although it is straightforward to obtain mean particle mass, we provide functions to do so for the convenience of the user. We use the following relation for calculating these quantities. $$\rho = n \mu m_p = n_e \mu_e m_p = n_i \mu_i m_p = n_H m_H X^{-1}$$ @@ -311,7 +312,7 @@ plt.show() > **Note**: `AstroPlasma` assumes by default that the data is located at `/data/`. -The user can change this to something else by using `Ionization.base_dir = ""` or `EmissionSpectrum.base_dir = ""`, where these new directories must contain the valid `hdf5` data files. +The user can change this to something else using `Ionization.base_dir = ""` or `EmissionSpectrum.base_dir = ""`, where these new directories must contain the valid `hdf5` data files. > **Note**: One can also use the `pypoetry` tool to install and create an `in-place` virtual environment for this repo. @@ -323,9 +324,9 @@ https://indianinstituteofscience-my.sharepoint.com/:f:/g/personal/alankardutta_i ### Downloading files on demand -We made it easy for you in the code to download only the required files on-the-go using our built in service (Cloudy Interpolator web application). +We made it easy for you in the code to download only the required files on the go using our built-in service (Cloudy Interpolator web application). -To activate this feature, you should create `.env` file in the project root directory and provide following information. +To activate this feature, you should create a `.env` file in the project root directory and provide the following information. ```sh ASTROPLASMA_SERVER=http://web-server-url-here @@ -341,24 +342,24 @@ export ASTROPLASMA_SERVER=http://web-server-url-here setenv ASTROPLASMA_SERVER http://web-server-url-here ``` -All the environemnt variables you can configure (either in env file or via export) +All the environment variables you can configure (either in env file or via export) |Environment Variable|Description| |:----:|:----:| -|ASTROPLASMA_SERVER|Base url of the web-server to enable file downloading. To get this information, you can open issue [here](https://github.com/dutta-alankar/AstroPlasma/issues/new?title=[REQUEST]%20Access%20to%20the%20pre-computed%20dataset&body=Hi,%20I%20want%20to%20access%20the%20webserver%20to%20download%20the%20dataset%0A%0AName:%20John%20Doe%0AEmail:%20john.doe@example.com)| -|PARALLEL_DOWNLOAD_JOBS|Parallel jobs spawned to download the files. The default value is 3. You can increase or decrease based on download bandwidth of your network connection.| -|CHUNK_SIZE|Download chunk size of the dataset files. Default is `4096`. If your download is aborted because on unstable network, try decreasing this value.| +|ASTROPLASMA_SERVER|Base URL of the web server to enable file downloading. To get this information, you can open issue [here](https://github.com/dutta-alankar/AstroPlasma/issues/new?title=[REQUEST]%20Access%20to%20the%20pre-computed%20dataset&body=Hi,%20I%20want%20to%20access%20the%20webserver%20to%20download%20the%20dataset%0A%0AName:%20John%20Doe%0AEmail:%20john.doe@example.com)| +|PARALLEL_DOWNLOAD_JOBS|Parallel jobs spawned to download the files. The default value is 3. You can increase or decrease based on the download bandwidth of your network connection.| +|CHUNK_SIZE|Download the chunk size of the dataset files. The default is `4096`. If your download is aborted because of the unstable network, try decreasing this value.| ## Note to contributors If you wish to contribute, fork this repo and open pull requests to the `dev` branch of this repo. Once everything gets tested and is found working, the new code will be merged with the `master` branch. -For a successful merge, the code must atleast pass all the pre-existing tests. It is recommended to run `pre-commit` locally before pushing your changes to the repo for a proposed PR. To do so just run `pre-commit run --all-files`. +For a successful merge, the code must at least pass all the pre-existing tests. It is recommended to run `pre-commit` locally before pushing your changes to the repo for a proposed PR. To do so just run `pre-commit run --all-files`. -> **Note** It is recommended to install the git pre-commit hook using `pre-commit install` to check all the staged files. +> **Note** It is recommended that the git pre-commit hook be installed using `pre-commit install` to check all the staged files. ### Instructions on generating `Cloudy` database -All the codes required to generate the `Cloudy` database is in `cloudy-codes` directory. This part of the code is not as clean and user-friendly as the rest of `AstroPlasma` because it is not needed for an average user. Although I plan to improve this as well in near future. I have tested this using `Cloudy 17` ([link here to know more on `Cloudy`](https://pa.as.uky.edu/gary/cloudy-project)) +All the codes required to generate the `Cloudy` database are in the `cloudy-codes` directory. This part of the code is not as clean and user-friendly as the rest of `AstroPlasma` because it is unnecessary for an average user. Although I plan to improve this as well in the near future. I have tested this using `Cloudy 17` ([link here to know more on `Cloudy`](https://pa.as.uky.edu/gary/cloudy-project)) #### Setting up and compiling `Cloudy` - export `CLOUDY_DATA_PATH` to the `data` directory of `Cloudy` (for example, `c17.03/data`) - I have tested my building the library using Makefiles in `source/sys_gcc_shared` directory of `Cloudy`. Run `make` from inside this directory. If `make` succeeds then `cloudy.exe` and a shared library `libcloudy.so` will get compiled. @@ -374,18 +375,18 @@ All the codes required to generate the `Cloudy` database is in `cloudy-codes` di - export `AstroPlasma/cloudy-codes/ionFrac/src` to `LD_LIBRARY_PATH` - Inside the `AstroPlasma/cloudy-codes/ionFrac/generateIonFraction-parallel.py` script, change the parameters (`total_size`, `batch_dim`, `nH`, `temperature`, `metallicity`, `redshift`) to desired resolution and range. - Now one can run this script in parallel using `mpiexec -n python generateIonFraction-parallel.py`. I have tested this using `Python 3.11.6` with `mpi4py`, `numpy`, `h5py` and `colorama` packages installed. - **Note for cluster usres**: A sample slurm command that can be copied and executed from the terminal of a cluster is also provided in `slurm-python-job`. However, this neededs tweaking according the specifics of the cluster. Since, this job runs interactively, it is advisable to use something like gnu `screen` ot `tmux` to run this in a detached terminal as using these tools, interruptions in the connection to the cluster won't the kill the job. Also, the user need to make sure that the binaries compiled should be compiled for the compute nodes and not the login nodes if they are of different configuration. One can see the progress of the run in the log files generated by slurm. For example, `tail -F ~/AstroPlasma/cloudy-codes/ionFrac/IonCloudy-2325.log` enables you see the status of the running job with jobID `2325` in this example. + **Note for cluster usres**: A sample `slurm` command that can be copied and executed from the terminal of a cluster is also provided in `slurm-python-job`. However, this needed tweaking according to the specifics of the cluster. Since this job runs interactively, it is advisable to use something like gnu `screen` or `tmux` to run this in a detached terminal, as using these tools, interruptions in the connection to the cluster won't kill the job. Also, the user needs to make sure that the binaries compiled should be compiled for the compute nodes and not the login nodes if they are of different configurations. One can see the progress of the run in the log files generated by slurm. For example, `tail -F ~/AstroPlasma/cloudy-codes/ionFrac/IonCloudy-2325.log` enables you to see the running job status with jobID `2325` in this example. - Upon successful run, several ascii files with `ionization` in their name will get generated in a directory called `auto` that is created in `AstroPlasma/cloudy-codes/ionFrac/src`. The final `hdf5` files for the database is created in the `data` directory in`AstroPlasma/cloudy-codes/ionFrac/src`. This directory should be copied to `AstroPlasma/astro_plasma/data/` and renamed as `ionization`. - Generating *emission* data - - The steps are similar as above. But in this case both `libcloudy.so` and `cloudy.exe` files need to be copied to `AstroPlasma/cloudy-codes/emmSpec/` from `source/sys_gcc_shared` directory of `Cloudy`. + - The steps are similar to the above. But in this case, both `libcloudy.so` and `cloudy.exe` files need to be copied to `AstroPlasma/cloudy-codes/emmSpec/` from the `source/sys_gcc_shared` directory of `Cloudy`. - Generating optically thin radiative *Cooling* table - This is not used by `AstroPlasma` as of now but is a useful feature of `Cloudy` and hence included in the repo. - Copy `libcloudy.so` to `AstroPlasma/cloudy-codes/coolingFunction/` - From inside `AstroPlasma/cloudy-codes/coolingFunction/` directory, execute `bash ./compile-script.sh`. This will compile and generate the executables that can create the cooling tables. - - Currently there are two types of cooling tables available one with plasma in equilibrium background radiation (PIE) and one without any background radiation (CIE). If you are unsure which one to use, *I would recommend PIE*. + - Currently, there are two types of cooling tables available: one with plasma in equilibrium background radiation (PIE) and one without any background radiation (CIE). If you are unsure which one to use, *I would recommend PIE*. - export `AstroPlasma/cloudy-codes/coolingFunction` to `LD_LIBRARY_PATH`. - - To generate the cooling table run `./hazy_coolingcurve_
`. For eample, `./hazy_coolingcurve_PIE 0.3 0.1 True` will create a cooling table for plasma with 0.3 solar metallicity. The temperature spacing in the table is set to 0.1 dex in this example. The table always starts from 10 K and runs till 109 K. `True` in command line arguments shows the progress bar as the code runs. + - To generate the cooling table run `./hazy_coolingcurve_
`. For example, `./hazy_coolingcurve_PIE 0.3 0.1 True` will create a cooling table for plasma with 0.3 solar metallicity. The temperature spacing in the table is set to 0.1 dex in this example. The table always starts from 10 K and runs till 109 K. `True` in command line arguments shows the progress bar as the code runs. - The name of the cooling table created is `cooltable__Z=.dat`. - Useful to note that the cooling loss rate from the tabulated Λ(T) in the file is nH2Λ(T), where nH=ρXH/mH. Here ρ is density and nH is total Hydrogen number density of the plasma. Usually, XH=0.7154. The unit of Λ(T) in the table is erg cm3 s-1. The photoionization background considered here is `Haardt-Madau 2012` at redshift 0. -Good luck generating the database! I understand that this can be daunting and non-intutitve for a beginner. If you encounter any issues, please don't hesitate to contact me for help! +Good luck generating the database! I understand that this can be daunting and non-intuitive for a beginner. If you encounter any issues, please don't hesitate to contact me for help! From 8545b49f16defdfa826203ec0fd04a6ba01cb118 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 28 Apr 2024 06:59:47 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc40608..becfe1f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Running Cloudy models on the fly, especially when there are a lot of models to r ![GitHub repo size](https://img.shields.io/github/repo-size/dutta-alankar/AstroPlasma) | ![GitHub repo file count](https://img.shields.io/github/directory-file-count/dutta-alankar/AstroPlasma) | -![Lines of code](https://raw.githubusercontent.com/dutta-alankar/AstroPlasma/badges/lines_of_code.svg) +![Lines of code](https://raw.githubusercontent.com/dutta-alankar/AstroPlasma/badges/lines_of_code.svg) ![GitHub last commit (branch)](https://img.shields.io/github/last-commit/dutta-alankar/AstroPlasma/main) | ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/dutta-alankar/AstroPlasma) From 1c09d88caa877fd8ef948f082c62abf200147ab9 Mon Sep 17 00:00:00 2001 From: Alankar Dutta Date: Sun, 28 Apr 2024 13:07:27 +0530 Subject: [PATCH 4/4] [DOC] Badge addition in `README.md` --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index becfe1f..1da0a3b 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,15 @@ -> A *Cloudy* database with functions to quickly interpolate physical state of astrophysical plasma without detailed plasma modeling +> A *Cloudy* database with functions to quickly interpolate the physical state of astrophysical plasma without detailed plasma modeling Running Cloudy models on the fly, especially when there are a lot of models to run with different parameters, can become extremely expensive. `AstroPlasma` aims to provide a workaround using a library of pre-computed cloudy models to generate most of the common plasma properties for a large range of parameter space by interpolation. Owing to a simple and easy-to-use interface, `AstroPlasma` also provides an abstraction layer enabling the user to get the plasma properties without worrying much about the details of plasma modeling. We find this extremely useful while building models and predicting observables like column densities in different kinds of astrophysical systems. [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/dutta-alankar/AstroPlasma) -[![PyPI](https://img.shields.io/badge/requires-Python%20≥%203.8-blue?logo=python&logoColor=white)](https://www.python.org/downloads/release/python-3811/) +[![PyPI](https://img.shields.io/badge/requires-Python%20≥%203.10-blue?logo=python&logoColor=white)](https://www.python.org/downloads/release/python-310/) + +![](https://github.com/dutta-alankar/AstroPlasma/actions/workflows/AstroPlasma.yml/badge.svg?branch=main) ![GitHub repo size](https://img.shields.io/github/repo-size/dutta-alankar/AstroPlasma) | ![GitHub repo file count](https://img.shields.io/github/directory-file-count/dutta-alankar/AstroPlasma) |