Ejemplo n.º 1
0
def gnss_velocity_fields(dset: "Dataset") -> None:
    """Add GNSS site velocity fields to dataset

    Args:
        dset:     A Dataset containing model data.
    """

    # Add velocity in topocentric coordinates
    lat, lon, height = dset.site_pos.pos.llh.T
    vel_enu = np.squeeze(
        rotation.trs2enu(lat, lon) @ dset.site_vel[:, :, None])
    dset.add_float("site_vel_east", val=vel_enu[:, 0], unit="meter/second")
    dset.add_float("site_vel_north", val=vel_enu[:, 1], unit="meter/second")
    dset.add_float("site_vel_up", val=vel_enu[:, 2], unit="meter/second")

    # Add horizontal velocity (HV), vertical velocity (VV) and 3D velocity
    dset.add_float("site_vel_h",
                   val=np.sqrt(vel_enu[:, 0]**2 + vel_enu[:, 1]**2),
                   unit="meter/second")
    dset.add_float("site_vel_v",
                   val=np.absolute(vel_enu[:, 2]),
                   unit="meter/second")
    dset.add_float(
        "site_vel_3d",
        val=np.sqrt(dset.site_vel[:, 0]**2 + dset.site_vel[:, 1]**2 +
                    dset.site_vel[:, 2]**2),
        #val=np.sqrt(vel_enu[:,0] ** 2 + vel_enu[:,1] ** 2 + vel_enu[:,2] ** 2),
        unit="meter/second",
    )

    # Add site velocity and standard deviation of site velocity coordinates
    dset.add_float("site_vel_x", val=dset.site_vel[:, 0], unit="meter/second")
    dset.add_float("site_vel_y", val=dset.site_vel[:, 1], unit="meter/second")
    dset.add_float("site_vel_z", val=dset.site_vel[:, 2], unit="meter/second")
    dset.add_float("site_vel_sigma_x",
                   val=np.sqrt(dset.estimate_cov_site_vel_xx),
                   unit="meter/second")
    dset.add_float("site_vel_sigma_y",
                   val=np.sqrt(dset.estimate_cov_site_vel_yy),
                   unit="meter/second")
    dset.add_float("site_vel_sigma_z",
                   val=np.sqrt(dset.estimate_cov_site_vel_zz),
                   unit="meter/second")
Ejemplo n.º 2
0
def _plot_velocity(dset: "Dataset", figure_dir: "pathlib.PosixPath") -> None:
    """Plot site velocity plots

    Args:
       dset:        A dataset containing the data.
       figure_dir:  Figure directory
    """

    
    lat, lon, height = dset.site_pos.pos.llh.T
    vel_enu = np.squeeze(rotation.trs2enu(lat, lon) @  dset.site_vel[:,:,None]) 

    plot_scatter_subplots(
        x_array=dset.time.gps.datetime,
        y_arrays=[vel_enu[:, 0], vel_enu[:, 1], vel_enu[:, 2]],
        xlabel="Time [GPS]",
        ylabels=["East", "North", "Up"],
        colors=["steelblue", "darkorange", "limegreen"],
        y_units=["m/s", "m/s", "m/s"],
        figure_path=figure_dir / f"plot_timeseries_enu.{FIGURE_FORMAT}",
        opt_args={
            "figsize": (6, 6.8),
            "plot_to": "file",
            "sharey": True,
            "title": "Site velocity",
            "statistic": ["rms", "mean", "std", "min", "max", "percentile"],
        },
    )

    vel_h = np.sqrt(vel_enu[:,0] ** 2 + vel_enu[:,1] ** 2) 
    vel_v = np.absolute(vel_enu[:,2])
    #vel_3d = np.sqrt(vel_enu[:,0] ** 2 + vel_enu[:,1] ** 2 + vel_enu[:,2] ** 2)
    vel_3d = np.sqrt(dset.site_vel[:,0] ** 2 + dset.site_vel[:,1] ** 2 + dset.site_vel[:,2] ** 2)

    plot_scatter_subplots(
        x_array=dset.time.gps.datetime,
        y_arrays=[dset.pdop, vel_h, vel_v, vel_3d],
        xlabel="Time [GPS]",
        ylabels=["PDOP", "HV", "VV", "3D"],
        colors=["steelblue", "darkorange", "limegreen", "red"],
        y_units=[None, "m/s", "m/s", "m/s"],
        figure_path=figure_dir / f"plot_timeseries_pdop_hv_3d.{FIGURE_FORMAT}",
        opt_args={
            "figsize": (7, 7),
            "plot_to": "file",
            "sharey": False,
            # "title": "2D (horizontal) and 3D velocity",
            "statistic": ["rms", "mean", "std", "min", "max", "percentile"],
        },
    )

    plot_scatter_subplots(
        x_array=vel_enu[:, 0],
        y_arrays=[vel_enu[:, 1]],
        xlabel="East [m/s]",
        ylabels=["North"],
        y_units=["m/s"],
        figure_path=figure_dir / f"plot_horizontal_velocity.{FIGURE_FORMAT}",
        opt_args={
            "grid": True,
            "figsize": (6, 6),
            "histogram": "x, y",
            "histogram_binwidth": 0.002,
            "plot_to": "file",
            "title": "Horizontal velocity",
            "xlim": [-0.1, 0.1],
            "ylim": [-0.1, 0.1],
        },
    )
