AntSimi / py-eddy-tracker

Eddy identification and tracking
https://py-eddy-tracker.readthedocs.io/en/latest/
GNU General Public License v3.0
123 stars 53 forks source link

ValueError: Invalid format string #240

Open Lindsey-D opened 4 months ago

Lindsey-D commented 4 months ago

When I run the example for identification: EddyId nrt_global_allsat_phy_l4_20220301_20220307.nc 20220301 adt ugos vgos longitude latitude pyeddy/test/ -v DEBUG

I got this error:

Traceback (most recent call last): File "\?\C:\Users\DLX.conda\envs\cyc\Scripts\EddyId-script.py", line 33, in sys.exit(load_entry_point('pyEddyTracker==3.6.1+12.gc7430ce', 'console_scripts', 'EddyId')()) File "C:\Users\DLX.conda\envs\cyc\lib\site-packages\py_eddy_tracker\appli\grid.py", line 152, in eddy_id out_name = date.strftime("%(path)s/%(signtype)s%Y%m%dT%H%M%S.nc") ValueError: Invalid format string

Do you have any suggestions? Thanks

AntSimi commented 4 months ago

Which version of python did you use?

Lindsey-D commented 4 months ago

Which version of python did you use?

3.8.19

AntSimi commented 4 months ago

I can't reproduce error on unix platform

KMartin0013 commented 4 months ago

I think this function "strftime" works differently between Windows and Unix. When I run this in Mac, similar error also emerged. So I try to rewrite the the grid.py as:

>     # out_date_name = date.strftime("%(path)s/%(sign_type)s_%Y%m%dT%H%M%S.nc")
>     out_name = date.strftime("_%Y%m%dT%H%M%S.nc")

and the "def write_file" in observation.py as:

def write_file(
        # self, path="./", filename="%(path)s/%(sign_type)s.nc", zarr_flag=False, **kwargs
        self, path="./", filename=None, zarr_flag=False, **kwargs
    ):
        """Write a netcdf or zarr with eddy obs.
        Zarr is usefull for large dataset > 10M observations

        :param str path: set path variable
        :param str filename: model to store file
        :param bool zarr_flag: If True, method will use zarr format instead of netcdf
        :param dict kwargs: look at :py:meth:`to_zarr` or :py:meth:`to_netcdf`
        """
        # filename = filename % dict(
        #     path=path,
        #     sign_type=self.sign_legend,
        #     prod_time=datetime.now().strftime("%Y%m%d"),
        # )

        if filename == None :
            filename = "%s/%s.nc" % (path, self.sign_legend)
        else:
            filename = "%s/%s" % (path, self.sign_legend) + filename

I don't think it is good, but a compromise for windows/mac. Furthermore, this change may also cause other potential issues (but I haven't met yet). Maybe changing the system to Unix could solve a lot of similar issues.