title: How to generate a fits file from the beginning
body: <p>In this post, they explain how to generate a fits file from ascii file. However, I also would like to know how to define header and data into fits file.  (<a href="https://stackoverflow.com/questions/28893314/converting-ascii-table-to-fits-image">Converting ASCII Table to FITS image</a>)</p>
  
  <p>For example, when I call a spectral fits file with astropy (which is downloaded from a telescope), I can call data and header separately. </p>
  
  <p>I.E</p>
  
  <pre><code>  In [1]:hdu = fits.open('observation.fits', memmap=True)
  
    In [2]:header = hdu[0].header
  
    In [3]:header 
     Out [3]: 
     SIMPLE  =                    T / conforms to FITS standard                      
     BITPIX  =                     8                                                 
     NAXIS   =                     1
     NAXIS1  =                     47356                      
     EXTEND  =                    T                                                  
     DATE    = 'date' / file creation date (YYYY-MM-DDThh:mm:ss UT)   
     ORIGIN  = 'XXX     '           / European Southern Observatory                  
     TELESCOP= 'XXX'         / ESO Telescope Name                             
     INSTRUME= 'Instrument'           / Instrument used.                               
     OBJECT  = 'ABC '           / Original target.                               
     RA      =           30.4993 / xx:xx:xx.x RA (J2000) pointing                 
     DEC     =            -20.0009 / xx:xx:xx.x DEC (J2000) pointing               
  
     CTYPE1  = 'WAVE    '           / wavelength axis in nm                          
     CRPIX1  =                   0. / Reference pixel in z                           
     CRVAL1  =     298.903594970703 / central wavelength                             
     CDELT1  =   0.0199999995529652 / nm per pixel                                   
     CUNIT1  = 'nm      '           / spectral unit                                  
  
    ..
     bla bla
    ..                                                                               
     END                                                                             
  
  
  
  
     In [3]:data = hdu[0].data
     In [4]:data 
     Out [4]:array([  1000,   1001,   1002, ...,
       5.18091546e-13,   4.99434453e-13,   4.91280864e-13])
  
  
     Lets assume, I have data like below
  
     WAVE FLUX
     1000 2.02e-12
     1001 3.03e-12
     1002 4.04e-12
    ..
     bla bla
    ..
  </code></pre>
  
  <p>So, I'd like to generate a spectral fits file with my own data (with its own header).</p>
  
  <p>Mini question : Now lets assume, I generate spectral fits file correctly, but I realised that I forgot to take logarithm of WAVE values in X axis (1000, 1001, 1002, ....) . How can I do that without touching FLUX values of Y-axis (2.02e-12, 3.03e-13,  4.04e-13) ? </p>