snowexsql package¶
Submodules¶
snowexsql.analysis module¶
snowexsql.conversions module¶
Module contains all conversions used for manipulating data. This includes: filetypes, datatypes, etc. Many tools here will be useful for most end users of the database.
- snowexsql.conversions.points_to_geopandas(results)[source]¶
Converts a successful query list into a geopandas data frame
- Args:
results: List of PointData objects
- Returns:
df: geopandas.GeoDataFrame instance
- snowexsql.conversions.query_to_geopandas(query, engine, **kwargs)[source]¶
Convert a GeoAlchemy2 Query meant for postgis to a geopandas dataframe. Requires that a geometry column is included
- Args:
query: GeoAlchemy2.Query Object engine: sqlalchemy engine
- Returns:
df: geopandas.GeoDataFrame instance
snowexsql.data module¶
Module contains all the data models for the database. Classes here actually represent tables where columns are mapped as attributed. Any class inheriting from Base is a real table in the database. This is called Object Relational Mapping in the sqlalchemy or ORM.
- class snowexsql.data.ImageData(**kwargs)[source]¶
Bases:
snowexsql.data.SnowData
,snowexsql.data.Measurement
,sqlalchemy.orm.decl_api.Base
Class representing the images table. This table holds all images/rasters
- date¶
- date_accessed¶
- description¶
- doi¶
- id¶
- instrument¶
- observers¶
- raster¶
- site_name¶
- time_created¶
- time_updated¶
- type¶
- units¶
- class snowexsql.data.LayerData(**kwargs)[source]¶
Bases:
snowexsql.data.SingleLocationData
,snowexsql.data.Measurement
,sqlalchemy.orm.decl_api.Base
Class representing the layers table. This table holds all layers or profile data. Here a single data entry is a single value at depth in the snowpack and a single coordinate pair. e.g. SMP profiles, Hand hardness, temperature etc…
- bottom_depth¶
- comments¶
- date¶
- date_accessed¶
- depth¶
- doi¶
- easting¶
- elevation¶
- flags¶
- geom¶
- id¶
- instrument¶
- latitude¶
- longitude¶
- northing¶
- observers¶
- pit_id¶
- sample_a¶
- sample_b¶
- sample_c¶
- site_id¶
- site_name¶
- time¶
- time_created¶
- time_updated¶
- type¶
- units¶
- utm_zone¶
- value¶
- class snowexsql.data.Measurement[source]¶
Bases:
object
Base Class providing attributes required for a measurement of any kind
- instrument = Column(None, String(length=50), table=None)¶
- observers = Column(None, String(length=100), table=None)¶
- type = Column(None, String(length=50), table=None)¶
- units = Column(None, String(length=50), table=None)¶
- class snowexsql.data.PointData(**kwargs)[source]¶
Bases:
snowexsql.data.SingleLocationData
,snowexsql.data.Measurement
,sqlalchemy.orm.decl_api.Base
Class representing the points table. This table holds all point data. Here a single data entry is a single coordinate pair with a single value e.g. snow depths
- date¶
- date_accessed¶
- doi¶
- easting¶
- elevation¶
- equipment¶
- geom¶
- id¶
- instrument¶
- latitude¶
- longitude¶
- northing¶
- observers¶
- site_id¶
- site_name¶
- time¶
- time_created¶
- time_updated¶
- type¶
- units¶
- utm_zone¶
- value¶
- version_number¶
- class snowexsql.data.SingleLocationData[source]¶
Bases:
snowexsql.data.SnowData
Base class for points and profiles
- easting = Column(None, Float(), table=None)¶
- elevation = Column(None, Float(), table=None)¶
- geom = Column(None, Geometry(geometry_type='POINT', from_text='ST_GeomFromEWKT', name='geometry'), table=None)¶
- latitude = Column(None, Float(), table=None)¶
- longitude = Column(None, Float(), table=None)¶
- northing = Column(None, Float(), table=None)¶
- site_id = Column(None, String(length=50), table=None)¶
- time = Column(None, Time(timezone=True), table=None)¶
- utm_zone = Column(None, Integer(), table=None)¶
- class snowexsql.data.SiteData(**kwargs)[source]¶
Bases:
snowexsql.data.SingleLocationData
,sqlalchemy.orm.decl_api.Base
Table for storing pit site meta data, This table doesn’t represent any main data record but only support data for each site
- air_temp¶
- aspect¶
- date¶
- date_accessed¶
- doi¶
- easting¶
- elevation¶
- geom¶
- ground_condition¶
- ground_roughness¶
- ground_vegetation¶
- id¶
- latitude¶
- longitude¶
- northing¶
- pit_id¶
- precip¶
- site_id¶
- site_name¶
- site_notes¶
- sky_cover¶
- slope_angle¶
- time¶
- time_created¶
- time_updated¶
- total_depth¶
- tree_canopy¶
- utm_zone¶
- vegetation_height¶
- weather_description¶
- wind¶
- class snowexsql.data.SnowData[source]¶
Bases:
object
Base class for which all data will have these attributes
- date = Column(None, Date(), table=None)¶
- date_accessed = Column(None, Date(), table=None)¶
- doi = Column(None, String(length=50), table=None)¶
- id = Column(None, Integer(), table=None, primary_key=True, nullable=False)¶
- site_name = Column(None, String(length=250), table=None)¶
- time_created = Column(None, DateTime(timezone=True), table=None, server_default=DefaultClause(<sqlalchemy.sql.functions.now at 0x7f30eef53190; now>, for_update=False))¶
- time_updated = Column(None, DateTime(timezone=True), table=None, onupdate=ColumnDefault(<sqlalchemy.sql.functions.now at 0x7f30eef533d0; now>))¶
snowexsql.db module¶
This module contains tool used directly regarding the database. This includes getting a session, initializing the database, getting table attributes, etc.
- snowexsql.db.get_db(db_str, credentials=None, return_metadata=False)[source]¶
Returns the DB engine, MetaData, and session object
- Args:
db_str: Just the name of the database credentials: Path to a json file containing username and password for the database return_metadata: Boolean indicating whether the metadata object is
being returned, useful only for developers
- Returns:
- tuple: engine - sqlalchemy Engine object for directly sending
querys to the DB
- session - sqlalchemy Session Object for using object
relational mapping (ORM)
- metadata (optional) - sqlalchemy MetaData object for
modifying the database
snowexsql.functions module¶
This module holds all PostGIS functions that have not been mapped yet for use with ORM. Many function already exist in GeoAlchemy.functions module
- class snowexsql.functions.ST_Clip(*args, **kwargs)[source]¶
Bases:
geoalchemy2.functions.GenericFunction
- identifier = 'ST_Clip'¶
- name = 'ST_Clip'¶
- type¶
alias of
geoalchemy2.types.Raster
- class snowexsql.functions.ST_Count(*args, **kwargs)[source]¶
Bases:
geoalchemy2.functions.GenericFunction
- identifier = 'ST_Count'¶
- name = 'ST_Count'¶
- type¶
alias of
sqlalchemy.sql.sqltypes.Integer
- class snowexsql.functions.ST_PixelAsPoint(*args, **kwargs)[source]¶
Bases:
geoalchemy2.functions.GenericFunction
- identifier = 'ST_PixelAsPoint'¶
- name = 'ST_PixelAsPoint'¶
- type¶
alias of
geoalchemy2.types.Geometry
- class snowexsql.functions.ST_PixelAsPoints(*args, **kwargs)[source]¶
Bases:
geoalchemy2.functions.GenericFunction
- identifier = 'ST_PixelAsPoints'¶
- name = 'ST_PixelAsPoints'¶
- type¶
alias of
geoalchemy2.types.CompositeType
- typemap = {'geom': ARRAY(Geometry(from_text='ST_GeomFromEWKT', name='geometry')), 'val': ARRAY(Float()), 'x': ARRAY(Integer()), 'y': ARRAY(Integer())}¶
snowexsql.utilities module¶
Module for storing misc. type functions that don’t warrant a separate module but to provide some use in the code set.
- snowexsql.utilities.get_logger(name, debug=True, ext_logger=None)[source]¶
Retrieve a colored logs logger and assign a custom name to it.
- Args:
name: Name of the loggger debug: Boolean for where to show debug statements ext_logger: Recieves a logger object and installs colored logs to it.
- Returns:
log: Logger object with colored logs installed
Module contents¶
Top-level package for snowexsql.