-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated minor things in the readme * Added in script published lidar canopy height and snow depth for farmers-creamers AK * Added in CSU gpr for farmers-creamers in AK. * Fixed #27
- Loading branch information
1 parent
f05cbd9
commit dbac8e0
Showing
6 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
""" | ||
Upload the SnowEx AK lidar products from Farmers and Creamers field | ||
for now. | ||
# To run with all the scripts | ||
python run.py | ||
# To run individually | ||
python add_AK_lidar.py | ||
""" | ||
import os | ||
from datetime import date | ||
from pathlib import Path | ||
from subprocess import Popen | ||
|
||
from snowex_db.batch import UploadRasterBatch | ||
|
||
|
||
def main(): | ||
""" | ||
Uploader script partial SnowEx Lidar | ||
""" | ||
|
||
# Typical kwargs for the dataset | ||
kwargs = {'instrument': 'lidar', | ||
'observers': 'chris larsen', | ||
'description': '0.5m products', # Datasheet says 0.25 but data is actually 0.5 | ||
'tiled': True, | ||
'epsg': 26906, # Alaska is Zone 6 | ||
'no_data': -9999, | ||
'in_timezone': 'AKST', | ||
'doi':'https://doi.org/10.5067/BV4D8RRU1H7U', | ||
"site_name": "farmers-creamers" | ||
} | ||
# Build a list of uploaders and then execute them | ||
uploaders = [] | ||
|
||
# Directory of SNOWEX products | ||
lidar_dir = Path('../download/data/SNOWEX/SNEX23_Lidar.001/') | ||
reprojected = lidar_dir.joinpath('reprojected') | ||
|
||
if not reprojected.is_dir(): | ||
os.mkdir(reprojected) | ||
|
||
|
||
# Reproject using GDAL | ||
print('Reprojecting files...') | ||
raw_files = lidar_dir.glob('*/*.tif') | ||
for f in raw_files: | ||
# Watch out for files already in the reprojection | ||
if f.parent != reprojected: | ||
output = reprojected.joinpath(f.name) | ||
cmd = f'gdalwarp -overwrite -t_srs EPSG:{kwargs["epsg"]} {f} {output}' | ||
print(cmd) | ||
p = Popen(cmd,shell=True) | ||
p.wait() | ||
|
||
######################################## Farmers/Creamers Field (FLCF) ################################################### | ||
# Snow off - canopy height | ||
f = reprojected.joinpath("SNEX23_Lidar_FLCF_CH_0.25M_20221024_V01.0.tif") | ||
uploaders.append(UploadRasterBatch([f], date=date(2022, 10, 24), | ||
type="canopy_height", units="meters", **kwargs)) | ||
|
||
# Snow Depth | ||
f = reprojected.joinpath(reprojected, "SNEX23_Lidar_FLCF_SD_0.25M_20230311_V01.0.tif") | ||
uploaders.append(UploadRasterBatch([f], date=date(2023, 3, 11), | ||
type="depth", units="meters", **kwargs)) | ||
|
||
errors = 0 | ||
for u in uploaders: | ||
u.push() | ||
errors += len(u.errors) | ||
|
||
|
||
# Add this so you can run your script directly without running run.py | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
Read in the SnowEx 2023 CSU GPR data collected at Farmers Loop and Creamers Field. | ||
1. Data is preliminary and currently only available via email from Randall B. | ||
2A. python run.py # To run all together all at once | ||
2B. python add_gpr.py # To run individually | ||
""" | ||
|
||
from pathlib import Path | ||
from snowexsql.db import get_db | ||
from snowex_db.upload import PointDataCSV | ||
import pandas as pd | ||
|
||
|
||
def main(): | ||
file = Path('../download/data/SnowEx223_FLCF_1GHz_GPR_CSU.csv') | ||
|
||
# Fix quirks | ||
df = pd.read_csv(file, dtype=str) | ||
|
||
# Upload is not able to handle the Notes col. So just remove it for now | ||
modified = file.parent.joinpath(file.stem + f'_mod{file.suffix}') | ||
print(f"Removing Notes Column prior to upload. Writing to {modified}") | ||
|
||
coi = [c for c in df.columns if c != 'Notes'] | ||
|
||
# No time is a problem. Use 12 AKST == 9pm (21:00) UTC | ||
df['Time[HHMM]'] = '21:00' | ||
|
||
# Write out the modified version | ||
df[coi].to_csv(modified, index=False) | ||
|
||
|
||
kwargs = { | ||
# Keyword argument to upload depth measurements | ||
'depth_is_metadata': False, | ||
|
||
# Constant Metadata for the GPR data | ||
'site_name': 'farmers-creamers', | ||
'observers': 'Randall Bonnell', | ||
'instrument': 'pulseEkko pro 1 GHz GPR', | ||
'in_timezone': 'UTC', | ||
'out_timezone': 'UTC', | ||
'doi': None, # Data is preliminary | ||
'epsg': 26906 | ||
} | ||
|
||
# Grab a db connection to a local db named snowex | ||
db_name = 'localhost/snowex' | ||
engine, session = get_db(db_name, credentials='./credentials.json') | ||
|
||
# Instantiate the point uploader | ||
csv = PointDataCSV(modified, **kwargs) | ||
# Push it to the database | ||
csv.submit(session) | ||
|
||
# Close out the session with the DB | ||
session.close() | ||
|
||
# return the number of errors for run.py can report it | ||
return len(csv.errors) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters