This project contains code in support of the Lake Clark NPP Fish Monitoring
database LACL_Fish
hosted internally on the Alaska Region's SQL Server.
Contacts:
- Dan Young (LACL)
- Joel Reynolds (NR)
- James Kramer (LACL)
This project has had 3 phases, starting in 2014, as of 2020, only phases 2 and 3 appear to be active.
This was the original 2014 project. It loaded and processed different data files from several RFID sensors that collected data on RFID tagged fish. The raw files are stored in the database as well as data tables and location data resulting from the processing of the files. This project was modeled on the Animal Movements Database.
The C# solution and most of the files/folders are part of this phase. It also created the majority of the database objects. This phase provides a simple WinForms GUI app (FileUploader project) for uploading files to the database and reviewing the files (and their contents). It requires one library project DataModel.
There are also two SQL CLR projects (to load custom functions into the SQL Server database).
-
This project creates an SQL Assembly for a store procedure called
dbo.ProcessRawDataFile
which takes aFileId
from thedbo.RawDataFiles
and process the file contents in the blob column into tabular data in thedbo.TelemetryData*
tables depending on the type/contents of file. This assembly has been loaded into the server. If it needs to be modified, see the Animal Movements repo for instructions on loading the compiled assembly into the database and creating the stored procedure that calls it. -
This project creates an SQL Assembly for several scalar valued functions (
dbo.DateTimeFromAts
,dbo.DateTimeFromAtsWithSeconds
,dbo.LocalTime
,dbo.Sha1Hash
anddbo.UtcTime
) that can be called by other database objects Currently onlydbo.Sha1hash
is being used in the definition of thedbo.RawDataFiles
table. If these functions need to be modified, see the Animal Movements repo for instructions on loading the compiled assembly into the database and creating the functions that call it.
Data files provided by Dan Young were loaded into the database, and a number of queries were provided to analyze the data and visualize it in ArcMap. It has not been updated since 2014.
NOTE: This phase was never fully automated. Some of the processing was done manually with the queries found in Database/Helpful Queries.sql.
AntennaLocations
- Derived fromTelemetryData*
tablesLocations
- Derived fromTelemetryData*
tablesLookupFileFormats
- Manually created/maintainedLookupLocationType
- Manually created/maintainedLookupRadioManufacturers
- Manually created/maintainedRawDataFiles
- Maintained by user usingFileUploader
app.TelemetryDataATSStationary
- Derived fromRawDataFiles
TelemetryDataATSTracking
- Derived fromRawDataFiles
TelemetryDataSRX400Antennas
- Derived fromRawDataFiles
TelemetryDataSRX400BatteryStatus
- Derived fromRawDataFiles
TelemetryDataSRX400Channels
- Derived fromRawDataFiles
TelemetryDataSRX400Environments
- Derived fromRawDataFiles
TelemetryDataSRX400Locations
- Derived fromRawDataFiles
TelemetryDataSRX400TrackingData
- Derived fromRawDataFiles
ProcessRawDataFile
- wrapper for CLR (C#) Assembly parse the file contents blob if a record inRawDataFiles
and populates theTelemetryData*
tablesRawDataFile_Delete
- deletes a record fromRawDataFiles
. Users cannot directly edit the table and must use this procedure which validates the request and applies required business rules.RawDataFile_Insert
- Adds a record toRawDataFiles
. See discussion above.
DateTimeFromAts
- Returns a Datetime from the text in an ATS data file.DateTimeFromAtsWithSeconds
- Returns a Datetime from the text in an ATS data file.LocalTime
- Returns a local DateTime from a UTC DataTime.Sha1Hash
- Provides a computed column in theRawDataFiles
table. Hashes the file contents column (blob) to allow detection of duplicate files.UtcTime
- Returns a UTC DateTime from a local DataTime.
LocationsWithFileError
- Location data suitable for ArcGIS
Also see Database/Helpful Queries.sql.
This phase added sonar data files to the LACL Fish database. These files are
text output from a manual review process of raw sonar data by a technician.
The text files are processed by a Python script and the data is loaded into
the three SonarCount*
tables. All of the files for this phase are in the
SonarFiles folder.
I recall this phase began in 2018 with an initial upload of data from 2016-2018. Updates were done with data collected in 2019 and then again in 2020.
Every year, a folder of files is provided by LACL (James Kramer in 2020).
The parse.py
script Config
object is edited to first test the input files
(an entire folder of files can be processed at once). If there are no
processing errors in the test, then edit the Config
to do an actual database
update and then re-run the script. In the past the processing has failed due to
a corrupt (usually empty) sonar file. These can be removed from the processing
folder and returned to LACL for remedial action. The remainder of the files can
then be processed. It is also possible that a new (unexpected) file format is
submitted which may require edits to the script. Hopefully small tweaks to the
global configuration parameters will be sufficient.
Once the data is loaded the LACL staff access the data directly using Azure Data Studio and SQL queries.
build_db_with_types.sql
- An SQL script to build the initial schema. This schema was not used (seebuild_db.sql
), as there were too many data loading errors importing text to real database types likeint
/float
/datetime
, etc. instead the schema uses allvarchar
columns, that are converted in queries as needed for analysis.build_db.sql
- An SQL script initially used to create the initial empty tables. This is no longer needed, unless the database is recreated from scratch.parse.py
- a Python 2/3 script to read a folder of sonar data files and check for potential problems (without loading data), or load the data into the database. This script needs to be edited before being run on a new collection of data files. See the comments at the head of this file for additional information on the correct usage.project_assignment.sql
- Correct the project names after the initial load. Theparse.py
script has been corrected since then and this script is no longer needed.Sample_Queries.sql
- Examples of queries the users might use to start analyzing the data.Variability_of_Attributes.sql
- Analysis of the variability of the values inSonarCountFileSummaries
. This can be used to normalized or aggregate the data. Currently is only for information.
SonarCountFileCounts
- In addition to summary metadata, each file usually includes a list of records for each fish count in the file. All these records are captured in this table.SonarCountFiles
- One record for each file uploaded. The record includes aContents
field which contains the entire contents of the source file.SonarCountFileSummaries
- Each file contains a summary (metadata) about the counts in the file. This data is extracted to tabular form in this table (one record per file).
This project is derived from a spreadsheet created each year that captures the manual escapement counts from observers in the Newhalen fish counting tower. The data has been binned into time intervals for most days during the summer.
The initial spreadsheet was converted to CSV and upload into the Escapements
table. Each year a new spreadsheet is provided and it is appended to the
table with the same process. It may be necessary to adjust the layout and
formatting of the excel file before exporting to CSV, so that the CSV file
creates the same schema. I suggest loading into a test table to ensure a
compatible schema before appending the test table into the Escapements
table.
Azure Data Studio and Sql Server Management Studio have tools to load a CSV
file into a new table in SQL server. You can check for Primary Key violations
before appending with something like
Select Location, DateStamp, Hour, count(*) as Duplicates
from Escape2020 group by Location, DateStamp, Hour having count(*) > 1
Then use a command like
INSERT INTO Escapements SELECT * FROM Escape2020
Once the data is loaded the LACL staff access the data directly using Azure Data Studio and SQL queries.
All project Files are in the Escapements folder.
build_db.sql
- An SQL script to recreate an emptyEscapements
table. This is no longer needed, unless the database is recreated from scratch.LACL_Tower_vs_Sonar_Counts.sql
- A request query that compares the sonar data (phase 2) with the escapement data. See the comments in the file for details.
Escapements
- See build_db.sql for the table schema.