Commit 32937c84 authored by vertighel's avatar vertighel
Browse files

First dev

parent 0e277d33
Loading
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+178 −0
Original line number Diff line number Diff line
.*
*~
#*

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
#   For a library or package, you might want to ignore these files since the code is
#   intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don't work, or not
#   install all needed dependencies.
#Pipfile.lock

# UV
#   Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
#   This is especially recommended for binary packages to ensure reproducibility, and is more
#   commonly ignored for libraries.
#uv.lock

# poetry
#   Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
#   This is especially recommended for binary packages to ensure reproducibility, and is more
#   commonly ignored for libraries.
#   https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
#   Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
#   pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
#   in version control.
#   https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
#  JetBrains specific template is maintained in a separate JetBrains.gitignore that can
#  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
#  and can be added to the global gitignore or merged into this file.  For a more nuclear
#  option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc
 No newline at end of file
+195 −45
Original line number Diff line number Diff line
# noche

# Noche - Noctis Header. 
## FITS Header Builder for the observatories of the NOCTIS network

**Noche** is a Python module that helps construct FITS headers for
imaging (and maybe spectroscopic) observations using templates and
observatory-specific metadata.

It is developed for the NOCTIS - Network of Observing Networked
Observational Coordination of Telescopes for Teaching and Science
network.

https://noctis.inaf.it/en/index.html

## Features
- Load an empty base header from a default `.ini` file
- Set a NOCTIS observatory from default `.ini` files, or from a custom file;
- Resolve object coordinates via Simbad from name, or set coordinates;
- Automatically compute WCS, parallactic angle, airmass, and moon/sun-related metadata, etc.

## Installation

```bash
# Clone the repository
git clone https://www.ict.inaf.it/gitlab/noctis/noche.git

# Enter the directory
cd noche

# Optional: Install it locally if you want
pip install -e .
```

## Usage Example
```python
from noche import Noche
from astropy.time import Time

# Instantiate a Noche class. It loads by default an empty header
n = Noche() 

# Inspect with
print(n.header.tostring)

# Show which observatories belongs to the NOCTIS network
print(n.noctis_observatories)
# ['grt', 'opc', 'oarpaf', 'ogg', 'ossfoligno', 'abobservatory']

# Load the values specific of one of the NOCTIS observatories
n.load_noctis_observatory("oarpaf")

# You can inspect changes with
print(n.header.tostring)

# Load the values from a custom .ini file:
n.load_observatory("./noche/observatories/opc.ini")

# Set coordinates and observation time. 
n.set_coordinates("05 30 00.0", "70 01 01", Time.now().isot)

# Set an object name, 
# optionally resolving and update coordinates from Simbad, 
# optionally update observation time
n.set_object("Polaris", update_coord=True, obstime="2025-10-13T22:33:44.5")

# Update Wcs Keywords providing an angle:
n.set_wcs(45)

# List the header keywords that are still empty
n.check_empty()

```

---

## Class and Method Documentation

### `class Noche`
Builds and maintains an astropy FITS header for astronomical observations.

#### `__init__(self, header_template_path=None)`
Initializes a new FITS header.

**Parameters**
- `header_template_path` : str
  Path to the header configuration template. If `None`, use default.

#### `@property def noctis_observatories(self)`
ist available [observatory].ini files in the module directory.

#### `load_default_header(self, path)`
Loads the base header from a default or a custom `.ini` configuration file.

**Parameters**
- `path` : str
  Path to a config file in INI format.

#### `load_noctis_observatory(self, name='oarpaf', flavor=None)`
Loads observatory site data and updates header values accordingly.

**Parameters**
- `name` : str
  One of the supported observatories.
- `flavor` : str, optional
  Specific section in the file to load.

#### `load_observatory(self, path='oarpaf.ini', flavor=None)`
Loads observatory site data and updates header values accordingly.

**Parameters**
- `path` : str
  Path to the observatory INI file.
- `flavor` : str, optional
  Specific section in the file to load.

#### `set_location(self, lon, lat, alt)`
Sets the location of the observatory.

**Parameters**
- `lon` : float
  Longitude in degrees
- `lat` : float
  Latitude in degrees
- `alt` : float
  Altitude in meters

#### `set_obstime(self, obstime)`
Sets the observation time.

**Parameters**
- `obstime` : str or `astropy.time.Time`
  Time of the observation.

#### `set_object(self, objname, update_coord=True, obstime=None)`
Sets object name and optionally resolves coordinates via Simbad.

**Parameters**
- `objname` : str
  Name of the astronomical object.
- `update_coord` : bool, default=True
  Whether to resolve and update coordinates.
- `obstime` : str or `astropy.time.Time`, optional
  Time of the observation.

#### `set_coordinates(self, ra, dec, obstime=None)`
Sets the RA and DEC of the object.

**Parameters**
- `ra` : float
  Right Ascension (in hours or degrees).
- `dec` : float
  Declination (in degrees).
- `obstime` : str or `astropy.time.Time`, optional
  Time of the observation.

#### `set_altaz_and_parallactic(self)`
Calculates altitude, azimuth, airmass, hour angle, and parallactic angle.

**Raises**
- `ValueError` if observation time or location is not set.

#### `set_wcs(self, angle=None)`
Sets World Coordinate System (WCS) parameters in the header.

**Parameters**
- `angle` : float, optional
  Rotation angle in radians. Defaults to DEROTANG header value.

**Raises**
- `ValueError` if coordinates or location are missing.

