# Linear scaling of moment tensor symbols for psmeca

**URL:** <https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978>\
**Category:** Q&A\
**Created:** [August 11, 2021, 6:26pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978 "2021-08-11T18:26:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 11, 2021, 6:26pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/1 "2021-08-11T18:26:25Z")

</div>

Hi,

I find it useful to use psmeca type moment tensor symbols to visualize strain(-rate) or stress tensors which may or may not have anything to do with earthquakes, in which case a linear scaling of the symbol size may be better, or required.

I was wondering if we could modify psmeca to accommodate this. I realize that there are a bunch of flags to modify the scaling, have them constant, etc., but in the end, it seems that the magnitude (i.e. ~log(moment)) is always used, like

`size = (meca_computed_mw(moment, meca.magms) / 5.0) * scale;`

This makes sense for earthquakes, of course, unless one wants to make the point how much bigger large events actually are, which can also be helpful for teaching.

In the attached difference log between today’s github psmeca.c and my suggested code version, I introduce a new flag, -Q, which does modify the scaling, and it is calibrated to not make the PS conversion flip out for huge symbols when run on a typical sort of gCMT datasets. This seems to work and I added a warning to lesson the surprise. [psmeca\_linear\_scale\_diff.txt](https://forum.generic-mapping-tools.org/uploads/short-url/gV7nDN3lK2SKo2QKrZtNwxZZGNj.txt) (3.9 KB)

Could we add this modification to the git branch/does someone have a more elegant and general implementation?

Thanks!

T

PS: While I haven’t carefully checked I also wonder about the S flag and its norminal size. Where is that actually used/is that supposed to work like this?

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [August 12, 2021, 1:54am UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/2 "2021-08-12T01:54:26Z")

</div>

Hi Torsten-

We should be able to include this feature pretty quickly, but we may wish to implement it differently (rather than a new -Q, it will likely be added via a modifier to -M, for instance). Could you please open a feature request on [GitHub](https://github.com/GenericMappingTools/gmt) instead and maybe preempt a few of our general concerns in the process:

1. What’s the reference moment? Your patch uses a reference moment of 10\*\*26, but that may make no sense for your strain or stress tensor cases. Should this be an option, e.g. -M+s ?
2. For earthquake moment tensors, a linear scaling would seem to make little sense because the moment of an Mw 5 earthquake is about 32 times larger than that of an Mw4 earthquake, so would not the plot be useless?

Cheers, Paul

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 12, 2021, 12:43pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/3 "2021-08-12T12:43:41Z")

</div>

Hi Paul,

Thanks!

1. I’ll try to code this up via an -M modifier and then file as a request like you suggest. Would be good to have an option to pass the normalizing moment.

2. Of course, huge differences in moment between magnitudes, but I use such plots to illustrate to 101 students where all the action is, and if you have a smaller region with only moderate magnitude differences, you can see some stuff (like how different size the symbols are!) However, the main application would of course be properties that don’t vary over many orders of magnitude.

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 14, 2021, 5:28pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/4 "2021-08-14T17:28:20Z")

</div>

This version of psmeca would seem to do the trick and uses -M as suggested. There’s probably a better way to handle the arguments (so that it doesn’t bomb for -M+s or -Ml+s without value, for example), but it seems to work. I’ll put that in as a request.  
[psmeca\_diff.txt](https://forum.generic-mapping-tools.org/uploads/short-url/nBDHTEg7HBnmksuvwXVmbs8i7F0.txt) (4.8 KB)

git diff with current psmeca.c

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [August 15, 2021, 7:02pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/5 "2021-08-15T19:02:33Z")

</div>

@pwessel has opened a pull request for the linear scaling feature, with more changes included to make the syntax more intuitive.

@thwbecker It would be good if you have time testing it and leave your comments.

> <https://github.com/GenericMappingTools/gmt/pull/5649>
>
> This PR implements Torsten Becker's \[suggestion\](https://forum.generic-mapping-t…ools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/4) of an option to scale symbol sizes proportional to moment and not just magnitude. We do this by introducing some common constants in \_meca.h\_ that sets the default earthquake parameters and then use those in \*\*coupe\*\* and \*\*meca\*\*. Changing mode and setting parameters are done via new modifiers to \*\*-S\*\*. We also deprecated \*\*-M\*\*. Summary of changes:
> 
> 1. Change from magnitude to moment scaling via \*\*-S\*\* modifier \*\*+l\*\*.
> 2. Set reference magnitude or moment via \*\*-S\*\* modifier \*\*+s\*\*\_reference\_.
> 3. Set fixed symbol size via \*\*-S\*\* modifier \*\*+m\*\* (deprecated option \*\*-M\*\* handled via backward compatibility).
> 4. Update test scripts to use the new syntax after first passing with the old syntax. All tests pass.
> 5. Documentation has been updated to reflect the changes.
> 
> Currently, the default reference parameters are these (in meca.h):
> 
> \`\`\`
> \#define SEIS\_MAG\_REFERENCE 5 /\* Reference magnitude for -S \*/
> \#define SEIS\_MOMENT\_MANT\_REFERENCE 4	/\* Mantissa for reference moment for -S \*/
> \#define SEIS\_MOMENT\_EXP\_REFERENCE 23	/\* Exponent for reference moment for -S \*/
> \`\`\`
> 
> @seisman may revise these and possibly add corresponding SI units versions for the moment attributes so that we can upgrade the reference value to take a unit, e.g. \*\*-S...+s\*\*1e26\*\*u\*\* (for US unit or whatever).

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 16, 2021, 11:44pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/6 "2021-08-16T23:44:05Z")

</div>

Thanks much! It probably says right there in that post, but I am not that familiar with git - should I do anything besides git pull and recompile for testing?

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [August 17, 2021, 12:14am UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/7 "2021-08-17T00:14:12Z")

</div>

While in the top GMT dir:

```auto
git fetch
git checkout seis-linear-scaling

```

Then recompile and test. Would be great if you can make a short test script (see those in test/seis for what they typically look like) and share so we can add it to the test suite. We can polish it.

Once you are done and want to switch back to master, do

```auto
git checkout master

```

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 17, 2021, 3:07pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/8 "2021-08-17T15:07:05Z")

</div>

Hmm, this should work, but I cannot get the branch with the checkout command, and  
`git branch -a`  
only shows the master.

> git branch -a

- master  
remotes/origin/HEAD → origin/master  
remotes/origin/master

should I see check out the whole thing differently? I do see the changes you made on the Git web page.

---

<div class="post-metadata">

**Author:** ![maxrjones](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/maxrjones/32/2698_2.png) [@maxrjones](https://forum.generic-mapping-tools.org/u/maxrjones)\
**Post date:** [August 17, 2021, 4:17pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/9 "2021-08-17T16:17:20Z")

</div>

You could try:  
`git checkout --track origin/seis-linear-scaling`

If you are testing remote branches often, you may want to set your local repository to track all remote branches. Right now, it is only tracking the master branch.

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 17, 2021, 4:19pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/10 "2021-08-17T16:19:10Z")

</div>

Thanks, but that doesn’t work either. Should I set up the whole repository different?

---

<div class="post-metadata">

**Author:** ![maxrjones](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/maxrjones/32/2698_2.png) [@maxrjones](https://forum.generic-mapping-tools.org/u/maxrjones)\
**Post date:** [August 17, 2021, 4:23pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/11 "2021-08-17T16:23:44Z")

</div>

Here is what I sent to someone else who was having the same problem, which worked for them:

> Ok, I think the problem is that if you did a shallow clone (like instructed in the building.md file), it is not set up to track remote branches.
> 
> For me, if I type git config --list, the line for remote.origin.fetch is `remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*`
> 
> If you see something like this instead: `remote.origin.fetch=+refs/heads/master:refs/remotes/origin/master`, it means that the local repository is not setup to track remote branches.
> 
> You can change that by running:
> 
> `git remote set-branches origin '*'`
> 
> After running that command, if you run `git branch -r` you should see a longer list.

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 17, 2021, 4:35pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/12 "2021-08-17T16:35:22Z")

</div>

Thanks, that did the trick! Now I have 1Gb full of branches!

---

<div class="post-metadata">

**Author:** ![maxrjones](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/maxrjones/32/2698_2.png) [@maxrjones](https://forum.generic-mapping-tools.org/u/maxrjones)\
**Post date:** [August 17, 2021, 4:50pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/13 "2021-08-17T16:50:09Z")

</div>

Glad it worked, even if the size is sub-optimal 🙂 The repo size is largely related to the tests, which help keep GMT stable but rely on postscript files which git was not designed to track. I added a potential solution to the agenda for the next community meeting and am hopeful that we can make progress on it soon.

---

<div class="post-metadata">

**Author:** ![maxrjones](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/maxrjones/32/2698_2.png) [@maxrjones](https://forum.generic-mapping-tools.org/u/maxrjones)\
**Post date:** [August 17, 2021, 4:55pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/14 "2021-08-17T16:55:35Z")

</div>

Also, there is probably a way to only track specific remote branches if you want to use a fresh, shallow clone in the future to save space.

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 17, 2021, 10:06pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/15 "2021-08-17T22:06:37Z")

</div>

Thanks, works great! I did a couple of tests, and I think all works as it should. There’s a minor issue in that the -S+f option gets interpreted as a font for size \< 0 (and not switch off labeling as old style -Sm/ did), but that should not affect (m)any.

As for a silly (but perhaps in certain instance instructive) example of using linear scaling with moment for gCMTs, here’s the kind of plot you can get with

sort -gr +9 tmp.mdat | psmeca -Sm0.4+f0+l+s5e25

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/e/e16e199322a79faa908605f4bd375765898b804f.png)

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [August 17, 2021, 11:37pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/16 "2021-08-17T23:37:14Z")

</div>

Thanks Torsten, could you share your tmp.mdat file so we can build a test script out of this?  
As for the comment on -S+f, do you mean if you give -S+f-1 ?

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 19, 2021, 12:17am UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/17 "2021-08-19T00:17:15Z")

</div>

meca.h should be indicating those two reference values are floats, like so (note “.”)

#define SEIS\_MAG\_REFERENCE 5. /\* Reference magnitude for -S _/  
 #define SEIS\_MOMENT\_MANT\_REFERENCE 4. /_ Mantissa for reference moment for -S \*/

else the compiler thinks those are ints and the help page doesn’t display the right numbers with the %g format.

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 19, 2021, 12:21am UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/18 "2021-08-19T00:21:59Z")

</div>

And forgot to reply to all here, here’s the file, [tmp.txt](https://forum.generic-mapping-tools.org/uploads/short-url/qRMLqfPlDdXw2lG9hLeYLSb0a2q.txt) (1.4 KB)

gmtselect -R30/40/23/30 on a recent gCMT catalog in meca style

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [August 19, 2021, 6:02pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/19 "2021-08-19T18:02:32Z")

</div>

Thanks Torsten, the PR has now been [merged](https://github.com/GenericMappingTools/gmt/pull/5649) into master.

---

<div class="post-metadata">

**Author:** ![thwbecker](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/thwbecker/32/1215_2.png) [@thwbecker](https://forum.generic-mapping-tools.org/u/thwbecker)\
**Post date:** [August 19, 2021, 6:31pm UTC](https://forum.generic-mapping-tools.org/t/linear-scaling-of-moment-tensor-symbols-for-psmeca/1978/20 "2021-08-19T18:31:23Z")

</div>

Awesome, thanks all!
