-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added SBE 37 MicroCAT * Added .gitattributes * Add LFS tracking to .asc file * run autoformatting * Added SBE 37 MicroCAT * Added SBE37 MicroCat to setup and init * Fixed bugs in mc.py * Fix mc test script * Improve profiling CTD obs and row_start values (#243) * Reset row_start and obs indexes after trimming, and add warning message * Improve long_names for profiles * Update standard_name for specific conductance (#244) * Added SBE 37 MicroCAT * Added .gitattributes * Added .gitattribute * run autoformatting * Added SBE 37 MicroCAT * Added SBE37 MicroCat to setup and init * Fixed bugs in mc.py * Fix mc test script * Made pull request edits to mc.py * Added .gitignore * Added .gitignore * Fixed .gitattributes --------- Co-authored-by: De Meo <[email protected]> Co-authored-by: Dan Nowacki <[email protected]>
- Loading branch information
1 parent
f7c6850
commit c7593d0
Showing
12 changed files
with
325 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Seabird SBE 37 MicroCAT | ||
************** | ||
|
||
Data will generally be processed using a series of run scripts. The first script for each instrument type | ||
depends on two :doc:`configuration files </config>`. | ||
|
||
Instrument data to raw .cdf | ||
=========================== | ||
|
||
Convert from exported .csv file to a raw netCDF file with .cdf extension using ``runmcasc2cdf.py``. | ||
|
||
runmcasc2cdf.py | ||
---------------- | ||
|
||
.. argparse:: | ||
:ref: stglib.core.cmd.mcasc2cdf_parser | ||
:prog: runmcasc2cdf.py | ||
|
||
Raw .cdf to CF-compliant .nc | ||
============================ | ||
|
||
Convert the raw .cdf data into a CF-compliant netCDF file with .nc extension using ``runmccdf2nc.py``. | ||
|
||
runmccdf2nc.py | ||
--------------- | ||
|
||
.. argparse:: | ||
:ref: stglib.core.cmd.mccdf2nc_parser | ||
:prog: runmccdf2nc.py |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
indexvel, | ||
iq, | ||
lisst, | ||
mc, | ||
rdi, | ||
rsk, | ||
sig, | ||
|
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,194 @@ | ||
import pandas as pd | ||
import xarray as xr | ||
|
||
from .core import qaqc, utils | ||
|
||
|
||
def read_asc(filnam, skiprows=50, encoding="utf-8"): | ||
"""Read data from an SBE 37 MicroCAT .asc file into an xarray | ||
Dataset. | ||
Parameters | ||
---------- | ||
filnam : string | ||
The filename | ||
skiprows : int, optional | ||
How many header rows to skip. Default 50 | ||
encoding : string, optional | ||
File encoding. Default 'utf-8' | ||
Returns | ||
------- | ||
xarray.Dataset | ||
An xarray Dataset of the MicroCAT data | ||
""" | ||
|
||
df = pd.read_csv( | ||
filnam, | ||
skiprows=skiprows, | ||
header=None, | ||
names=["Temp", "Cond", "Sal", "Date", "Time"], | ||
parse_dates={"time": ["Date", "Time"]}, | ||
encoding=encoding, | ||
index_col=False, | ||
) | ||
print(df) | ||
df.set_index("time", inplace=True) | ||
mc = df.to_xarray() | ||
return mc | ||
|
||
|
||
def asc_to_cdf(metadata): | ||
""" | ||
Load a raw .asc file and generate a .cdf file | ||
""" | ||
basefile = metadata["basefile"] | ||
|
||
ds = read_asc(basefile + ".asc", skiprows=metadata["skiprows"]) | ||
|
||
metadata.pop("skiprows") | ||
|
||
ds = utils.write_metadata(ds, metadata) | ||
|
||
ds = utils.ensure_cf(ds) | ||
|
||
# configure file | ||
cdf_filename = ds.attrs["filename"] + "-raw.cdf" | ||
|
||
ds.to_netcdf(cdf_filename, unlimited_dims=["time"]) | ||
|
||
print(f"Finished writing data to {cdf_filename}") | ||
|
||
return ds | ||
|
||
|
||
def cdf_to_nc(cdf_filename): | ||
""" | ||
Load a raw .cdf file and generate a processed .nc file | ||
""" | ||
|
||
# Load raw .cdf data | ||
ds = xr.open_dataset(cdf_filename) | ||
|
||
# remove units in case we change and we can use larger time steps | ||
ds.time.encoding.pop("units") | ||
|
||
# Rename variables to CF compliant names | ||
ds = ds_rename_vars(ds) | ||
|
||
# Add attributes | ||
ds = ds_add_attrs(ds) | ||
|
||
# Call QAQC | ||
ds = mc_qaqc(ds) | ||
|
||
# Run utilities | ||
ds = utils.create_z(ds) | ||
ds = utils.clip_ds(ds) | ||
ds = utils.ds_add_lat_lon(ds) | ||
ds = utils.create_nominal_instrument_depth(ds) | ||
ds = utils.add_start_stop_time(ds) | ||
ds = utils.add_min_max(ds) | ||
ds = utils.add_delta_t(ds) | ||
|
||
# Write to .nc file | ||
print("Writing cleaned/trimmed data to .nc file") | ||
nc_filename = ds.attrs["filename"] + "-a.nc" | ||
|
||
ds.to_netcdf( | ||
nc_filename, unlimited_dims=["time"], encoding={"time": {"dtype": "i4"}} | ||
) | ||
utils.check_compliance(nc_filename, conventions=ds.attrs["Conventions"]) | ||
|
||
print(f"Done writing netCDF file {nc_filename}") | ||
|
||
|
||
def ds_rename_vars(ds): | ||
""" | ||
Rename variables to be CF compliant | ||
""" | ||
varnames = {"Temp": "T_28", "Cond": "C_51", "Sal": "S_41"} | ||
|
||
# Check to make sure they exist before trying to rename | ||
newvars = {} | ||
for k in varnames: | ||
if k in ds: | ||
newvars[k] = varnames[k] | ||
return ds.rename(newvars) | ||
|
||
|
||
def ds_add_attrs(ds): | ||
""" | ||
Add attributes: units, standard name from CF website, long names | ||
""" | ||
ds = utils.ds_coord_no_fillvalue(ds) | ||
|
||
ds["time"].attrs.update( | ||
{"standard_name": "time", "axis": "T", "long_name": "time (UTC)"} | ||
) | ||
|
||
if "T_28" in ds: | ||
ds["T_28"].attrs.update( | ||
{ | ||
"units": "degree_C", | ||
"standard_name": "sea_water_temperature", | ||
"long_name": "Temperature", | ||
} | ||
) | ||
|
||
if "C_51" in ds: | ||
ds["C_51"].attrs.update( | ||
{ | ||
"units": "S/m", | ||
"long_name": "Conductivity", | ||
"standard_name": "sea_water_electrical_conductivity", | ||
} | ||
) | ||
|
||
if "S_41" in ds: | ||
ds["S_41"].attrs.update( | ||
{ | ||
"units": "1", | ||
"long_name": "Salinity, PSU", | ||
"comments": "Practical salinity units (PSU)", | ||
"standard_name": "sea_water_practical_salinity", | ||
} | ||
) | ||
|
||
return ds | ||
|
||
|
||
def mc_qaqc(ds): | ||
""" | ||
QA/QC | ||
Trim MicroCAT data based on metadata | ||
""" | ||
|
||
varlist = ["T_28", "C_51", "S_41"] | ||
|
||
[varlist.append(k) for k in ds.data_vars if k not in varlist] | ||
|
||
for var in varlist: | ||
ds = qaqc.trim_min(ds, var) | ||
|
||
ds = qaqc.trim_max(ds, var) | ||
|
||
ds = qaqc.trim_min_diff(ds, var) | ||
|
||
ds = qaqc.trim_min_diff_pct(ds, var) | ||
|
||
ds = qaqc.trim_max_diff(ds, var) | ||
|
||
ds = qaqc.trim_max_diff_pct(ds, var) | ||
|
||
ds = qaqc.trim_med_diff(ds, var) | ||
|
||
ds = qaqc.trim_med_diff_pct(ds, var) | ||
|
||
ds = qaqc.trim_bad_ens(ds, var) | ||
|
||
for var in varlist: | ||
ds = qaqc.trim_by_any( | ||
ds, var | ||
) # re-run and trim by other variables as necessary | ||
|
||
return ds |
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,6 @@ | ||
basefile: mc3575 | ||
filename: 11263mc | ||
LatLonDatum: NAD83 | ||
skiprows: 51 | ||
initial_instrument_height: 0.15 | ||
initial_instrument_height_note: height above seabed |
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,29 @@ | ||
SciPi; "John Warner" | ||
PROJECT; "USGS Coastal and Marine Hazards and Resources Program" | ||
EXPERIMENT; CCB21 | ||
DESCRIPTION; "Cape Cod Bay, Sandy Neck Beach, Barnstable, MA" | ||
title; "Time-series measurements of oceanographic and water quality data collected in Cape Cod Bay, Barnstable, MA, March 10 to April 7, 2021" | ||
DATA_SUBTYPE; MOORED | ||
DATA_ORIGIN; "USGS WHCMSC Coastal and Estuarine Dynamics" | ||
COORD_SYSTEM; GEOGRAPHIC | ||
Conventions; CF-1.8 | ||
MOORING; 1126 | ||
WATER_DEPTH; 8.7 | ||
WATER_DEPTH_NOTE; "(meters), Mean water level from pressure data" | ||
height_above_geopotential_datum; -0.5 | ||
geopotential_datum_name; NAVD88 | ||
latitude; 41.742668 | ||
longitude; -70.330457 | ||
magnetic_variation; -14.47 | ||
Deployment_date; "10-Mar-2021 15:58" | ||
Recovery_date; "07-Apr-2021 14:09" | ||
DATA_CMNT; "No magnetic variation recorded, used data from IGRF model via ngdc.noaa.gov." | ||
platform_type; Quadpod | ||
DRIFTER; 0 | ||
POS_CONST; 0 | ||
DEPTH_CONST; 0 | ||
WATER_MASS; "Cape Cod Bay" | ||
VAR_FILL; NaN | ||
institution; "United States Geological Survey, Woods Hole Coastal and Marine Science Center" | ||
institution_url; https://woodshole.er.usgs.gov | ||
Field_Activity_Number; 2021-018-FA |
Git LFS file not shown
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