Skip to content

Filename order is not consistent between platforms (Unix & Windows) #50

@TaylorMutch

Description

@TaylorMutch

I am using a subprocess to call the clover to_netcdf on a filename pattern such as It*-Ts*-sc.tif to return a NetCDF file with a time dimensions. The problem is that the order in which the files are stacked is different between Windows and Unix systems, resulting in the order of the timesteps to be unpredicatable. I am not using the datetime-pattern parameter, but these files are not datetimes at all.

For example, if my stack of GeoTIFFs are the following:

It0001-Ts0000-sc.tif
It0001-Ts0001-sc.tif
It0001-Ts0002-sc.tif
It0001-Ts0003-sc.tif

calling glob.glob on Windows will return them in ascending order:

pattern = 'It*-Ts*-sc.tif'
files = glob.glob(pattern)
print(files)
['It0001-Ts0000-sc.tif', 'It0001-Ts0001-sc.tif', 'It0001-Ts0002-sc.tif', 'It0001-Ts0003-sc.tif', ...]

On Unix, the pattern seems unpredictable:

print(files)
['It0001-Ts0003-sc.tif', 'It0001-Ts0000-sc.tif', 'It0001-Ts0002-sc.tif', 'It0001-Ts0001-sc.tif', ...]

Would it be possible to add a sort parameter to the to_netcdf command? In my implementation I have modified clover.cli.convert.py @ line 87 to call filesnames.sort(), which puts them filenames back in the same order as they are on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions