# -*- coding: utf-8 -*-
"""
Created on Wed May 6 10:56:38 2020
@author: xavier.mouy
"""
import pandas as pd
import os
[docs]
class DeploymentInfo():
"""
A class to handle acoustic deployment metadata.
Carries deployment metadata that can be used to populate metadata fields
in :class:`~ecosound.core.annotation.Annotation` or
:class:`~ecosound.core.measurement.Measurement` objects.
Attributes
----------
data : pandas DataFrame
DataFrame containing deployment information.
"""
[docs]
def __init__(self):
"""
Initialize object with empty .data attribute.
Returns
-------
None.
"""
self.data =[]
[docs]
def write_template(self, filepath):
"""
Create a blank deployment file.
Create an empty template CSV file with the required headers. The
created file contains only the column headers; an operator must fill
in all deployment information manually. Once complete, this file can
be loaded with :meth:`DeploymentInfo.read`.
Parameters
----------
filepath : str
path and name of the deployment csv file to create.
Returns
-------
None. Write a blank csv deployment file that an operator can fill in.
"""
if os.path.isfile(filepath):
raise ValueError('File already exists.')
metadata = pd.DataFrame({
'audio_channel_number': [],
'UTC_offset': [],
'sampling_frequency': [],
'bit_depth': [],
'mooring_platform_name': [],
'recorder_type': [],
'recorder_SN': [],
'hydrophone_model': [],
'hydrophone_SN': [],
'hydrophone_depth': [],
'location_name': [],
'location_lat': [],
'location_lon': [],
'location_water_depth': [],
'deployment_ID': [],
'deployment_date':[],
'recovery_date':[],
})
metadata.to_csv(filepath,
sep=',',
encoding='utf-8',
header=True,
index=False,
)
[docs]
def read(self, filepath):
"""
Read metadata information from csv file.
Load data from a CSV file containing deployment metadata and populate
the ``data`` attribute of the DeploymentInfo object. The CSV file must
follow the same column headers and format as the template generated by
:meth:`DeploymentInfo.write_template`.
Parameters
----------
filepath : str
Path of the csv file to read.
Returns
-------
None. Populates the ``data`` attribute of the DeploymentInfo object
with the contents of the CSV file.
"""
df = pd.read_csv(filepath,
delimiter=',',
#header=None,
skiprows=0,
na_values=None,
)
self.data = df
return df