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

Added a rename function #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Added a rename function #40

wants to merge 1 commit into from

Conversation

Surfix
Copy link
Contributor

@Surfix Surfix commented Jul 25, 2022

Hi @ZachKeskinen and @jacktarricone , I wrote a simple function that extracts info from the annotation and tiff files to rename UAVSAR data in a directory. I found it useful to append the date of first and second pass to the tiff files I am working with. Perhaps this might be a useful addition to the package.

@Surfix Surfix requested a review from ZachHoppinen July 25, 2022 14:12
Copy link
Contributor

@ZachHoppinen ZachHoppinen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this Naheem! I think it would be also to incorporate this in!

I have a few small changes to match the overall patterns of the repo and a few bigger questions:

  1. This will only work for ground projected interferogram pairs, so not Polsar or slant range uavsar images. Can we a check at the start of the script to ensure there are only .grd.tiff and .ann.tiff images? Also rename from rename.py to something like rename_interferogram_grd.py?

  2. At the end if the user specifies clean_dir can we move all the images back into the original directory in_dir from renamed/ directory and get rid of renamed? I just don't want to have an empty directory with just a renamed/ directory. It would be better to just be left with the same directory with renamed files in it.

The renamed files are stored in a new directory called renamed.

Args:
dir_in (_type_): path to the directory containing the tiff files to be renamed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type should probably be string?

os.makedirs(dir_out)

#read the metadata from the csv file
metadata = pd.read_csv(glob.glob(dir_in + '/*grd.csv')[0]) #it gives a list, so select the only item in the list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you from glob import glob and then just use glob here to match the pattern in the rest of the repo?

#grab the last two sets of strings from the tiff name
set2 = (tiff.split('/')[-1]).split('_')[-2]
set1 = (tiff.split('/')[-1]).split('_')[-1]
new_name = dir_out + file_name + '_' + date1 + '_' + date2 + '_' + set2 + '_' + set1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using an f-string here?

join(dir_out, f'{file_name}{date1}{date2}{set2}{set1}

file_name = (tiff.split('/')[-1]).split('_')[0]

#grab the last two sets of strings from the tiff name
set2 = (tiff.split('/')[-1]).split('_')[-2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are set2 and set1 polarizations? What are these variables?


if clean_dir == False:
shutil.copy(tiff, new_name)
elif clean_dir == True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user passes clean_dir == true, could we move them to this new directory and then have a section that moves the tiffs back into the main directory and removes the newly created renamed directory?



#loop through the files
for tiff in glob.glob(dir_in + '/*grd.tiff'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for POLSAR, slant range images. Maybe a different script name that clarifies this is only for renaming uavsar interferogram ground projected images? and a check to make sure that the in_dir contains that right type of images?

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 this pull request may close these issues.

2 participants