AstarVienna / ScopeSim_Templates

GNU General Public License v3.0
2 stars 4 forks source link

cluster template breaks with current dev version of scopesim. #24

Closed krachyon closed 2 years ago

krachyon commented 2 years ago

trying to observe the default cluster template with MICADO results in an error:

from scopesim_templates import cluster
from scopesim import OpticalTrain, download_package
download_package(["locations/Armazones",
                  "telescopes/ELT",
                  "instruments/MICADO"])

micado = OpticalTrain('MICADO')
cluster = cluster()
micado.observe(cluster)

Traceback (most recent call last):
  File "~/reproenv/repro.py", line 11, in <module>
    ot.observe(cluster)
  File "~/reproenv/ScopeSim/scopesim/optics/optical_train.py", line 180, in observe
    fov.extract_from(source)
  File "~/reproenv/ScopeSim/scopesim/optics/fov.py", line 106, in extract_from
    fields_in_fov[ifld] = fu.extract_area_from_table(fld, volume)
  File "~/reproenv/ScopeSim/scopesim/optics/fov_utils.py", line 258, in extract_area_from_table
    fov_xs = (fov_volume["xs"] * fov_unit).to(table["x"].unit)
  File "~/reproenv/repro/lib/python3.10/site-packages/astropy/units/quantity.py", line 844, in to
    unit = Unit(unit)
  File "~/reproenv/repro/lib/python3.10/site-packages/astropy/units/core.py", line 2062, in __call__
    raise TypeError("None is not a valid Unit")
TypeError: None is not a valid Unit

used versions:

-e git+https://github.com/astronomyk/ScopeSim/@16e29056c43b810ef1d464f4f0338d73770f9262#egg=ScopeSim
-e git+https://github.com/AstarVienna/ScopeSim_Templates/@9d0596872de3be447005b4542c2196119a2dd573#egg=ScopeSim_Templates
-e git+https://github.com/AstarVienna/skycalc_ipy.git@cb3a497e2b29daf2be9c147960897876b091aeac#egg=skycalc_ipy

Adding the unit in the template seems to be all that's required

diff --git a/scopesim_templates/stellar/clusters.py b/scopesim_templates/stellar/clusters.py
index 3c08f26..4ab90f9 100644
--- a/scopesim_templates/stellar/clusters.py
+++ b/scopesim_templates/stellar/clusters.py
@@ -93,7 +93,7 @@ def cluster(mass=1E3, distance=50000, core_radius=1, **kwargs):
     # 7. make x,y from half_light_radius and distance
     rad2arcsec = 206264.80624709636
     fwhm = 2 * core_radius / distance * rad2arcsec
-    x, y = cu.gaussian_distribution(len(masses), fwhm=fwhm, seed=params["seed"])
+    x, y = cu.gaussian_distribution(len(masses), fwhm=fwhm, seed=params["seed"]) * u.arcsec

     # 8. make table with (x,y,ref,weight)
     tbl = Table(names=["x", "y", "ref", "weight", "masses", "spec_types"],
hugobuddel commented 2 years ago

I think this has been resolved now, can you confirm @krachyon ?

I'm currently facing some other problems with simulating a cluster though, for which I have not yet been able to create a minimal example, but that I'm tracking in the MicadoWISE repository: https://gitlab.astro-wise.org/micado/micadowise/-/issues/232