pythonastronomyfits

How to turn a list of files into a parfive.results.Results type?


I'm downloading a list of .fits files through the Fido.fetch() function from sunpy, and in the end of the process they are grouped in a parfive.results.Results type.

The next step of the process takes this type and applies the sunpy.map.Map() function.

import sunpy.map
from sunpy.net import Fido
from sunpy.net import attrs as a

#list of variables: cadence,start_date,end_date
#physobs_list = [a.Physobs.los_velocity, a.Physobs.los_magnetic_field, a.Physobs.intensity] 

result = Fido.search(a.Time(start_date, end_date),
                     a.Instrument.hmi, physobs_list[0] | physobs_list[1] | physobs_list[2], cadence)

file_download= Fido.fetch(result)
map_seq = sunpy.map.Map(sorted(file_download))

My problem is: I have a few files stored and I want to skip the Fido.fetch() step, but I don't know how to turn my files into the parfive.results.Results type, which sunpy.map.Map() reads. How can I do it?


Solution

  • I just had this problem today. I'm not 100% sure why this works, but parfive.results.Results uses collections.UserList as a base. You need to convert your list of local files into the UserList format. I did the following:

    from collections import UserList
    import os 
    
    local_files = os.listdir(local_directory)
    map_seq = sunpy.map.Map(UserList(local_files),sequence=True)
    

    Hope this helps!