Issue
I have this folder in my GitHub repo:
Inside this repo, I have a Jupyter notebook, and I use MyBinder to render this notebook into a web app. Inside the notebook, I iterate over the files in the rasters_as_int
folder and extract the date from the file name. All the files have the same name pattern, for example, one of the files is named: MODAL2_M_CLD_FR_2019-06-01_rgb_3600x1800.FLOAT.TIFF
.
In the previous version of the repo, there was no folder and all these files were on the repo "main page" (sorry if this is not the proper name for it), so in the notebook, I used the glob
package to iterate over them (and extract the date using Python split
method):
rasters_list = glob.glob('*TIFF*')
And it works perfectly.
However, I can't seem to find how to iterate when these files are in the rasters_as_in
folder.
I tried many options but nothing seems to work:
rasters_list = glob.glob('rasters_as_int/*TIFF*')
rasters_list = glob.glob('/rasters_as_int/*TIFF*')
rasters_list = glob.glob('./rasters_as_int/*TIFF*')
rasters_list = glob.glob('rasters_as_int\\*TIFF*')
rasters_list = glob.glob('\\rasters_as_int\\*TIFF*')
rasters_list = glob.glob('.\\rasters_as_int\\*TIFF*')
rasters_list = glob.glob('rasters_as_int/*')
rasters_list = glob.glob('/rasters_as_int/*')
rasters_list = glob.glob('./rasters_as_int/*')
rasters_list = glob.glob('.\\rasters_as_int\\*')
rasters_list = glob.glob('/rasters_as_int/*',recursive=True)
Solution
Your third option works fine.
I just tested that and a variation at https://mybinder.org/v2/gh/ran-pelta/CloudTool/7bd082bb3cf7b2e202dc43841fc60e7796c7402a , which uses the repo before you removed the rasters_as_int
directory. Example glob that works to give output I show next:
rasters_list = glob.glob('./rasters_as_int/*TIFF')
And I get stuff like this (truncated for brevity with ...
) when I put rasters_list
alone in a subsequent cell:
['./rasters_as_int/MODAL2_M_CLD_FR_2020-01-01_rgb_3600x1800.FLOAT.TIFF',
'./rasters_as_int/MODAL2_M_CLD_FR_2019-06-01_rgb_3600x1800.FLOAT.TIFF',
'./rasters_as_int/MODAL2_M_CLD_FR_2020-03-01_rgb_3600x1800.FLOAT.TIFF',
'./rasters_as_int/MODAL2_M_CLD_FR_2020-12-01_rgb_3600x1800.FLOAT.TIFF', ...
]
(See a picture below of that, too. I added it now for more context since I ended up adding an image showing the plot.)
You probably weren't accounting for the ./rasters_as_int/
part in your split of the file name? Because it looks like you changed it from date = pd.to_datetime(i.split('_')[4]) # this is if the TIFFs are in current folder
to date = pd.to_datetime(tail.split('_')[4])
.
And with that glob command the notebook works from here using what is in rasters_as_int
. I see the dates along the plot.
Here's showing what I see from that glob as an image,too, since it shows your other code in context:
Answered By - Wayne
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.