Ejemplo n.º 3
0
def gnss_velocity(dset: "Dataset") -> None:
    """Write GNSS velocity results


    Args:
        dset:  A dataset containing the data.
    """
    file_path = config.files.path("output_velocity", file_vars=dset.vars)

    # Add date field to dataset
    if "date" not in dset.fields:
        dset.add_text(
            "date",
            val=[d.strftime("%Y/%m/%d %H:%M:%S") for d in dset.time.datetime])

    # Add velocity in topocentric coordinates
    lat, lon, height = dset.site_pos.pos.llh.T
    vel_enu = np.squeeze(
        rotation.trs2enu(lat, lon) @ dset.site_vel[:, :, None])
    dset.add_float("site_vel_east", val=vel_enu[:, 0], unit="meter/second")
    dset.add_float("site_vel_north", val=vel_enu[:, 1], unit="meter/second")
    dset.add_float("site_vel_up", val=vel_enu[:, 2], unit="meter/second")

    # Add horizontal velocity (HV), vertical velocity (VV) and 3D velocity
    dset.add_float("site_vel_h",
                   val=np.sqrt(vel_enu[:, 0]**2 + vel_enu[:, 1]**2),
                   unit="meter/second")
    dset.add_float("site_vel_v",
                   val=np.absolute(vel_enu[:, 2]),
                   unit="meter/second")
    dset.add_float(
        "site_vel_3d",
        val=np.sqrt(dset.site_vel[:, 0]**2 + dset.site_vel[:, 1]**2 +
                    dset.site_vel[:, 2]**2),
        #val=np.sqrt(vel_enu[:,0] ** 2 + vel_enu[:,1] ** 2 + vel_enu[:,2] ** 2),
        unit="meter/second",
    )

    # Add site velocity and standard deviation of site velocity coordinates
    dset.add_float("site_vel_x", val=dset.site_vel[:, 0], unit="meter/second")
    dset.add_float("site_vel_y", val=dset.site_vel[:, 1], unit="meter/second")
    dset.add_float("site_vel_z", val=dset.site_vel[:, 2], unit="meter/second")
    dset.add_float("site_vel_sigma_x",
                   val=np.sqrt(dset.estimate_cov_site_vel_xx),
                   unit="meter/second")
    dset.add_float("site_vel_sigma_y",
                   val=np.sqrt(dset.estimate_cov_site_vel_yy),
                   unit="meter/second")
    dset.add_float("site_vel_sigma_z",
                   val=np.sqrt(dset.estimate_cov_site_vel_zz),
                   unit="meter/second")

    # Put together fields in an array as specified by the 'dtype' tuple list
    if config.tech.estimate_epochwise.bool:  # Epochwise estimation or over whole time period

        output_list = list()
        for epoch in dset.unique("time"):
            idx = dset.filter(time=epoch)

            # Append current epoch position solution to final output solution
            output_list.append(
                tuple([
                    get_field(dset, f.field, f.attrs, f.unit)[idx][0]
                    for f in FIELDS
                ]))

    else:
        # Get position solution for first observation
        idx = np.squeeze(np.array(np.nonzero(dset.time.gps.mjd)) ==
                         0)  # first observation -> TODO: Better solution?
        output_list = [
            tuple([
                get_field(dset, idx, f.field, f.attrs, f.unit)[idx][0]
                for f in FIELDS
            ])
        ]

    output_array = np.array(output_list,
                            dtype=[(f.name, f.dtype) for f in FIELDS])

    # Write to disk
    header = get_header(
        FIELDS,
        pgm_version=f"where {where.__version__}",
        run_by=util.get_user_info()["inst_abbreviation"]
        if "inst_abbreviation" in util.get_user_info() else "",
        summary="GNSS velocity results",
    )
    np.savetxt(
        file_path,
        output_array,
        fmt=tuple(f.format for f in FIELDS),
        header=header,
        delimiter="",
        encoding="utf8",
    )