Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.1
hooks:
# Run the linter.
# To be renabled once fixes are made.
# - id: ruff
# args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: []
submodules: false
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
To install:
python setup.py build
and
python setup.py install
python setup.py install

To also install the optional LOFAR features (requires lofar.parmdb + pyrap):

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# RMextract
extract TEC, vTEC, Earthmagnetic field and Rotation Measures from GPS and WMM data for radio interferometry observations
extract TEC, vTEC, Earthmagnetic field and Rotation Measures from GPS and WMM data for radio interferometry observations

Please cite as: Mevius, M. (2018) RMextract, Astrophysics Source Code Library, record [ascl:1806.024]

WMM model data:
WMM model data:
NCEI Geomagnetic Modeling Team and British Geological Survey. 2019. World Magnetic Model 2020. NOAA National Centers for Environmental Information. doi: 10.25921/11v3-da71, 2020

IRI model:
D. Bilitza, IRI the International Standard for the Ionosphere, Adv. Radio Sci., 16, 1-11, https://doi.org/10.5194/ars-16-1-2018, 2018.
D. Bilitza, IRI the International Standard for the Ionosphere, Adv. Radio Sci., 16, 1-11, https://doi.org/10.5194/ars-16-1-2018, 2018.

IRIPlas model:
T. Gulyaeva and D. Bilitza, "Towards ISO standard earth ionosphere and plasmasphere model," in New Developments in the Standard Model R. Larsen, Ed. Hauppauge, New York: NOVA, 2012, pp. 1-48.
144 changes: 86 additions & 58 deletions RMextract/EMM/EMM.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,111 @@


class WMM:
def __init__(self,cof=resource_filename(__name__,'WMM.COF'),date=2010.,lon=0.,lat=0.,h=0.):
def __init__(
self,
cof=resource_filename(__name__, "WMM.COF"),
date=2010.0,
lon=0.0,
lat=0.0,
h=0.0,
):
try:
cof=cof.replace("WMM.COF","")
if not os.path.isfile(cof+"WMM.COF"):
print ("initializing model failed. Did you specify correct location for coefficient files")
cof = cof.replace("WMM.COF", "")
if not os.path.isfile(cof + "WMM.COF"):
print(
"initializing model failed. Did you specify correct location for coefficient files"
)
return
self.WMM_Model=emm.WMM_Model(cof+"WMM",date,lon,lat,h)
self.WMM_Model = emm.WMM_Model(cof + "WMM", date, lon, lat, h)
except (RuntimeError, TypeError, NameError):
print ("initializing mdoel failed. Did you specify correct location for coefficient files")
self.date=date
self.lon=lon
self.lat=lat
self.h=h
self.changed=False
print(
"initializing mdoel failed. Did you specify correct location for coefficient files"
)
self.date = date
self.lon = lon
self.lat = lat
self.h = h
self.changed = False

def getXYZ(self):
'''get BField, convert to (ITRF) X,Y,Z coordinates'''
N,E,D=self.getNED()
lat=radians(self.lat)
lon=radians(self.lon)
X=-1*cos(lat)*cos(lon)*D-sin(lat)*cos(lon)*N-sin(lon)*E
Y=-1*cos(lat)*sin(lon)*D-sin(lat)*sin(lon)*N+cos(lon)*E
Z=-1*sin(lat)*D+N*cos(lat)
return X,Y,Z
"""get BField, convert to (ITRF) X,Y,Z coordinates"""
N, E, D = self.getNED()
lat = radians(self.lat)
lon = radians(self.lon)
X = -1 * cos(lat) * cos(lon) * D - sin(lat) * cos(lon) * N - sin(lon) * E
Y = -1 * cos(lat) * sin(lon) * D - sin(lat) * sin(lon) * N + cos(lon) * E
Z = -1 * sin(lat) * D + N * cos(lat)
return X, Y, Z

def getNED(self):
#check if something has changed
# check if something has changed
if self.WMM_Model.getDate() != self.date:
self.changed=True
self.changed = True
self.WMM_Model.setDate(self.date)
if self.WMM_Model.getLon() != self.lon or self.WMM_Model.getLat() != self.lat :
self.changed=True
self.WMM_Model.setLonLat(self.lon,self.lat)
if self.WMM_Model.getLon() != self.lon or self.WMM_Model.getLat() != self.lat:
self.changed = True
self.WMM_Model.setLonLat(self.lon, self.lat)
if self.WMM_Model.getHeight() != self.h:
self.changed=True
self.changed = True
self.WMM_Model.setHeight(self.h)
if self.changed:
self.WMM_Model.setEM()
self.changed=False

