Skip to content

Commit

Permalink
New script for compute galactic noise added
Browse files Browse the repository at this point in the history
  • Loading branch information
snonis committed Oct 25, 2024
1 parent 32e233d commit 2aa9d01
Show file tree
Hide file tree
Showing 20 changed files with 2,653 additions and 2,891 deletions.
72 changes: 72 additions & 0 deletions data/download_LFmap_grand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#! /usr/bin/env python3

'''
Created on 19 juil. 2022
@author: Jean-Marc Colley, CNRS/IN2P3/LPNHE
'''
import tarfile
import os
import sys
import os.path as osp
from urllib import request
#TODO: add progressbar to grand lib
#import progressbar

from grand import GRAND_DATA_PATH, grand_add_path_data

#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/133380/grand_model_2207.tar.gz"
#FILE_MODEL = "grand_model_2207.tar.gz"
#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/201909/grand_model_2306.tar.gz"
#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/251637/grand_model_190224.tar.gz"
LINK_MODEL = "https://forge.in2p3.fr/attachments/download/326497/LFmap.tar.gz"
FILE_MODEL = LINK_MODEL.split("/")[-1]
# class MyProgressBar():
# def __init__(self):
# self.pbar = None
#
# def __call__(self, block_num, block_size, total_size):
# if not self.pbar:
# self.pbar=progressbar.ProgressBar(maxval=total_size)
# self.pbar.start()
#
# downloaded = block_num * block_size
# if downloaded < total_size:
# self.pbar.update(downloaded)
# else:
# self.pbar.finish()


# 1- test if download is necessary
if os.path.exists(grand_add_path_data('noise/LFmap')):
print("==============================")
print('Skip download LFmap files for Galactic noise simulations')
sys.exit(0)

GRAND_DATA_PATH_1 = osp.join(grand_add_path_data('noise'))
tar_file = osp.join(GRAND_DATA_PATH_1, FILE_MODEL)

# 2- download
print("==============================")
print("Download LFmap model (~ 6.4 MB) for GRAND, please wait ...")
try:
request.urlretrieve(LINK_MODEL, tar_file)
print("Successfully downloaded")
except:
print(f"download failed {LINK_MODEL}")
sys.exit(1)

# 3- extract
print("==============================")
print('Extract tar file')
try:
my_tar = tarfile.open(tar_file)
my_tar.extractall(grand_add_path_data('noise'))
my_tar.close()
os.remove(tar_file) # delete zipped file are extraction.
except:
print(f"Extract failed '{tar_file}'")
sys.exit(1)
print("LFmap model available in grand/data/noise directory !")
sys.exit(0)
18 changes: 9 additions & 9 deletions data/download_data_grand.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/133380/grand_model_2207.tar.gz"
#FILE_MODEL = "grand_model_2207.tar.gz"
#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/201909/grand_model_2306.tar.gz"
#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/251637/grand_model_190224.tar.gz"
LINK_MODEL = "https://forge.in2p3.fr/attachments/download/312643/RFchain_V3.tar.gz"
LINK_MODEL = "https://forge.in2p3.fr/attachments/download/251637/grand_model_190224.tar.gz"
FILE_MODEL = LINK_MODEL.split("/")[-1]


# class MyProgressBar():
# def __init__(self):
# self.pbar = None
Expand All @@ -39,17 +40,16 @@


# 1- test if download is necessary
if os.path.exists(grand_add_path_data('detector/RFchain_v2')):
if os.path.exists(grand_add_path_data('detector')):
print("==============================")
print('Skip download data model')
sys.exit(0)

GRAND_DATA_PATH_1 = osp.join(grand_add_path_data('detector'))
tar_file = osp.join(GRAND_DATA_PATH_1, FILE_MODEL)
tar_file = osp.join(GRAND_DATA_PATH, FILE_MODEL)

