Download and process fits files

In this example, using the utility download_fits we download data for a selected imager and then process the fits files.

Import Required Modules

from datetime import datetime, timedelta

from sunpy.net import attrs as a

from PyThea.config import selected_imagers
from PyThea.utils import download_fits, load_fits, single_imager_maps_process

Retrieve the list of available imagers and their corresponding keys using the following,

for key in selected_imagers.imager_dict.keys():
    imager = selected_imagers.imager_dict[key]
    detector_or_wavelenght = imager['detector'] if 'detector' in imager else imager['wavelength']
    print(f'{imager["source"]}/{imager["instrument"]}-{detector_or_wavelenght}:  {key}')
SOHO/LASCO-C2:  LC2
SOHO/LASCO-C3:  LC3
SDO/AIA-193:  AIA-193
SDO/AIA-211:  AIA-211
STEREO_A/SECCHI-COR2:  COR2A
STEREO_B/SECCHI-COR2:  COR2B
STEREO_A/SECCHI-EUVI:  EUVIA
STEREO_B/SECCHI-EUVI:  EUVIB
STEREO_A/SECCHI-COR1:  COR1A
STEREO_B/SECCHI-COR1:  COR1B
STEREO_A/SECCHI-HI1:  HI1A
STEREO_B/SECCHI-HI1:  HI1B
STEREO_A/SECCHI-HI2:  HI2A
STEREO_B/SECCHI-HI2:  HI2B
PSP/WISPR-Inner:  WISPR1
PSP/WISPR-Outer:  WISPR2

First, select the imager and specify the time range of the query. For this example we will download data from SOHO LASCO coronagraph.

# Set the SOHO LASCO imager key.
imager = 'LC2'

# Query data for one hour before and one hour after a selected time.
date_process = datetime.strptime('2021-10-28T16:30:00', '%Y-%m-%dT%H:%M:%S')
time_range = [-1, 1]
timerange = a.Time(date_process + timedelta(hours=time_range[0]),
                   date_process + timedelta(hours=time_range[1]))

Download the fits files from VSO using the download_fits utility.

files = download_fits(timerange, imager)

print(f'Files downloaded from VSO: {len(files)}')
Results from 1 Provider:

10 Results from the VSOClient:
Source: http://vso.stanford.edu/cgi-bin/search
Total estimated size: 21.084 Mbyte

       Start Time               End Time        Source ... Extent Type   Size
                                                       ...              Mibyte
----------------------- ----------------------- ------ ... ----------- -------
2021-10-28 15:36:06.000 2021-10-28 15:36:31.000   SOHO ...      CORONA 2.01074
2021-10-28 15:48:05.000 2021-10-28 15:48:31.000   SOHO ...      CORONA 2.01074
2021-10-28 16:00:05.000 2021-10-28 16:00:30.000   SOHO ...      CORONA 2.01074
2021-10-28 16:12:05.000 2021-10-28 16:12:30.000   SOHO ...      CORONA 2.01074
2021-10-28 16:24:06.000 2021-10-28 16:24:31.000   SOHO ...      CORONA 2.01074
2021-10-28 16:36:05.000 2021-10-28 16:36:30.000   SOHO ...      CORONA 2.01074
2021-10-28 16:48:05.000 2021-10-28 16:48:30.000   SOHO ...      CORONA 2.01074
2021-10-28 17:00:05.000 2021-10-28 17:00:30.000   SOHO ...      CORONA 2.01074
2021-10-28 17:12:06.000 2021-10-28 17:12:31.000   SOHO ...      CORONA 2.01074
2021-10-28 17:24:05.000 2021-10-28 17:24:30.000   SOHO ...      CORONA 2.01074



Files Downloaded:   0%|          | 0/10 [00:00<?, ?file/s]


22834546.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]





22834549.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]



22834547.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]

22834545.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]




22834548.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]


22834546.fts:   3%|▎         | 57.0k/2.11M [00:00<00:03, 563kB/s]

22834545.fts:   4%|▍         | 81.8k/2.11M [00:00<00:02, 814kB/s]





