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

"find_files_and_readers" doesn't work on Windows #372

Closed
RutgerK opened this issue Jul 17, 2018 · 3 comments · Fixed by #373
Closed

"find_files_and_readers" doesn't work on Windows #372

RutgerK opened this issue Jul 17, 2018 · 3 comments · Fixed by #373

Comments

@RutgerK
Copy link
Contributor

RutgerK commented Jul 17, 2018

As already briefly discussed at issue #366, parsing the reader yaml files causes the pattern to change the path separator depending on the platform. This results in the satpy.find_files_and_readers function to never return any results.

The path separator in the yaml files are, by convention, specified as "/", for example the SLSTR yaml:

'{mission_id:3s}_SL_{processing_level:1s}_{datatype_id:_<6s}_{start_time:%Y%m%dT%H%M%S}_{end_time:%Y%m%dT%H%M%S}_{creation_time:%Y%m%dT%H%M%S}_{duration:4d}_{cycle:3d}_{relative_orbit:3d}_{frame:4d}_{centre:3s}_{mode:1s}_{timeliness:2s}_{collection:3s}.SEN3/{dataset_name}_radiance_an.nc'

The AbstractYAMLReader splits this pattern on that same separator, but then uses os.path.join to join in back to a path. In doing this, the os.path.join will use the platform depending separator. So on Windows, the pattern shown above transforms to:

'{mission_id:3s}_SL_{processing_level:1s}_{datatype_id:_<6s}_{start_time:%Y%m%dT%H%M%S}_{end_time:%Y%m%dT%H%M%S}_{creation_time:%Y%m%dT%H%M%S}_{duration:4d}_{cycle:3d}_{relative_orbit:3d}_{frame:4d}_{centre:3s}_{mode:1s}_{timeliness:2s}_{collection:3s}.SEN3\\{dataset_name}_radiance_an.nc'

The code doing this is:

file_patterns = [os.path.join(*pattern.split('/'))
                             for pattern in filetype_info['file_patterns']]

https://github.com/pytroll/satpy/blob/master/satpy/readers/yaml_reader.py#L99

When searching for files, the get_filebase function splits on "/", but this separator won't occur because of the os.path.join mentioned above. Hence the length of the split will always return 1, causing the function to only return the filename, whereas it should return the parent folder as well.

The resulting fnmatch attempt will always fail because its comparing:

fnmatch('S1_radiance_an.nc', '???_SL_?_??????_????????T??????_????????T??????_????????T??????_????_???_???_????_???_?_??_???.SEN3\\*_radiance_an.nc')

Personally I think that using os.path.sep in get_filebase should work, since the pattern is created/parsed by using os.path.join. On Windows it does work, I tested it for the OLCI L1 and SLSTR L1 readers. But @djhoese expressed some concerns about this:
#366 (comment)

I'm not familiar enough with SatPy's internals to understand the implications of such a change.

@RutgerK RutgerK changed the title find_files_and_readers doesn't work on Windows "find_files_and_readers" doesn't work on Windows Jul 17, 2018
@mraspaud
Copy link
Member

@RutgerK I don't think there is more to it than what you describe, so feel free to submit a PR with the fix in get_filebase

Thanks for researching this !

@djhoese
Copy link
Member

djhoese commented Jul 17, 2018

@RutgerK Awesome! Thanks so much for tracking this down. I couldn't find that file_patterns line when you first brought this up in your other issue. This all makes sense now. A pull request would be very appreciated.

@RutgerK
Copy link
Contributor Author

RutgerK commented Jul 18, 2018

Ok, great that it's cleared up. I'll make the PR in the coming days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants