ehpor / hcipy

A framework for performing optical propagation simulations, meant for high contrast imaging, in Python.
https://hcipy.org
MIT License
90 stars 30 forks source link

Atmospheric refraction #123

Open syhaffert opened 2 years ago

syhaffert commented 2 years ago

I am currently working on adding atmospheric refraction. I can do two things:

1) use a python library that has various methods implemented and verified and I make an optical element interface to the functions. 2) implement all the functions myself.

2 is substantially more work but option 1 will require an external library. Any thoughts?

ehpor commented 2 years ago

This would strongly depend on the quality of that library and if it's likely to keep being maintained in the future (if it has dependencies of its own).

syhaffert commented 2 years ago

This is the library I am looking at: https://gitlab.astro-wise.org/micado/atmosphericmodel As far as I can see the only requirements are numpy and scipy for the parts we need. There is an extra dependency on pyslalib. However, we will not use that part. The code itself looks good and is part of a MICADO simulator package from ASTRON.

ehpor commented 2 years ago

That package is not on conda, so that would need to be an optional dependency (or it would break our conda-forge package). Or we can ask the author to submit it to conda-forge. Also, while it was built for use with MICADO, it is not part of SimCADO, the MICADO simulator. SimCADO has their own function to do atmospheric refraction (a super simplified model) and does not import this package. AtmosphericModel has few dependencies, so it's unlikely to break. It looks like it's at least semi-maintained as well.

As another option, have you considered PyERFA? It's what astropy uses for atmospheric refraction, I think, so it's already a required dependency of astropy. Therefore, it's a no brainer to add that as a dependency of hcipy too. It's not accurate below 5deg, but I don't think any of us in HCI are interested in that. Or are you looking for more features than it provides?

yosata commented 6 months ago

Hi there, I worked on the AstroAtmosphere package for the first bit of my PhD project so I can provide some extra context. Apologies if it is not appreciated to bump a two year old issue ;)

I would be happy to upload the package to conda if that helps. I would need to figure out how to do that, but I don't expect that to be too difficult. It is available on PyPI as you have seen. Depending on the accuracy you need many other packages may be sufficient too, so it all depends on your goals. From a quick look at PyERFA it is very similar to SLALIB (or PySLALIB), but using slightly updated equations. The refractive index that was used by Hohenkerk & Sinclair is from a very old equation from Barrel & Sears (1939!), which works okay at visible wavelengths but is not the most accurate in the era of ELTs, especially in near-infrared and UV regimes. Unfortunately, that's still the equation used by ZEMAX and one of the reasons why I spend some time making a more modular package that splits the assumed atmospheric geometry and the refractive index parts, and also assumes a more modern description by default (Ciddor, 1996).

For ELT+AO applications you would probably want to use the refractive index as described by Mathar (2004 & 2007), which appears to be very accurate in near- to mid-IR wavelengths. It is still an item on my long-term to do list to add a Python native implementation of the full model. Fortunately, the approximation using a Taylor expansion from the 2007 paper is easy and quick to implement (link) and that could be done easily within HCIPy itself, I would imagine.

And you're right that it is not part of ScopeSIM (formerly SimCADO). I was talking to Kieran about implementing it, but that got put on the backburner at some point after a refactoring of the code broke the atmospheric dispersion effect for some time.