22834549.fts:   5%|▌         | 114k/2.11M [00:00<00:01, 1.06MB/s]




22834548.fts:   2%|▏         | 49.8k/2.11M [00:00<00:04, 483kB/s]



22834547.fts:   6%|▌         | 122k/2.11M [00:00<00:01, 1.01MB/s]

22834545.fts:  47%|████▋     | 994k/2.11M [00:00<00:00, 5.69MB/s]




22834548.fts:  43%|████▎     | 899k/2.11M [00:00<00:00, 5.14MB/s]





22834549.fts:  52%|█████▏    | 1.11M/2.11M [00:00<00:00, 5.98MB/s]


22834546.fts:  53%|█████▎    | 1.11M/2.11M [00:00<00:00, 5.87MB/s]



22834547.fts:  39%|███▊      | 817k/2.11M [00:00<00:00, 3.98MB/s]





Files Downloaded:  10%|█         | 1/10 [00:00<00:05,  1.63file/s]
















22834550.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]




22834553.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]


22834551.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]





22834552.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]



22834554.fts:   0%|          | 0.00/2.11M [00:00<?, ?B/s]

22834550.fts:  55%|█████▌    | 1.17M/2.11M [00:00<00:00, 11.3MB/s]


22834551.fts:  50%|█████     | 1.06M/2.11M [00:00<00:00, 10.6MB/s]





22834552.fts:  22%|██▏       | 456k/2.11M [00:00<00:00, 4.05MB/s]




22834553.fts:  19%|█▉        | 403k/2.11M [00:00<00:00, 2.97MB/s]






Files Downloaded:  60%|██████    | 6/10 [00:00<00:00,  9.06file/s]








22834554.fts:   0%|          | 1.02k/2.11M [00:00<06:00, 5.85kB/s]



Files Downloaded:  80%|████████  | 8/10 [00:00<00:00, 10.43file/s]





22834554.fts:  20%|██        | 423k/2.11M [00:00<00:01, 1.33MB/s]



22834554.fts:  26%|██▌       | 551k/2.11M [00:00<00:01, 1.14MB/s]



22834554.fts:  32%|███▏      | 665k/2.11M [00:00<00:01, 1.13MB/s]



22834554.fts:  39%|███▉      | 828k/2.11M [00:00<00:01, 1.27MB/s]



22834554.fts:  45%|████▌     | 958k/2.11M [00:01<00:01, 731kB/s]




Files Downloaded: 100%|██████████| 10/10 [00:01<00:00,  5.01file/s]
Files Downloaded: 100%|██████████| 10/10 [00:01<00:00,  5.61file/s]
Files downloaded from VSO: 10

Load the downloaded fits into maps using the load_fits utility.

maps = load_fits(files)

print(f'Files loaded in maps: {len(files)}')
Files loaded in maps: 10

Process the loaded maps using the single_imager_maps_process utility. This function filters, prepares, and process the maps.

The default options for the maps processing, for each imager, can be found in,

print(selected_imagers.imager_dict[imager]['process'])

# For LASCO-C2 select only the images with dimensions 1024x1024 and only total brightness images. Then the filtered images are prepared. Depending on the instrument, this includes pointing corrections, calibrations, observer location corrections, exposure time normalization, and others.
{'dimensions': (<Quantity 1024. pix>, <Quantity 1024. pix>), 'polar': 'Clear', 'superpixel': 2}

At the last step, the images are callibrated and resampled using SynPy’s superpixel method and the final maps are processed into running/base difference or plain image sequence maps.

processed_images = single_imager_maps_process(maps,
                                              **selected_imagers.imager_dict[imager]['process'],
                                              image_mode='Running Diff.',
                                              diff_num=1)

# These images can now be used in the fitting process or just plot them (see example).
Preparing image sequence for C2. This could take a while...
INFO: Obtained JPL HORIZONS location for SOHO (spacecraft) (-21) [sunpy.coordinates.ephemeris]

Total running time of the script: (0 minutes 8.607 seconds)

Gallery generated by Sphinx-Gallery