chird / meteoJS

Javascript Library for meteorological and atmospheric tools
Apache License 2.0
25 stars 6 forks source link

issue with mixingRatio line & i need to disable the hodograph svg #72

Closed HadjerSahariYassir closed 1 year ago

HadjerSahariYassir commented 1 year ago

Hi Chird, hope you're doing well. I have an issue with mixingRation line when i move the line it is stopped at the left boundry the line can't be moved in the yellow zone, i didn't find where is the mistake , as shown in the next picture. image

And here is the code

diagram.on("mousemove", (p) => {
      if (!out3) return;
      let tdGroup = diagram.svgNode.group();
      tdGroup.clear();
      const maxPressure = 1050;
      const minPressure = 100;
      const options = {
        mixingratio: {
          maxPressure: diagram.coordinateSystem.options.pressure.max,
        },
      };
      let hmr = saturationHMRByTempAndPres(p.diagramTmpk, p.diagramPres);
      const y0 = Math.max(
        0,
        options.mixingratio.maxPressure === undefined
          ? 0
          : diagram.coordinateSystem.getYByPHMR(maxPressure, hmr)
      );
      const x0 = diagram.coordinateSystem.getXByYHMR(y0, hmr);
      const y1 = Math.min(
        diagram.coordinateSystem.height,
        minPressure === undefined
          ? diagram.coordinateSystem.height
          : diagram.coordinateSystem.getYByPHMR(100, hmr)
      );
      const x1 = diagram.coordinateSystem.getXByYHMR(y1, hmr);
      let points = [[x0, y0]];
      const yInterval = 10;
      for (let y = y0 + yInterval; y < y1; y += yInterval) {
        points.push([diagram.coordinateSystem.getXByYHMR(y, hmr), y]);
      }
      points.push([x1, y1]);

      points.length == 2
        ? tdGroup.line(
            points[0][0],
            diagram.coordinateSystem.height - points[0][1],
            points[1][0],
            diagram.coordinateSystem.height - points[1][1]
          )
        : polyline_mix
            .plot(
              points.map(function (point) {
                point[1] = diagram.coordinateSystem.height - point[1];
                return point;
              }, diagram)
            )
            .fill("none")
            .stroke({ width: 4, color: "green", dasharray: [6, 6] })

     /* polyline_mix.on("mouseup", () => {
        out3 = false;
      });
      polyline_mix.off("mouseup");
      diagram.on("mouseup", () => {
        out3 = false;
      });*/
    });

and if possible also is there a way to disable all the hodographe svg image

And Thanks a lot Cheers

chird commented 1 year ago

Hi hadjersh97, This is an exciting but challenging issue. It's a problem of the calculation algorithm. Within the function saturationHMRByTempAndPres the saturation vapour pressure is calculated at the passed temperature. The used calculation is not able to compute the low values in the yellow area accurately. Accordingly, you would have to create your own, more accurate computation for the humidity mixing ratio so that you can move the line in the yellow area.

The much simpler case is hiding the hodograph. There's a constructor option for this.

new ThermodynamicDiagram({
  …
  hodograph: {
    visible: false
  }
  …
});
chird commented 1 year ago

I found a more accurate computation, the Buck equation. (see Wikipedia)

const T = tempKelvinToCelsius(p.diagramTmpk)
const eWater = 0.61121 * Math.exp((18.678 - T/234.5) * (T/(257.14+T))) * 10;
const hmr = 621.97*eWater/(p.diagramPres - eWater);

But you will see that in the upper left corner the equation is not accurate either. The line is not drawn exactly at the cursor.

HadjerSahariYassir commented 1 year ago

Hi chird,

  1. Yes in the upper left corner, the line is not drawn exactly at the cursor. but i can keep it like that.

  2. For the second issue which is hodograph , it works once , but i need to update hodograph visibility according to the user (checkbox) , Enable/disable , i didn't find function similar to update of sounding ?

  3. Also please , i still have a task to zoom the ThermodinamicDiagram so it is possible ? Thanks so much!

chird commented 1 year ago

Hi ,

I found your old questions. Sorry for my late reply.

  1. You can just set the visible property of the Hodograph. If your basic ThermodynamicDiagram object is diagram, you can just use:

    diagram.hodograph.visible = false;
  2. See my answer in #74

Cheers