#### `set_ambient(self)`
Adds information on Sun altitude, Moon phase, and Moon distance to target.

**Raises**
- `ValueError` if coordinates or location are missing.

#### `check_empty(self)`
Prints out FITS header keys that have `None` values.

#### `_update(self)`
Automatically fills in derived keywords if coordinates, time, and location are available.

#### `_parse(self, val)`
Parses a value from a configuration string.

**Parameters**
- `val` : str
  Value as string from config file.

**Returns**
- Parsed value as `int`, `float`, `bool`, or `str`.

---




@@ -44,50 +238,6 @@ Use the built-in continuous integration in GitLab.

***

# Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.

## Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

## Name
Choose a self-explaining name for your project.

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.

## Contributing
State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.

## License
For open source projects, say how it is licensed.

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

noche/__init__.py

0 → 100644
+1 −0
Original line number Diff line number Diff line
from .noche import Noche
+96 −0
Original line number Diff line number Diff line
#------------------------------------------------------------------------------|
[Initial]
SIMPLE = True         | Standard FITS format
BITPIX = 16           | Array data type
NAXIS = 2             | Number of data axes
NAXIS1 =              | [px] Length of data axis 1 (X)
NAXIS2 =              | [px] Length of data axis 2 (Y)
EXTEND = True         | FITS file may contain extensions
BSCALE = 1            | Scale factor applied to data
BZERO = 32768         | Offset applied to data after scaling
OBSERVER =            | Observer name

[Object]
OBJECT =              | Name of observed object
RA =                  | [hh:mm:ss.ss] Right Ascension in sexagesimal format
DEC =                 | [+dd:mm:ss.ss] Declination in sexagesimal format
RA_DEG =              | [deg] Right Ascension in decimal degrees
DEC_DEG =             | [deg] Declination in decimal degrees
ALT =                 | [deg] Altitude of object above horizon
AZ =                  | [deg] Azimuth of object from North (E=90)
HA =                  | [h] Hour Angle
LST =                 | [h] Local Sidereal Time
PARANGLE =            | [deg] Object Parallactic angle
POSANGLE =            | [deg] Object Position angle
AIRMASS =             | Approximate air mass

[Time]
DATE =                | [YYYY-MM-DD] File creation date
DATE-OBS =            | [YYYY-MM-DDTHH:MM:SS] UTC date and time of observation
MJD-OBS =             | [d] Modified Julian Date of observation
                      
[Telescope]           
TELESCOP =            | Telescope name
FOCALLEN =            | [mm] Telescope focal length
APTDIA =              | [mm] Telescope aperture diameter
OBS-LONG =            | [deg] Observatory longitude (East < 0)
OBS-LAT =             | [deg] Observatory latitude (North > 0)
OBS-ELEV =            | [m] Observatory altitude above sea level
FOCUSPOS =            | [um] Focuser position
FOCUSTEM =            | [C] Focuser temperature
DEROTANG = 0          | [deg] Rotator angle
                      
[Imaging]          
INSTRUME =            | Instrument name
OBSTYPE =             | Observation type

[Detector]          
DETECTOR =            | Detector identifier
DETSIZE =             | [px] Physical CCD dimensions
XPIXSZ =              | [um] Pixel X axis size
YPIXSZ =              | [um] Pixel Y axis size
PIXSCALE =            | [arcsec/px] Plate scale in binning 1
SET-TEMP =            | [C] CCD temperature set point
CCD-TEMP =            | [C] CCD temperature
GAIN =                | [e-/ADU] Gain
RDNOISE =             | [e- RMS] Readout noise

IMAGETYP =            | Frame type (LIGHT, DARK, BIAS, FLAT)
FILTER =              | Photometric filter used
EXPTIME =             | [s] Exposure time
XBINNING =            | Binning factor in X
YBINNING =            | Binning factor in Y
                      
[Ambient]             
SUNALT =              | [deg] Sun altitude (< 0 means night)
MOONDIST =            | [deg] Moon-target angular distance
MOONPHAS =            | Lunar phase (0=new, 1=full)
TEMPERAT =            | [C] Ambient temperature

[WCS]
WCSAXES = 2           | Number of axes
CTYPE1 = RA---TAN     | Right ascension, gnomonic projection
CTYPE2 = DEC--TAN     | Declination, gnomonic projection
CUNIT1 = deg          | Units of coordinate axis 1
CUNIT2 = deg          | Units of coordinate axis 2
CRPIX1 =              | [px] X reference pixel
CRPIX2 =              | [px] Y reference pixel
CRVAL1 =              | [deg] RA at reference pixel
CRVAL2 =              | [deg] DEC at reference pixel
CDELT1 =              | [deg/px] RA pixel scale
CDELT2 =              | [deg/px] DEC pixel scale
PC1_1 = -1.0          | Rotation matrix element
PC1_2 = 0.0           | Rotation matrix element
PC2_1 = 0.0           | Rotation matrix element
PC2_2 = 1.0           | Rotation matrix element
RADESYS = ICRS        | Coordinate system reference frame
EQUINOX = 2000.0      | [yr] Equinox of coordinates

[Final]
FILEORIG =            | Original file name
SWCREATE =            | Software that created this file
CHECKSUM =            | Checksum of header
DATASUM =             | Data sum of FITS file
ORIGIN = NOCHE v0.1   | Origin of FITS file
COMMENT = NOCTIS common header
HISTORY = Updated by NOCHE

noche/noche.py

0 → 100644
+451 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading