# Help on drifting grating and masks

**URL:** <https://mworks.discourse.group/t/help-on-drifting-grating-and-masks/252>\
**Category:** Support\
**Created:** [May 7, 2019, 1:52pm UTC](https://mworks.discourse.group/t/help-on-drifting-grating-and-masks/252 "2019-05-07T13:52:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [May 7, 2019, 1:52pm UTC](https://mworks.discourse.group/t/help-on-drifting-grating-and-masks/252/1 "2019-05-07T13:52:57Z")

</div>

Hi Chris,

I am interested in finding the FWHM of the MWorks gaussian mask that is created with stddev 0.3 and mean 0.1, normalized=true.

For those parameters, if I follow the calculations in the code on github

> <https://github.com/mworks/mworks/blob/master/plugins/core/DriftingGratingStimulus/DriftingGratingStimulus.cpp>

I find that the region where mask == 1 is about 0.5_size. But when I actually measure the stimulus onscreen, I get a region where mask == 1 that is about 0.3_size or even a bit smaller.

Can you calculate/measure the length of the region where mask==1 with these parameters, and the FWHM?

Another note from testing today:

- Could it be that the drifting\_grating starting\_phase parameter is not phase in degrees, as stated in the docs? If I set the stimulus spatial frequency to 0.05, I need to set starting phase to a value greater than 40 to even shift a half-phase.

Thanks,  
Mark

plot of stimulus profile:  
  
code I used, following MWorks code as closely as possible, to create mask

from numpy import pi, sqrt, exp  
def simMWorksMask(stdDev=0.3, mean=0.0, doNorm=True):  
nPts = 128  
maskCenter = 0.5  
xv = np.linspace(0.0, 1.0, nPts)  
yv = np.linspace(0.0, 1.0, nPts)

```
def distance(x0,x1):
    return (np.sqrt((x0[0]-x1[0])**2 + (x0[1]-x1[1])**2))

stdDev=stdDev#/2
mean=mean#/2
maskImage = np.zeros((nPts,nPts))
if doNorm:
    mult = (1.0 / (stdDev * sqrt(2.0 * pi)))
else:
    mult = 1.0
for (iX,tX) in enumerate(xv):
    for (iY,tY) in enumerate(yv):
        dist = distance(((tX,tY)), (maskCenter,maskCenter))
        maskImage[iY,iX] = ( mult *
                              exp(-1.0 * (dist - mean) * (dist - mean) / (2.0 * stdDev * stdDev)));
return (maskImage,xv,yv)

```

maskImage = simMWorksMask()

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [May 7, 2019, 3:29pm UTC](https://mworks.discourse.group/t/help-on-drifting-grating-and-masks/252/2 "2019-05-07T15:29:56Z")

</div>

Hi Mark,

Your code is calculating `dist` differently than MWorks. Your code:

```
dist = distance(((tX,tY)), (maskCenter,maskCenter))

```

MWorks:

```
dist = distance(maskVaryingCoords, maskCenter) / maskRadius;

```

You’re not dividing by `maskRadius` (0.5). I think that’s the source of the discrepancy.

> Could it be that the drifting\_grating starting\_phase parameter is not phase in degrees, as stated in the docs? If I set the stimulus spatial frequency to 0.05, I need to set starting phase to a value greater than 40 to even shift a half-phase.

It’s in degrees of phase, not degrees of visual angle. Changing `starting_phase` from zero to 180 inverts the grating (highs become lows, lows become highs). Or am I misunderstanding the question?

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [May 13, 2019, 6:29pm UTC](https://mworks.discourse.group/t/help-on-drifting-grating-and-masks/252/3 "2019-05-13T18:29:21Z")

</div>

Thanks for this.

1. You found the bug in my code, appreciated.
2. Of course, degrees of phase. Whoops. You’re right. Thanks.

Mark

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 8:50pm UTC](https://mworks.discourse.group/t/help-on-drifting-grating-and-masks/252/4 "2022-07-19T20:50:12Z")

</div>


