Author Topic: Variables to add keywords on ingest: season and orientation?  (Read 1458 times)

Offline myotis

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Variables to add keywords on ingest: season and orientation?
« on: September 04, 2022, 12:46:41 AM »
Is there any clever way to use variables on ingest to add these two specific keywords to the XMP file.

1. Using the capture date, add a keyword of "Spring", "Summer" "Autumn" or "Winter" ie if the photograph was taken in March, April or May, add "Spring" as a keyword.

2. Using the EXIF data, add either "Vertical" or "Horizontal" as a keyword, depending on file orientation.

I've had a look at the variables, and I suspect the answer is no, but thought I should ask.

Thanks,

Graham

Offline Mick O (Camera Bits)

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 525
    • View Profile
    • Camera Bits
Re: Variables to add keywords on ingest: season and orientation?
« Reply #1 on: September 05, 2022, 11:28:22 AM »
Regarding adding the season, you could use a "brute force" code replacement file to do it. It's not actually that difficult if using a spreadsheet... so, I'll go ahead and do it.

Load the attached Tab-Separated Value file as a Code Replacement file into Photo Mechanic. The following code will evaluate to the name of the season if placed into the keyword or most other fields in PM.

Code: [Select]
=sn{mn0}{day0}=
Note: I didn't go so far as to take time of day into account, so photos taken at 1AM on June 21 will still return "Summer"  even though Summer didn't start until 5:14 A.M. EDT.  If you need that level of detail, you may need to tweak your own spreadsheet :-)

Vertical vs Horizontal ... You could try a similar brute force method creating a sheet with a column of possible aspect ratios (0 - .99 being "Vertical" 1 being "Square" and  1.01 - 4 being "Horizontal")  I think the {aspect} variable will only return a value to two decimal places, but am not 100% sure.   I will let you decide how important that is if you want to tackle it. :-)

-Mick
Mick O
Camera Bits

Offline myotis

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Variables to add keywords on ingest: season and orientation?
« Reply #2 on: September 05, 2022, 11:50:13 AM »
Hello Mick,

That is very clever.

I will give it a go (might not have time for a couple of days) and let you know how I get on.

Many thanks,

Graham

Offline myotis

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Variables to add keywords on ingest: season and orientation?
« Reply #3 on: September 06, 2022, 03:46:22 AM »
Regarding adding the season, you could use a "brute force" code replacement file to do it. It's not actually that difficult if using a spreadsheet... so, I'll go ahead and do it.

Load the attached Tab-Separated Value file as a Code Replacement file into Photo Mechanic. The following code will evaluate to the name of the season if placed into the keyword or most other fields in PM.

Code: [Select]
=sn{mn0}{day0}=
Note: I didn't go so far as to take time of day into account, so photos taken at 1AM on June 21 will still return "Summer"  even though Summer didn't start until 5:14 A.M. EDT.  If you need that level of detail, you may need to tweak your own spreadsheet :-)

Vertical vs Horizontal ... You could try a similar brute force method creating a sheet with a column of possible aspect ratios (0 - .99 being "Vertical" 1 being "Square" and  1.01 - 4 being "Horizontal")  I think the {aspect} variable will only return a value to two decimal places, but am not 100% sure.   I will let you decide how important that is if you want to tackle it. :-)

-Mick

Hello Mick,

I now have the seasons working, in fact it was simpler than your spreadsheet as I only wanted to assign months to a season. 

Aspect, however, doesn't work.

This seems to give the aspect ratio rather than the orientation, as it returns 1.5 or 1.51 for my Nikon files regardless of orientation.

I think I need the exif tag "orientation" which has 8 values 1-4 for horizontal and 5-8 for vertical, but orientation doesn't seem to be an available variable.

At least it's not autocompleting when I type it in the way that {aspect} autocompletes.

Am I trying to use the wrong variable?

Edit: I've just found {rotate} and I wonder if that might work?  Checking some images it seems as if {rotate} returns "none" for horizontal and "90CW" or "90CCW". for vertical. Are there any other outputs that I need to be aware of.  I assume the CW  and CCW mean rotate right or rotate left.

Graham
« Last Edit: September 06, 2022, 06:22:41 AM by myotis »

Offline Mick O (Camera Bits)

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 525
    • View Profile
    • Camera Bits
Re: Variables to add keywords on ingest: season and orientation?
« Reply #4 on: September 06, 2022, 10:10:21 AM »
I hadn't thought of the rotation in the metadata, apologies.  I had only tried with files that were natively sized. It seems like none of these variables on their own will let you know if you have a portrait or a landscape image.   Making a "brute force" code replacement might still be possible but it would significantly longer to account for the different combinations. {aspect} being 0-0.99 with {rotation} of "none" should be reliably "Vertical" etc etc.

Update:

The possible values returned by {rotation} are below, so as long as your massive Code Replacement file accounted for all of them, you should, in theory,  be able to reliably determine Vertical, Horizontal, or Square by combining {aspect} and {rotation}

