dfm / python-fsps

Python bindings to Charlie Conroy's Flexible Stellar Population Synthesis (FSPS) Fortran code
https://python-fsps.readthedocs.io
MIT License
66 stars 38 forks source link

Add custom filters #46

Closed dr-guangtou closed 8 years ago

dr-guangtou commented 8 years ago

Hi

I am currently working on images from Hyper-Suprime Camera survey, and it would be great if the HSC filters can be added to FSPS. I have the un-normalized transimission curve of these filters, and just want to make sure that my assumption about how to do this is correct.

  1. Add the transmission curve data to $FSPS_DIR/data/allfilters.dat like this:

HSC-g filter

  1. 0
  2. 0.03125
  3. 0.166326530612245
  4. 0.458
  5. 0.764705882352941
  6. Add the pivot wavelength of the filter to $FSPS_DIR/data/filter_lambda_eff.dat
  7. Add the name of the filter to $FSPS_DIR/data/FILTER_LIST
  8. Add the absolute magnitude of sun in the newly added filter to $FSPS_DIR/data/magsun.dat

    (Related to this, can I calculated this value using the solar SED in $FSPS_DIR/SPECTRA/SUN_STScI.SED?)

  9. Modify the nbands parameter in the $FSPS_DIR/src/sps_vars.f90 routine
  10. Add the filter key to https://github.com/dfm/python-fsps/blob/master/fsps/data/filter_keys.txt

Please let me know if I missed anything. And, do you think it is worth adding a function to make this step easier? Thanks!

bd-j commented 8 years ago

That should work. Note that FSPS doesn't actually use the FILTER_LIST, magsun.dat, and filter_lambda_eff.dat files, but I think python-FSPS does at some level.

We are working on a way to do this more easily, which should be ready soon. When it is ready you'll just have to replace FILTER_LIST and allfilters.dat (or give another file name as the "alt_filter_file" variable in fsps/src/sps_vars.f90).

dr-guangtou commented 8 years ago

Hi Ben,

Thanks for the reply. That would be great! I'll close the issue for now.

kh-kr commented 3 years ago

Hi,

I have added Gaia DR2 and EDR3 filters by updating the below mentioned files as: 1) $FSPS_DIR/data/filter_lambda_eff.dat 144 5048.62 145 6246.77 146 7740.87 147 5109.71 148 6217.59 149 7769.02 2) $FSPS_DIR/data/FILTER_LIST 144 Gaia2r_Gbp Gaia-DR2 Bp 145 Gaia2r_G Gaia-DR2 G 146 Gaia2r_Grp Gaia-DR2 Rp 147 Gaia3_Gbp Gaia-DR3 Bp 148 Gaia3_G Gaia-DR3 G 149 Gaia3_Grp Gaia-DR3 Rp 3) I do not know what to change in the $FSPS_DIR/data/magsun.dat file so I kept it as it is. 4) Modified the nbands parameter in the $FSPS_DIR/src/sps_vars.f90 routine from 143 to 149.

I then uninstalled fsps and reinstalled it by this command: "FFLAGS="-DBASTI=1 -DMIST=0 -DPADOVA=0 -DMILES=1 -DBASEL=0" python -m pip install fsps==0.4.0rc1 --no-binary fsps"

I successfully imported Gaia filters, but when I was trying to get isochrone files using the code:

sps = fsps.StellarPopulation(zcontinuous=1) sps.params['imf_type'] = 0 # Salpeter IMF sps.params['sfh'] = 1 # Tau model SFH iso = sp.isochrones()

Then getting IndexError as: IndexError Traceback (most recent call last)

in 12 sps.params['imf_type'] = 0 # Salpeter IMF 13 sps.params['sfh'] = 1 # Tau model SFH ---> 14 iso = sp.isochrones() 15 16 ~/anaconda3/lib/python3.7/site-packages/fsps/fsps.py in isochrones(self, outfile) 863 absfile, 864 comments="#", --> 865 dtype=np.dtype([(n, np.float) for n in header]), 866 ) 867 return cmd_data ~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin, encoding, max_rows, like) 1144 # converting the data 1145 X = None -> 1146 for x in read_data(_loadtxt_chunksize): 1147 if X is None: 1148 X = np.array(x, dtype) ~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py in read_data(chunk_size) 998 999 # Then pack it according to the dtype's nesting -> 1000 items = pack_items(items, packing) 1001 X.append(items) 1002 if len(X) > chunk_size: ~/anaconda3/lib/python3.7/site-packages/numpy/core/_internal.py in __call__(self, *args, **kwargs) 870 self.func = func 871 def __call__(self, *args, **kwargs): --> 872 return self.func(self, *args, **kwargs) 873 ~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py in pack_items(self, items, packing) 955 ret = [] 956 for length, subpacking in packing: --> 957 ret.append(self(items[start:start+length], subpacking)) 958 start += length 959 return tuple(ret) ~/anaconda3/lib/python3.7/site-packages/numpy/core/_internal.py in __call__(self, *args, **kwargs) 870 self.func = func 871 def __call__(self, *args, **kwargs): --> 872 return self.func(self, *args, **kwargs) 873 ~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py in pack_items(self, items, packing) 946 """Pack items into nested lists based on re-packing info.""" 947 if packing is None: --> 948 return items[0] 949 elif packing is tuple: 950 return tuple(items) IndexError: list index out of range I am completely new to this, so I don't know how to deal with this. Can anyone help me, please?