Skip to main content

SNOWPAT

This is a toolbox for handling file formates most often used in Snow Science.

There are 4 submodules: pysmet: Used to read and write SMET files snowpackreader: Used to read SNOWPACK output files (.pro) and handle profiles easily (soon also with visualization) SnowLense: Plotting Framework for files that can be read with this module (SMET not yet available) icsv: Read and write iCSV Files. (Next generation SMET, provided by standalone package interoperable-csv; import icsv) (see Documentation)

iCSV package links:

News

2026-05-11: ICSV now lives in its own repository at: https://gitlabext.wsl.ch/patrick.leibersperger/icsv. Snowpat still reexports it. 2025-03-13: It is now possible to write Snowpack objects to .pro files. (If necessary also a series of profiles, could be written to a .pro file, not implemented yet). Manual JSON profiles can be written to .pro files including stability calculations.

2025-01-06: Happy New Year! New year new bugs, please update snowpat, as a function used in the plotting is deprecated in the newest matplotlib.

2024-05-05: A module to read and write iCSV files.

2024-03-25: Installation via PyPi now possible

2024-03-08: Plotting of Snow Profiles is available with SnowLense module

2024-03-01: A simple merge function is now available to join to SMET Files: merge(SMETFile, override) and mergeFromFile(filename, override)

Installation

Installation via pip and poetry is supported.

It is as easy as:

pip install snowpat

You can also install from git (needs git to be installed) to always get the latest release:

pip install [--user] git+https://gitlabext.wsl.ch/patrick.leibersperger/snowpat.git

the --user option might be needed if you do not have admin rights.

Upgrade

If you already have an installation of Sowpat, that is out of date, run:

pip install [--user] --upgrade snowpat
pip install [--user] --upgrade git+https://gitlabext.wsl.ch/patrick.leibersperger/snowpat.git

Manually

Download the folder, and from the main directory run:

poetry install

or:

pip install [--user] .

Documentation

The main documentation can be found under the respective module names, i.e. pySMET and SMET, as well as snowpackreader

Extensive Documentation is available online, it uses http, so you might get a privacy error in your browser; Or prepuilt in artifacts.zip, whic can be found in job artifacts: under (Number) files download the folder.

If you download the zip folder just open index.html in your browser.

Or you can build the docs yourself.

MkDocs

To create the docs with MkDocs: Install via

pip install mkdocs

run:

mkdocs serve

from the main directory and follow the link shown (localhost)

License

This project is licensed under the terms of the GNU-GPL-3.0 license.

Examples

Please see the Documentation for more Examples and information on the full capabilities

from snowpat import pysmet as smet
from snowpat import snowpackreader as spr

Examples iCSV

from snowpat import icsv

file = icsv.read(filename)
data_pandas = file.data
data_xarray = file.to_xarray()
# metadata and fields can be accessed with get_attribute
field_delimiter = file.metadata.get_attribute("field_delimiter")
fields = file.fields.get_attribute("fields")
# required keys will always be present, as a sanity check is done. Any other might return None if it is not available.
# To see what metadata is available, you can print the information:
file.info() # prints information about the whole file
print(file.metadata) # prints information on the metadata only
print(file.fields) # print information on the fields section

# changing metadata
file.metadata.set_attribute("field_delimiter", ":")

# and for writing to an output again (if no output filename is provided, the given filename is used with an out flag):
file.write(out_filename)

# It is possible to convert SMET files to iCSV:
from snowpat import pysmet as smet
smet_file = smet.read(smet_filename)
icsv_file = from_smet(smet_file)

Examples pySMET

from snowpat import pysmet as smet

file = smet.read(filename)
data_pandas = file.data
data_numpy = file.toNumpy()
# meta_data only contains the mandatory SMET metadata
station_id = file.meta_data.station_id
lon = file.meta_data.location.longitude

# optional_meta_data according to the file format can be accessed like this:
timezone = file.optional_meta_data.tz

# acdd metadata (anything preceded with acdd_ or known acdd attributes are stored in acdd metadata)
acdd_creator_name = file.acdd_meta_data.get_attribute("creator_name")

# everything else is in other metadata
value = file.other_metadata["key"]

# changing metadata
file.meta_data.station_ID = "WFJ"
file.acdd_meta_data.set_attribute("creator_name", "SomeName")

# for easier access and visibility of metadata do:
file.all_meta_data # And access values by keys in this dictionary

# and for writing to an output again (if no output filename is provided, the given filename is used with an out flag):
file.write(out_filename)

# a summary is also available wih
file.info()

#UNTESTED:
# it is also possible to merge to SMET files, as long as they are compatible (metadata and fields)
other_file = smet.read(other_filename)
file.merge(other_file)

# or
list_of_files_to_merge = [filename1, filename2,filename3,...]
merged_file = smet.merge_files(list_of_files_to_merge)

Examples snowpackreader

from snowpat import snowpackreader as spr
pro = spr.readPRO("test.pro")

# print a summary of the file
pro.info()

# all available dates
dates = pro.get_all_dates()

# will only return data above the ground after this
pro.discard_below_ground(True)
# get a Snowpack object (internal data class for Profiles) on a specific date
profile = pro.get_profile_on(dates[0])
# convert it to a dataframe with minimum stability and surface hoar as metadata
# column names will be data codes, except for "0500"= height (layer boundaries)-> 2 columns: layer middle and layer thickness
profile.toDf().head()
wl = profile.weak_layer # or profile.get_param["0534"]
sh = profile.surface_hoar # pr profile.get_param["0514"]

# There is help, to deal with the DataCodes:
# per default, the names are as in the .pro Header (without units)
pro.update_name_of_code("0503", "Snow Density")
density_code = pro.name_to_code("Snow Density")

# read from JSON (as best as it can)
profile, metadata, date = spr.read_json_profile("test.json")

# write profile to .pro
metadata = {
    "StationName": "Test",
    "Latitude": 47.123,
    "Longitude": 8.123,
    "Altitude": 1234,
    "SlopeAngle": 12,
    "SlopeAzi": 123
}
date = datetime.datetime.now()
pro.write_pro_file("out.pro", metadata, date)

Logo was creaeted with: hotpot.ai/art-generator

Metadata

Release files for snowpat 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snowpat 0.12.0
File Size Uploaded Provenance Actions
snowpat-0.12.0.tar.gz 477.6 kB Without provenance Details for snowpat-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for snowpat 0.12.0
File Interpreter ABI Platform Actions
snowpat-0.12.0-py3-none-any.whl Python 3 none any Details for snowpat-0.12.0-py3-none-any.whl

Total release size: 970.2 kB

Release files / snowpat-0.12.0.tar.gz

Download URL snowpat-0.12.0.tar.gz
Size 477.6 kB
Tags Source
SHA-256 checksum
How to use checksums
43181785114bcf8ba03ddcaf6eace3194919154f82138aa57347f9c8a771bbbb
BLAKE2b-256 checksum
How to use checksums
ab91c8fe791f225f762a610c8f3fe92fc41612d519b605fb535601069351228a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / snowpat-0.12.0-py3-none-any.whl

Download URL snowpat-0.12.0-py3-none-any.whl
Size 492.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9635a5fafbaaaf7d26fff40a6c34e9d6a2ce8dd7837a2eb8bec409262c26f4e7
BLAKE2b-256 checksum
How to use checksums
f1824b8b6b810eb3eb24fd0d7bc87d4c65157012c1b68f419b254ff499bab05f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for snowpat 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page