Code Monkey home page Code Monkey logo

dynaspec's Introduction

👋 I am an evolutionary behavioral ecologist, that ended up doing a lot of coding just to be able to customize my data analyses

I use github to make my research reproducible by sharing the data and code of my projects (most of my repos are research projects). I also use it to develop and maintain several R packages:

:name status badge

Package What it does
baRulho Aims to facilitate the implementation of (animal) sound transmission experiments from playback design to degradation quantification
suwo Access nature media repositories
warbleR Quantify the structure of animal acoustic signals
ohun Optimize sound event detection
dynaSpec Create dynamic visualizations of sound (spectrogram movies)
Rraven Connecting R and Raven sound analysis software
PhenotypeSpace Quantify multivariate phenotypic spaces (under development)
brmsish Custom manipulation of brms bayesian models that I like (not sure if this should be a true package!)
NatureSounds Examples of natural acoustic data

📫 How to reach me: marcelo.araya (at) ucr.ac.cr (If you have question about using any of my software packages please read the associated documentation first)

dynaspec's People

Contributors

drwilkins avatar louis-backstrom avatar marce10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dynaspec's Issues

warnings/errors when checking package

ggSpec: no visible global function definition for ‘xlim’
ggSpec: no visible global function definition for ‘ylim’
ggSpec: no visible global function definition for ‘scale_fill_viridis’
ggSpec: no visible global function definition for ‘scale_fill_gradient’
ggSpec: no visible binding for global variable ‘..level..’
ggSpec: no visible global function definition for ‘element_line’
ggSpec: no visible global function definition for ‘ggsave’
mytheme: no visible global function definition for ‘margin’
mytheme: no visible global function definition for ‘element_text’
mytheme_lg: no visible global function definition for ‘margin’
mytheme_lg: no visible global function definition for ‘element_text’
oscillo_dynaspec_int: no visible global function definition for ‘par’
oscillo_dynaspec_int: no visible global function definition for ‘plot’
pagedSpec: no visible global function definition for ‘ggsave’
pagedSpec: no visible global function definition for ‘readPNG’
pagedSpec: no visible global function definition for ‘element_line’
pagedSpec: no visible global function definition for ‘unit’
pagedSpec: no visible global function definition for ‘aes’
pagedSpec: no visible binding for global variable ‘xmin’
pagedSpec: no visible binding for global variable ‘ymin’
pagedSpec: no visible binding for global variable ‘xmax’
pagedSpec: no visible binding for global variable ‘ymax’
pagedSpec: no visible global function definition for ‘animate’
pagedSpec: no visible global function definition for ‘av_renderer’
paged_spectro: no visible global function definition for ‘ggsave’
paged_spectro: no visible global function definition for ‘readPNG’
paged_spectro: no visible global function definition for ‘element_line’
paged_spectro: no visible global function definition for ‘unit’
paged_spectro: no visible global function definition for ‘aes’
paged_spectro: no visible binding for global variable ‘xmin’
paged_spectro: no visible binding for global variable ‘ymin’
paged_spectro: no visible binding for global variable ‘xmax’
paged_spectro: no visible binding for global variable ‘ymax’
paged_spectro: no visible global function definition for ‘animate’
paged_spectro: no visible global function definition for ‘av_renderer’
prepStaticSpec: no visible global function definition for ‘plot’
prep_static_ggspectro: no visible global function definition for ‘plot’
Undefined global functions or variables:
..level.. aes animate av_renderer element_line element_text ggsave
margin par plot readPNG scale_fill_gradient scale_fill_viridis unit
xlim xmax xmin ylim ymax ymin
Consider adding
importFrom("graphics", "par", "plot")
to your NAMESPACE file.

checking Rd line widths ... NOTE
Error: 63: Tag \url not expected in code block

add colab notebook

add colab notebook so people can make videos without dealing with dependency issues

audio sampling rate of 48000 or maybe more might be a problem in the final video's audio

