ACCarnall / bagpipes

Bagpipes is a state of the art code for generating realistic model galaxy spectra and fitting these to spectroscopic and photometric observations. Users should install with pip, not by cloning the repository.
http://bagpipes.readthedocs.io
GNU General Public License v3.0
71 stars 37 forks source link

Instructions to build custom model grid? #31

Closed Jerry-Ma closed 1 month ago

Jerry-Ma commented 1 year ago

Hi,

Thanks a lot for this fantastic tool! I was wondering if we can have the ability to customize the built-in model grids?

In particular, I am looking for creating the nebular emission model with a larger range of logU than the current (-4, -2).

Any help would be highly appreciated!

ACCarnall commented 1 year ago

Thanks for getting in touch! This is hopefully a fairly straightforward process, try out the following instructions and let me know if you have any trouble:

Nikhil0504 commented 1 year ago

Hey,

I was going through the same issue and got it. I would like to provide the steps for it in the issue since the documentation to create new cloudy models was really spare.

If you want to change the logU values, go the config.py file in L112.

First, we will need to create two new environment variables CLOUDY_DATA_PATH and CLOUDY_EXE that directs to the cloudy data folder and cloudy.exe files respectively.

Here is a template code in python for that (if you don't want it in your shell config):

import os

os.environ['CLOUDY_DATA_PATH'] = '/Users/user/Documents/Astronomy_Research/Software/c17.03/data'
os.environ['CLOUDY_EXE'] = '/Users/user/Documents/Astronomy_Research/Software/c17.03/source/cloudy.exe'

After making these environment variables you can run this to create the new cloudy grids.

import bagpipes as pipes
pipes.models.making.make_cloudy_models.run_cloudy_grid()

This should create the grids for you!

MohammadRih commented 1 month ago

Hi, I plan to make a more extensive model for the range of logU. I have followed the path that was mentioned and everything seems to be going well, but it seems that I ran into a problem at the last stage. I have brought you the picture of the problem, and according to my investigations, I have found that the Bagpipes has saved and named about 124 lines in the ''cloudy_lines.txt'', but Cloudy has created only about 40 lines in the ''.lines'' file, and it seems that at this point I have a problem. I will be very happy and grateful if you provide me a solution if you think so. Screenshot from 2024-03-24 11-30-15

pietro31700 commented 1 month ago

Hi, I've just faced this problem. In the newer versions of cloudy the line TOTL 1.08303m is no longer recognised and cloudy is stopped there when building lines (line 42). I've solved replacing "TOTL" with "Blnd" in the file cloudy_lines.txt. The easiest way to achieve this without editing bagpipes' files is to directly change the file in the cloudy installation: "< cloudy dir >/data/pipes_cloudy_lines.txt" that you should already have because you have launched run_cloudy_grid() once. When starting the creation of new grids bagpipes check if that file exists in the cloudy installation directory and in that case it won't replace it, so you can safely edit it.

MohammadRih commented 1 month ago

Thanks for your kind and fully described reply and solution to this problem. I have a small question and that is, you mentioned by replacing "TOTL" with "Blnd" the problem was solved. I cannot understand it correctly. Do You mean I should just replace "TOTL" with "Blnd" and keep the wavelength untouchable or should I have to correct the wavelength with another value too?! thanks for your patience

pietro31700 commented 1 month ago

Hi, It should be fine to replace the type of blending only (cloudy should recognise the line even if sligtly different), however the now used line is Blnd 1.08302m as you can find here Cloudy_He_lines

MohammadRih commented 1 month ago

Thanks I am very grateful for your help.

ACCarnall commented 1 month ago

Glad you found your answer, and thanks Pietro. I'll just add that the version of Cloudy that the current bagpipes version was written for is 17.03, so if you want to get things working without any changes to bagpipes I'd expect you can just install this cloudy version and carry on as normal. I'll add updating bagpipes to work with the latest cloudy version to my to-do list.

MohammadRih commented 1 month ago

Thanks a lot for the more detail you provide; having these updates is wonderful.