# 2- download
print("==============================")
print("Download new RFchain model (~ 450 KB) for GRAND, please wait ...")
print("Download data model (~ 1GB) for GRAND, please wait ...")
try:
request.urlretrieve(LINK_MODEL, tar_file)
print("Successfully downloaded")
Expand All @@ -62,11 +62,11 @@
print('Extract tar file')
try:
my_tar = tarfile.open(tar_file)
my_tar.extractall(grand_add_path_data('detector'))
my_tar.extractall(grand_add_path_data(''))
my_tar.close()
os.remove(tar_file) # delete zipped file are extraction.
except:
print(f"Extract failed '{tar_file}'")
sys.exit(1)
print("data model available in grand/data/detector directory !")
sys.exit(0)
print("data model available in grand/data directory !")
sys.exit(0)
72 changes: 72 additions & 0 deletions data/download_new_RFchain_grand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#! /usr/bin/env python3

'''
Created on 19 juil. 2022
@author: Jean-Marc Colley, CNRS/IN2P3/LPNHE
'''
import tarfile
import os
import sys
import os.path as osp
from urllib import request
#TODO: add progressbar to grand lib
#import progressbar

from grand import GRAND_DATA_PATH, grand_add_path_data

#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/133380/grand_model_2207.tar.gz"
#FILE_MODEL = "grand_model_2207.tar.gz"
#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/201909/grand_model_2306.tar.gz"
#LINK_MODEL = "https://forge.in2p3.fr/attachments/download/251637/grand_model_190224.tar.gz"
LINK_MODEL = "https://forge.in2p3.fr/attachments/download/312643/RFchain_V3.tar.gz"
FILE_MODEL = LINK_MODEL.split("/")[-1]
# class MyProgressBar():
# def __init__(self):
# self.pbar = None
#
# def __call__(self, block_num, block_size, total_size):
# if not self.pbar:
# self.pbar=progressbar.ProgressBar(maxval=total_size)
# self.pbar.start()
#
# downloaded = block_num * block_size
# if downloaded < total_size:
# self.pbar.update(downloaded)
# else:
# self.pbar.finish()


# 1- test if download is necessary
if os.path.exists(grand_add_path_data('detector/RFchain_v2')):
print("==============================")
print('Skip download data model')
sys.exit(0)

GRAND_DATA_PATH_1 = osp.join(grand_add_path_data('detector'))
tar_file = osp.join(GRAND_DATA_PATH_1, FILE_MODEL)

# 2- download
print("==============================")
print("Download new RFchain model (~ 450 KB) for GRAND, please wait ...")
try:
request.urlretrieve(LINK_MODEL, tar_file)
print("Successfully downloaded")
except:
print(f"download failed {LINK_MODEL}")
sys.exit(1)

# 3- extract
print("==============================")
print('Extract tar file')
try:
my_tar = tarfile.open(tar_file)
my_tar.extractall(grand_add_path_data('detector'))
my_tar.close()
os.remove(tar_file) # delete zipped file are extraction.
except:
print(f"Extract failed '{tar_file}'")
sys.exit(1)
print("data model available in grand/data/detector directory !")
sys.exit(0)
2 changes: 1 addition & 1 deletion examples/sim/rf_chain_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"}\n",
"plt.rcParams.update(params)\n",
"\n",
"import grand.sim.detector.rf_chain2 as grfc\n",
"import grand.sim.detector.rf_chain as grfc\n",
"\n",
"freq_MHz = np.arange(30, 251, 1)\n",
"l_col = [\"k\", \"y\", \"b\"]"
Expand Down
2 changes: 1 addition & 1 deletion grand/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def grand_add_path_data(s_file):
from grand.sim.efield2voltage import Efield2Voltage
from grand.sim.detector.antenna_model import tabulated_antenna_model, AntennaModel
from grand.sim.detector.process_ant import AntennaProcessing
from grand.sim.detector.rf_chain2 import RFChain
from grand.sim.detector.rf_chain import RFChain
from grand.sim.noise.galaxy import galactic_noise
from grand.sim.shower.gen_shower import ShowerEvent
from grand.sim.shower.pdg import ParticleCode
Expand Down
Loading

0 comments on commit 2aa9d01

Please sign in to comment.