Git Product home page Git Product logo

rpgprpy's Introduction

RPGPRpy

Python wrapper for RGPR (ground-penetrating radar visualisation & processing).


Work in progress!


You find RGPR an interesting package for GPR (ground-penetrating radar) data processing but you do not like the R language... RGPRpy may be an alternative for you...

# -*- coding: utf-8 -*-
"""
Created on Thu May 12 20:47:05 2022

https://github.com/davidthaler/Python-wrapper-for-R-Forecast/blob/master/rforecast/converters.py
https://github.com/theislab/anndata2ri/tree/master/anndata2ri

@author: Hubere
"""

import numpy as np
import matplotlib.pyplot as plt

import rpy2
print(rpy2.__version__)


from rpy2.robjects.packages import importr
# import R's "base" package
base = importr('base')

# import R's utility package
devtools = importr('devtools')

devtools.install_github("emanuelhuber/RGPR")

rgpr = importr('RGPR')

x = rgpr.readGPR("C:/Users/Hubere/Documents/GPR/BUF2____0001_1.rd3")

rgpr.plot_GPR(x)

# x = R object of type S4
type(x)

# class
tuple(x.rclass)

dir(x)

# Slots
tuple(x.slotnames())


# The attributes can also be accessed through the rpy2 property slots. slots is a mapping between attributes names (keys) and their associated R object (values). It can be used as Python dict:

# print keys
print(tuple(x.slots.keys()))

# fetch `phenoData`
xdat = x.slots['data']

tuple(xdat.rclass)

# Mapping S4 classes to Python classes
from rpy2.robjects.methods import RS4
class GPR(RS4):
    pass

x_myclass = GPR(x)


def rpy2py_s4(obj):
    if 'GPR' in obj.rclass:
        res = GPR(obj)
    else:
        res = robj
    return res

# try it
rpy2py_s4(x)


# The conversion system can also be made aware our new class by customizing the handling of S4 objects.

# A simple implementation is a factory function that will conditionally wrap the object in our Python class ExpressionSet:
from rpy2.robjects import default_converter
from rpy2.robjects.conversion import Converter, localconverter

my_converter = Converter('ExpressionSet-aware converter',
                         template=default_converter)

from rpy2.rinterface import SexpS4
my_converter.rpy2py.register(SexpS4, rpy2py_s4)



from multipledispatch import dispatch
from functools import partial

my_namespace = dict()
dispatch = partial(dispatch, namespace=my_namespace)

@dispatch(GPR)
def gainAGC(x, 
            w = 10, 
            p = 2, 
            r = 0.5, 
            track = False):
    res = rgpr.gainAGC(x,
                       w = w,
                       p = p,
                       r = r,
                       track = track)
    return res

res = gainAGC(x_myclass)

xdata = res.slots['data']
pydata = np.array(xdata)
plt.plot(pydata[:,10])

plt.imshow(pydata, interpolation='nearest', aspect = 'auto')
plt.show()

rpgprpy's People

Contributors

emanuelhuber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jagmon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.