HydrologicEngineeringCenter / FIRO_TSEnsembles

Time series of ensembles in SqLite
Other
2 stars 2 forks source link

Ensemble Units and EnsembleTimeSeries Units Confusion #176

Open danhamill opened 1 year ago

danhamill commented 1 year ago

Ensemble takes a unit string in its constructor

https://github.com/HydrologicEngineeringCenter/FIRO_TSEnsembles/blob/cdb29fd0b417a24eb1ae692d78d74c4209a5a437/FIRO_TSEnsembles/src/main/java/hec/ensemble/Ensemble.java#L24-L28

EnsembleTimeSeries also takes a unit string in its constructor

https://github.com/HydrologicEngineeringCenter/FIRO_TSEnsembles/blob/cdb29fd0b417a24eb1ae692d78d74c4209a5a437/FIRO_TSEnsembles/src/main/java/hec/ensemble/EnsembleTimeSeries.java#L37-L40

The schema for the ensemble table does not have a unit string

https://github.com/HydrologicEngineeringCenter/FIRO_TSEnsembles/blob/cdb29fd0b417a24eb1ae692d78d74c4209a5a437/FIRO_TSEnsembles/src/main/resources/database.sql#L64-L75

If read an ensemble from an existing database and add it to a new ensemble time series and write to a database:

recordID = RecordIdentifier("american.FOLSOM","flow")
newEts = EnsembleTimeSeries(recordID, "kcfs","PER-AVER", randomID)
e = eTs.getEnsemble(issueDate)
randomMember=1
selectedMember = e.getValues()[randomMember:randomMember+1]
selectedEnsemble = Ensemble(issueDate, selectedMember, e.getStartDateTime(), Duration.ofHours(1), "cfs" )
newEts.addEnsember(selectedEnsemble)
tempDb = SqliteDatabase(templateDb, SqliteDatabase.CREATION_MODE.CREATE_NEW_OR_OPEN_EXISTING_UPDATE)

I initially set selectedEnsemble units to cfs because .getValues() on the original ensemble e returns in units of cfs.

When I go to read the ensemble from tempDb and call getUnits I am seeing kcfs units

image

danhamill commented 1 year ago

I am concerned because I don want the units to be converted twice.

The only place I can see where kcfs gets converted to cfs is:

https://github.com/HydrologicEngineeringCenter/FIRO_TSEnsembles/blob/cdb29fd0b417a24eb1ae692d78d74c4209a5a437/FIRO_TSEnsembles/src/main/java/hec/ensemble/RfcCsvFile.java#L124C1-L144C6

HenryGeorgist commented 1 year ago

units arent necessarily fully implemented it seems like we need to update the table if it is not currently tracked and modified on conversion.

danhamill commented 1 year ago

so maybe this should be 'cfs'

https://github.com/HydrologicEngineeringCenter/FIRO_TSEnsembles/blob/cdb29fd0b417a24eb1ae692d78d74c4209a5a437/FIRO_TSEnsembles/src/main/java/hec/ensemble/CsvEnsembleReader.java#L104

since the units are converted parseData

https://github.com/HydrologicEngineeringCenter/FIRO_TSEnsembles/blob/cdb29fd0b417a24eb1ae692d78d74c4209a5a437/FIRO_TSEnsembles/src/main/java/hec/ensemble/RfcCsvFile.java#L140

ktarbet commented 1 year ago

You have raised two issues:

CREATE TABLE IF NOT EXISTS ensemble_timeseries
      ( id integer not null primary key,
       location NVARCHAR(100), 
       parameter_name NVARCHAR(100), 
       units NVARCHAR(100), 
       data_type NVARCHAR(100), 
       version NVARCHAR(100),
       catalog_id int references catalog(id)
                 );