Describe the bug
The audio in this video(https://www.youtube.com/watch?v=OxvKoPyX-4o) is different from originial xeno-canto audio although the visualization is right.
After some test, I found out downsample of audio in R language package including packages seewave , and av (fucntion resamp and downsample)is not generating correct result like a resampling in software Audacity. Oversample seems to be ok as the screenshot below.

To Reproduce
Here is the code I used to check audio resample functions of R packages, you can check the spectrom after resample or video output using Audacity as the attached screenshot. There are a lot of echoes( disturbance? I don't know how to describe this phenomenon) in all the frequencies. ffmpeg does degrade the input audio( some missing in the spectrogram compare to original audio ) but it should have nothing to do with this problem. This seems to be R package problem.

library('monitoR')#for better MP3 slicing, the read_wave or TuneR's readWave can't slice mp3 files, they just read the whole file into the wav variable.
ngh_wren <- readMP3(filename = "Nightingale-Wren.mp3", from = 1, to = 3) #https://xeno-canto.org/518334
ngh_wren_44100_downsample <- downsample(ngh_wren, 44100)
ngh_wren_44100 <- resamp(ngh_wren,f=48000, g=44100, channel = 1, output="Wave")
ngh_wren_96000 <- resamp(ngh_wren,f=48000, g=96000, channel = 1, output="Wave")
ngh_wren_48000 <- resamp(ngh_wren_44100,f=44100,  g=48000, channel = 1, output="Wave")
print(ngh_wren)
print(ngh_wren_44100_downsample)
savewav(ngh_wren, filename = "ngh_wren_orginal.wav")
savewav(ngh_wren_44100_downsample, filename = "ngh_wren_44100_downsample.wav")
savewav(ngh_wren_44100, filename = "ngh_wren_44100_resamp.wav")
savewav(ngh_wren_48000, filename = "ngh_wren_48000_resamp_from_44100.wav")
savewav(ngh_wren_96000, filename = "ngh_wren_96000_resamp.wav")

scrolling_spectro(wave = ngh_wren, wl = 300, 
              t.display = 3, pal = viridis, 
              grid = FALSE, flim = c(0.1, 9), 
              width = 1080, height =720, fps=24,collevels = seq(-100, 0, 1),
              res = 72, file.name = "ngh_wren_orginal.mp4",,colbg = "black",
              osc = TRUE,colwave = "#03bef7d1")# video's audio is damaged as the screenshot below
ngh_wren_original_44100_audacity <- read_wave("ngh_wren_original_44100_audacity.wav") # resample originial audio to 44100 using Audacity
print(ngh_wren_original_44100_audacity)
scrolling_spectro(wave = ngh_wren_original_44100_audacity, wl = 512, 
              t.display = 3, pal = viridis, 
              grid = FALSE, flim = c(0.1, 9), 
              width = 1080, height =720, fps=24,collevels = seq(-100, 0, 1),
              res = 72, file.name = "ngh_wren_original_44100_audacity.mp4",,colbg = "black",
              osc = TRUE,colwave = "#03bef7d1")# final video will have the right audio now.

Screenshots
resample_issue_of_R

Additional context
I wonder if it's needed to add some silence in the beginning of the final video, can't we just using the original audio if no silence needed at the beginning?
I think a solution to this problem might be using the original audio and add silence at the beginning and ending without altering the audio frequency or feeding in a preprocessed 44.1kHz audio in software like Audacity. Or doing some postprocess using other software by replacing the audio track.

use ffmpeg to create spectrogram video

use ffmepg to create the spectrogram video first and then take the frames from that video to put them into the dynaspec scrolling_spectro() video frames

errors on several functions from devtools::check

Hi Matt,

CRAN is asking us to submit a new version that deals with some silly issues about imports. However, I am getting several errors related to your functions. Here is the error log:

── R CMD check results ───────────────────────────────────────────────────────────────────────── dynaSpec 1.0.0 ────
Duration: 27s

checking examples ... ERROR
Running examples in ‘dynaSpec-Ex.R’ failed
The error most likely occurred in:

base::assign(".ptime", proc.time(), pos = "CheckExEnv")

Name: paged_spectro

Title: Make a paged dynamic spectrogram similar to spectral display in

Adobe Audition

Aliases: paged_spectro pagedSpectro pagedSpec

** Examples

{

  • #show wav files included with dynaSpec
  • f <- list.files(pattern=".wav", full.names = TRUE, path = system.file(package="dynaSpec"))
  • femaleBarnSwallow<-prep_static_ggspectro(f[1],destFolder="wd",onlyPlotSpec = F, bgFlood=T)
  • paged_spectro(femaleBarnSwallow)
  • maleBarnSwallow<-prep_static_ggspectro(f[2],destFolder="wd",onlyPlotSpec = F, bgFlood=T,min_dB=-40)
  • paged_spectro(femaleBarnSwallow)
  • Make a multipage dynamic spec of a humpback whale song

  • Note, we're saving PNGs of our specs in the working directory; to add

  • axis labels, we set onlyPlotSpec to F, and to make the same background

  • color for the entire figure, we set bgFlood=T;

  • The yLim is set to only go to 0.7kHz, where the sounds are for these big whales;

  • #also applying an amplitude transform to boost signal.
  • #This is a longer file, so we're taking the first 12 seconds with crop=12
  • #xLim=3 means each "page" will be 3 seconds, so we'll have 4 dynamic spec pages that get combined
  • humpback <- prep_static_ggspectro(
  • "http://www.oceanmammalinst.org/songs/hmpback3.wav",savePNG=T,destFolder="wd",
  • onlyPlotSpec=F,bgFlood=T,yLim=c(0,.7),crop=12,xLim=3,ampTrans=3)
  • #to generate multipage dynamic spec (movie), run the following
  • paged_spectro(humpback)
  • see more examples at https://marce10.github.io/dynaSpec/

  • }
    Error in ggSpec(wav = prepped$newWav, soundFile = soundFile, segLens = prepped$segLens, :
    F used instead of FALSE
    Calls: prep_static_ggspectro -> ggSpec
    Execution halted

checking dependencies in R code ... WARNING
'::' or ':::' import not declared from: ‘fs’

checking Rd \usage sections ... WARNING
Undocumented arguments in documentation object 'is.url'
‘x’

Undocumented arguments in documentation object 'prep_static_ggspectro'
‘plotLegend’ ‘onlyPlotSpec’ ‘specWidth’ ‘specHeight’ ‘...’

Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
See chapter ‘Writing R documentation files’ in the ‘Writing R
Extensions’ manual.

checking data for ASCII and uncompressed saves ... WARNING

Note: significantly better compression could be obtained
      by using R CMD build --resave-data
                old_size new_size compress
canyon_wren.rda    505Kb    326Kb       xz

checking R code for possible problems ... NOTE
pagedSpec: no visible binding for global variable ‘xmin’
pagedSpec: no visible binding for global variable ‘ymin’
pagedSpec: no visible binding for global variable ‘xmax’
pagedSpec: no visible binding for global variable ‘ymax’
paged_spectro: no visible binding for global variable ‘xmin’
paged_spectro: no visible binding for global variable ‘ymin’
paged_spectro: no visible binding for global variable ‘xmax’
paged_spectro: no visible binding for global variable ‘ymax’
Undefined global functions or variables:
xmax xmin ymax ymin

scrolling_spectro() function fails to produce mp4

I ran the example code:

library(dynaSpec)
library(viridis)
library(tuneR)
library(seewave)
library(warbleR)  

data("canyon_wren")
scrolling_spectro(
	wave = canyon_wren,
	wl = 300,
	t.display = 1.7,
	pal = viridis,
	grid = FALSE,
	flim = c(1, 9),
	width = 1000,
	height = 500,
	res = 120,
	file.name = "default.mp4"
)

but get the following:

|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=03m 19s
Error in system(cll1, intern = TRUE, ignore.stdout = TRUE, ignore.stderr = TRUE) :
error in running command
Warning messages:
1: In graphics::par(opar) : graphical parameter "cin" cannot be set
2: In graphics::par(opar) : graphical parameter "cra" cannot be set
3: In graphics::par(opar) : graphical parameter "csi" cannot be set
4: In graphics::par(opar) : graphical parameter "cxy" cannot be set
5: In graphics::par(opar) : graphical parameter "din" cannot be set
6: In graphics::par(opar) : calling par(new=TRUE) with no plot
7: In graphics::par(opar) : graphical parameter "page" cannot be set

I used:
macOS Monterey Version 12.4
R version 4.1.3 (2022-03-10) -- "One Push-Up"
RStudio version: RStudio 2022.02.3+492 "Prairie Trillium" Release (1db809b8323ba0a87c148d16eb84efe39a8e7785, 2022-05-16) for macOS
Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4_0) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.10 Chrome/69.0.3497.128 Safari/537.36

If try to run a wav file locally from my own computer, I get a different error:

Error in z[(fl1:fl2) + 1, ] : subscript out of bounds
Warning messages:
1: In graphics::par(opar) : graphical parameter "cin" cannot be set
2: In graphics::par(opar) : graphical parameter "cra" cannot be set
3: In graphics::par(opar) : graphical parameter "csi" cannot be set
4: In graphics::par(opar) : graphical parameter "cxy" cannot be set
5: In graphics::par(opar) : graphical parameter "din" cannot be set
6: In graphics::par(opar) : calling par(new=TRUE) with no plot
7: In graphics::par(opar) : graphical parameter "page" cannot be set

CRAN version saves only audio, remotes from github version returns error

Hi there,

I'm very keen to use dynaSpec to show some spectrograms along with some video we have of bats socializing. However, I'm having issues getting dynaSpec up and running.

I'm on a Windows 11 machine and I've installed FFMPEG via this link (namely, I installed the build ffmpeg-master-latest-win64-gpl.zip).

If I load dynaSpec after installing from CRAN, I get the following error when I try to run your example:

data("canyon_wren")
scrolling_spectro(wave = canyon_wren, wl = 300, 
                  t.display = 1, pal = viridis, 
                  grid = FALSE, flim = c(1, 9), 
                  width = 1000, height = 500, res = 120, 
                  file.name = "black.mp4", colbg = "black")

Returns:
Warning messages:
1: In system(cll1, intern = TRUE, ignore.stdout = TRUE, ignore.stderr = TRUE) :
  running command 'ffmpeg -framerate 50 -i C:\Users\AVAKIA~1\AppData\Local\Temp\RtmpmcHk6L/%05d.temp.img.tiff -c:v libx264 -profile:v high -crf 2 -pix_fmt yuv420p -y C:\Users\AVAKIA~1\AppData\Local\Temp\RtmpmcHk6L/scroll.spectro.temp.mp4' had status 69
2: In graphics::par(opar) : graphical parameter "cin" cannot be set
3: In graphics::par(opar) : graphical parameter "cra" cannot be set
4: In graphics::par(opar) : graphical parameter "csi" cannot be set
5: In graphics::par(opar) : graphical parameter "cxy" cannot be set
6: In graphics::par(opar) : graphical parameter "din" cannot be set
7: In graphics::par(opar) : graphical parameter "page" cannot be set

An .mp4 file is then opened/saved that contains the audio but no video.

I tried re-installing dynaSpec from github via remotes. Now when I try to run the example, nothing is created or saved, and instead I get the error:

Error in checkCluster(cl) : not a valid cluster

Any suggestions for how to get around the errors in either case?

Thanks!

My ffmpeg install version:

C:\Users\Ava Kiai>ffmpeg -version
ffmpeg version N-108709-g3bd0bf76fb-20221017 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 12.1.0 (crosstool-NG 1.25.0.55_3defb7b)
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20221017
libavutil      57. 39.101 / 57. 39.101
libavcodec     59. 50.101 / 59. 50.101
libavformat    59. 34.101 / 59. 34.101
libavdevice    59.  8.101 / 59.  8.101
libavfilter     8. 49.101 /  8. 49.101
libswscale      6.  8.112 /  6.  8.112
libswresample   4.  9.100 /  4.  9.100
libpostproc    56.  7.100 / 56.  7.100

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.