Basic UsageΒΆ
pyGnuastro is divided into separate modules(Overview of the Python Modules)
and each module can be imported using the '.'
after the package name as::
import pygnuastro.MODULE_NAME
.
For Example
import pygnuastro.cosmology
# Calling the age function in the cosmology module
print(pygnuastro.cosomology.age(5))
Most functions also provide passing arguments as keywords.
import pygnuastro.cosmology as cosmo
proper_distance = cosmo.proper_distance(H0 = 65, Z = 5,
omatter = 0.3,
olambda = 0.2,
oradiation = 0.5)
For functions which are supposed to return or pass a NumPy array, we take an example of a simple program which reads an input FITS image and stores it as a NumPy array, then
import pygnuastro.fits
import numpy
# Here 'in' will be a NumPy array.
in = pygnuastro.fits.img_read(filename = "input.fits", hdu = 0)
if gnuastro.fits.img_write(in, "output.fits"):
print("Write successful.")
else:
print("Error in writing file")