Skip to content

slope on droplets off #67

Description

@m0ose

I was looking at the slopes on the droplets model https://code.agentscript.org/views2/droplets.html , and it occurred to me that the slopes look wrong. If you look at model.slopes they are all values like 1.4 which is like 80 degrees. I was not expecting slopes bigger than like 10 degrees for that area.

I think it has to do with the way dzdx and dzdy are calculated. They are treating the z values in meters, but the x,y values in terms of pixel dimensions. I think that the x and y should be in terms of meters too.

I wrote some helper functions that seem to work. My question is wether you would be interested in me putting those into a pull request? would we be interested in another class for GeoDatasets?

/** * utils *  * */functiongeoDzdx(elevation,widthInMeters){constpixelScale=widthInMeters/elevation.widthconstdzdx=elevation.dzdx(2,(1/8)*(1/pixelScale))// (1/8) for the kernel and 1/pixelscale to get units rightreturndzdx}functiongeoDzdy(elevation,heightInMeters){constpixelScale=heightInMeters/elevation.heightconstdzdy=elevation.dzdy(2,(1/8)*(1/pixelScale))returndzdy}functionslope(dzdx,dzdy){constslopes=dzdx.map((x,i)=>{consty=dzdy.data[i]consta=Math.hypot(-x,-y)constsl=(Math.PI/2)-Math.atan2(1,a)returnsl})returnslopes}/** * Calculate the slope of elevation Dataset in meters * @param {DataSet} elevationDS * @param {number} widthMeters The width in meters of the elevation dataset * @param {number} heightMeters The height in meters of the elevation dataset * @return {DataSet} slopes The slopes in radians * */functionslopeFromElevationDS(elevationDS,widthMeters,heightMeters){constdzdx=geoDzdx(elevationDS,widthMeters)constdzdy=geoDzdy(elevationDS,heightMeters)constslopes=slope(dzdx,dzdy)returnslopes}/** * Calculate the slope of elevation Dataset in meters * @param {DataSet} elevationDS * @param {[west, south, east, north]} bounds * @return {DataSet} slopes The slopes in radians * */functionslopeFromElevationDS_bounds(elevationDS,bounds){constsizeMeters=bboxMetricSize(bounds)returnslopeFromElevationDS(elevationDS,sizeMeters[0],sizeMeters[1])}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions