Skip to content

Commit

Permalink
Merge pull request #2 from SuperDARN/pydmap_fix
Browse files Browse the repository at this point in the history
Pydmap Read
  • Loading branch information
asreimer authored Jan 7, 2019
2 parents c4ec146 + 9846d32 commit 6cb97d1
Show file tree
Hide file tree
Showing 33 changed files with 2,103 additions and 5,270 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ dmypy.json
*.o
*~
*.log
*.log*
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Include the README
include *.md

# Include the licesnse file
include LICENSE

# Include data files (metadata for pydarn package)
include pydarn/logging_config.yaml
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# pydarn
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/) [![GitHub version](https://badge.fury.io/gh/boennemann%2Fbadges.svg)](http://badge.fury.io/gh/boennemann%2Fbadges)

SuperDARN data visualization library.

## Getting Started

The following instructions will allow you to install and give some examples on how to use pydarn.

### Prerequisites

**python 3.6+**

| Ubuntu | OpenSuse | Fedora |
| ----------- | -------------- | ------------- |
| libyaml-dev | python3-PyYAML | libyaml-devel |

You can check your python version with
`$ python --version` or
`$ python3 --version`
### Installing

1. Clone git repository:
`git clone https://github.com/SuperDARN/pydarn.git`

2. Installing pydarn
1. **Recommended**: Installing a [virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtualenv/), this option allows the library to install needed version of libraries without affecting system libraries.
* First install the environment:
`$ python3 -m pip install --user virtualenv`
`$ python3 -m virtualenv <environment name>`
`$ source <environment name>/bin/activate`
* Navigate to where you cloned pydarn:
`$ python3 setup.py install`
2. Install in the system (root privileges required):
`$ sudo python3 setup.py install`

### Examples

#### Reading DMAP file
The following example shows how to read in a FITACF file, one of the SuperDARN's DMAP file types.

```python
import pydarn
dmap_file = "./20180410.C0.sas.fitacf"
dmap_reader = pydarn.DmapRead(dmap_file)
dmap_data = dmap_reader.read_records()

# dmap_data[record number][paramter name].value
print(dmap_data[0]['bmnum'].value)
```

#### Turn on debugging

```python
import pydarn
import logging

pydarn_logger = logging.getLogger('pydarn').setLevel(logging.DEBUG)

dmap_file = "./20180410.C0.sas.fitacf"
damp_reader = pydarn.DmapRead(dmap_file)
dmap_data = dmap_reader.read_records()

print(dmap_data[0]['origin.time'].value)
```
Run the code and two log files will be produced:
* pydarn.log - DEBUG level info
* pydarn_error.log - ERROR level info

### Release History

* 0.0.1
* Add: Pydmap DmapRead implemented.
11 changes: 7 additions & 4 deletions pydarn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
import yaml

# Importing pydarn exception classes
from .exceptions.pydmap_exceptions import EmptyFileError
from .exceptions.pydmap_exceptions import DmapDataError
from .exceptions import pydmap_exceptions

# Importing pydarn pydmap data structure classes
from .pydmap.datastructures import DmapScalar
from .pydmap.datastructures import DmapArray
from .pydmap.datastructures import DmapRecord

# Importing pydarn pydmap classes
from .io.pydmap.dmap import RawDmapRead
from .io.pydmap.dmap import parse_dmap_format_from_file
from .pydmap.io import DmapRead

"""
Pydarn uses yaml for logging configuration because it is the
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pydarn/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .pydmap_exceptions import EmptyFileError

69 changes: 67 additions & 2 deletions pydarn/exceptions/pydmap_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,81 @@
import logging
pydarn_logger = logging.getLogger('pydarn')

class CursorError(Exception):
"""
Raise if the cursor is not correctly set
"""
def __init__(self,cursor, expected_value=0, mesage=''):
self.cursor
if message == '':
self.message = "Error: Cursor is at {cursor} and"\
"it needs to be {expected}".format(cursor=cursor,
expected=expected_value)
else:
self.message=message
super().__init__(self.message)
pydarn_logger.error(self.message)


class EmptyFileError(Exception):
"""
Raised if a file is empty
"""
def __init__(self,filename):
self.filename = filename
self.message = "Error: {} is empty,"\
self.message = "Error: {} is empty or"\
" please check this is the correct file".format(filename)
super().__init__(self.message)
pydarn_logger.error("EmptyFileError: {} is empty".format(filename))
pydarn_logger.error(self.message)


class DmapDataTypeError(Exception):
"""
Raised if the data type is not correct.
"""
def __init__(self, filename, data_name, data_type, cursor):
self.filename = filename
self.message = "Error: Dmap data type {data_type} for {name}"\
" at cursor = {cursor} does not exist in dmap data types."\
"filename: {filename}".format(name=data_name,
data_type=data_type,
filename=filename,
cursor=cursor)
super().__init__(self.message)
pydarn_logger.error(self.message)


class ZeroByteError(Exception):
"""
Raised if an element has <= 0 bytes.
:pram filename: The file that contains the element
:pram element_info: String containg element info.
"""
def __init__(self,filename, element_info, cursor):
self.filename = filename
self.message = "Error: {filename} contains an {element} <= 0"\
" at cursor = {cursor}.".format(filename=filename,
element=element_info,
cursor=cursor)
super().__init__(self.message)
pydarn_logger.error(self.message)


class MismatchByteError(Exception):
"""
Raised if an element has <= 0 bytes.
:pram filename: The file that contains the element
:pram element_info: String containg element info.
"""
def __init__(self, filename, element_info, cursor):
self.filename = filename
self.message = "Error: {filename} contains an {element}"\
" at cursor = {cursor}.".format(filename=filename,
element=element_info,
cursor=cursor)
super().__init__(self.message)
pydarn_logger.error(self.message)


class DmapDataError(Exception):
"""Raised if there is an error in parsing of data
Expand Down
1 change: 0 additions & 1 deletion pydarn/io/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion pydarn/io/pydmap/__init__.py

This file was deleted.

Loading

0 comments on commit 6cb97d1

Please sign in to comment.