Skip to content

Commit

Permalink
IO Changes for V2.0.0 (#739)
Browse files Browse the repository at this point in the history
* ENH: Initial commit for io v2

* ENH: Updating IO module for V2.0.0 standards and all the subsequent changes.

* FIX: Fix for old syntax.

* FIX: Update test_plotting.py for new syntax.

* FIX: Fix for example needing to be updated.

---------

Co-authored-by: Zach Sherman <[email protected]>
Co-authored-by: zssherman <[email protected]>
  • Loading branch information
3 people authored Nov 30, 2023
1 parent 14a9757 commit c985def
Show file tree
Hide file tree
Showing 67 changed files with 290 additions and 302 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ An example:

.. code-block:: python
def read_netcdf(filenames, variables=None):
def read_arm_netcdf(filenames, variables=None):
"""
Returns `xarray.Dataset` with stored data and metadata from a
Expand Down Expand Up @@ -226,7 +226,7 @@ An example:
import act
the_ds, the_flag = act.io.armfiles.read_netcdf(
the_ds, the_flag = act.io.arm.read_arm_netcdf(
act.tests.sample_files.EXAMPLE_SONDE_WILDCARD)
print(the_ds.act.datastream)
"""
Expand Down
10 changes: 5 additions & 5 deletions act/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
__getattr__, __dir__, __all__ = lazy.attach(
__name__,

submodules=['armfiles', 'csvfiles', 'icartt', 'mpl', 'neon', 'noaagml', 'noaapsl', 'pysp2'],
submodules=['arm', 'csv', 'icartt', 'mpl', 'neon', 'noaagml', 'noaapsl', 'pysp2'],
submod_attrs={
'armfiles': [
'arm': [
'WriteDataset',
'check_arm_standards',
'create_ds_from_arm_dod',
'read_netcdf',
'read_arm_netcdf',
'check_if_tar_gz_file',
'read_mmcr',
'read_arm_mmcr',
],
'csvfiles': ['read_csv'],
'csv': ['read_csv'],
'icartt': ['read_icartt'],
'mpl': ['proc_sigma_mplv5_read', 'read_sigma_mplv5'],
'neon': ['read_neon_csv'],
Expand Down
13 changes: 5 additions & 8 deletions act/io/armfiles.py → act/io/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from act.utils.io_utils import cleanup_files, is_gunzip_file, unpack_gzip, unpack_tar


def read_netcdf(
def read_arm_netcdf(
filenames,
concat_dim=None,
return_None=False,
Expand Down Expand Up @@ -99,14 +99,11 @@ def read_netcdf(
.. code-block :: python
import act
ds = act.io.armfiles.read_netcdf(act.tests.sample_files.EXAMPLE_SONDE_WILDCARD)
ds = act.io.arm.read_arm_netcdf(act.tests.sample_files.EXAMPLE_SONDE_WILDCARD)
print(ds)
"""

message = 'act.io.armfiles.read_netcdf will be replaced in version 2.0.0 by act.io.arm.read_arm_netcdf()'
warnings.warn(message, DeprecationWarning, 2)

ds = None
filenames, cleanup_temp_directory = check_if_tar_gz_file(filenames)

Expand Down Expand Up @@ -315,7 +312,7 @@ def keep_variables_to_drop_variables(filenames, keep_variables, drop_variables=N
import act
filename = '/data/datastream/hou/houkasacrcfrM1.a1/houkasacrcfrM1.a1.20220404.*.nc'
drop_vars = act.io.armfiles.keep_variables_to_drop_variables(
drop_vars = act.io.arm.keep_variables_to_drop_variables(
filename, ['lat','lon','alt','crosspolar_differential_phase'],
drop_variables='variable_name_that_only_exists_in_last_file_of_the_day')
Expand Down Expand Up @@ -440,7 +437,7 @@ def create_ds_from_arm_dod(
.. code-block :: python
dims = {'time': 1440, 'drop_diameter': 50}
ds = act.io.armfiles.create_ds_from_arm_dod(
ds = act.io.arm.create_ds_from_arm_dod(
'vdis.b1', dims, version='1.2', scalar_fill_dim='time')
"""
Expand Down Expand Up @@ -811,7 +808,7 @@ def check_if_tar_gz_file(filenames):
return filenames, cleanup


def read_mmcr(filenames):
def read_arm_mmcr(filenames):
"""
Reads in ARM MMCR files and splits up the variables into specific
Expand Down
6 changes: 2 additions & 4 deletions act/io/csvfiles.py → act/io/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
"""

import pathlib

import pandas as pd

from .armfiles import check_arm_standards
from act.io.arm import check_arm_standards


def read_csv(filename, sep=',', engine='python', column_names=None, skipfooter=0, ignore_index=True, **kwargs):
Expand Down Expand Up @@ -48,7 +46,7 @@ def read_csv(filename, sep=',', engine='python', column_names=None, skipfooter=0
import act
ds = act.io.csvfiles.read(act.tests.sample_files.EXAMPLE_CSV_WILDCARD)
ds = act.io.csv.read(act.tests.sample_files.EXAMPLE_CSV_WILDCARD)
"""

Expand Down
4 changes: 1 addition & 3 deletions act/io/mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import shutil
import subprocess
import tempfile

import dask
import xarray as xr

from act.io.armfiles import check_arm_standards
from act.io.arm import check_arm_standards

if shutil.which('mpl2nc') is not None:
MPLIMPORT = True
Expand Down
2 changes: 1 addition & 1 deletion act/io/neon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import xarray as xr
import datetime as dt
import numpy as np
from act.io.csvfiles import read_csv
from act.io.csv import read_csv


def read_neon_csv(files, variable_files=None, position_files=None):
Expand Down
10 changes: 5 additions & 5 deletions act/io/noaagml.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def read_gml_halo(filename, **kwargs):
break
header += 1

ds = act.io.csvfiles.read_csv(
ds = act.io.csv.read_csv(
filename, sep=r'\s+', header=header,
na_values=['Nan', 'NaN', 'nan', 'NAN'], **kwargs)
var_names = list(ds.data_vars)
Expand Down Expand Up @@ -418,7 +418,7 @@ def read_gml_co2(filename=None, convert_missing=True, **kwargs):
with open(test_filename) as fc:
skiprows = int(fc.readline().strip().split()[-1]) - 1

ds = act.io.csvfiles.read_csv(
ds = act.io.csv.read_csv(
filename, sep=r'\s+', skiprows=skiprows, **kwargs)

timestamp = np.full(ds['year'].size, np.nan, dtype="datetime64[ns]")
Expand Down Expand Up @@ -538,7 +538,7 @@ def read_gml_ozone(filename=None, **kwargs):
pass
skiprows += 1

ds = act.io.csvfiles.read_csv(
ds = act.io.csv.read_csv(
filename, sep=r'\s+', skiprows=skiprows, **kwargs)
ds.attrs['station'] = str(ds['STN'].values[0]).lower()

Expand Down Expand Up @@ -772,7 +772,7 @@ def read_gml_radiation(filename=None, convert_missing=True,
names.insert(ii + num, 'qc_' + name)
num += 1

ds = act.io.csvfiles.read_csv(filename, sep=r'\s+', header=None, skiprows=2, column_names=names, **kwargs)
ds = act.io.csv.read_csv(filename, sep=r'\s+', header=None, skiprows=2, column_names=names, **kwargs)

if isinstance(filename, (list, tuple)):
filename = filename[0]
Expand Down Expand Up @@ -994,7 +994,7 @@ def read_gml_met(filename=None, convert_missing=True, **kwargs):
minutes = False
del column_names['minute']

ds = act.io.csvfiles.read_csv(
ds = act.io.csv.read_csv(
filename, sep=r'\s+', header=None,
column_names=column_names.keys(), **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion act/io/noaapsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import xarray as xr
import datetime as dt

from act.io.csvfiles import read_csv
from act.io.csv import read_csv


def read_psl_wind_profiler(filepath, transpose=True):
Expand Down
2 changes: 1 addition & 1 deletion act/plotting/distributiondisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DistributionDisplay(Display):
.. code-block:: python
ds = act.read_netcdf(the_file)
ds = act.io.read_arm_netcdf(the_file)
disp = act.plotting.DistsributionDisplay(ds, subplot_shape=(3,), figsize=(15, 5))
The DistributionDisplay constructor takes in the same keyword arguments as
Expand Down
2 changes: 1 addition & 1 deletion act/plotting/histogramdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class HistogramDisplay(Display):
.. code-block:: python
ds = act.read_netcdf(the_file)
ds = act.io.read_arm_netcdf(the_file)
disp = act.plotting.HistogramDisplay(ds, subplot_shape=(3,), figsize=(15, 5))
The HistogramDisplay constructor takes in the same keyword arguments as
Expand Down
2 changes: 1 addition & 1 deletion act/plotting/skewtdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class and has therefore has the same attributes as that class.
.. code-block :: python
sonde_ds = act.io.armfiles.read_netcdf(
sonde_ds = act.io.arm.read_arm_netcdf(
act.tests.sample_files.EXAMPLE_SONDE1)
skewt = act.plotting.SkewTDisplay(sonde_ds)
Expand Down
4 changes: 2 additions & 2 deletions act/plotting/timeseriesdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TimeSeriesDisplay(Display):
.. code-block:: python
ds = act.read_netcdf(the_file)
ds = act.io.read_arm_netcdf(the_file)
disp = act.plotting.TimeSeriesDisplay(ds, subplot_shape=(3,), figsize=(15, 5))
The TimeSeriesDisplay constructor takes in the same keyword arguments as
Expand Down Expand Up @@ -825,7 +825,7 @@ def plot_barbs_from_spd_dir(
--------
..code-block :: python
sonde_ds = act.io.armfiles.read_netcdf(
sonde_ds = act.io.arm.read_arm_netcdf(
act.tests.sample_files.EXAMPLE_TWP_SONDE_WILDCARD)
BarbDisplay = act.plotting.TimeSeriesDisplay(
{'sonde_darwin': sonde_ds}, figsize=(10,5))
Expand Down
2 changes: 1 addition & 1 deletion act/plotting/windrosedisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class and has therefore has the same attributes as that class.
.. code-block :: python
sonde_ds = act.io.armfiles.read_netcdf('sonde_data.nc')
sonde_ds = act.io.arm.read_arm_netcdf('sonde_data.nc')
WindDisplay = act.plotting.WindRoseDisplay(sonde_ds, figsize=(8,10))
"""
Expand Down
8 changes: 4 additions & 4 deletions act/qc/add_supplemental_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def read_yaml_supplemental_qc(
.. code-block:: python
from act.tests import EXAPLE_MET_YAML, EXAMPLE_MET1
from act.io.armfiles import read_netcdf
from act.io.arm import read_arm_netcdf
from act.qc.add_supplemental_qc import read_yaml_supplemental_qc
ds = read_netcdf(EXAMPLE_MET1, cleanup_qc=True)
ds = read_arm_netcdf(EXAMPLE_MET1, cleanup_qc=True)
result = read_yaml_supplemental_qc(ds, EXAPLE_MET_YAML,
variables=['rh_mean'], assessments='Bad')
print(result)
Expand Down Expand Up @@ -263,9 +263,9 @@ def apply_supplemental_qc(
.. code-block:: python
from act.tests import EXAPLE_MET_YAML, EXAMPLE_MET1
from act.io.armfiles import read_netcdf
from act.io.arm import read_arm_netcdf
from act.qc.add_supplemental_qc import apply_supplemental_qc
ds = read_netcdf(EXAMPLE_MET1, cleanup_qc=True)
ds = read_arm_netcdf(EXAMPLE_MET1, cleanup_qc=True)
apply_supplemental_qc(ds, EXAPLE_MET_YAML, apply_all=False)
print(ds['qc_temp_mean'].attrs['flag_meanings'])
Expand Down
4 changes: 2 additions & 2 deletions act/qc/bsrn_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def bsrn_limits_test(
--------
.. code-block:: python
ds = act.io.armfiles.read_netcdf(act.tests.EXAMPLE_BRS, cleanup_qc=True)
ds = act.io.arm.read_arm_netcdf(act.tests.EXAMPLE_BRS, cleanup_qc=True)
ds.qcfilter.bsrn_limits_test(
gbl_SW_dn_name='down_short_hemisp',
glb_diffuse_SW_dn_name='down_short_diffuse_hemisp',
Expand Down Expand Up @@ -404,7 +404,7 @@ def bsrn_comparison_tests(
--------
.. code-block:: python
ds = act.io.armfiles.read_netcdf(act.tests.EXAMPLE_BRS, cleanup_qc=True)
ds = act.io.arm.read_arm_netcdf(act.tests.EXAMPLE_BRS, cleanup_qc=True)
ds.qcfilter.bsrn_comparison_tests(
gbl_SW_dn_name='down_short_hemisp',
glb_diffuse_SW_dn_name='down_short_diffuse_hemisp',
Expand Down
10 changes: 5 additions & 5 deletions act/qc/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def cleanup(
.. code-block:: python
files = act.tests.sample_files.EXAMPLE_MET1
ds = act.io.armfiles.read_netcdf(files)
ds = act.io.arm.read_arm_netcdf(files)
ds.clean.cleanup()
"""
Expand Down Expand Up @@ -779,12 +779,12 @@ def normalize_assessment(
--------
.. code-block:: python
ds = act.io.armfiles.read_netcdf(files)
ds = act.io.arm.read_arm_netcdf(files)
ds.clean.normalize_assessment(variables='temp_mean')
.. code-block:: python
ds = act.io.armfiles.read_netcdf(files, cleanup_qc=True)
ds = act.io.arm.read_arm_netcdf(files, cleanup_qc=True)
ds.clean.normalize_assessment(qc_lookup={'Bad': 'Incorrect', 'Indeterminate': 'Suspect'})
"""
Expand Down Expand Up @@ -847,12 +847,12 @@ def clean_cf_qc(self, variables=None, sep='__', **kwargs):
--------
.. code-block:: python
ds = act.io.armfiles.read_netcdf(files)
ds = act.io.arm.read_arm_netcdf(files)
ds.clean.clean_cf_qc(variables='temp_mean')
.. code-block:: python
ds = act.io.armfiles.read_netcdf(files, cleanup_qc=True)
ds = act.io.arm.read_arm_netcdf(files, cleanup_qc=True)
"""

Expand Down
Loading

0 comments on commit c985def

Please sign in to comment.