Update#2: If you want to handle anything with {aspect} up to 4, you could do it with 400 lines per each of the 8 {rotation} values so roughly 3200 lines in your code replacement file. 

Code: [Select]
none
mirror
90 CW
mirror 90 CW
180
mirror 180
90 CCW
mirror 90 CCW

Mick
« Last Edit: September 06, 2022, 10:43:39 AM by Mick O (Camera Bits) »
Mick O
Camera Bits

Offline myotis

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Variables to add keywords on ingest: season and orientation?
« Reply #5 on: September 06, 2022, 10:40:45 AM »
I hadn't thought of the rotation in the metadata, apologies.  I had only tried with files that were natively sized. It seems like none of these variables on their own will let you know if you have a portrait or a landscape image.   Making a "brute force" code replacement might still be possible but it would significantly longer to account for the different combinations. {aspect} being 0-0.99 with {rotation} of "none" should be reliably "Vertical" etc etc.

Update:

The possible values returned by {rotation} are below, so as long as your massive Code Replacement file accounted for all of them, you should, in theory,  be able to reliably determine Vertical, Horizontal, or Square by combining {aspect} and {rotation}

Code: [Select]
none
mirror
90 CW
mirror 90 CW
180
mirror 180
90 CCW
mirror 90 CCW

Mick

I am guessing that these match the exif orientation values from 1 to 8 that include mirrored and flipped images. My guess is that for raws from the camera only "none", "90CW" and "90CCW" are likely to occur.

I'm unsure why they need to be combined with aspect, and I'm not sure if I want to make a massive file.

I think I may just do as I'm doing, which is to use LR, C1 or Neofinder to filter/search on orientation and manually add the keywords. 

Hopefully, adding an orientation search/filter won't be too long in coming to PM+.

Thanks for your help. This little training session has opened up new possibilities in PM for me.

Offline myotis

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Variables to add keywords on ingest: season and orientation?
« Reply #6 on: September 07, 2022, 06:46:01 AM »
Just to add a bit to this as I've been looking into this.

It seems that, as you suggest, and I didn't really doubt it, the orientation is more complex than just the tag, and different applications seem to have verying levels of success in deciding on image orientation

However, I wonder if PM is actually doing some of the hard work.

For example the orientation tag in my vertical Nikon Files is "Rotate 270 CW" but evaluating {rot} in PM gives me "90 CCW".

This suggests to me that {rot} is giving an orientation value (ie the one that PM uses to orientate a preview) after PM has interpreted the original EXIF value of "Rotate 270 CW". So some of the problems in fully understanding the orientation may have already been worked out by the PM coders.

Anyway, I am giving it a go with just the eight rotation values you gave me to extract either a Vertical or Horizontal code replacements.

I will monitor it and see how well it works

Offline myotis

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Variables to add keywords on ingest: season and orientation?
« Reply #7 on: September 07, 2022, 08:37:07 AM »
Having added the code replacement text into the keyword fields of existing photographs, is there a way of forcing a bulk evaluation of them.

I was hoping that opening or saving the metatdata info form would have forced an evaluation, but it isn't.

Offline Mick O (Camera Bits)

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 525
    • View Profile
    • Camera Bits
Re: Variables to add keywords on ingest: season and orientation?
« Reply #8 on: September 07, 2022, 09:21:59 AM »
Could you elaborate a little bit more on what steps you are trying?

Typically, you would select a group of photos, open the Metadata Template (not Metdata Info) apply a keyword, or a variable or a code replacement in that template and click "Apply to selected" and then the variables and/or code replacements get evaluated and applied to the selected photos at that time.

If this is what you are trying, and the code replacements are not getting evaluated, then that suggests either a misformed code replacement or code replacement file. or you didn't actually lose the code replacement file in.  But without knowing what you're doing I can't say for sure.

Mick
Mick O
Camera Bits

Offline myotis

  • Full Member
  • ***
  • Posts: 188
    • View Profile
Re: Variables to add keywords on ingest: season and orientation?
« Reply #9 on: September 07, 2022, 09:46:42 AM »
Could you elaborate a little bit more on what steps you are trying?

Typically, you would select a group of photos, open the Metadata Template (not Metdata Info) apply a keyword, or a variable or a code replacement in that template and click "Apply to selected" and then the variables and/or code replacements get evaluated and applied to the selected photos at that time.

If this is what you are trying, and the code replacements are not getting evaluated, then that suggests either a misformed code replacement or code replacement file. or you didn't actually lose the code replacement file in.  But without knowing what you're doing I can't say for sure.

Mick

Thanks Mick,

Mmmm, what you describe is what I have done in the past, I'm not sure why I did it the way I did it.

I added the variable code as a keyword using the batch option by adding to selected images.  I was hoping that when I opened the metadata info form (by clicking on the "i" on the thumbnail) it would  recognise the code and evaluate it. I can evaluate it manually, so nothing wrong with code or the code replacement file.

I will redo it with the metadata template. 

As it is, I have "manually" run the evaluation on about 300 images and so far the orientation code replacement is working as hoped for.

Cheers,

Graham