Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

micado.flatlamp() not accepting parameters #123

Open
oczoske opened this issue Feb 13, 2025 · 4 comments
Open

micado.flatlamp() not accepting parameters #123

oczoske opened this issue Feb 13, 2025 · 4 comments
Labels
API How users interact with the software

Comments

@oczoske
Copy link
Collaborator

oczoske commented Feb 13, 2025

In [177]: simtp.micado.flatlamp(fraction=1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[177], line 1
----> 1 simtp.micado.flatlamp(fraction=1)

File ~/ELT_Development/ScopeSim_Templates/scopesim_templates/utils/general_utils.py:74, in add_function_call_str.<locals>.wrapper(*args, **kwargs)
     72 call_str = function_call_str(func, args, kwargs)
     73 logging.debug("Calling %s ...", call_str)
---> 74 src = func(*args, **kwargs)
     75 src.meta["object"] = func.__name__
     76 src.meta["function_call"] = call_str

TypeError: flatlamp() got an unexpected keyword argument 'fraction'

This must have something to do with the decorator in micado/__init__.py:

@add_function_call_str
def flatlamp():
    return _flatlamp()

as simtp.micado._flatlamp(fraction=1) works!

@oczoske oczoske added the API How users interact with the software label Feb 13, 2025
@teutoburg
Copy link
Contributor

I think it's not the decorator but rather the wrapper (micado.__init__.flatlamp()), which does not have any arguments defined.

Cannot try it right now but this might fix it:

@add_function_call_str
def flatlamp(*args, **kwargs):
    return _flatlamp(*args, **kwargs)

Actually it should have been written like this in the first place to allow any arguments to pass through. I'm not sure why we have these re-definitions there anyway...

@hugobuddel
Copy link
Collaborator

The point of those wrappers was to make parameterless functions, to be used as e.g. the TARGET of an exposure. That is, to put that in the FITS TARGET fits header etc. So it would mimic an actual observation. It should be parameterless because if it would be an actual astronomical source, then those do not have parameters either.

Making it parameterless also makes it easier to do a round trip: run the simulation directly from the FITS headers (e.g. for reproducibility, or when connecting ScopeSim to the ICS, or maybe when replicating a true observation): just import the function, no need to parse parameters from the FITS header.

That was the idea at least, but I guess this is not used at all anymore. So feel free to butcher it.

The flatlamp is perhaps a bad example, because as you realized with METIS, it should just be described in the IRDB and not in ScopeSim_Templates.

@hugobuddel
Copy link
Collaborator

The goal of the @add_function_call_str is to produce a representation of the source that can be stored in the FITS headers. We originally placed the keyword somewhere in the HIERARCH SIM hierarchy in the headers, and those did not support the CONTINUE keyword because they are HIERARCH (a HIERARCH keyword technically did not have a value to CONTINUE). Therefor the string must be short, and the more parameters to the function, the longer the string, leading to errors if it became too long. So no parameters was the safest.

Then at some point Kieran changed the keyword to FNSRC0 IIRC, something non-HIERARCH anyway, so that the CONTINUE keyword could be used, making that argument less relevant.

And then, since this week, astropy supports HIERARCH+CONTINUE, see astropy/astropy#17748 , so we could now switch back to using the original HIERARCH SIM keyword to store the source.

@oczoske
Copy link
Collaborator Author

oczoske commented Feb 15, 2025

See #124 and AstarVienna/irdb#209.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API How users interact with the software
Projects
None yet
Development

No branches or pull requests

3 participants