Skip to main content

Weave insitu data together

Project description

insitupy

https://img.shields.io/pypi/v/insitupy.svg https://img.shields.io/travis/m3works/insitupy.svg Documentation Status

Manage reading and analyzing raw files of insitu data. The goal is to get raw insitu data files into manageable classes with helpful functions and provide access to the data as GeoPandas Arrays.

The first application of this will be for SnowEx pit data.

THIS IS A WORK IN PROGRESS (use at your own risk as outlined in the MIT license). We fully welcome any contribution and ideas. Snow science works better together!

Features

  • Parsing of raw insitu data files with a variable number of header lines

  • Reading csv data files into a pandas DataFrame, and parsing metadata into usable format

  • Flexible user-defined variables

  • Reading both pit and point data

  • Parsing of date and location data

Example

I want to read in a file that looks like this:

# Location,East River
# Date/Local Standard Time,2020-04-27T08:45
# Latitude,38.92524
# Longitude,-106.97112
# Flags,random flag
# Top (cm),Bottom (cm),Density (kg/m3)
95.0,85.0,401.0
85.0,75.0,449.0
75.0,65.0,472.0

The metadata and data parsers are configured with a lot of defaults for working with SnowEx data, so the simple approach is

from insitupy.campaigns.snowex import SnowExProfileData
my_data = SnowExProfileDataCollection.from_csv(
    "./fake_data.csv", allow_map_failure=True
)
print(my_data.profiles[0].df)
print(my_data.profiles[0].metadata)

If you want to try your hand at defining variables yourself, you can do as follows:

I can define a metadata file that looks like this:

LATITUDE:
  auto_remap: true
  code: latitude
  description: Latitude
  map_from:
  - lat
  - latitude
  match_on_code: true
LONGITUDE:
  auto_remap: true
  code: longitude
  description: Longitude
  map_from:
  - long
  - lon
  - longitude
DATETIME:
  auto_remap: true
  code: datetime
  description: Combined date and time
  map_from:
  - Date/Local Standard Time
  - date/local_standard_time
  - datetime
  - "date&time"
  - date/time
  - date/local_time
  match_on_code: true
SITE_NAME:
  auto_remap: true
  code: site_name
  description: Name of campaign site
  map_from:
      - location
  match_on_code: true

and a primary variable file like:

BOTTOM_DEPTH:
  auto_remap: true
  code: bottom_depth
  description: Lower edge of measurement
  map_from:
  - bottom
  - bottom_depth
  match_on_code: true
DENSITY:
  auto_remap: true
  code: density
  description: measured snow density
  map_from:
  - density
  - density_mean
  match_on_code: true
DEPTH:
  auto_remap: true
  code: depth
  description: top or center depth of measurement
  map_from:
  - depth
  - top
  match_on_code: true
LAYER_THICKNESS:
  auto_remap: true
  code: layer_thickness
  description: thickness of layer
  map_from: null
  match_on_code: true

Then read in the file like this:

from insitupy.campaigns.snowex import SnowExProfileData
my_data = SnowExProfileDataCollection.from_csv(
    "./fake_data.csv", allow_map_failure=True,
    # Use the files YOU defined here
    primary_variable_files=["../primaryvariables.yaml"],
    metadata_variable_files=["../metadatavariables.yaml"],
)
print(my_data.profiles[0].df)
print(my_data.profiles[0].metadata)

Variables

Types of variables

There are two types of variable definitions:

  1. primary variables - These are the data that expect to be found in the data columns

  2. metadata variables - These are the data that are expected to be found in the header lines

Variables definitions

The variables are defined the same way, in separate yaml files. A standard definition looks like this

TOTAL_DEPTH:
  code: total_depth
  description: Total depth of measurement
  map_from:
  - total_snow_depth
  - hs
  match_on_code: true
  auto_remap: true
  • code: The string that will be used to reference this variable

  • description: A description of the variable

  • map_from: A list of strings that will be used to match the variable in the data

  • match_on_code: If true, the variable will be matched if the code values is found

    in the data, not just the map_from values

  • auto_remap: If true, the variable will be remapped to the code value

Overriding variables

We can provide a list of variable files that will override as you go down the list. For instance, if we created our variables like this

from insitupy.variables import ExtendableVariables
variable_paths = ['variables/primary_variables1.yaml', 'variables/primary_variables2.yaml']
my_vars = ExtendableVariables(variable_paths)

Any variable with the same key in primary_variables2.yaml will override the same variable in primary_variables1.yaml

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2024-03-27)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

insitupy-0.3.0.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

insitupy-0.3.0-py2.py3-none-any.whl (30.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file insitupy-0.3.0.tar.gz.

File metadata

  • Download URL: insitupy-0.3.0.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for insitupy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7fd5fbc2c451234645f05a66d90f36c0a7e9946856ed36b1ff228670132d9d4b
MD5 7a96d02e710f30e945ffb34263aeef65
BLAKE2b-256 2a8fcfb03df7c814d539d4d519fbaa0eb8ac290a2b0e059bd886f265aa9be31a

See more details on using hashes here.

File details

Details for the file insitupy-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: insitupy-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 30.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for insitupy-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9ce7112b164fa959540fa362157ae4a51861e383635358df65a3fd894fade8c4
MD5 72b3f5d2a6fece37d8ce93f4967f563f
BLAKE2b-256 a74024e07b364617f63ffc7930c93d14a795fb7371e944ed1a43ff269b83b3ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page