return self.WMM_Model.getX(),self.WMM_Model.getY(),self.WMM_Model.getZ()
#North, East,Down

def getProjectedField(self,lon,lat):
'''get fieldstrength in direction lon,lat'''
x,y,z=self.getXYZ()
return sin(lat)*z+cos(lat)*cos(lon)*x +cos(lat)*sin(lon)*y
self.changed = False

def getProjectedFieldVector(self,lon,lat):
'''get field with one axis projected in direction lon,lat'''
x,y,z=self.getXYZ()
return [sin(lat)*z+cos(lat)*cos(lon)*x +cos(lat)*sin(lon)*y,
-1*sin(lon)*x +cos(lon)*y,
cos(lat)*z-sin(lat)*cos(lon)*x -sin(lat)*sin(lon)*y]
return self.WMM_Model.getX(), self.WMM_Model.getY(), self.WMM_Model.getZ()
# North, East,Down

def getProjectedFieldArray(self,lon_array,lat_array,h_array,los_dir):
'''returns numpy array with projected BField along LOS (given in lon,lat) for ray tracing'''
result=np.zeros((len(lon_array),3))

for idx,self.lon,self.lat,self.h in zip(range(len(lon_array)),lon_array,lat_array,h_array):
result[idx]=self.getProjectedFieldVector(los_dir[0],los_dir[1])
def getProjectedField(self, lon, lat):
"""get fieldstrength in direction lon,lat"""
x, y, z = self.getXYZ()
return sin(lat) * z + cos(lat) * cos(lon) * x + cos(lat) * sin(lon) * y

def getProjectedFieldVector(self, lon, lat):
"""get field with one axis projected in direction lon,lat"""
x, y, z = self.getXYZ()
return [
sin(lat) * z + cos(lat) * cos(lon) * x + cos(lat) * sin(lon) * y,
-1 * sin(lon) * x + cos(lon) * y,
cos(lat) * z - sin(lat) * cos(lon) * x - sin(lat) * sin(lon) * y,
]

def getProjectedFieldArray(self, lon_array, lat_array, h_array, los_dir):
"""returns numpy array with projected BField along LOS (given in lon,lat) for ray tracing"""
result = np.zeros((len(lon_array), 3))

for idx, self.lon, self.lat, self.h in zip(
range(len(lon_array)), lon_array, lat_array, h_array
):
result[idx] = self.getProjectedFieldVector(los_dir[0], los_dir[1])
return result


class EMM(WMM):
def __init__(self,cof=resource_filename(__name__,'EMM2000.COF'),date=2010.,lon=0.,lat=0.,h=0.):
def __init__(
self,
cof=resource_filename(__name__, "EMM2000.COF"),
date=2010.0,
lon=0.0,
lat=0.0,
h=0.0,
):
try:
cof=cof.replace("EMM2000.COF","")
if not os.path.isfile(cof+"EMM2000.COF"):
print ("initializing model",cof+"EMM2000.COF","failed. Did you specify correct location for coefficient files")
cof = cof.replace("EMM2000.COF", "")
if not os.path.isfile(cof + "EMM2000.COF"):
print(
"initializing model",
cof + "EMM2000.COF",
"failed. Did you specify correct location for coefficient files",
)
return
self.WMM_Model=emm.EMM_Model(cof+"EMM",date,lon,lat,h)

