synoptic.polars_namespace.SynopticFrame#

class synoptic.polars_namespace.SynopticFrame(df)[source]#

Custom Polars namespace for SynopticPy DataFrames.

Parameters:

df (DataFrame)

__init__(df)[source]#
Parameters:

df (DataFrame)

Return type:

None

Methods

__init__(df)

pivot(*[, sensor_index])

Pivot a long-form SynopticPy DataFrame to wide-form.

with_local_timezone()

Convert datetime columns from UTC to local timezone.

with_network_name([which])

Provide DataFrame with network_name column.

with_wind_uv()

Provide wind_u and wind_v columns from wind speed and direction.

write_met(file)

Write to 11-column ASCII file for Model Evaluation Tools (MET) ASCII2NC tool.

pivot(*, sensor_index=1, **kwargs)[source]#

Pivot a long-form SynopticPy DataFrame to wide-form.

This likely gets what you’re looking for, but it is recommended to use Polars directly to accomplish more customized pivots.

  • Long-form DataFrame has a row for each observation.

  • Wide-form DataFrame has a station variables are in their own column for each station.

Parameters:
  • sensor_index (int) – Sensor index to filter prior to the pivot.

  • **kwargs – Keyword arguments for Polars pivot.

Return type:

DataFrame

with_local_timezone()[source]#

Convert datetime columns from UTC to local timezone.

Returns:

  • DataFrame if only one unique timezone is present, else returns

  • a dict of DataFrames, one item for each timezone.

Return type:

DataFrame | dict

with_network_name(which='short')[source]#

Provide DataFrame with network_name column.

Parameters:

which ({'short', 'long'}) – Specify if the network shortname or longname is joined.

Return type:

DataFrame

with_wind_uv()[source]#

Provide wind_u and wind_v columns from wind speed and direction.

IMPORTANT Requires a wide-form DataFrame (pivoted) with columns wind_speed and wind_direction.

Return type:

DataFrame

write_met(file)[source]#

Write to 11-column ASCII file for Model Evaluation Tools (MET) ASCII2NC tool.

WARNING: I haven’t actually tested that the file it writes can be used by MET’s ASCII2NC tool. This is primarily a proof of concept. Please open a PR if you want to see this feature improved and tested.

> The default ASCII point observation format consists of one row of data > per observation value. Each row of data consists of 11 columns as shown > in [Table 7.4](https://met.readthedocs.io/en/latest/Users_Guide/reformat_point.html#table-reformat-point-ascii2nc-format).

Description https://met.readthedocs.io/en/latest/Users_Guide/reformat_point.html#ascii2nc-tool

Sample Data dtcenter/MET

Parameters:

file (Path | str)

Return type:

None