jgdtrans.par module#
Provides par file parsers.
- jgdtrans.par.is_format(format: _types.FormatType) bool#
Returns
Truewhen format is valid.- Parameters:
format – a test value
- Returns:
Truewhen format is valid
Examples
>>> is_format("TKY2JGD") True >>> is_format("SemiDynaEXE") True >>> is_format("Hi!") False
- jgdtrans.par.load(fp: TextIO, format: _types.FormatType, *, description: str | None = None) ParData#
Deserialize a par-formatted file-like obj into a
ParData.This fills by 0.0 for altituse parameter when
'TKY2JGD'or'PatchJGD'given to format, and for latitude and longitude when'PatchJGD_H'or'HyokoRev'given.See
FormatTypefor detail of'PatchJGD_HV'.- Parameters:
fp – a par-formatted file-like obj
format – the format of fp
description – the description of the parameter, defaulting the fp header
- Returns:
the
ParDataobj- Raises:
ParseParFileError – when invalid data found
Examples
>>> with open("SemiDyna2023.par") as fp: ... data = load(fp, format="SemiDynaEXE") >>> tf = Tramsformer(data=data) >>> result = tf.transform(35.0, 145.0)
>>> s = '''<15 lines> ... MeshCode dB(sec) dL(sec) dH(m) ... 12345678 0.00001 0.00002 0.00003''' >>> with io.StringIO(s) as fp: ... load(fp, format="SemiDynaEXE").parameter[12345678] Parameter(latitude=0.00001, longitude=0.0002, altitude=0.0003)
- jgdtrans.par.loads(s: str, format: _types.FormatType, *, description: str | None = None) ParData#
Deserialize a par-formatted
strinto aParData.This fills by 0.0 for altituse parameter when
'TKY2JGD'or'PatchJGD'given to format, and for latitude and longitude when'PatchJGD_H'or'HyokoRev'given.See
FormatTypefor detail of'PatchJGD_HV'.- Parameters:
s – a par-formatted text
format – the format of s
description – the description of the parameter, defaulting the s header
- Returns:
the
ParDataobj- Raises:
ParseParFileError – when invalid data found
Examples
>>> s = '''<15 lines> ... MeshCode dB(sec) dL(sec) dH(m) ... 12345678 0.00001 0.00002 0.00003''' >>> data = loads(s, format="SemiDynaEXE") >>> tf = Tramsformer(data=data) >>> result = tf.transform(35.0, 145.0)
>>> s = '''<15 lines> ... MeshCode dB(sec) dL(sec) dH(m) ... 12345678 0.00001 0.00002 0.00003''' >>> loads(s, format="SemiDynaEXE").parameter[12345678] Parameter(latitude=0.00001, longitude=0.0002, altitude=0.0003)
- class jgdtrans.par.Parameter(latitude: float, longitude: float, altitude: float)#
Bases:
NamedTupleThe parameter triplet.
We emphasize that the unit of latitude and longitude is [sec], not [deg].
It should fill by
0.0instead ofnanwhen the parameter does not exist, as parsers does.- latitude: float#
The latitude parameter [sec].
- longitude: float#
The latitude parameter [sec].
- altitude: float#
The altitude parameter [m].
- property horizontal: float#
\(\sqrt{\text{latitude}^2 + \text{longitude}^2}\) [sec].
- class jgdtrans.par.ParData(format: _types.FormatType, parameter: dict[int, Parameter], description: str | None = None)#
Bases:
objectPar data obj.
- format: _types.FormatType#
The format of par file.
See
FormatTypefor detail of'PatchJGD_HV'.
- parameter: dict[int, Parameter]#
The transformation parameter.
The entry represents single line of the par file’s parameter section, the key is meshcode, and the value is a
Parameter(a triplet of latitude [sec], longitude [sec] and altitude [m]).
- description: str | None = None#
The description.
- mesh_unit() Literal[1, 5]#
Returns a mesh unit.
- classmethod from_dict(obj: _types.ParDataLikeMappingType) Self#
Makes a
ParDataobj fromMappingobj.This parses meshcode, the key of parameter, into
int.See
FormatTypefor detail of'PatchJGD_HV'.- Parameters:
obj – the
Mappingof the format, the parameters, and the description (optional)- Returns:
the
ParDataobj- Raises:
DeserializeError – when fail to parse the meshcode
Examples
>>> mapping = { ... 'format': 'SemiDynaEXE', ... 'parameter': { ... 12345678: { ... 'latitude': 0.1 ... 'longitude': 0.2 ... 'altitude': 0.3 ... }, ... ... ... }, ... 'description': 'important my param', # optional ... } >>> data = ParData.from_dict(mapping) >>> data.format 'SemiDynaEXE' >>> data.parameter {12345678: Parameter(0.1, 0.2, 0.3), ...} >>> data.description 'important my param'
>>> mapping = { ... 'format': 'SemiDynaEXE', ... 'parameter': { ... '12345678': { ... 'latitude': 0.1 ... 'longitude': 0.2 ... 'altitude': 0.3 ... }, ... ... ... }, ... } >>> data = ParData.from_dict(mapping) >>> data.format 'SemiDynaEXE' >>> data.parameter {12345678: Parameter(0.1, 0.2, 0.3), ...} >>> data.description None
See also
- to_dict() _types.ParDataDictType#
Returns a
dictwhich represents self.This method is an inverse of
ParData.from_dict().- Returns:
the
dictobj which typed asTransformerDict
Examples
>>> data = ParData( ... description="my param", ... format="SemiDynaEXE", ... parameter={12345678: Parameter(0.1, 0.2, 0.3)}, ... ) >>> data.to_dict() { 'format': 'SemiDynaEXE', 'parameter': { 12345678: { 'latitude': 0.1, 'longitude': 0.2, 'altitude': 0.3, } }, 'description': 'my param', }
See also
Transformer.from_dict()
- statistics() Statistics#
Returns the statistics of the parameter.
See
StatisticDatafor details of result’s components.- Returns:
the statistics of the parameter
Examples
From SemiDynaEXE2023.par
>>> data = ParData( ... format='SemiDynaEXE' ... parameter={ ... 54401005: Parameter(-0.00622, 0.01516, 0.0946), ... 54401055: Parameter(-0.0062, 0.01529, 0.08972), ... 54401100: Parameter(-0.00663, 0.01492, 0.10374), ... 54401150: Parameter(-0.00664, 0.01506, 0.10087), ... } ... ) >>> data.statistics() StatisticalSummary( latitude=Statistics( count=4, mean=-0.006422499999999999, std=0.00021264700797330775, abs=0.006422499999999999, min=-0.00664, max=-0.0062 ), longitude=Statistics( count=4, mean=0.0151075, std=0.00013553136168429814, abs=0.0151075, min=0.01492, max=0.01529 ), altitude=Statistics( count=4, mean=0.0972325, std=0.005453133846697696, abs=0.0972325, min=0.08972, max=0.10374 ) )
- class jgdtrans.par.StatisticData(count: int | None, mean: float | None, std: float | None, abs: float | None, min: float | None, max: float | None)#
Bases:
objectThe statistics of parameter.
This is a component of the result that
Transformer.statistics()returns.- count: int | None#
The count.
- mean: float | None#
The mean ([sec] or [m]).
- std: float | None#
The standard variance ([sec] or [m]).
- abs: float | None#
\((1/n) \sum_{i=1}^n \left| \text{parameter}_i \right|\) ([sec] or [m]).
- min: float | None#
The minimum ([sec] or [m]).
- max: float | None#
The maximum ([sec] or [m]).
- class jgdtrans.par.Statistics(latitude: StatisticData, longitude: StatisticData, altitude: StatisticData, horizontal: StatisticData)#
Bases:
objectThe statistical summary of parameter.
This is a result that
Transformer.statistics()returns.- latitude: StatisticData#
The statistics of latitude.
- longitude: StatisticData#
The statistics of longitude.
- altitude: StatisticData#
The statistics of altitude.
- horizontal: StatisticData#
The statistics of horizontal.