self.WMM_Model = emm.EMM_Model(cof + "EMM", date, lon, lat, h)
except (RuntimeError, TypeError, NameError):
print ("initializing mdoel failed. Did you specify correct location for coefficient files")
self.date=date
self.lon=lon
self.lat=lat
self.h=h
self.changed=False
print(
"initializing mdoel failed. Did you specify correct location for coefficient files"
)
self.date = date
self.lon = lon
self.lat = lat
self.h = h
self.changed = False
2 changes: 1 addition & 1 deletion RMextract/EMM/EMM2006.COF
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@
15 12 -0.0122 -0.3175
15 13 -0.1348 0.2017
15 14 0.1178 0.0045
15 15 -0.1924 -0.0323
15 15 -0.1924 -0.0323
2 changes: 1 addition & 1 deletion RMextract/EMM/EMM2007.COF
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@
15 12 -0.0258 -0.3018
15 13 -0.1043 0.1802
15 14 0.1248 0.0019
15 15 -0.2030 -0.0546
15 15 -0.2030 -0.0546
2 changes: 1 addition & 1 deletion RMextract/EMM/EMM2008.COF
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@
15 12 -0.0319 -0.2968
15 13 -0.0867 0.1659
15 14 0.1288 -0.0080
15 15 -0.2127 -0.0613
15 15 -0.2127 -0.0613
2 changes: 1 addition & 1 deletion RMextract/EMM/EMM2009.COF
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@
15 12 -0.0357 -0.2965
15 13 -0.0793 0.1511
15 14 0.1344 -0.0122
15 15 -0.2360 -0.0622
15 15 -0.2360 -0.0622
32 changes: 16 additions & 16 deletions RMextract/EMM/EMM_Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ WMM_Model::~WMM_Model(){
MAG_FreeMagneticModelMemory(TimedMagneticModel);
TimedMagneticModel=NULL;
}
for(int i = 0; i < epochs + 1; i++)
for(int i = 0; i < epochs + 1; i++)
if (MagneticModels[i]){
MAG_FreeMagneticModelMemory(MagneticModels[i]);
MagneticModels[i]=NULL;
}
};

WMM_Model::WMM_Model(){
WMM_Model::WMM_Model(){
TimedMagneticModel=NULL;
for(int i = 0; i < epochs + 1; i++)

for(int i = 0; i < epochs + 1; i++)
MagneticModels[i]=NULL;
};

WMM_Model::WMM_Model(const char CoeffFile[256], const float date,const float lon,const float lat,const float h){
TimedMagneticModel=NULL;
for(int i = 0; i < epochs + 1; i++)

for(int i = 0; i < epochs + 1; i++)
MagneticModels[i]=NULL;

char filename[256];
char filenameSV[256];

sprintf(filename, "%s.COF", CoeffFile);

FILE * filename_valid=fopen (filename, "r");
assert(filename_valid);
fclose(filename_valid);
Expand Down Expand Up @@ -65,13 +65,13 @@ void WMM_Model::setEM()

void WMM_Model::setDate(const float date){
UserDate.DecimalYear=date; //decimal year

}

void WMM_Model::setLonLat(const float lon,const float lat){
CoordGeodetic.phi=lat;//lattitude in degrees
CoordGeodetic.lambda=lon; //longitude in degrees

}
void WMM_Model::setHeight(const float h){
CoordGeodetic.HeightAboveEllipsoid=h; //Height above WGS-84 elipsoid
Expand All @@ -93,16 +93,16 @@ float WMM_Model::getZ(){

EMM_Model::EMM_Model(const char CoeffFile[256], const float date,const float lon,const float lat,const float h){
TimedMagneticModel=NULL;
for(int i = 0; i < epochs + 1; i++)

for(int i = 0; i < epochs + 1; i++)
MagneticModels[i]=NULL;
char filename[256];
char filenameSV[256];

sprintf(filename, "%s%d.COF", CoeffFile,2010);
sprintf(filenameSV, "%s%dSV.COF",CoeffFile,2010);
//check if filename exists

FILE * filename_valid=fopen (filename, "r");
assert(filename_valid);
fclose(filename_valid);
Expand Down Expand Up @@ -133,7 +133,7 @@ EMM_Model::EMM_Model(const char CoeffFile[256], const float date,const float lon
nMax = MagneticModels[epochs]->nMax;
NumTerms = ((nMax + 1) * (nMax + 2) / 2);
TimedMagneticModel = MAG_AllocateModelMemory(NumTerms); /* For storing the time modified WMM Model parameters */
for(int i = 0; i < epochs; i++)
for(int i = 0; i < epochs; i++)
if(MagneticModels[i] == NULL || TimedMagneticModel == NULL)
{
MAG_Error(2);
Expand Down
2 changes: 1 addition & 1 deletion RMextract/EMM/EMM_Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C"{
/* The Geomagnetism Library is used to make a command prompt program. The program prompts
the user to enter a location, performs the computations and prints the results to the
standard output. The program expects the files GeomagnetismLibrary.c, GeomagnetismHeader.h,
EMM2010.COF, EMM2010SV.COF and EGM9615.h to be in the same directory.
EMM2010.COF, EMM2010SV.COF and EGM9615.h to be in the same directory.

Manoj.C.Nair
Nov 23, 2009
Expand Down
Loading