Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving each scene in a separate image file #1087

Closed
anikfal opened this issue Feb 27, 2020 · 4 comments
Closed

Saving each scene in a separate image file #1087

anikfal opened this issue Feb 27, 2020 · 4 comments

Comments

@anikfal
Copy link

anikfal commented Feb 27, 2020

Description

By using scn.save_datasets(writer='simple_image'), all the scenes would be saved into one single image file. Rather I want each scene to be saved in a separate file.

Code

from satpy import Scene, find_files_and_readers
from datetime import datetime
files = find_files_and_readers(base_dir='/home/amirhossein/msg_data/', reader='seviri_l1b_nc')
scn = Scene(filenames=files)
composite = 'dust'
scn.load([composite])
scn.save_datasets(writer='simple_image')

Output showing all the scenes saved in one single file
dust_20190401_060009b

@mraspaud
Copy link
Member

@anikfal thank you for the bug report.

This is actually a know issue that we haven't solved yet, but doesn't come from the save_datasets function, but rather from loading multiple datasets at once. I suspect you have 4 sets of file for 4 different time slots in the directory you look for ?
At the moment, satpy doesn't know how to separate these, so you might need to indicate a time also in find_files_and_readers to load just one set of files at the time.

@djhoese and @sfinkens have been working on grouping files for the multiscene, maybe they have some idea on how to go further with this ?

@anikfal
Copy link
Author

anikfal commented Feb 27, 2020

@mraspaud Thank you for your reply.

I suspect you have 4 sets of file for 4 different time slots in the directory you look for ?

Yes. They are 4 sample data files (MSG SEVIRI) with 15 minute intervals between each time slots.

you might need to indicate a time also in find_files_and_readers to load just one set of files at the time.

I found it better to separate my favorite files in another directory, instead of indicating the time range. Because find_files_and_readers seems to read all the files, whether or not being indicated in the time range.

Anyway, in my case (Linux OS), by using a simple shell script and modifying the python code, it is possible to workaround this issue:

New python code (code1.py) to be used in the shell script

from satpy.scene import Scene
from glob import glob
import sys
files = glob(sys.argv[1])
scn = Scene(reader="seviri_l1b_nc", filenames=files)
composite = 'dust'
scn.load([composite])
scn.save_datasets(writer='simple_image')

Shell script (code2.sh) to run code1.py for multiple data files

for filename in my_directory/W_XX-EUMETSAT-Darmstadt,VIS+IR+HRV+IMAGERY,MSG1+SEVIRI_C_EUMG_2019040106*
do
        python code1.py $filename
done

@djhoese
Copy link
Member

djhoese commented Feb 27, 2020

@anikfal There is some python code to handle this, but I think for your use case your shell script might be the simplest solution. The MultiScene class has a from_files method which will attempt to group files based on the filename start_time (or other parameters). This method uses the satpy.readers.group_files function to do this grouping so if you wanted to customize how you work with each group you could do that instead of using the MultiScene.

Glad you got something working.

@mraspaud
Copy link
Member

mraspaud commented Mar 2, 2020

I'm closing this as it seems to work now for the OP. I opened another issue for the start and end time limits not working.

@mraspaud mraspaud closed this as completed Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants